To reduce clutter in the temporary directory, group the test subdirectories in a common parent. On test success, remove the corresponding subdirectory that holds data for the test. The subdirectory is retained to aid diagnosis in the case that the test fails.
Signed-off-by: Earl Chew <[email protected]> --- tests/bg_setenv.bats | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/bg_setenv.bats b/tests/bg_setenv.bats index 67cee8f..aa38bb7 100755 --- a/tests/bg_setenv.bats +++ b/tests/bg_setenv.bats @@ -17,6 +17,19 @@ setup() { # file respectively DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )" PATH="$DIR/..:$PATH" + + # Place the temporaries in directory specific to the tests for + # the package to reduce the clutter in the parent directory. + export TMPDIR="${TMPDIR-/tmp}/efibootguardtest" + rm -rf "$TMPDIR" + mkdir -p "$TMPDIR" +} + +teardown() { + # Remove the temporary test directory if the tests succeeded + # and did not leave any partial computation. Otherwise leave + # information to help diagnose test failures. + find "$TMPDIR" -maxdepth 0 -type d -empty -delete } create_sample_bgenv() { @@ -46,6 +59,8 @@ foo = bar" ]] run md5sum "$envfile" [[ "$output" =~ ^6ad1dd1d98209a03d7b4fc2d2f16f9ec\s*.* ]] + + rm -rf "${envfile%/*}" } @test "create an empty BGENV.DAT" { @@ -68,6 +83,8 @@ watchdog timeout: 0 seconds ustate: 0 (OK) user variables:" ]] + + rm -rf "${envfile%/*}" } @test "modify BGENV, discard existing values" { @@ -90,6 +107,8 @@ user variables:" ]] run md5sum "$envfile" [[ "$output" =~ ^15bc40c9feae99cc879cfc55e0132caa\s*.* ]] + + rm -rf "${envfile%/*}" } @test "modify BGENV, preserve existing values" { @@ -113,6 +132,8 @@ foo = bar" ]] run md5sum "$envfile" [[ "$output" =~ ^a24b154a48e1f33b79b87e0fa5eff8a1\s*.* ]] + + rm -rf "${envfile%/*}" } @test "bg_printenv ustate" { @@ -123,6 +144,8 @@ foo = bar" ]] run bg_printenv "--filepath=$envfile" --output ustate [[ "$output" = "Values: ustate: 0 (OK)" ]] + + rm -rf "${envfile%/*}" } @test "bg_printenv with all fields is the same as omitting fields" { @@ -133,6 +156,8 @@ ustate: 0 (OK)" ]] expected_output=$(bg_printenv "--filepath=$envfile") run bg_printenv "--filepath=$envfile" --output in_progress,revision,kernel,kernelargs,watchdog_timeout,ustate,user [[ "$output" = "$expected_output" ]] + + rm -rf "${envfile%/*}" } @test "bg_printenv ustate raw" { @@ -142,6 +167,8 @@ ustate: 0 (OK)" ]] create_sample_bgenv "$envfile" run bg_printenv "--filepath=$envfile" --output ustate --raw [[ "$output" = "USTATE=0" ]] + + rm -rf "${envfile%/*}" } @test "bg_printenv multiple fields raw" { @@ -153,4 +180,6 @@ ustate: 0 (OK)" ]] [[ "$output" = "KERNEL=C:BOOT:kernel.efi KERNELARGS=root=/dev/sda USTATE=0" ]] + + rm -rf "${envfile%/*}" } -- 2.39.1 -- You received this message because you are subscribed to the Google Groups "EFI Boot Guard" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/efibootguard-dev/20230727005427.4016747-1-earl_chew%40yahoo.com.
