]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: expand the expression in `cleanup_initdir()`
authorFrantisek Sumsal <frantisek@sumsal.cz>
Sat, 1 Oct 2022 19:56:08 +0000 (21:56 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Sat, 1 Oct 2022 23:27:13 +0000 (00:27 +0100)
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

index e9da6e3d1133d7940ea3a1490a4847dee45ca791..58860dc94471c454bb7811c479b07937c8ccd593 100644 (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() {