Skip to content

Place SHELLSPEC_INFILE file under the temporary directory#361

Open
thanegill wants to merge 1 commit into
shellspec:masterfrom
thanegill:fix-infile-relative-path
Open

Place SHELLSPEC_INFILE file under the temporary directory#361
thanegill wants to merge 1 commit into
shellspec:masterfrom
thanegill:fix-infile-relative-path

Conversation

@thanegill
Copy link
Copy Markdown

When --random is used, the runner writes the shuffled spec list to $SHELLSPEC_INFILE, which defaults to the relative path file. This drops a stray file named file into the working/project directory, silently overwrites any existing ./file, and is never cleaned up, unlike every other internal scratch file.

Reproduce this issue with:

mkdir /tmp/shellspec_test && cd /tmp/shellspec_test
shellspec --init
echo 'IMPORTANT - do not delete' > file

shellspec --random specfiles      # also: --random examples

cat file        # -> overwritten with the spec list
ls file         # -> still present after shellspec exits

Along with this fix:

  • Added spec/random_no_stray_file_spec.sh: a regression spec parameterized over both --random specfiles and --random examples (the two paths through the write). It runs the binary in an isolated project and asserts the working directory gains no unexpected entries. Because the self-test suite runs under --sandbox, which makes PATH read-only, the nested binary is launched via a fresh sh -c with PATH restored from $SHELLSPEC_POSIX_PATH.
  • Also added a CHANGELOG.md entry under [Unreleased].

When --random is used, the runner writes the shuffled spec list to
$SHELLSPEC_INFILE, which defaulted to the relative path "file". That left a
stray "file" in the working/project directory, truncating any existing
./file, and — unlike every other internal scratch file, which lives under
$SHELLSPEC_TMPBASE and is removed by cleanup() — it was never cleaned up.

Set SHELLSPEC_INFILE to "$SHELLSPEC_TMPBASE/.shellspec-infile" alongside the
sibling temporary files so it is isolated, never clobbers a user's file, and
is removed on exit. Add a regression spec that runs the binary with --random
and asserts no stray file is left in the working directory.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant