move cbor tests into tests/

This commit is contained in:
Simon Cruanes 2022-07-02 23:49:41 -04:00
parent e242b004ad
commit 3e2379660e
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
4 changed files with 14 additions and 34 deletions

View file

@ -11,16 +11,3 @@
(deps t_appendix_a.exe appendix_a.json) (deps t_appendix_a.exe appendix_a.json)
(action (action
(run ./t_appendix_a.exe ./appendix_a.json))) (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)))

View file

@ -5,5 +5,5 @@
(preprocess (preprocess
(action (action
(run %{project_root}/src/core/cpp/cpp.exe %{input-file}))) (run %{project_root}/src/core/cpp/cpp.exe %{input-file})))
(libraries containers containers.bencode containers.unix threads (libraries containers containers.bencode containers.cbor containers.unix
containers_testlib iter gen uutf csexp)) threads containers_testlib iter gen uutf csexp))

View file

@ -33,5 +33,6 @@ Containers_testlib.run_all ~descr:"containers" [
T_utf8string.get(); T_utf8string.get();
T_vector.get(); T_vector.get();
T_bencode.get(); T_bencode.get();
T_cbor.get();
T_unix.get(); T_unix.get();
];; ];;

View file

@ -1,10 +1,8 @@
module Q = QCheck include (val Containers_testlib.make ~__FILE__ ())
module Cbor = Containers_cbor module Cbor = Containers_cbor;;
let suite = ref [] [@@@ifge 4.08];;
[@@@ifge 4.08]
let gen_c : Cbor.t Q.Gen.t = let gen_c : Cbor.t Q.Gen.t =
let open Q.Gen in let open Q.Gen in
@ -55,20 +53,14 @@ let rec shrink (c:Cbor.t) : Cbor.t Q.Iter.t =
| `Bytes s -> | `Bytes s ->
let+ s = Q.Shrink.string s in `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 q ~count:10_000 arb @@ fun c ->
let s = Cbor.encode c in
let t1 = let c' = Cbor.decode_exn s in
Q.Test.make ~count:10_000 ~name:"to_from_same" arb @@ fun c -> if not (c = c') then
let s = Cbor.encode c in Q.Test.fail_reportf "@[<hv2>roundtrip failed:@ from %a@ to %a@]"
let c' = Cbor.decode_exn s in Cbor.pp_diagnostic c Cbor.pp_diagnostic c';
if not (c = c') then true;;
Q.Test.fail_reportf "@[<hv2>roundtrip failed:@ from %a@ to %a@]"
Cbor.pp_diagnostic c Cbor.pp_diagnostic c';
true
let () = suite := t1 :: !suite
[@@@endif] [@@@endif]
let () = QCheck_base_runner.run_tests_main !suite