21255d
From 2e50a00f6930f1c65ca804b78f4a853e2ae2d2c0 Mon Sep 17 00:00:00 2001
21255d
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
21255d
Date: Tue, 17 Nov 2020 17:13:31 +0100
21255d
Subject: [PATCH] test/udev-test: gracefully exit when imports fail
21255d
21255d
In Fedora rawhide various perl modules are now available as separate
21255d
packages that are not pulled in by dependencies. If we don't have some
21255d
package, skip the tests.
21255d
21255d
This ugly code is apparently the way to do conditional imports:
21255d
https://www.cs.ait.ac.th/~on/O/oreilly/perl/cookbook/ch12_03.htm.
21255d
21255d
(cherry picked from commit d40763838278246e2073d15ca927ee700e583afc)
21255d
21255d
Related: #1642728
21255d
---
21255d
 test/udev-test.pl | 18 +++++++++++++-----
21255d
 1 file changed, 13 insertions(+), 5 deletions(-)
21255d
21255d
diff --git a/test/udev-test.pl b/test/udev-test.pl
21255d
index cf6ca6b80c..5b1e33504e 100755
21255d
--- a/test/udev-test.pl
21255d
+++ b/test/udev-test.pl
21255d
@@ -18,11 +18,19 @@
21255d
 
21255d
 use warnings;
21255d
 use strict;
21255d
-use POSIX qw(WIFEXITED WEXITSTATUS);
21255d
-use IPC::SysV qw(IPC_PRIVATE S_IRUSR S_IWUSR IPC_CREAT);
21255d
-use IPC::Semaphore;
21255d
-use Time::HiRes qw(usleep);
21255d
-use Cwd qw(getcwd abs_path);
21255d
+
21255d
+BEGIN {
21255d
+    my $EXIT_TEST_SKIP = 77;
21255d
+
21255d
+    unless (eval "use POSIX qw(WIFEXITED WEXITSTATUS);
21255d
+                  use Cwd qw(getcwd abs_path);
21255d
+                  use IPC::Semaphore;
21255d
+                  use IPC::SysV qw(IPC_PRIVATE S_IRUSR S_IWUSR IPC_CREAT);
21255d
+                  use Time::HiRes qw(usleep); 1") {
21255d
+        warn "Failed to import dependencies, skipping the test: $@";
21255d
+        exit($EXIT_TEST_SKIP);
21255d
+    }
21255d
+}
21255d
 
21255d
 my $udev_bin            = "./test-udev";
21255d
 my $valgrind            = 0;