Skip to content

Commit

Permalink
Add internal tests for Util.Pp
Browse files Browse the repository at this point in the history
  • Loading branch information
shym committed Aug 22, 2023
1 parent 0e72927 commit 32ab8db
Show file tree
Hide file tree
Showing 5 changed files with 320 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/dune
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,31 @@
(package qcheck-multicoretests-util)
(libraries qcheck-multicoretests-util))

(test
(name util_pp)
(modules util_pp)
(package qcheck-multicoretests-util)
(libraries qcheck-multicoretests-util))

(rule
(alias runtest)
(package qcheck-multicoretests-util)
(action
(progn
(with-outputs-to util_pp_trunc79.output
(setenv MCTUTILS_TRUNCATE 79
(run %{dep:util_pp.exe})))
(diff? util_pp_trunc79.expected util_pp_trunc79.output))))

(rule
(alias runtest)
(package qcheck-multicoretests-util)
(action
(progn
(with-outputs-to util_pp_trunc5.output
(setenv MCTUTILS_TRUNCATE 5
(run %{dep:util_pp.exe})))
(diff? util_pp_trunc5.expected util_pp_trunc5.output))))

(executable
(name cleanup_lin)
Expand Down
101 changes: 101 additions & 0 deletions test/util_pp.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
Test of pp_bool:
true

Test of pp_int (positive):
12345

Test of pp_int (negative):
-12345

Test of pp_int32 (positive):
12345l

Test of pp_int64 (negative):
-12345L

Test of pp_float (infinity):
infinity

Test of pp_float (pi):
3.14159265359

Test of pp_char (printable):
'a'

Test of pp_char (unprintable):
'\000'

Test of pp_string:
"Hello world"

Test of pp_string (long):
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"

Test of pp_option pp_int (positive):
Some 12345

Test of pp_option pp_int (negative):
Some (-12345)

Test of pp_result pp_int pp_string:
Ok (-12345)

Test of pp_result pp_int pp_string:
Error "Failure"

Test of pp_pair pp_char pp_int:
('a', -12345)

Test of pp_list pp_int:
[1; 2; 3; -1; -2; -3]

Test of pp_list pp_int (long):
[1; 2; 3; -1; -2; -3; 1; 2; 3; -1; -2; -3; 1; 2; 3; -1; -2; -3; 1; 2; 3; -1;
-2; -3; 1; 2; 3; -1; -2; -3; 1; 2; 3; -1; -2; -3; 1; 2; 3; -1; -2; -3; 1;
2; 3; -1; -2; -3; 1; 2; 3; -1; -2; -3; 1; 2; 3; -1; -2; -3; 1; 2; 3; -1;
-2; -3; 1; 2; 3; -1; -2; -3; 1; 2; 3; -1; -2; -3; 1; 2; 3; -1; -2; -3; 1;
2; 3; -1; -2; -3; 1; 2; 3; -1; -2; -3; 1; 2; 3; -1; -2; -3; 1; 2; 3; -1;
-2; -3; 1; 2; 3; -1; -2; -3; 1; 2; 3; -1; -2; -3; 1; 2; 3; -1; -2; -3; 1;
2; 3; -1; -2; -3; 1; 2; 3; -1; -2; -3; 1; 2; 3; -1; -2; -3; 1; 2; 3; -1;
-2; -3; 1; 2; 3; -1; -2; -3; 1; 2; 3; -1; -2; -3; 1; 2; 3; -1; -2; -3; 1;
2; 3; -1; -2; -3; 1; 2; 3; -1; -2; -3; 1; 2; 3; -1; -2; -3; 1; 2; 3; -1;
-2; -3; 1; 2; 3; -1; -2; -3; 1; 2; 3; -1; -2; -3; 1; 2; 3; -1; -2; -3; 1;
2; 3; -1; -2; -3; 1; 2; 3; -1; -2; -3; 1; 2; 3; -1; -2; -3; 1; 2; 3; -1;
-2; -3; 1; 2; 3; -1; -2; -3; 1; 2; 3; -1; -2; -3; 1; 2; 3; -1; -2; -3; 1;
2; 3; -1; -2; -3; 1; 2; 3; -1; -2; -3; 1; 2; 3; -1; -2; -3; 1; 2; 3; -1;
-2; -3; 1; 2; 3; -1; -2; -3; 1; 2; 3; -1; -2; -3; 1; 2; 3; -1; -2; -3; 1;
2; 3; -1; -2; -3; 1; 2; 3; -1; -2; -3; 1; 2; 3; -1; -2; -3; 1; 2; 3; -1;
-2; -3; 1; 2; 3; -1; -2; -3; 1; 2; 3; -1; -2; -3; 1; 2; 3; -1; -2; -3; 1;
2; 3; -1; -2; -3; 1; 2; 3; -1; -2; -3; 1; 2; 3; -1; -2; -3; 1; 2; 3; -1;
-2; -3; 1; 2; 3; -1; -2; -3; 1; 2; 3; -1; -2; -3; 1; 2; 3; -1; -2; -3; 1;
2; 3; -1; -2; -3]

Test of pp_seq pp_int:
<-5; -4; -3; -2; -1; 0; 1; 2; 3; 4; 5>

Test of pp_seq pp_int (long):
<-50; -49; -48; -47; -46; -45; -44; -43; -42; -41; -40; -39; -38; -37; -36;
-35; -34; -33; -32; -31; -30; -29; -28; -27; -26; -25; -24; -23; -22; -21;
-20; -19; -18; -17; -16; -15; -14; -13; -12; -11; -10; -9; -8; -7; -6; -5;
-4; -3; -2; -1; 0; 1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 11; 12; 13; 14; 15; 16;
17; 18; 19; 20; 21; 22; 23; 24; 25; 26; 27; 28; 29; 30; 31; 32; 33; 34; 35;
36; 37; 38; 39; 40; 41; 42; 43; 44; 45; 46; 47; 48; 49; 50>

Test of pp_array pp_int:
[|1; 2; 3; -1; -2; -3|]

Test of pp_array pp_int (long):
[|0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0;
0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0;
0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0;
0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0|]

Test of pp_record:
{ key = 123; value = "content" }

44 changes: 44 additions & 0 deletions test/util_pp.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
(* Tests of Util.Pp *)

open Util.Pp

let pr name pp x = Printf.printf "Test of %s:\n%s\n\n" name (to_show pp x)

let seq_interval x y () =
let rec aux i =
let open Seq in
if i <= y then Cons (i, fun () -> aux (i + 1)) else Nil
in
aux x

let _ =
pr "pp_bool" pp_bool true;
pr "pp_int (positive)" pp_int 12345;
pr "pp_int (negative)" pp_int (-12345);
pr "pp_int32 (positive)" pp_int32 12345l;
pr "pp_int64 (negative)" pp_int64 (-12345L);
pr "pp_float (infinity)" pp_float Float.infinity;
pr "pp_float (pi)" pp_float Float.pi;
pr "pp_char (printable)" pp_char 'a';
pr "pp_char (unprintable)" pp_char '\000';
pr "pp_string" pp_string "Hello world";
pr "pp_string (long)" pp_string (String.make 1234 'a');
pr "pp_bytes (empty)" pp_bytes Bytes.empty;
pr "pp_bytes (long)" pp_bytes (Bytes.make 1234 'b');
pr "pp_option pp_int (positive)" (pp_option pp_int) (Some 12345);
pr "pp_option pp_int (negative)" (pp_option pp_int) (Some (-12345));
pr "pp_result pp_int pp_string" (pp_result pp_int pp_string) (Ok (-12345));
pr "pp_result pp_int pp_string" (pp_result pp_int pp_string) (Error "Failure");
pr "pp_pair pp_char pp_int" (pp_pair pp_char pp_int) ('a', -12345);
let l = [ 1; 2; 3; -1; -2; -3 ] in
pr "pp_list pp_int" (pp_list pp_int) l;
let l = l @ l @ l @ l in
let l = l @ l @ l @ l in
let l = l @ l @ l @ l in
pr "pp_list pp_int (long)" (pp_list pp_int) l;
pr "pp_seq pp_int" (pp_seq pp_int) (seq_interval (-5) 5);
pr "pp_seq pp_int (long)" (pp_seq pp_int) (seq_interval (-50) 50);
pr "pp_array pp_int" (pp_array pp_int) [| 1; 2; 3; -1; -2; -3 |];
pr "pp_array pp_int (long)" (pp_array pp_int) (Array.make 100 0);
pr "pp_record" pp_record
[ pp_field "key" pp_int 123; pp_field "value" pp_string "content" ]
75 changes: 75 additions & 0 deletions test/util_pp_trunc5.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
Test of pp_bool:
true

Test of pp_int (positive):
12345

Test of pp_int (negative):
-12345

Test of pp_int32 (positive):
12345l

Test of pp_int64 (negative):
-12345L

Test of pp_float (infinity):
infinity

Test of pp_float (pi):
3.14159265359

Test of pp_char (printable):
'a'

Test of pp_char (unprintable):
'\000'

Test of pp_string:
"Hello world"

Test of pp_string (long):
... (truncated)

Test of pp_bytes (empty):
""

Test of pp_bytes (long):
... (truncated)

Test of pp_option pp_int (positive):
Some 12345

Test of pp_option pp_int (negative):
Some (-12345)

Test of pp_result pp_int pp_string:
Ok (-12345)

Test of pp_result pp_int pp_string:
... (truncated)

Test of pp_pair pp_char pp_int:
('a', -12345)

Test of pp_list pp_int:
... (truncated)

Test of pp_list pp_int (long):
... (truncated)

Test of pp_seq pp_int:
... (truncated)

Test of pp_seq pp_int (long):
... (truncated)

Test of pp_array pp_int:
... (truncated)

Test of pp_array pp_int (long):
... (truncated)

Test of pp_record:
... (truncated)

75 changes: 75 additions & 0 deletions test/util_pp_trunc79.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
Test of pp_bool:
true

Test of pp_int (positive):
12345

Test of pp_int (negative):
-12345

Test of pp_int32 (positive):
12345l

Test of pp_int64 (negative):
-12345L

Test of pp_float (infinity):
infinity

Test of pp_float (pi):
3.14159265359

Test of pp_char (printable):
'a'

Test of pp_char (unprintable):
'\000'

Test of pp_string:
"Hello world"

Test of pp_string (long):
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... (truncated)

Test of pp_bytes (empty):
""

Test of pp_bytes (long):
"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb... (truncated)

Test of pp_option pp_int (positive):
Some 12345

Test of pp_option pp_int (negative):
Some (-12345)

Test of pp_result pp_int pp_string:
Ok (-12345)

Test of pp_result pp_int pp_string:
Error "Failure"

Test of pp_pair pp_char pp_int:
('a', -12345)

Test of pp_list pp_int:
[1; 2; 3; -1; -2; -3]

Test of pp_list pp_int (long):
[1; 2; 3; -1; -2; -3; 1; 2; 3; -1; -2; -3; 1; 2; 3; -1; -2; -3; 1... (truncated)

Test of pp_seq pp_int:
<-5; -4; -3; -2; -1; 0; 1; 2; 3; 4; 5>

Test of pp_seq pp_int (long):
<-50; -49; -48; -47; -46; -45; -44; -43; -42; -41; -40; -39; -38;... (truncated)

Test of pp_array pp_int:
[|1; 2; 3; -1; -2; -3|]

Test of pp_array pp_int (long):
[|0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; ... (truncated)

Test of pp_record:
{ key = 123; value = "content" }

0 comments on commit 32ab8db

Please sign in to comment.