diff --git a/.gitlab/ci/jobs/packaging/opam_package.yml b/.gitlab/ci/jobs/packaging/opam_package.yml index 7c4053d2bc4721afb7a2842292994f035e28f663..fad56f2e56081fdc8d91e7f35926d3bf9c36c6fb 100644 --- a/.gitlab/ci/jobs/packaging/opam_package.yml +++ b/.gitlab/ci/jobs/packaging/opam_package.yml @@ -215,6 +215,13 @@ opam:octez-accuser-PtMumbai: # Ignoring unreleased package octez-accuser-alpha. +opam:octez-alcotezt: + extends: + - .opam_template + - .rules_template__trigger_opam_batch_7 + variables: + package: octez-alcotezt + opam:octez-baker-PtLimaPt: extends: - .opam_template diff --git a/dune-project b/dune-project index 4565a0c8033c3381dea5d50c973df21951ecfe72..00f4e61be533f573bb94c2d9d7c8c15aa1364c49 100644 --- a/dune-project +++ b/dune-project @@ -6,6 +6,7 @@ (package (name octez-accuser-PtLimaPt)) (package (name octez-accuser-PtMumbai)) (package (name octez-accuser-alpha)) +(package (name octez-alcotezt)) (package (name octez-baker-PtLimaPt)) (package (name octez-baker-PtMumbai)) (package (name octez-baker-alpha)) diff --git a/manifest/main.ml b/manifest/main.ml index fa155f68c1f00e2665c4d5cdd19c2f1b7b8532e0..4741d79ba572ac34b6630dbbb0bf459ec65c3b6e 100644 --- a/manifest/main.ml +++ b/manifest/main.ml @@ -333,22 +333,6 @@ let tezos_rust_lib = let tezos_rust_lib_sapling = opam_only ~can_vendor:false "tezos-rust-libs" V.(at_least "1.1") -let tezt_lib = - external_lib - ~js_compatible:false - "tezt" - V.(at_least "3.0.0") - ~main_module:"Tezt" - -let tezt_core_lib = - external_sublib - tezt_lib - ~js_compatible:true - "tezt.core" - ~main_module:"Tezt_core" - -let tezt_js_lib = external_sublib tezt_lib ~js_compatible:true "tezt.js" - let tls = external_lib "tls" V.(at_least "0.13.0") let unix = external_lib ~opam:"base-unix" "unix" V.True @@ -388,6 +372,58 @@ let () = (* INTERNAL LIBS *) +let tezt_lib = + external_lib + ~js_compatible:false + "tezt" + V.(at_least "3.0.0") + ~main_module:"Tezt" + +let tezt_core_lib = + external_sublib + tezt_lib + ~js_compatible:true + "tezt.core" + ~main_module:"Tezt_core" + +let tezt_js_lib = external_sublib tezt_lib ~js_compatible:true "tezt.js" + +(* The main module [Octez_alcotest] is [open_] so that one can replace + the [alcotest] dependency with [alcotezt] and it just works. + If we use [~internal_name:"alcotest"] here, it would also work, + except in cases where the real Alcotest is also a dependency. *) +let alcotezt = + public_lib + "octez-alcotezt" + ~path:"tezt/lib_alcotezt" + (* TODO: https://gitlab.com/tezos/tezos/-/issues/4727 + + we mark "octez-alcotezt" as released but the real solution is to + modify the manifest to add build instructions for dune to be + used `with-test` *) + ~release_status:Released + ~synopsis: + "Provide the interface of Alcotest for Octez, but with Tezt as backend" + ~js_compatible:true + ~deps:[tezt_core_lib] + |> open_ + +let tezt ~opam ~path ?js_compatible ?modes ?(deps = []) ?dep_globs ?dep_files + ?synopsis ?opam_with_test l = + tezt_without_tezt_lib_dependency + ~opam + ~path + ?synopsis + ?js_compatible + ?modes + ~lib_deps:((tezt_core_lib |> open_ |> open_ ~m:"Base") :: deps) + ~exe_deps:[tezt_lib] + ~js_deps:[tezt_js_lib] + ?dep_globs + ?dep_files + ?opam_with_test + l + let octez_test_helpers = public_lib "tezos-test-helpers" @@ -586,13 +622,18 @@ let octez_lwt_result_stdlib_examples_traces = ~opam_with_test:Only_on_64_arch let _octez_lwt_result_stdlib_tests = - tests + tezt [ + "support"; + "traits"; + "traits_tiered"; "test_hashtbl"; "test_list_basic"; "test_list_basic_lwt"; "test_seq_basic"; "test_generic"; + "test_fuzzing_tests"; + "test_fuzzing_helpers"; "test_fuzzing_seq"; "test_fuzzing_list"; "test_fuzzing_set"; @@ -606,7 +647,7 @@ let _octez_lwt_result_stdlib_tests = octez_lwt_result_stdlib |> open_; octez_lwt_result_stdlib_examples_traces; lwt_unix; - alcotest_lwt; + alcotezt; qcheck_alcotest; octez_test_helpers |> open_; ] @@ -769,12 +810,12 @@ let _octez_hacl_tests_1 = ~js_compatible:true let _octez_error_monad_tests = - tests + tezt ["test_registration"; "test_splitted_error_encoding"] ~path:"src/lib_error_monad/test" ~opam:"tezos-error-monad" ~modes:[Native; JS] - ~deps:[octez_error_monad |> open_; data_encoding; alcotest] + ~deps:[octez_error_monad |> open_; data_encoding; alcotezt] ~js_compatible:true let octez_rpc = @@ -1105,9 +1146,11 @@ let octez_base_unix = uri; ] -let lib_base_tests ?dep_files names = - tests - names +let _octez_base_tests = + tezt + [ + "test_bounded"; "test_time"; "test_protocol"; "test_p2p_addr"; "test_sized"; + ] ~path:"src/lib_base/test" ~opam:"tezos-base" ~deps: @@ -1115,21 +1158,18 @@ let lib_base_tests ?dep_files names = octez_base |> open_; octez_error_monad |> open_; data_encoding; - qcheck_alcotest; octez_test_helpers |> open_; + qcheck_alcotest; + alcotezt; + ] + ~dep_files: + [ + (* Note: those files are only actually needed by test_p2p_addr. *) + "points.ok"; + "points.ko"; ] - ?dep_files ~modes:[Native; JS] ~js_compatible:true - ~modules:names - -let _octez_base_tests_1 = - lib_base_tests ["test_bounded"; "test_time"; "test_protocol"] - -let _octez_base_tests_2 = - lib_base_tests ["test_p2p_addr"] ~dep_files:["points.ok"; "points.ko"] - -let _octez_base_tests_3 = lib_base_tests ["test_sized"] let _octez_base_unix_tests = test @@ -3013,8 +3053,9 @@ let octez_benchmark_examples = ] let _octez_benchmark_tests = - tests + tezt [ + "test"; "test_sparse_vec"; "test_costlang"; "test_probe"; @@ -3026,7 +3067,7 @@ let _octez_benchmark_tests = ~synopsis:"Tezos: tests for lib-benchmarks" ~deps: [ - alcotest_lwt; + alcotezt; octez_base |> open_ ~m:"TzPervasives"; octez_base_unix; octez_stdlib_unix; @@ -3070,19 +3111,6 @@ let octez_shell_benchmarks = ] ~linkall:true -let tezt ~opam ~path ?js_compatible ?modes ?(deps = []) ?dep_globs ?synopsis l = - tezt_without_tezt_lib_dependency - ~opam - ~path - ?synopsis - ?js_compatible - ?modes - ~lib_deps:((tezt_core_lib |> open_ |> open_ ~m:"Base") :: deps) - ~exe_deps:[tezt_lib] - ~js_deps:[tezt_js_lib] - ?dep_globs - l - let tezt_performance_regression = public_lib "tezt-performance-regression" diff --git a/manifest/manifest.ml b/manifest/manifest.ml index a0133835958e27cbd222e90b7cdf0c4f38307deb..b8ff8c90f305c63c819f1214caddc297464ea0f2 100644 --- a/manifest/manifest.ml +++ b/manifest/manifest.ml @@ -1782,16 +1782,19 @@ type tezt_target = { exe_deps : target list; js_deps : target list; dep_globs : string list; + dep_files : string list; modules : string list; js_compatible : bool option; modes : Dune.mode list option; synopsis : string option; + opam_with_test : with_test option; } let tezt_targets_by_path : tezt_target String_map.t ref = ref String_map.empty let tezt ~opam ~path ?js_compatible ?modes ?(lib_deps = []) ?(exe_deps = []) - ?(js_deps = []) ?(dep_globs = []) ?synopsis modules = + ?(js_deps = []) ?(dep_globs = []) ?(dep_files = []) ?synopsis + ?opam_with_test modules = if String_map.mem path !tezt_targets_by_path then invalid_arg ("cannot call Manifest.tezt twice for the same directory: " ^ path) ; @@ -1802,10 +1805,12 @@ let tezt ~opam ~path ?js_compatible ?modes ?(lib_deps = []) ?(exe_deps = []) exe_deps; js_deps; dep_globs; + dep_files; modules; js_compatible; modes; synopsis; + opam_with_test; } in tezt_targets_by_path := String_map.add path tezt_target !tezt_targets_by_path @@ -1819,10 +1824,12 @@ let register_tezt_targets ~make_tezt_exe = exe_deps; js_deps; dep_globs; + dep_files; modules; js_compatible; modes; synopsis; + opam_with_test; } = let path_with_underscores = String.map (function '-' | '/' -> '_' | c -> c) path @@ -1852,7 +1859,9 @@ let register_tezt_targets ~make_tezt_exe = ?modes ~deps:(lib :: deps) ~dep_globs + ~dep_files ~modules:[exe_name] + ?opam_with_test ~dune: Dune. [ @@ -3040,7 +3049,9 @@ let check_circular_opam_deps () = in while not (Queue.is_empty to_visit) do let elt = Queue.take to_visit in - let elt_path = Hashtbl.find shortest_path elt.kind in + let elt_path = + Option.value ~default:[] (Hashtbl.find_opt shortest_path elt.kind) + in list_iter (deps_of elt) (fun (dep : Target.internal) -> if not (Hashtbl.mem shortest_path dep.kind) then ( let path = dep :: elt_path in diff --git a/manifest/manifest.mli b/manifest/manifest.mli index 1cd25805387c394c56f1fb1f8ce98fab9398db07..83cee60178c6b9553772cfa5189ec8c1c1004d9c 100644 --- a/manifest/manifest.mli +++ b/manifest/manifest.mli @@ -920,7 +920,9 @@ val tezt : ?exe_deps:target list -> ?js_deps:target list -> ?dep_globs:string list -> + ?dep_files:string list -> ?synopsis:string -> + ?opam_with_test:with_test -> string list -> unit diff --git a/opam/octez-alcotezt.opam b/opam/octez-alcotezt.opam new file mode 100644 index 0000000000000000000000000000000000000000..92de02f5e009d231cd1c7afc6dff76db4a84bc8f --- /dev/null +++ b/opam/octez-alcotezt.opam @@ -0,0 +1,20 @@ +# This file was automatically generated, do not edit. +# Edit file manifest/main.ml instead. +opam-version: "2.0" +maintainer: "contact@tezos.com" +authors: ["Tezos devteam"] +homepage: "https://www.tezos.com/" +bug-reports: "https://gitlab.com/tezos/tezos/issues" +dev-repo: "git+https://gitlab.com/tezos/tezos.git" +license: "MIT" +depends: [ + "dune" { >= "3.0" } + "ocaml" { >= "4.14" } + "tezt" { >= "3.0.0" } +] +build: [ + ["rm" "-r" "vendors"] + ["dune" "build" "-p" name "-j" jobs] + ["dune" "runtest" "-p" name "-j" jobs] {with-test} +] +synopsis: "Provide the interface of Alcotest for Octez, but with Tezt as backend" diff --git a/opam/tezos-base.opam b/opam/tezos-base.opam index ccae4c4d6f5a3aaad3cfe27182f213b282d1c2f2..c8ad4e8bb84263e8a00c57c6a458f20db8f0bcbd 100644 --- a/opam/tezos-base.opam +++ b/opam/tezos-base.opam @@ -24,12 +24,15 @@ depends: [ "uri" { >= "3.1.0" } "tezos-hacl" "tezos-stdlib-unix" - "qcheck-alcotest" { with-test & >= "0.20" } "tezos-test-helpers" {with-test} + "qcheck-alcotest" { with-test & >= "0.20" } + "tezt" { with-test & >= "3.0.0" } + "octez-alcotezt" {with-test} ] build: [ ["rm" "-r" "vendors"] ["dune" "build" "-p" name "-j" jobs] ["dune" "runtest" "-p" name "-j" jobs] {with-test} + ["dune" "build" "@runtezt" "-p" name "-j" jobs] {with-test} ] synopsis: "Tezos: meta-package and pervasive type definitions for Tezos" diff --git a/opam/tezos-benchmark-tests.opam b/opam/tezos-benchmark-tests.opam index d542840b32955f52d413b38eb5cb0b4457df4567..2f7622e316ad2919926ac153933196940da32e8b 100644 --- a/opam/tezos-benchmark-tests.opam +++ b/opam/tezos-benchmark-tests.opam @@ -10,7 +10,8 @@ license: "MIT" depends: [ "dune" { >= "3.0" } "ocaml" { >= "4.14" } - "alcotest-lwt" { with-test & >= "1.5.0" } + "tezt" { with-test & >= "3.0.0" } + "octez-alcotezt" {with-test} "tezos-base" {with-test} "tezos-stdlib-unix" {with-test} "tezos-micheline" {with-test} @@ -22,5 +23,6 @@ build: [ ["rm" "-r" "vendors"] ["dune" "build" "-p" name "-j" jobs] ["dune" "runtest" "-p" name "-j" jobs] {with-test} + ["dune" "build" "@runtezt" "-p" name "-j" jobs] {with-test} ] synopsis: "Tezos: tests for lib-benchmarks" diff --git a/opam/tezos-error-monad.opam b/opam/tezos-error-monad.opam index 401f99dacd55b6513eedff366fb50c095c3f1373..3074dc58273e649e34031965b8d93a669880157d 100644 --- a/opam/tezos-error-monad.opam +++ b/opam/tezos-error-monad.opam @@ -15,7 +15,8 @@ depends: [ "lwt-canceler" { >= "0.3" & < "0.4" } "lwt" { >= "5.6.0" } "tezos-lwt-result-stdlib" - "alcotest" { with-test & >= "1.5.0" } + "tezt" { with-test & >= "3.0.0" } + "octez-alcotezt" {with-test} ] conflicts: [ "result" { < "1.5" } @@ -24,5 +25,6 @@ build: [ ["rm" "-r" "vendors"] ["dune" "build" "-p" name "-j" jobs] ["dune" "runtest" "-p" name "-j" jobs] {with-test} + ["dune" "build" "@runtezt" "-p" name "-j" jobs] {with-test} ] synopsis: "Tezos: error monad" diff --git a/opam/tezos-lwt-result-stdlib.opam b/opam/tezos-lwt-result-stdlib.opam index 275f1eb38155083abc5eef983e3b156488d3424c..d24b598a9d8ca6a978a654056bf59a87bb700268 100644 --- a/opam/tezos-lwt-result-stdlib.opam +++ b/opam/tezos-lwt-result-stdlib.opam @@ -11,7 +11,8 @@ depends: [ "dune" { >= "3.0" } "ocaml" { >= "4.14" } "lwt" { >= "5.6.0" } - "alcotest-lwt" { with-test & >= "1.5.0" } + "tezt" { with-test & >= "3.0.0" } + "octez-alcotezt" {with-test} "qcheck-alcotest" { with-test & >= "0.20" } "tezos-test-helpers" {with-test} ] @@ -19,5 +20,6 @@ build: [ ["rm" "-r" "vendors"] ["dune" "build" "-p" name "-j" jobs] ["dune" "runtest" "-p" name "-j" jobs] { with-test & arch != "arm32" & arch != "x86_32" } + ["dune" "build" "@runtezt" "-p" name "-j" jobs] { with-test & arch != "arm32" & arch != "x86_32" } ] synopsis: "Tezos: error-aware stdlib replacement" diff --git a/src/lib_base/test/dune b/src/lib_base/test/dune index af54f30a627d9369beab456e3622c6999c73a180..f70a1b5aeef2a7f1fa04ab733de1c45c8a17641a 100644 --- a/src/lib_base/test/dune +++ b/src/lib_base/test/dune @@ -3,105 +3,62 @@ (env (_ (env-vars (NODE_PRELOAD hacl-wasm,ocaml-bls12-381,secp256k1-wasm)))) -(executables - (names test_bounded test_time test_protocol) - (modes native js) +(library + (name src_lib_base_test_tezt_lib) + (instrumentation (backend bisect_ppx)) (libraries + tezt.core tezos-base tezos-error-monad data-encoding + tezos-test-helpers qcheck-alcotest - tezos-test-helpers) + octez-alcotezt) (js_of_ocaml) + (library_flags (:standard -linkall)) (flags (:standard) + -open Tezt_core + -open Tezt_core.Base -open Tezos_base -open Tezos_error_monad - -open Tezos_test_helpers) - (modules test_bounded test_time test_protocol)) - -(rule - (alias runtest) - (package tezos-base) - (action (run %{dep:./test_bounded.exe}))) - -(rule - (alias runtest) - (package tezos-base) - (action (run %{dep:./test_time.exe}))) - -(rule - (alias runtest) - (package tezos-base) - (action (run %{dep:./test_protocol.exe}))) - -(rule - (alias runtest_js) - (package tezos-base) - (action (run node %{dep:./test_bounded.bc.js}))) - -(rule - (alias runtest_js) - (package tezos-base) - (action (run node %{dep:./test_time.bc.js}))) - -(rule - (alias runtest_js) - (package tezos-base) - (action (run node %{dep:./test_protocol.bc.js}))) + -open Tezos_test_helpers + -open Octez_alcotezt) + (modules test_bounded test_time test_protocol test_p2p_addr test_sized)) (executable - (name test_p2p_addr) - (modes native js) + (name main) + (modes native) (libraries - tezos-base - tezos-error-monad - data-encoding - qcheck-alcotest - tezos-test-helpers) - (js_of_ocaml) - (flags - (:standard) - -open Tezos_base - -open Tezos_error_monad - -open Tezos_test_helpers) - (modules test_p2p_addr)) + src_lib_base_test_tezt_lib + tezt) + (modules main)) (rule - (alias runtest) + (alias runtezt) (package tezos-base) (deps points.ok points.ko) - (action (run %{dep:./test_p2p_addr.exe}))) + (action (run %{dep:./main.exe}))) (rule - (alias runtest_js) - (package tezos-base) - (deps points.ok points.ko) - (action (run node %{dep:./test_p2p_addr.bc.js}))) + (targets main.ml) + (action (with-stdout-to %{targets} (echo "let () = Tezt.Test.run ()")))) (executable - (name test_sized) - (modes native js) + (name main_js) + (modes js) (libraries - tezos-base - tezos-error-monad - data-encoding - qcheck-alcotest - tezos-test-helpers) + src_lib_base_test_tezt_lib + tezt.js) (js_of_ocaml) - (flags - (:standard) - -open Tezos_base - -open Tezos_error_monad - -open Tezos_test_helpers) - (modules test_sized)) + (modules main_js)) (rule - (alias runtest) + (alias runtezt_js) (package tezos-base) - (action (run %{dep:./test_sized.exe}))) + (deps points.ok points.ko) + (action (run node %{dep:./main_js.bc.js}))) (rule - (alias runtest_js) - (package tezos-base) - (action (run node %{dep:./test_sized.bc.js}))) + (targets main_js.ml) + (action (with-stdout-to %{targets} (echo "let () = Tezt_js.Test.run ()")))) diff --git a/src/lib_base/test/test_bounded.ml b/src/lib_base/test/test_bounded.ml index c8795c8d9620ca5baf663b1f73dd696637eb452c..cfd150d44e7395df93ad55f54e37b8fe31b09984 100644 --- a/src/lib_base/test/test_bounded.ml +++ b/src/lib_base/test/test_bounded.ml @@ -266,7 +266,7 @@ end = struct in let* ety = oneofl values in match ety with - | E (type a) (ty : a Bounded.Internal_for_tests.t) -> + | E ty -> let* (module S : S) = gen_from_ty ty in let* element = S.gen in return (E' {bounded = (module S); element}) diff --git a/src/lib_base/test/test_p2p_addr.ml b/src/lib_base/test/test_p2p_addr.ml index 55b3b8e1daaf929bfa422d29f5eff3cd2343d847..5b87808e231f745e7eee462cf2c022d3cc657c75 100644 --- a/src/lib_base/test/test_p2p_addr.ml +++ b/src/lib_base/test/test_p2p_addr.ml @@ -117,7 +117,7 @@ let eq l r = eq_addr l.addr r.addr && l.port = r.port && eq_peer_id l.peer_id r.peer_id let process_points filename f = - let file = open_in filename in + let file = open_in (project_root // "src/lib_base/test" // filename) in try while true do f (input_line file) diff --git a/src/lib_benchmark/test/dune b/src/lib_benchmark/test/dune index 9c04c4134e7691a1931ceabe7119a98bd335f493..8ce01ffb4c9295240c7770fa37849afeb88200ec 100644 --- a/src/lib_benchmark/test/dune +++ b/src/lib_benchmark/test/dune @@ -1,15 +1,12 @@ ; This file was automatically generated, do not edit. ; Edit file manifest/main.ml instead. -(executables - (names - test_sparse_vec - test_costlang - test_probe - test_measure - test_benchmark_helpers) +(library + (name src_lib_benchmark_test_tezt_lib) + (instrumentation (backend bisect_ppx)) (libraries - alcotest-lwt + tezt.core + octez-alcotezt tezos-base tezos-base.unix tezos-stdlib-unix @@ -17,31 +14,33 @@ tezos-crypto tezos-benchmark tezos-benchmark-examples) + (library_flags (:standard -linkall)) (flags (:standard) - -open Tezos_base.TzPervasives)) - -(rule - (alias runtest) - (package tezos-benchmark-tests) - (action (run %{dep:./test_sparse_vec.exe}))) - -(rule - (alias runtest) - (package tezos-benchmark-tests) - (action (run %{dep:./test_costlang.exe}))) + -open Tezt_core + -open Tezt_core.Base + -open Octez_alcotezt + -open Tezos_base.TzPervasives) + (modules + test + test_sparse_vec + test_costlang + test_probe + test_measure + test_benchmark_helpers)) -(rule - (alias runtest) - (package tezos-benchmark-tests) - (action (run %{dep:./test_probe.exe}))) +(executable + (name main) + (libraries + src_lib_benchmark_test_tezt_lib + tezt) + (modules main)) (rule - (alias runtest) + (alias runtezt) (package tezos-benchmark-tests) - (action (run %{dep:./test_measure.exe}))) + (action (run %{dep:./main.exe}))) (rule - (alias runtest) - (package tezos-benchmark-tests) - (action (run %{dep:./test_benchmark_helpers.exe}))) + (targets main.ml) + (action (with-stdout-to %{targets} (echo "let () = Tezt.Test.run ()")))) diff --git a/src/lib_benchmark/test/test_inference.ml b/src/lib_benchmark/test/test_inference.ml index 882d38d9ead59a3e4a0c889eaec99394e6be144c..c45f43a6415508963f8cf2d81599a9634b60438c 100644 --- a/src/lib_benchmark/test/test_inference.ml +++ b/src/lib_benchmark/test/test_inference.ml @@ -116,3 +116,6 @@ let test () = 30.0 < T.const && T.const < 36.0 && T.quadratic_term =~ 0.042 let tests = [Test.tztest_assert "regression" `Quick @@ test] + +let () = + Alcotest_lwt.run "tezos-benchmark" [("inference", tests)] |> Lwt_main.run diff --git a/src/lib_error_monad/test/dune b/src/lib_error_monad/test/dune index 8af8148905198eabab4cc78d05c658530bc0cc77..384c1c1638e758bc4eaa399d970f17e7af59f89e 100644 --- a/src/lib_error_monad/test/dune +++ b/src/lib_error_monad/test/dune @@ -1,34 +1,55 @@ ; This file was automatically generated, do not edit. ; Edit file manifest/main.ml instead. -(executables - (names test_registration test_splitted_error_encoding) - (modes native js) +(library + (name src_lib_error_monad_test_tezt_lib) + (instrumentation (backend bisect_ppx)) (libraries + tezt.core tezos-error-monad data-encoding - alcotest) + octez-alcotezt) (js_of_ocaml) + (library_flags (:standard -linkall)) (flags (:standard) - -open Tezos_error_monad)) + -open Tezt_core + -open Tezt_core.Base + -open Tezos_error_monad + -open Octez_alcotezt) + (modules test_registration test_splitted_error_encoding)) + +(executable + (name main) + (modes native) + (libraries + src_lib_error_monad_test_tezt_lib + tezt) + (modules main)) (rule - (alias runtest) + (alias runtezt) (package tezos-error-monad) - (action (run %{dep:./test_registration.exe}))) + (action (run %{dep:./main.exe}))) (rule - (alias runtest) - (package tezos-error-monad) - (action (run %{dep:./test_splitted_error_encoding.exe}))) + (targets main.ml) + (action (with-stdout-to %{targets} (echo "let () = Tezt.Test.run ()")))) + +(executable + (name main_js) + (modes js) + (libraries + src_lib_error_monad_test_tezt_lib + tezt.js) + (js_of_ocaml) + (modules main_js)) (rule - (alias runtest_js) + (alias runtezt_js) (package tezos-error-monad) - (action (run node %{dep:./test_registration.bc.js}))) + (action (run node %{dep:./main_js.bc.js}))) (rule - (alias runtest_js) - (package tezos-error-monad) - (action (run node %{dep:./test_splitted_error_encoding.bc.js}))) + (targets main_js.ml) + (action (with-stdout-to %{targets} (echo "let () = Tezt_js.Test.run ()")))) diff --git a/src/lib_lwt_result_stdlib/test/dune b/src/lib_lwt_result_stdlib/test/dune index 3c02112391062d74dc05e5b56490221e90447ed9..e4cbb73ad6bbb2d4e33f27abbb00a064a10a2daa 100644 --- a/src/lib_lwt_result_stdlib/test/dune +++ b/src/lib_lwt_result_stdlib/test/dune @@ -1,76 +1,54 @@ ; This file was automatically generated, do not edit. ; Edit file manifest/main.ml instead. -(executables - (names - test_hashtbl - test_list_basic - test_list_basic_lwt - test_seq_basic - test_generic - test_fuzzing_seq - test_fuzzing_list - test_fuzzing_set - test_fuzzing_seq_tiered - test_fuzzing_option) +(library + (name src_lib_lwt_result_stdlib_test_tezt_lib) + (instrumentation (backend bisect_ppx)) (libraries + tezt.core tezos-lwt-result-stdlib tezos-lwt-result-stdlib.examples.traces lwt.unix - alcotest-lwt + octez-alcotezt qcheck-alcotest tezos-test-helpers) + (library_flags (:standard -linkall)) (flags (:standard) + -open Tezt_core + -open Tezt_core.Base -open Tezos_lwt_result_stdlib - -open Tezos_test_helpers)) - -(rule - (alias runtest) - (package tezos-lwt-result-stdlib) - (action (run %{dep:./test_hashtbl.exe}))) - -(rule - (alias runtest) - (package tezos-lwt-result-stdlib) - (action (run %{dep:./test_list_basic.exe}))) - -(rule - (alias runtest) - (package tezos-lwt-result-stdlib) - (action (run %{dep:./test_list_basic_lwt.exe}))) - -(rule - (alias runtest) - (package tezos-lwt-result-stdlib) - (action (run %{dep:./test_seq_basic.exe}))) - -(rule - (alias runtest) - (package tezos-lwt-result-stdlib) - (action (run %{dep:./test_generic.exe}))) - -(rule - (alias runtest) - (package tezos-lwt-result-stdlib) - (action (run %{dep:./test_fuzzing_seq.exe}))) - -(rule - (alias runtest) - (package tezos-lwt-result-stdlib) - (action (run %{dep:./test_fuzzing_list.exe}))) + -open Octez_alcotezt + -open Tezos_test_helpers) + (modules + support + traits + traits_tiered + test_hashtbl + test_list_basic + test_list_basic_lwt + test_seq_basic + test_generic + test_fuzzing_tests + test_fuzzing_helpers + test_fuzzing_seq + test_fuzzing_list + test_fuzzing_set + test_fuzzing_seq_tiered + test_fuzzing_option)) -(rule - (alias runtest) - (package tezos-lwt-result-stdlib) - (action (run %{dep:./test_fuzzing_set.exe}))) +(executable + (name main) + (libraries + src_lib_lwt_result_stdlib_test_tezt_lib + tezt) + (modules main)) (rule - (alias runtest) + (alias runtezt) (package tezos-lwt-result-stdlib) - (action (run %{dep:./test_fuzzing_seq_tiered.exe}))) + (action (run %{dep:./main.exe}))) (rule - (alias runtest) - (package tezos-lwt-result-stdlib) - (action (run %{dep:./test_fuzzing_option.exe}))) + (targets main.ml) + (action (with-stdout-to %{targets} (echo "let () = Tezt.Test.run ()")))) diff --git a/tezt/lib_alcotezt/alcotest.ml b/tezt/lib_alcotezt/alcotest.ml new file mode 100644 index 0000000000000000000000000000000000000000..8809f5313a4019bf2df6ffb8870b7e889021cb01 --- /dev/null +++ b/tezt/lib_alcotezt/alcotest.ml @@ -0,0 +1,109 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2022 Nomadic Labs *) +(* *) +(* Permission is hereby granted, free of charge, to any person obtaining a *) +(* copy of this software and associated documentation files (the "Software"),*) +(* to deal in the Software without restriction, including without limitation *) +(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) +(* and/or sell copies of the Software, and to permit persons to whom the *) +(* Software is furnished to do so, subject to the following conditions: *) +(* *) +(* The above copyright notice and this permission notice shall be included *) +(* in all copies or substantial portions of the Software. *) +(* *) +(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) +(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) +(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) +(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) +(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) +(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) +(* DEALINGS IN THE SOFTWARE. *) +(* *) +(*****************************************************************************) + +open Tezt_core + +type return = unit + +type speed_level = [`Quick | `Slow] + +type 'a test_case = string * speed_level * ('a -> return) + +let test_case name speed_level body = (name, speed_level, body) + +exception Test_error + +type 'a test = string * 'a test_case list + +(* TODO: https://gitlab.com/tezos/tezos/-/issues/4726 + + group tests individually *) +let run library_name tests = + tests + |> List.iter @@ fun (test_name, test_cases) -> + Test.register + ~__FILE__:library_name + ~title:(library_name ^ ": " ^ test_name) + ~tags:["alcotest"] + @@ fun () -> + (test_cases + |> List.iter @@ fun (test_case_name, speed_level, body) -> + match speed_level with + | `Slow when Cli.get_bool ~default:false "quick" -> + Log.info "Skipped test: %s" test_case_name + | `Slow | `Quick -> + Log.info "Test: %s" test_case_name ; + body ()) ; + Base.unit + +type 'a testable = (module Tezt_core.Check.EQUALABLE with type t = 'a) + +let string : string testable = + (module struct + include String + + let pp = Format.pp_print_string + end) + +let result (type a e) (ok : a testable) (error : e testable) : + (a, e) result testable = + let module Ok = (val ok) in + let module Error = (val error) in + (module struct + type t = (a, e) result + + let pp fmt = function + | Ok x -> Format.fprintf fmt "@[Ok@ (%a)@]" Ok.pp x + | Error x -> Format.fprintf fmt "@[Error@ (%a)@]" Error.pp x + + let equal = Result.equal ~ok:Ok.equal ~error:Error.equal + end) + +let check testable msg expected actual = + Check.(expected = actual) + (Check.equalable_module testable) + ~error_msg:(msg ^ ": expected %L, got %R") + +let fail message = Test.fail "%s" message + +let failf x = Format.kasprintf fail x + +(* Some Octez tests use Format.eprintf directly. + Not even in the tests but in the libraries themselves. + We redirect the output to Tezt.Log. + + Ideally we would do the same for the Printf module, which is in particular + called by QCheck_alcotest to print the seed, but the Printf module cannot + redirect its output... *) +let redirect_formatter fmt = + let buffer = Buffer.create 256 in + Format.pp_set_formatter_output_functions fmt (Buffer.add_substring buffer) + @@ fun () -> + Log.info "%s" (String.trim (Buffer.contents buffer)) ; + Buffer.clear buffer + +let () = + redirect_formatter Format.std_formatter ; + redirect_formatter Format.err_formatter diff --git a/tezt/lib_alcotezt/alcotest.mli b/tezt/lib_alcotezt/alcotest.mli new file mode 100644 index 0000000000000000000000000000000000000000..c25a2396e514a1aa259b422a6e8c0b26d8aa3b33 --- /dev/null +++ b/tezt/lib_alcotezt/alcotest.mli @@ -0,0 +1,93 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2022 Nomadic Labs *) +(* *) +(* Permission is hereby granted, free of charge, to any person obtaining a *) +(* copy of this software and associated documentation files (the "Software"),*) +(* to deal in the Software without restriction, including without limitation *) +(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) +(* and/or sell copies of the Software, and to permit persons to whom the *) +(* Software is furnished to do so, subject to the following conditions: *) +(* *) +(* The above copyright notice and this permission notice shall be included *) +(* in all copies or substantial portions of the Software. *) +(* *) +(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) +(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) +(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) +(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) +(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) +(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) +(* DEALINGS IN THE SOFTWARE. *) +(* *) +(*****************************************************************************) + +(** Wrapper to run Alcotest tests with Tezt as a backend. *) + +(** This module provides a subset of the interface of the [Alcotest] module + of the real Alcotest library. But instead of using Alcotest to run the tests, + it uses Tezt. This allows to transition from Alcotest to Tezt without + having to actually change the code. In turn, this allows to benefit from + Tezt features such as auto-balancing in the CI. One can then use Tezt's + modules in the test, to gradually migrate the test to Tezt and stop using + this wrapper. + + This module is intended as a way to help transition from Alcotest to Tezt, + not to use both at the same time forever. First use Alcotezt to have the test + runnable using Tezt, as a quick win to get auto-balancing etc. Then stop using + Alcotest functions and migrate existing calls at the pace that is convenient + for you. *) + +(** Return type for tests. *) +type return = unit + +(** Speed levels. + + In Alcotest, one can ask not to run slow tests with [-q] from the command-line. + In Tezt, the equivalent is [-a quick]. *) +type speed_level = [`Quick | `Slow] + +(** Test cases. + + The name of the Alcotest test case appears in Tezt's logs, + but it is not used in the Tezt test title, nor as a tag. *) +type 'a test_case = string * speed_level * ('a -> return) + +(** Make a test case. *) +val test_case : string -> speed_level -> ('a -> return) -> 'a test_case + +(** Can be raised to fail a test. *) +exception Test_error + +(** Tests. + + In Tezt, the name of the test is used as the title of the test. *) +type 'a test = string * 'a test_case list + +(** Run a test suite. + + In Tezt, this calls [Test.register] but does not actually run the test suite. + The name of the test suite is used as the filename for the Tezt test. *) +val run : string -> unit test list -> return + +(** Values that can be tested with {!check}. *) +type 'a testable = (module Tezt_core.Check.EQUALABLE with type t = 'a) + +(** The string testable type. *) +val string : string testable + +(** The result testable type. *) +val result : 'a testable -> 'e testable -> ('a, 'e) result testable + +(** Check that two values are equal. + + In Tezt, this becomes [Check.(=)] where [~error_msg] is + [msg ^ ": expected %L, got %R"] where [msg] is the [string] given to [check]. *) +val check : 'a testable -> string -> 'a -> 'a -> return + +(** Fail the current test (string version). *) +val fail : string -> 'a + +(** Fail the current test (format version). *) +val failf : ('a, Format.formatter, return, 'b) format4 -> 'a diff --git a/src/lib_benchmark/test/main.ml b/tezt/lib_alcotezt/alcotest_lwt.ml similarity index 61% rename from src/lib_benchmark/test/main.ml rename to tezt/lib_alcotezt/alcotest_lwt.ml index 73de2b199b6fbfa3b3eb75badf8f9d1b5eceb126..72e3a809576fbcd9b2e6a5c3cf8d332e506afb21 100644 --- a/src/lib_benchmark/test/main.ml +++ b/tezt/lib_alcotezt/alcotest_lwt.ml @@ -1,7 +1,7 @@ (*****************************************************************************) (* *) (* Open Source License *) -(* Copyright (c) 2020 Nomadic Labs. *) +(* Copyright (c) 2022 Nomadic Labs *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) @@ -23,6 +23,42 @@ (* *) (*****************************************************************************) -let () = - Alcotest_lwt.run "tezos-benchmark" [("inference", Test_inference.tests)] - |> Lwt_main.run +open Tezt_core +open Tezt_core.Base + +type return = unit Lwt.t + +type speed_level = [`Quick | `Slow] + +type 'a test_case = string * speed_level * ('a -> return) + +let test_case name speed_level body = + (* Not sure this is the right way to create the switch, maybe it should have + a larger scope. *) + let body args = Lwt_switch.with_switch (fun sw -> body sw args) in + (name, speed_level, body) + +let test_case_sync name speed_level body = + let body arg = + body arg ; + unit + in + (name, speed_level, body) + +type 'a test = string * 'a test_case list + +let run library_name tests = + (tests + |> List.iter @@ fun (test_name, test_cases) -> + Test.register ~__FILE__:library_name ~title:test_name ~tags:["alcotest"] + @@ fun () -> + test_cases + |> Lwt_list.iter_s @@ fun (test_case_name, speed_level, body) -> + match speed_level with + | `Slow when Cli.get_bool ~default:false "quick" -> + Log.info "Skipped test: %s" test_case_name ; + unit + | `Slow | `Quick -> + Log.info "Test: %s" test_case_name ; + body ()) ; + unit diff --git a/tezt/lib_alcotezt/alcotest_lwt.mli b/tezt/lib_alcotezt/alcotest_lwt.mli new file mode 100644 index 0000000000000000000000000000000000000000..06c1af33f1540964a1a83e9e2218847d62578cd5 --- /dev/null +++ b/tezt/lib_alcotezt/alcotest_lwt.mli @@ -0,0 +1,67 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2022 Nomadic Labs *) +(* *) +(* Permission is hereby granted, free of charge, to any person obtaining a *) +(* copy of this software and associated documentation files (the "Software"),*) +(* to deal in the Software without restriction, including without limitation *) +(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) +(* and/or sell copies of the Software, and to permit persons to whom the *) +(* Software is furnished to do so, subject to the following conditions: *) +(* *) +(* The above copyright notice and this permission notice shall be included *) +(* in all copies or substantial portions of the Software. *) +(* *) +(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) +(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) +(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) +(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) +(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) +(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) +(* DEALINGS IN THE SOFTWARE. *) +(* *) +(*****************************************************************************) + +(** Wrapper to run Alcotest tests with Tezt as a backend. *) + +(** This module provides a subset of the interface of the [Alcotest] module + of the real Alcotest library. But instead of using Alcotest to run the tests, + it uses Tezt. This allows to transition from Alcotest to Tezt without + having to actually change the code. In turn, this allows to benefit from + Tezt features such as auto-balancing in the CI. One can then use Tezt's + modules in the test, to gradually migrate the test to Tezt and stop using + this wrapper. *) + +(** Return type for tests. *) +type return = unit Lwt.t + +(** Speed levels. + + In Alcotest, one can ask not to run slow tests with [-q] from the command-line. + In Tezt, the equivalent is [-a quick]. *) +type speed_level = [`Quick | `Slow] + +(** Test cases. + + The name of the Alcotest test case appears in Tezt's logs, + but it is not used in the Tezt test title, nor as a tag. *) +type 'a test_case = string * speed_level * ('a -> return) + +(** Make a test case. *) +val test_case : + string -> speed_level -> (Lwt_switch.t -> 'a -> return) -> 'a test_case + +(** Make a test case (out of Lwt). *) +val test_case_sync : string -> speed_level -> ('a -> unit) -> 'a test_case + +(** Tests. + + In Tezt, the name of the test is used as the title of the test. *) +type 'a test = string * 'a test_case list + +(** Run a test suite. + + In Tezt, this calls [Test.register] but does not actually run the test suite. + The name of the test suite is used as the filename for the Tezt test. *) +val run : string -> unit test list -> return diff --git a/tezt/lib_alcotezt/dune b/tezt/lib_alcotezt/dune new file mode 100644 index 0000000000000000000000000000000000000000..a89575f1e1e219bd688ee152eac53cf422accbc7 --- /dev/null +++ b/tezt/lib_alcotezt/dune @@ -0,0 +1,10 @@ +; This file was automatically generated, do not edit. +; Edit file manifest/main.ml instead. + +(library + (name octez_alcotezt) + (public_name octez-alcotezt) + (instrumentation (backend bisect_ppx)) + (libraries + tezt.core) + (js_of_ocaml)) diff --git a/tezt/tests/dune b/tezt/tests/dune index 3c2151e23c03be3a27767fa374806e6ce4fcbade..24a1289a86af48f6128e7df1160cfec357a0c4ae 100644 --- a/tezt/tests/dune +++ b/tezt/tests/dune @@ -15,7 +15,11 @@ tezos-protocol-alpha src_proto_alpha_lib_protocol_test_regression_tezt_lib src_proto_016_PtMumbai_lib_protocol_test_regression_tezt_lib - src_proto_015_PtLimaPt_lib_protocol_test_regression_tezt_lib) + src_proto_015_PtLimaPt_lib_protocol_test_regression_tezt_lib + src_lib_lwt_result_stdlib_test_tezt_lib + src_lib_error_monad_test_tezt_lib + src_lib_benchmark_test_tezt_lib + src_lib_base_test_tezt_lib) (flags (:standard) -open Tezt