Move temp directory creation into test/utils

This commit is contained in:
Brian Picciano 2023-09-04 19:53:33 +02:00
parent 73db21f841
commit 0a482607d5
4 changed files with 21 additions and 7 deletions

View File

@ -171,6 +171,6 @@ in rec {
pkgs.yq-go pkgs.yq-go
]} ]}
export SHELL=${pkgs.bash}/bin/bash export SHELL=${pkgs.bash}/bin/bash
exec ${./tests}/entrypoint.sh "$@" exec ${pkgs.bash}/bin/bash ${./tests}/entrypoint.sh "$@"
''; '';
} }

View File

@ -1,3 +1,6 @@
# shellcheck source=../utils/with-tmp-for-case.sh
source "$UTILS"/with-tmp-for-case.sh
mkdir a mkdir a
mkdir b mkdir b
mkdir c mkdir c

14
tests/entrypoint.sh Executable file → Normal file
View File

@ -4,6 +4,8 @@ set -e
cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null
root=$(pwd) root=$(pwd)
export UTILS="$root"/utils
REGEXS=() REGEXS=()
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
@ -39,6 +41,11 @@ if [ -z "$KEEP_TMP" ]; then trap 'rm -rf $TMPDIR' EXIT; fi
export TMPDIR export TMPDIR
echo "tmp dir is $TMPDIR" echo "tmp dir is $TMPDIR"
# Blackhole these directories so that tests don't accidentally use the host's
# real ones.
export XDG_RUNTIME_DIR=/dev/null
export XDG_DATA_HOME=/dev/null
test_files=$( test_files=$(
find ./cases -type f -name '*.sh' \ find ./cases -type f -name '*.sh' \
| sed "s|^\./cases/||" \ | sed "s|^\./cases/||" \
@ -57,12 +64,7 @@ for file in $test_files; do
[ -z "$VERBOSE" ] && output="$TMPDIR/$file.log" || output=/dev/stdout [ -z "$VERBOSE" ] && output="$TMPDIR/$file.log" || output=/dev/stdout
( (
export TMPDIR="$TMPDIR/$file.tmp" export TEST_CASE_FILE="$file"
export XDG_RUNTIME_DIR="$TMPDIR/.run"
export XDG_DATA_HOME="$TMPDIR/.data"
mkdir -p "$TMPDIR" "$XDG_RUNTIME_DIR" "$XDG_DATA_HOME"
cd "$TMPDIR"
if ! $SHELL -e -x "$root/cases/$file" >"$output" 2>&1; then if ! $SHELL -e -x "$root/cases/$file" >"$output" 2>&1; then
echo "$file FAILED" echo "$file FAILED"

View File

@ -0,0 +1,9 @@
set -e
TMPDIR="$TMPDIR/$TEST_CASE_FILE.tmp"
XDG_RUNTIME_DIR="$TMPDIR/.run"
XDG_DATA_HOME="$TMPDIR/.data"
mkdir -p "$TMPDIR" "$XDG_RUNTIME_DIR" "$XDG_DATA_HOME"
cd "$TMPDIR"