From 47997e175c882d2ecdc88ecb7b59ce191574513e Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Wed, 19 Jun 2024 10:01:06 +0200 Subject: [PATCH 1/2] Allow expect_tests to be DCE by jsoo .. when setting FORCE_DROP_INLINE_TEST --- runtime/ppx_expect_runtime.ml | 2 ++ runtime/test_block.ml | 8 ++++++++ runtime/test_block.mli | 2 ++ src/ppx_expect.ml | 1 + 4 files changed, 13 insertions(+) diff --git a/runtime/ppx_expect_runtime.ml b/runtime/ppx_expect_runtime.ml index 403ba81..b5b02c5 100644 --- a/runtime/ppx_expect_runtime.ml +++ b/runtime/ppx_expect_runtime.ml @@ -128,3 +128,5 @@ module Write_corrected_file = Write_corrected_file module Make_test_block = Test_block.Make module For_external = Test_block.For_external module For_apply_style = Expectation.For_apply_style + +let tests_should_run = Test_block.tests_should_run diff --git a/runtime/test_block.ml b/runtime/test_block.ml index 11e85d6..a453ee7 100644 --- a/runtime/test_block.ml +++ b/runtime/test_block.ml @@ -159,6 +159,14 @@ module Configured (C : Expect_test_config_types.S) = struct ;; end +let tests_should_run = + try + ignore (Stdlib.Sys.getenv "FORCE_DROP_INLINE_TEST" : string); + false + with + | Not_found -> true +;; + (* The expect test currently being executed and some info we print if the program crashes in the middle of a test. *) module Current_test : sig diff --git a/runtime/test_block.mli b/runtime/test_block.mli index f9f0774..82e478f 100644 --- a/runtime/test_block.mli +++ b/runtime/test_block.mli @@ -90,6 +90,8 @@ module For_external : sig -> string end +val tests_should_run : bool + (** Action to perform when exiting from a program that runs expect tests. Alerts of runtime failure if the program exited while executing an expect test. *) val at_exit : unit -> unit diff --git a/src/ppx_expect.ml b/src/ppx_expect.ml index 42789f7..31a4486 100644 --- a/src/ppx_expect.ml +++ b/src/ppx_expect.ml @@ -207,6 +207,7 @@ let transform_let_expect ~trailing_location ~tags ~expected_exn ~description ~lo match Ppx_inline_test_lib.testing with | `Not_testing -> () | `Testing _ -> + if Ppx_expect_runtime.tests_should_run then let module Ppx_expect_test_block = Ppx_expect_runtime.Make_test_block (Expect_test_config) in From 01e5e458e01ec4764b7bfd3619dff50aaa248b36 Mon Sep 17 00:00:00 2001 From: hhugo Date: Tue, 27 Aug 2024 13:08:57 +0200 Subject: [PATCH 2/2] Update ppx_expect_runtime.ml --- runtime/ppx_expect_runtime.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/ppx_expect_runtime.ml b/runtime/ppx_expect_runtime.ml index 2179368..86a54ff 100644 --- a/runtime/ppx_expect_runtime.ml +++ b/runtime/ppx_expect_runtime.ml @@ -36,4 +36,4 @@ module Make_test_block = Test_block.Make module For_external = Test_block.For_external module For_apply_style = Test_spec.For_apply_style -let tests_should_run = Test_block.tests_should_run \ No newline at end of file +let tests_should_run = Test_block.tests_should_run