Skip to content

Commit

Permalink
show diff in property test (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
butterunderflow authored Aug 1, 2024
2 parents 206fa84 + ccf29cd commit 50be34b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
6 changes: 5 additions & 1 deletion tests/stress/dune
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@
(deps
%{bin:ff}
%{bin:ff_wrapper}
(glob_files *.fun)))
(glob_files *.fun)
%{lib-private:runtime:libfun_rt.a}
%{lib-private:runtime:fun_rt.hpp}
%{lib-private:runtime:fun_rt_core.hpp}
%{lib-private:runtime:fun_rt_lib.hpp}))
18 changes: 15 additions & 3 deletions tests/stress/test_entry.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ module U = Util
let sum_test =
let rec sum x = if x = 0 then 0 else x + sum (x - 1) in
QCheck.Test.make ~count:10 ~name:"sum.exe property" QCheck.small_nat
(fun i -> U.call_ff_int_to_int ~case:"sum.fun" i = sum i)
(fun i ->
Alcotest.(check int)
"int compare" (sum i)
(U.call_ff_int_to_int ~case:"sum.fun" i);
true)

let fib_test =
let rec fib x =
Expand All @@ -13,7 +17,11 @@ let fib_test =
| _ -> fib (x - 1) + fib (x - 2)
in
QCheck.Test.make ~count:5 ~name:"fib.exe propety" (QCheck.int_bound 30)
(fun i -> U.call_ff_int_to_int ~case:"fib.fun" i = fib i)
(fun i ->
Alcotest.(check int)
"int compare" (fib i)
(U.call_ff_int_to_int ~case:"fib.fun" i);
true)

module RTA = Rand_struct_access

Expand All @@ -23,8 +31,12 @@ let struct_acces_test =
(QCheck.make RTA.tree_gen ~print:(fun tree ->
fst (RTA.test_case_of_tree tree)))
(fun tree ->
let _int_list_tsetable = Alcotest.(list int) in
let prog, expect = RTA.test_case_of_tree tree in
U.call_ff_on_prog_to_int_list ~prog = expect))
Alcotest.(check (list int))
"int list should equal" expect
(U.call_ff_on_prog_to_int_list ~prog);
true))

let () =
let suite =
Expand Down
19 changes: 8 additions & 11 deletions tests/stress/util.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,15 @@ let call_ff_on_prog_to_int_list ~(prog : string) : int list =
let oc = open_out temp_file in
Printf.fprintf oc "%s" prog;
close_out oc;
(* compiling *)
Printf.printf "Call ff_wraper on tempfile %s\n" temp_file;
let _pid =
Unix.create_process "ff_wrapper"
[| "ff_wrapper"; temp_file |]
Unix.stdin Unix.stdout Unix.stderr
in
ignore (Unix.wait ());
let exe = Printf.sprintf "%s.out" temp_file in
Printf.printf "Dumped exe file path: %s\n" exe;
Lwt_main.run
(let* out = Lwt_process.pread (exe, [| exe |]) in
((* compiling *)
Printf.printf "Call ff_wraper on tempfile %s\n" temp_file;
let* ret =
Lwt_process.exec ("ff_wrapper", [| "ff_wrapper"; temp_file |])
in
let exe = Printf.sprintf "%s.out" temp_file in
Printf.printf "Dumped exe file path: %s\n" exe;
let* out = Lwt_process.pread (exe, [| exe |]) in
let lines = String.split_on_char '\n' out in
let ints =
List.(lines |> filter (fun s -> s <> "") |> map int_of_string)
Expand Down

0 comments on commit 50be34b

Please sign in to comment.