]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test/udev-test: gracefully exit when imports fail
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 17 Nov 2020 16:13:31 +0000 (17:13 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 17 Nov 2020 18:50:17 +0000 (03:50 +0900)
In Fedora rawhide various perl modules are now available as separate
packages that are not pulled in by dependencies. If we don't have some
package, skip the tests.

This ugly code is apparently the way to do conditional imports:
https://www.cs.ait.ac.th/~on/O/oreilly/perl/cookbook/ch12_03.htm.

test/udev-test.pl

index cf6ca6b80cefaaef011e85b60c3702b159241498..5b1e33504e0efc50b342e423106976faed5b0151 100755 (executable)
 
 use warnings;
 use strict;
-use POSIX qw(WIFEXITED WEXITSTATUS);
-use IPC::SysV qw(IPC_PRIVATE S_IRUSR S_IWUSR IPC_CREAT);
-use IPC::Semaphore;
-use Time::HiRes qw(usleep);
-use Cwd qw(getcwd abs_path);
+
+BEGIN {
+    my $EXIT_TEST_SKIP = 77;
+
+    unless (eval "use POSIX qw(WIFEXITED WEXITSTATUS);
+                  use Cwd qw(getcwd abs_path);
+                  use IPC::Semaphore;
+                  use IPC::SysV qw(IPC_PRIVATE S_IRUSR S_IWUSR IPC_CREAT);
+                  use Time::HiRes qw(usleep); 1") {
+        warn "Failed to import dependencies, skipping the test: $@";
+        exit($EXIT_TEST_SKIP);
+    }
+}
 
 my $udev_bin            = "./test-udev";
 my $valgrind            = 0;