Skip to content

Commit e242b00

Browse files
committed
use preproc to deal with 4.03 and others < 4.08 versions
1 parent 919360f commit e242b00

File tree

6 files changed

+33
-9
lines changed

6 files changed

+33
-9
lines changed

src/core/cpp/cpp.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ let eval ~major ~minor op i j =
3030

3131
let preproc_lines ~file ~major ~minor (ic:in_channel) : unit =
3232
let pos = ref 0 in
33-
let fail msg = failwith (Printf.sprintf "at line %d: %s" !pos msg) in
33+
let fail msg = failwith (Printf.sprintf "at line %d in '%s': %s" !pos file msg) in
3434
let pp_pos () = Printf.printf "#%d %S\n" !pos file in
3535

3636
let parse_line () : line =

src/testlib/containers_testlib.ml

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@ module Test = struct
3131
let str_loc (self:t) : string =
3232
Printf.sprintf "(test :file '%s' :n %d)" self.__FILE__ self.n
3333

34+
35+
[@@@ifge 4.08]
36+
37+
let get_state (r:_ QCheck.TestResult.t) : _ QCheck.TestResult.state =
38+
QCheck.TestResult.get_state r
39+
40+
[@@@else_]
41+
42+
(* must have qcheck < 0.17 *)
43+
let get_state (r:_ QCheck.TestResult.t) : _ QCheck.TestResult.state =
44+
r.state
45+
46+
[@@@endif]
47+
3448
let run ~seed (self:t) : _ result =
3549
match
3650
match self.run with
@@ -50,7 +64,7 @@ module Test = struct
5064

5165
(* create a random state from the seed *)
5266
let rand =
53-
let bits = String.to_seq seed |> Seq.map Char.code |> CCArray.of_seq in
67+
let bits = CCString.to_list seed |> List.map Char.code |> Array.of_list in
5468
Random.State.make bits
5569
in
5670

@@ -70,17 +84,17 @@ module Test = struct
7084

7185
let res = Q.Test.check_cell ~rand cell in
7286

73-
begin match Q.TestResult.get_state res with
74-
| QCheck2.TestResult.Success -> Ok ()
75-
| QCheck2.TestResult.Failed { instances } ->
87+
begin match get_state res with
88+
| QCheck.TestResult.Success -> Ok ()
89+
| QCheck.TestResult.Failed { instances } ->
7690
let msg = Format.asprintf "@[<v2>failed on instances:@ %a@]"
7791
(Fmt.list ~sep:(Fmt.return ";@ ") pp_cex) instances
7892
in
7993
Error msg
80-
| QCheck2.TestResult.Failed_other {msg} ->
94+
| QCheck.TestResult.Failed_other {msg} ->
8195
let msg = spf "failed: %s" msg in
8296
Error msg
83-
| QCheck2.TestResult.Error {instance; exn; backtrace} ->
97+
| QCheck.TestResult.Error {instance; exn; backtrace} ->
8498
let msg = Format.asprintf "@[<v2>raised %s@ on instance %a@ :backtrace %s@]"
8599
(Printexc.to_string exn) pp_cex instance backtrace
86100
in
@@ -166,12 +180,14 @@ let make ~__FILE__ () : (module S) =
166180
end) in
167181
(module M)
168182

183+
let getenv_opt s = try Some (Sys.getenv s) with _ -> None
184+
169185
let run_all ?seed:seed_hex ~descr (l:Test.t list list) : unit =
170186
let start = Unix.gettimeofday() in
171187

172188
(* generate or parse seed *)
173189

174-
let seed_hex = match seed_hex, Sys.getenv_opt "SEED" with
190+
let seed_hex = match seed_hex, getenv_opt "SEED" with
175191
| Some s, _ -> s
176192
| None, Some s -> s
177193
| None, None ->

src/testlib/dune

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
(library
33
(name containers_testlib)
44
(synopsis "Test library for containers")
5+
(preprocess (action (run %{project_root}/src/core/cpp/cpp.exe %{input-file})))
56
(libraries containers qcheck-core unix))

tests/core/dune

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
(name t)
33
(flags :standard -strict-sequence -warn-error -a+8 -open CCShims_)
44
(modes native)
5+
(preprocess
6+
(action
7+
(run %{project_root}/src/core/cpp/cpp.exe %{input-file})))
58
(libraries containers containers.bencode containers.unix threads
69
containers_testlib iter gen uutf csexp))

tests/core/t_format.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ t @@ fun () ->
4545
assert_equal ~printer:CCFun.id "coucou\n" (Buffer.contents buf2);
4646
true;;
4747

48+
[@@@ifge 4.8]
49+
4850
t @@ fun () ->
4951
set_color_default true;
5052
let s = sprintf
@@ -59,6 +61,8 @@ t @@ fun () ->
5961
true
6062
;;
6163

64+
[@@@endif]
65+
6266
t @@ fun () ->
6367
set_color_default true;
6468
let s = sprintf

tests/data/t_bijection.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module Test = (val Containers_testlib.make ~__FILE__())
33
open Test
44
open CCBijection;;
55

6-
module M = Make(Int)(String);;
6+
module M = Make(CCInt)(String);;
77

88

99
eq 2 (M.of_list [1,"1"; 2, "2"] |> M.cardinal);;

0 commit comments

Comments
 (0)