Skip to content

Commit 3e23796

Browse files
committed
move cbor tests into tests/
1 parent e242b00 commit 3e23796

File tree

4 files changed

+14
-34
lines changed

4 files changed

+14
-34
lines changed

src/cbor/tests/dune

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,3 @@
1111
(deps t_appendix_a.exe appendix_a.json)
1212
(action
1313
(run ./t_appendix_a.exe ./appendix_a.json)))
14-
15-
(executable
16-
(name t)
17-
(modules t)
18-
(preprocess
19-
(action
20-
(run %{project_root}/src/core/cpp/cpp.exe %{input-file})))
21-
(libraries qcheck-core qcheck-core.runner containers containers.cbor))
22-
23-
(rule
24-
(alias runtest)
25-
(action
26-
(run ./t.exe --no-colors)))

tests/core/dune

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
(preprocess
66
(action
77
(run %{project_root}/src/core/cpp/cpp.exe %{input-file})))
8-
(libraries containers containers.bencode containers.unix threads
9-
containers_testlib iter gen uutf csexp))
8+
(libraries containers containers.bencode containers.cbor containers.unix
9+
threads containers_testlib iter gen uutf csexp))

tests/core/t.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@ Containers_testlib.run_all ~descr:"containers" [
3333
T_utf8string.get();
3434
T_vector.get();
3535
T_bencode.get();
36+
T_cbor.get();
3637
T_unix.get();
3738
];;

src/cbor/tests/t.ml renamed to tests/core/t_cbor.ml

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11

2-
module Q = QCheck
3-
module Cbor = Containers_cbor
2+
include (val Containers_testlib.make ~__FILE__ ())
3+
module Cbor = Containers_cbor;;
44

5-
let suite = ref []
6-
7-
[@@@ifge 4.08]
5+
[@@@ifge 4.08];;
86

97
let gen_c : Cbor.t Q.Gen.t =
108
let open Q.Gen in
@@ -55,20 +53,14 @@ let rec shrink (c:Cbor.t) : Cbor.t Q.Iter.t =
5553
| `Bytes s ->
5654
let+ s = Q.Shrink.string s in `Bytes s
5755

56+
let arb = Q.make ~shrink ~print:Cbor.to_string_diagnostic gen_c;;
5857

59-
let arb = Q.make ~shrink ~print:Cbor.to_string_diagnostic gen_c
60-
61-
let t1 =
62-
Q.Test.make ~count:10_000 ~name:"to_from_same" arb @@ fun c ->
63-
let s = Cbor.encode c in
64-
let c' = Cbor.decode_exn s in
65-
if not (c = c') then
66-
Q.Test.fail_reportf "@[<hv2>roundtrip failed:@ from %a@ to %a@]"
67-
Cbor.pp_diagnostic c Cbor.pp_diagnostic c';
68-
true
69-
70-
let () = suite := t1 :: !suite
58+
q ~count:10_000 arb @@ fun c ->
59+
let s = Cbor.encode c in
60+
let c' = Cbor.decode_exn s in
61+
if not (c = c') then
62+
Q.Test.fail_reportf "@[<hv2>roundtrip failed:@ from %a@ to %a@]"
63+
Cbor.pp_diagnostic c Cbor.pp_diagnostic c';
64+
true;;
7165

7266
[@@@endif]
73-
74-
let () = QCheck_base_runner.run_tests_main !suite

0 commit comments

Comments
 (0)