Remove the temporary directory containing the test data to reduce clutter.
When diagnosing test failures, developers can use --no-tempdir-cleanup to
prevent BATS from removing test artifacts.
Signed-off-by: Earl Chew <
earl...@yahoo.com>
---
tests/bg_setenv.bats | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/tests/bg_setenv.bats b/tests/bg_setenv.bats
index 67cee8f..6d0249b 100755
--- a/tests/bg_setenv.bats
+++ b/tests/bg_setenv.bats
@@ -17,6 +17,13 @@ setup() {
# file respectively
DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )"
PATH="$DIR/..:$PATH"
+
+ # BATS_TEST_TMPDIR was introduced by BATS 1.4.0, and not available
+ # until Ubuntu 23.04.
+ [ -n "${BATS_TEST_TMPDIR:++}" ] || {
+ BATS_TEST_TMPDIR="$BATS_RUN_TMPDIR/test/$BATS_TEST_NUMBER"
+ mkdir -p "$BATS_TEST_TMPDIR"
+ }
}
create_sample_bgenv() {
@@ -29,7 +36,7 @@ create_sample_bgenv() {
@test "ensure BGENV.DAT backwards compatbility" {
local envfile
- envfile="$(mktemp -d)/BGENV.DAT"
+ envfile="$BATS_TEST_TMPDIR/BGENV.DAT"
create_sample_bgenv "$envfile"
run bg_printenv -f "$envfile"
@@ -50,7 +57,7 @@ foo = bar" ]]
@test "create an empty BGENV.DAT" {
local envfile
- envfile="$(mktemp -d)/BGENV.DAT"
+ envfile="$BATS_TEST_TMPDIR/BGENV.DAT"
run bg_setenv -f "$envfile"
[[ "$output" = "Output written to $envfile." ]]
@@ -72,7 +79,7 @@ user variables:" ]]
@test "modify BGENV, discard existing values" {
local envfile
- envfile="$(mktemp -d)/BGENV.DAT"
+ envfile="$BATS_TEST_TMPDIR/BGENV.DAT"
create_sample_bgenv "$envfile"
run bg_setenv -f "$envfile" -k C:BOOTNEW:kernel.efi
@@ -94,7 +101,7 @@ user variables:" ]]
@test "modify BGENV, preserve existing values" {
local envfile
- envfile="$(mktemp -d)/BGENV.DAT"
+ envfile="$BATS_TEST_TMPDIR/BGENV.DAT"
create_sample_bgenv "$envfile"
run bg_setenv -f "$envfile" -k C:BOOTNEW:kernel.efi -P
@@ -117,7 +124,7 @@ foo = bar" ]]
@test "bg_printenv ustate" {
local envfile
- envfile="$(mktemp -d)/BGENV.DAT"
+ envfile="$BATS_TEST_TMPDIR/BGENV.DAT"
create_sample_bgenv "$envfile"
run bg_printenv "--filepath=$envfile" --output ustate
@@ -127,7 +134,7 @@ ustate: 0 (OK)" ]]
@test "bg_printenv with all fields is the same as omitting fields" {
local envfile
- envfile="$(mktemp -d)/BGENV.DAT"
+ envfile="$BATS_TEST_TMPDIR/BGENV.DAT"
create_sample_bgenv "$envfile"
expected_output=$(bg_printenv "--filepath=$envfile")
@@ -137,7 +144,7 @@ ustate: 0 (OK)" ]]
@test "bg_printenv ustate raw" {
local envfile
- envfile="$(mktemp -d)/BGENV.DAT"
+ envfile="$BATS_TEST_TMPDIR/BGENV.DAT"
create_sample_bgenv "$envfile"
run bg_printenv "--filepath=$envfile" --output ustate --raw
@@ -146,7 +153,7 @@ ustate: 0 (OK)" ]]
@test "bg_printenv multiple fields raw" {
local envfile
- envfile="$(mktemp -d)/BGENV.DAT"
+ envfile="$BATS_TEST_TMPDIR/BGENV.DAT"
create_sample_bgenv "$envfile"
run bg_printenv "--filepath=$envfile" --output ustate,kernel,kernelargs --raw
--
2.39.1