Skip to content

Commit

Permalink
Merge pull request #395 from martin-schulze-vireso/bugfix/dont_remove…
Browse files Browse the repository at this point in the history
…_preprocessed_files_with_--no-tempdir-cleanup

Don't remove preprocessed files with --no-tempdir-cleanup
  • Loading branch information
martin-schulze-vireso committed Jan 22, 2021
2 parents aa6f2ca + 6c2d708 commit 2905040
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
6 changes: 0 additions & 6 deletions lib/bats-core/preprocessing.bash
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ bats_preprocess_source() {
# since the latter runs in bats-exec-test's bash while this runs in bats-exec-file's
export BATS_TEST_SOURCE="${BATS_TMPNAME}.src"
bats-preprocess "$BATS_TEST_FILENAME" >"$BATS_TEST_SOURCE"
trap 'bats_cleanup_preprocessed_source' ERR EXIT
trap 'bats_cleanup_preprocessed_source; exit 1' INT
}

bats_cleanup_preprocessed_source() {
rm -f "$BATS_TEST_SOURCE"
}

bats_evaluate_preprocessed_source() {
Expand Down
10 changes: 7 additions & 3 deletions libexec/bats-core/bats
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ formatter_flags=('--dummy-flag') # add a dummy flag to prevent unset varialeb er
formatter='tap'
report_formatter=''
recursive=
tempdir_cleanup=1
export BATS_TEMPDIR_CLEANUP=1
output=
if [[ -z "${CI:-}" && -t 0 && -t 1 ]] && command -v tput >/dev/null; then
formatter='pretty'
Expand Down Expand Up @@ -184,7 +184,11 @@ while [[ "$#" -ne 0 ]]; do
flags+=("--no-parallelize-within-files")
;;
--no-tempdir-cleanup)
tempdir_cleanup=''
BATS_TEMPDIR_CLEANUP=''
;;
--tempdir) # for internal test consumption only!
BATS_RUN_TMPDIR="$2"
shift
;;
-*)
abort "Bad command line option '$1'"
Expand All @@ -202,7 +206,7 @@ if [[ -d "$BATS_RUN_TMPDIR" ]]; then
exit 1
fi
mkdir -p "$BATS_RUN_TMPDIR"
if [[ -n "$tempdir_cleanup" ]]; then
if [[ -n "$BATS_TEMPDIR_CLEANUP" ]]; then
trap 'rm -rf "$BATS_RUN_TMPDIR"' ERR EXIT
fi

Expand Down
1 change: 0 additions & 1 deletion libexec/bats-core/bats-exec-file
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ bats_file_exit_trap() {
rm -rf "$BATS_OUT"
status=1
fi
bats_cleanup_preprocessed_source
exit $status
}

Expand Down
17 changes: 17 additions & 0 deletions test/bats.bats
Original file line number Diff line number Diff line change
Expand Up @@ -717,3 +717,20 @@ END_OF_ERR_MSG
[ "${lines[1]}" = "ok 1 a passing test" ]
[ ${#lines[@]} = 2 ]
}

@test "run tmpdir is cleaned up by default" {
TEST_TMPDIR="${BATS_RUN_TMPDIR}/$BATS_TEST_NAME"
bats --tempdir "$TEST_TMPDIR" "$FIXTURE_ROOT/passing.bats"

[ ! -d "$TEST_TMPDIR" ]
}

@test "run tmpdir is not cleanup up with --no-cleanup-tempdir" {
TEST_TMPDIR="${BATS_RUN_TMPDIR}/$BATS_TEST_NAME"
bats --tempdir "$TEST_TMPDIR" --no-tempdir-cleanup "$FIXTURE_ROOT/passing.bats"

[ -d "$TEST_TMPDIR" ]

# should also find preprocessed files!
[ $(find "$TEST_TMPDIR" -name '*.src' | wc -l) -eq 1 ]
}

0 comments on commit 2905040

Please sign in to comment.