Skip to content

Commit

Permalink
fix(cram): remove cram file after it is read
Browse files Browse the repository at this point in the history
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 <[email protected]>

ps-id: 9962A972-82F0-4FB5-A8C9-D9B91083F09C
  • Loading branch information
rgrinberg committed Nov 4, 2021
1 parent b1fe9ef commit 488f32c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/dune_rules/cram_exec.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion test/blackbox-tests/test-cases/github3857.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ dune install should not write anything to _build/
$ dune install --prefix _install
$ ls .
dune-project
github3857.t
1 change: 0 additions & 1 deletion test/blackbox-tests/test-cases/menhir/promote.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ Check what is being generated exactly:
parser.ml
parser.mli
parser.mly
run.t
1 change: 1 addition & 0 deletions test/blackbox-tests/test-cases/meta-template-version-bug.t
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 488f32c

Please sign in to comment.