From 9caab7b5591c3bc6575b8678d011529ae6e0fc0e Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Sat, 1 Oct 2022 21:56:08 +0200 Subject: [PATCH] test: expand the expression in `cleanup_initdir()` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Otherwise we might unexpectedly return 1 if the `get_bool` call fails. If the `get_bool` part in `get_bool "$TEST_SETUP_CLEANUP_ROOTDIR" && _umount_dir "${initdir:?}"` fails, the whole expression will short-circuit evaluate to 1, and since it's the last expression in the function it's also it's return value, which doesn't reflect the original intent of the expression: ``` # BUILD_DIR=$PWD/build make -C test/TEST-64-UDEV-STORAGE/ setup run TESTCASES=testcase_always_skip make: Entering directory '/home/fsumsal/repos/@systemd/systemd/test/TEST-64-UDEV-STORAGE' TEST-64-UDEV-STORAGE SETUP: systemd-udev storage tests Reusing existing image /var/tmp/systemd-test.uPbJZ9/default.img → /var/tmp/systemd-test.uPbJZ9/default.img TEST-64-UDEV-STORAGE RUN: systemd-udev storage tests ------ testcase_always_skip: BEGIN ------ Skipping... ------ testcase_always_skip: END (SKIP) ------ Passed tests: 0 * Skipped tests: 1 * testcase_always_skip Failed tests: 0 * TEST-64-UDEV-STORAGE RUN: systemd-udev storage tests [OK] make: Leaving directory '/home/fsumsal/repos/@systemd/systemd/test/TEST-64-UDEV-STORAGE' # BUILD_DIR=$PWD/build make -C test/TEST-64-UDEV-STORAGE/ setup run TESTCASES=testcase_always_skip make: Entering directory '/home/fsumsal/repos/@systemd/systemd/test/TEST-64-UDEV-STORAGE' TEST-64-UDEV-STORAGE SETUP: systemd-udev storage tests Reusing existing image /var/tmp/systemd-test.uPbJZ9/default.img → /var/tmp/systemd-test.uPbJZ9/default.img make: *** [Makefile:4: setup] Error 1 make: Leaving directory '/home/fsumsal/repos/@systemd/systemd/test/TEST-64-UDEV-STORAGE' ``` --- test/test-functions | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/test-functions b/test/test-functions index e9da6e3d113..58860dc9447 100644 --- a/test/test-functions +++ b/test/test-functions @@ -1372,7 +1372,9 @@ mount_initdir() { cleanup_initdir() { # only umount if create_empty_image_rootdir() was called to mount it - get_bool "$TEST_SETUP_CLEANUP_ROOTDIR" && _umount_dir "${initdir:?}" + if get_bool "$TEST_SETUP_CLEANUP_ROOTDIR"; then + _umount_dir "${initdir:?}" + fi } umount_loopback() {