From 32ab8db8c1527903a38d3361a38968298dbd4b70 Mon Sep 17 00:00:00 2001 From: Samuel Hym Date: Tue, 22 Aug 2023 15:17:22 +0200 Subject: [PATCH] Add internal tests for `Util.Pp` --- test/dune | 25 +++++++++ test/util_pp.expected | 101 ++++++++++++++++++++++++++++++++++ test/util_pp.ml | 44 +++++++++++++++ test/util_pp_trunc5.expected | 75 +++++++++++++++++++++++++ test/util_pp_trunc79.expected | 75 +++++++++++++++++++++++++ 5 files changed, 320 insertions(+) create mode 100644 test/util_pp.expected create mode 100644 test/util_pp.ml create mode 100644 test/util_pp_trunc5.expected create mode 100644 test/util_pp_trunc79.expected diff --git a/test/dune b/test/dune index 3e0e6d205..e340ec37f 100644 --- a/test/dune +++ b/test/dune @@ -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) diff --git a/test/util_pp.expected b/test/util_pp.expected new file mode 100644 index 000000000..45447a658 --- /dev/null +++ b/test/util_pp.expected @@ -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 p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bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" + +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" } + diff --git a/test/util_pp.ml b/test/util_pp.ml new file mode 100644 index 000000000..c52e4154b --- /dev/null +++ b/test/util_pp.ml @@ -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" ] diff --git a/test/util_pp_trunc5.expected b/test/util_pp_trunc5.expected new file mode 100644 index 000000000..361406566 --- /dev/null +++ b/test/util_pp_trunc5.expected @@ -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) + diff --git a/test/util_pp_trunc79.expected b/test/util_pp_trunc79.expected new file mode 100644 index 000000000..2b10a364f --- /dev/null +++ b/test/util_pp_trunc79.expected @@ -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" } +