diff --git a/src/cbor/tests/dune b/src/cbor/tests/dune index 7ae1aeb4..a596ddc2 100644 --- a/src/cbor/tests/dune +++ b/src/cbor/tests/dune @@ -11,16 +11,3 @@ (deps t_appendix_a.exe appendix_a.json) (action (run ./t_appendix_a.exe ./appendix_a.json))) - -(executable - (name t) - (modules t) - (preprocess - (action - (run %{project_root}/src/core/cpp/cpp.exe %{input-file}))) - (libraries qcheck-core qcheck-core.runner containers containers.cbor)) - -(rule - (alias runtest) - (action - (run ./t.exe --no-colors))) diff --git a/tests/core/dune b/tests/core/dune index 8a91091f..605daf0c 100644 --- a/tests/core/dune +++ b/tests/core/dune @@ -5,5 +5,5 @@ (preprocess (action (run %{project_root}/src/core/cpp/cpp.exe %{input-file}))) - (libraries containers containers.bencode containers.unix threads - containers_testlib iter gen uutf csexp)) + (libraries containers containers.bencode containers.cbor containers.unix + threads containers_testlib iter gen uutf csexp)) diff --git a/tests/core/t.ml b/tests/core/t.ml index f3c74c44..a4f5944a 100644 --- a/tests/core/t.ml +++ b/tests/core/t.ml @@ -33,5 +33,6 @@ Containers_testlib.run_all ~descr:"containers" [ T_utf8string.get(); T_vector.get(); T_bencode.get(); + T_cbor.get(); T_unix.get(); ];; diff --git a/src/cbor/tests/t.ml b/tests/core/t_cbor.ml similarity index 75% rename from src/cbor/tests/t.ml rename to tests/core/t_cbor.ml index 0199b53d..c358ee1d 100644 --- a/src/cbor/tests/t.ml +++ b/tests/core/t_cbor.ml @@ -1,10 +1,8 @@ -module Q = QCheck -module Cbor = Containers_cbor +include (val Containers_testlib.make ~__FILE__ ()) +module Cbor = Containers_cbor;; -let suite = ref [] - -[@@@ifge 4.08] +[@@@ifge 4.08];; let gen_c : Cbor.t Q.Gen.t = let open Q.Gen in @@ -55,20 +53,14 @@ let rec shrink (c:Cbor.t) : Cbor.t Q.Iter.t = | `Bytes s -> let+ s = Q.Shrink.string s in `Bytes s +let arb = Q.make ~shrink ~print:Cbor.to_string_diagnostic gen_c;; -let arb = Q.make ~shrink ~print:Cbor.to_string_diagnostic gen_c - -let t1 = - Q.Test.make ~count:10_000 ~name:"to_from_same" arb @@ fun c -> - let s = Cbor.encode c in - let c' = Cbor.decode_exn s in - if not (c = c') then - Q.Test.fail_reportf "@[roundtrip failed:@ from %a@ to %a@]" - Cbor.pp_diagnostic c Cbor.pp_diagnostic c'; - true - -let () = suite := t1 :: !suite +q ~count:10_000 arb @@ fun c -> + let s = Cbor.encode c in + let c' = Cbor.decode_exn s in + if not (c = c') then + Q.Test.fail_reportf "@[roundtrip failed:@ from %a@ to %a@]" + Cbor.pp_diagnostic c Cbor.pp_diagnostic c'; + true;; [@@@endif] - -let () = QCheck_base_runner.run_tests_main !suite