From 270100f0be307d5cbf0209389f3224e5ae502990 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20Roch=C3=A9?= Date: Wed, 25 Dec 2024 12:46:39 +0100 Subject: [PATCH] alcotest: expose run arguments --- alcotest/junit_alcotest.ml | 43 +++++++++++++++++++++++--- alcotest/junit_alcotest.mli | 27 ++++++---------- alcotest/test/alcotest_report.expected | 4 +-- junit_alcotest.opam | 2 +- 4 files changed, 52 insertions(+), 24 deletions(-) diff --git a/alcotest/junit_alcotest.ml b/alcotest/junit_alcotest.ml index 1cd1d31..200ada9 100644 --- a/alcotest/junit_alcotest.ml +++ b/alcotest/junit_alcotest.ml @@ -50,9 +50,27 @@ let wrap_test ?classname handle_result (name, s, test) = name, s, test ;; -let run ?argv name tl = A.run ~and_exit:false ?argv name tl - -let run_and_report ?(and_exit = true) ?package ?timestamp ?argv name tests = +let run_and_report + ?stdout + ?stderr + ?(and_exit = true) + ?verbose + ?compact + ?tail_errors + ?quick_only + ?show_errors + ?json + ?filter + ?log_dir + ?bail + ?record_backtrace + ?ci + ?package + ?timestamp + ?argv + name + tests + = let testcases = ref [] in let testsuite = Junit.Testsuite.make ?package ?timestamp ~name () in let tests = @@ -64,7 +82,24 @@ let run_and_report ?(and_exit = true) ?package ?timestamp ?argv name tests = in let exit = try - run ?argv name tests; + A.run + ?stdout + ?stderr + ?verbose + ?compact + ?tail_errors + ?quick_only + ?show_errors + ?json + ?filter + ?log_dir + ?bail + ?record_backtrace + ?ci + ?argv + ~and_exit:false + name + tests; fun () -> if and_exit then exit 0 else () with | A.Test_error as exn -> fun () -> if and_exit then exit 1 else reraise exn diff --git a/alcotest/junit_alcotest.mli b/alcotest/junit_alcotest.mli index 515bfa7..72b6243 100644 --- a/alcotest/junit_alcotest.mli +++ b/alcotest/junit_alcotest.mli @@ -6,7 +6,7 @@ (** [wrap_test handle_result test_cases] wraps test cases to create Junit testcases and pass them to [handle_result]. - Can be used with {!run} to create customized Junit testsuites if + Can be used with {!Alcotest.run} to create customized Junit testsuites if the output of {!run_and_report} is not as expected. @param classname @@ -21,20 +21,13 @@ val wrap_test -> unit Alcotest.test_case -> unit Alcotest.test_case -(** [run ?argv n t] is a wrapper around {!Alcotest.run}, only setting - [and_exit] to false. It is mandatory to be able to process results - after the end of the run. - - Low level function. It is easier to use {!run_and_report}. *) -val run : ?argv:string array -> string -> unit Alcotest.test list -> unit - (** [exit ()] exits with appropriate code if {!run_and_report}'s [and_exit] was [true] or raise {!Alcotest.Test_error} in case of error. *) type exit = unit -> unit -(** [run_and_report name tests] is a wrapper around {!run} and {!wrap_test}. It - runs the tests and creates a Junit testsuite from the results. +(** [run_and_report name tests] is a wrapper around {!Alcotest.run} and {!wrap_test}. + It runs the tests and creates a Junit testsuite from the results. As {!Alcotest.run} is always called with [and_exit = false] to be able to produce a report, the behavior is emulated by the returned @@ -49,10 +42,10 @@ type exit = unit -> unit [?argv] is forwarded to {!run}. [?package] and [?timestamp] are forwarded to {!Junit.Testsuite.make}. *) val run_and_report - : ?and_exit:bool - -> ?package:string - -> ?timestamp:Ptime.t - -> ?argv:string array - -> string - -> (string * unit Alcotest.test_case list) list - -> Junit.Testsuite.t * exit + : (?package:string + -> ?timestamp:Ptime.t + -> ?argv:string array + -> string + -> (string * unit Alcotest.test_case list) list + -> Junit.Testsuite.t * exit) + Alcotest.with_options diff --git a/alcotest/test/alcotest_report.expected b/alcotest/test/alcotest_report.expected index cd0c37c..072574f 100644 --- a/alcotest/test/alcotest_report.expected +++ b/alcotest/test/alcotest_report.expected @@ -1,12 +1,12 @@ Invalid_argument("7")Alcotest assertion failure -File "alcotest/junit_alcotest.ml", line 20, character 6: +File "alcotest/junit_alcotest.ml", line 22, character 6: FAIL string_of_int equals to '7' Expected: `"7"' Received: `"8"' Invalid_argument("7")Alcotest assertion failure -File "alcotest/junit_alcotest.ml", line 20, character 6: +File "alcotest/junit_alcotest.ml", line 22, character 6: FAIL string_of_int equals to '7' Expected: `"7"' diff --git a/junit_alcotest.opam b/junit_alcotest.opam index f8aa7d2..1f636b6 100644 --- a/junit_alcotest.opam +++ b/junit_alcotest.opam @@ -10,7 +10,7 @@ tags: ["junit" "jenkins" "alcotest"] depends: [ "dune" {>= "3.0"} "odoc" {with-doc & >= "1.1.1"} - "alcotest" {>= "1.7.0"} + "alcotest" {>= "1.8.0"} "junit" {= version} "ocamlformat" {= "0.27.0" & with-dev-setup} ]