Move temp directory creation into test/utils

main
Brian Picciano 9 months ago
parent 73db21f841
commit 0a482607d5
  1. 2
      default.nix
  2. 3
      tests/cases/01-create-network.sh
  3. 14
      tests/entrypoint.sh
  4. 9
      tests/utils/with-tmp-for-case.sh

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

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

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

@ -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"
Loading…
Cancel
Save