Skip to content

Commit 06a83b9

Browse files
authored
Merge pull request #566 from ocaml-multicore/util-pp-printers
Use `QCheck.Print` combinators in `Util.Pp` printers for consistency
2 parents a7bfabb + ddcebf1 commit 06a83b9

File tree

7 files changed

+41
-12
lines changed

7 files changed

+41
-12
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## NEXT RELEASE
44

5+
- #566: Use `QCheck.Print` combinators in `Util.Pp` too for consistency,
6+
e.g., to avoid that `STM` argument and result printer outputs differ.
57
- #562: Fix the `int32` and `int64` printers in both `Lin` and `STM` to add
68
missing `l` and `L` suffixes on literals.
79
- #560: Change `Lin.{constructible,deconstructible}` from an empty variant type

lib/util.ml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,14 @@ module Pp = struct
158158

159159
let pp_exn = of_show Printexc.to_string
160160
let pp_unit _ fmt () = pp_print_string fmt "()"
161-
let pp_bool _ fmt b = fprintf fmt "%B" b
162-
let pp_int par fmt i = fprintf fmt (if par && i < 0 then "(%d)" else "%d") i
163-
let pp_int32 par fmt i = fprintf fmt (if par && i < 0l then "(%ldl)" else "%ldl") i
164-
let pp_int64 par fmt i = fprintf fmt (if par && i < 0L then "(%LdL)" else "%LdL") i
165-
let pp_float par fmt f = fprintf fmt (if par && f < 0.0 then "(%F)" else "%F") f
166-
let pp_char _ fmt c = fprintf fmt "%C" c
167-
let pp_string _ fmt s = fprintf fmt "%S" s
168-
let pp_bytes _ fmt s = fprintf fmt "%S" (Bytes.to_string s)
161+
let pp_bool _ fmt b = fprintf fmt "%s" (QCheck.Print.bool b)
162+
let pp_int par fmt i = fprintf fmt (if par && i < 0 then "(%s)" else "%s") (QCheck.Print.int i)
163+
let pp_int32 par fmt i = fprintf fmt (if par && i < 0l then "(%s)" else "%s") (QCheck.Print.int32 i)
164+
let pp_int64 par fmt i = fprintf fmt (if par && i < 0L then "(%s)" else "%s") (QCheck.Print.int64 i)
165+
let pp_float par fmt f = fprintf fmt (if par && f < 0.0 then "(%s)" else "%s") (QCheck.Print.float f)
166+
let pp_char _ fmt c = fprintf fmt "%s" (QCheck.Print.char c)
167+
let pp_string _ fmt s = fprintf fmt "%s" (QCheck.Print.string s)
168+
let pp_bytes _ fmt s = fprintf fmt "%s" (QCheck.Print.bytes s)
169169

170170
let pp_option (pp_s : 'a t) par fmt o =
171171
match o with

test/util_pp.expected

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ Test of pp_int64 (negative):
1414
-12345L
1515

1616
Test of pp_float (infinity):
17-
infinity
17+
inf
18+
19+
Test of pp_float (neg_infinity):
20+
-inf
21+
22+
Test of pp_float (nan):
23+
nan
1824

1925
Test of pp_float (pi):
2026
3.14159265359

test/util_pp.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ let _ =
2727
pr "pp_int32 (positive)" pp_int32 12345l;
2828
pr "pp_int64 (negative)" pp_int64 (-12345L);
2929
pr "pp_float (infinity)" pp_float Float.infinity;
30+
pr "pp_float (neg_infinity)" pp_float Float.neg_infinity;
31+
pr "pp_float (nan)" pp_float nan;
32+
(*pr "pp_float (-. nan)" pp_float (-. nan);*)
3033
pr "pp_float (pi)" pp_float Float.pi;
3134
pr "pp_char (printable)" pp_char 'a';
3235
pr "pp_char (unprintable)" pp_char '\000';

test/util_pp_trunc150.expected

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ Test of pp_int64 (negative):
1414
-12345L
1515

1616
Test of pp_float (infinity):
17-
infinity
17+
inf
18+
19+
Test of pp_float (neg_infinity):
20+
-inf
21+
22+
Test of pp_float (nan):
23+
nan
1824

1925
Test of pp_float (pi):
2026
3.14159265359

test/util_pp_trunc5.expected

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ Test of pp_int64 (negative):
1414
-12345L
1515

1616
Test of pp_float (infinity):
17-
infinity
17+
inf
18+
19+
Test of pp_float (neg_infinity):
20+
-inf
21+
22+
Test of pp_float (nan):
23+
nan
1824

1925
Test of pp_float (pi):
2026
3.14159265359

test/util_pp_trunc79.expected

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ Test of pp_int64 (negative):
1414
-12345L
1515

1616
Test of pp_float (infinity):
17-
infinity
17+
inf
18+
19+
Test of pp_float (neg_infinity):
20+
-inf
21+
22+
Test of pp_float (nan):
23+
nan
1824

1925
Test of pp_float (pi):
2026
3.14159265359

0 commit comments

Comments
 (0)