naccyde / rpms / systemd

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