From 0c95e842adcd5a6af9eaf1ff82bde9cb0fff4b42 Mon Sep 17 00:00:00 2001 From: William Melody Date: Sun, 24 Jan 2016 22:31:42 -0800 Subject: [PATCH] Use /tmp directory for temp file generated with `mktemp`. Moving to `mktemp` with files in /tmp makes it possible to remove the local test/tmp directory. --- .gitignore | 2 -- test/test_helper.bash | 11 ++++++++--- test/tmp/.keep | 0 3 files changed, 8 insertions(+), 5 deletions(-) delete mode 100644 .gitignore delete mode 100644 test/tmp/.keep diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 1c0271c..0000000 --- a/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -test/tmp/* -!test/tmp/.keep diff --git a/test/test_helper.bash b/test/test_helper.bash index e536b5c..e3ee447 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -4,10 +4,15 @@ setup() { # The location of the `hosts` script being tested. export _HOSTS="${BATS_TEST_DIRNAME}/../hosts" - export HOSTS_PATH="${BATS_TEST_DIRNAME}/tmp/hosts" - cp "${BATS_TEST_DIRNAME}/fixtures/hosts" "${BATS_TEST_DIRNAME}/tmp/hosts" + export HOSTS_PATH="$(mktemp /tmp/hosts_test.XXXXXX)" || exit 1 + cat "${BATS_TEST_DIRNAME}/fixtures/hosts" > "${HOSTS_PATH}" } teardown() { - rm "${BATS_TEST_DIRNAME}/tmp/hosts" + if [[ -n "${HOSTS_PATH}" ]] && + [[ -e "${HOSTS_PATH}" ]] && + [[ "${HOSTS_PATH}" =~ ^/tmp ]] + then + rm "${HOSTS_PATH}" + fi } diff --git a/test/tmp/.keep b/test/tmp/.keep deleted file mode 100644 index e69de29..0000000