From 488f32c5d4f16a23e3f2e74efc5701bd9c7b51b9 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Thu, 21 Oct 2021 15:10:05 -0600 Subject: [PATCH] fix(cram): remove cram file after it is read Tests shouldn't be able to observe the test files. However, we must restore the file if we observe a diff. Signed-off-by: Rudi Grinberg ps-id: 9962A972-82F0-4FB5-A8C9-D9B91083F09C --- src/dune_rules/cram_exec.ml | 8 ++++++++ test/blackbox-tests/test-cases/github3857.t | 1 - test/blackbox-tests/test-cases/menhir/promote.t/run.t | 1 - .../blackbox-tests/test-cases/meta-template-version-bug.t | 1 + 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/dune_rules/cram_exec.ml b/src/dune_rules/cram_exec.ml index b2042a405a7..7f462a8e724 100644 --- a/src/dune_rules/cram_exec.ml +++ b/src/dune_rules/cram_exec.ml @@ -135,6 +135,12 @@ let cram_stanzas lexbuf = let run_expect_test file ~f = let file_contents = Io.read_file ~binary:false file in + (* Nasty hack so that the user doesn't observe the test file while running the + test. + + Eventually, we should just have a way to read the source from outside the + sandbox. *) + Path.unlink_no_err file; let open Fiber.O in let+ expected = let lexbuf = @@ -144,6 +150,8 @@ let run_expect_test file ~f = in let corrected_file = Path.extend_basename file ~suffix:".corrected" in if file_contents <> expected then + (* we only need to restore the test file so the diff doesn't fail *) + let () = Io.write_file file file_contents in Io.write_file ~binary:false corrected_file expected else if Path.exists corrected_file then Path.rm_rf corrected_file diff --git a/test/blackbox-tests/test-cases/github3857.t b/test/blackbox-tests/test-cases/github3857.t index c39f305aa35..115607514db 100644 --- a/test/blackbox-tests/test-cases/github3857.t +++ b/test/blackbox-tests/test-cases/github3857.t @@ -3,4 +3,3 @@ dune install should not write anything to _build/ $ dune install --prefix _install $ ls . dune-project - github3857.t diff --git a/test/blackbox-tests/test-cases/menhir/promote.t/run.t b/test/blackbox-tests/test-cases/menhir/promote.t/run.t index cdc3cfe6538..69409ff8990 100644 --- a/test/blackbox-tests/test-cases/menhir/promote.t/run.t +++ b/test/blackbox-tests/test-cases/menhir/promote.t/run.t @@ -14,4 +14,3 @@ Check what is being generated exactly: parser.ml parser.mli parser.mly - run.t diff --git a/test/blackbox-tests/test-cases/meta-template-version-bug.t b/test/blackbox-tests/test-cases/meta-template-version-bug.t index 121ec4655e7..21cbdf81bdd 100644 --- a/test/blackbox-tests/test-cases/meta-template-version-bug.t +++ b/test/blackbox-tests/test-cases/meta-template-version-bug.t @@ -2,6 +2,7 @@ This test demonstrates a bug when there's a package with a meta template and a custom version: $ git init -q + $ touch foo $ git add . $ git commit -qm _ $ git tag -a 1.0 -m 1.0