test: expand the expression in cleanup_initdir()

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'
```
This commit is contained in:
Frantisek Sumsal 2022-10-01 21:56:08 +02:00 committed by Luca Boccassi
parent 3d0c1256b4
commit 9caab7b559

View File

@ -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() {