[PATCH v2] Clean up temporary directories

5 views
Skip to first unread message

Earl Chew

unread,
Aug 8, 2023, 10:24:07 AM8/8/23
to efibootg...@googlegroups.com, earl...@yahoo.com, michae...@siemens.com
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

Jan Kiszka

unread,
Aug 8, 2023, 12:15:17 PM8/8/23
to Earl Chew, efibootg...@googlegroups.com, michae...@siemens.com
On 08.08.23 16:23, 'Earl Chew' via EFI Boot Guard wrote:
> 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.

The world is larger than Ubuntu - we can drop that reference here.

That means we will continue to leave the temp folder behind for older
versions of bats. Fine with me, maybe just state that explicitly in the
commit message.

Jan
Siemens AG, Technology
Linux Expert Center

Jan Kiszka

unread,
Aug 9, 2023, 9:06:13 AM8/9/23
to Earl Chew, efibootg...@googlegroups.com, michae...@siemens.com
On 08.08.23 18:15, 'Jan Kiszka' via EFI Boot Guard wrote:
> On 08.08.23 16:23, 'Earl Chew' via EFI Boot Guard wrote:
>> 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.
>
> The world is larger than Ubuntu - we can drop that reference here.
>
> That means we will continue to leave the temp folder behind for older
> versions of bats. Fine with me, maybe just state that explicitly in the
> commit message.
>

I've done that myself now and applied the result to next.

Thanks,
Jan

Earl Chew

unread,
Aug 9, 2023, 9:37:40 AM8/9/23
to Jan Kiszka, efibootg...@googlegroups.com, michae...@siemens.com

On 2023-08-09 06:06, Jan Kiszka wrote:
> I've done that myself now and applied the result to next.

Ok, thanks for taking care of that.

Earl
Reply all
Reply to author
Forward
0 new messages