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)
(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)))

View file

@ -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))

View file

@ -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();
];;

View file

@ -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 "@[<hv2>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 "@[<hv2>roundtrip failed:@ from %a@ to %a@]"
Cbor.pp_diagnostic c Cbor.pp_diagnostic c';
true;;
[@@@endif]
let () = QCheck_base_runner.run_tests_main !suite