|
|
594167 |
From 3c469acda5f5d62d56a16f075475c3b4f1da75e1 Mon Sep 17 00:00:00 2001
|
|
|
594167 |
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
|
|
594167 |
Date: Fri, 25 Mar 2022 15:56:16 +0100
|
|
|
594167 |
Subject: [PATCH] test-systemctl-enable: use magic syntax to allow inverted
|
|
|
594167 |
tests
|
|
|
594167 |
MIME-Version: 1.0
|
|
|
594167 |
Content-Type: text/plain; charset=UTF-8
|
|
|
594167 |
Content-Transfer-Encoding: 8bit
|
|
|
594167 |
|
|
|
594167 |
Inspired by 7910ec3bcde2ee0086b3e49f8aaa2a9f13f58d97.
|
|
|
594167 |
'! true' passes, because it's a conditional expression.
|
|
|
594167 |
But '( ! true )' fails, because '( … )' creates a subshell, i.e. a separate
|
|
|
594167 |
program, and '! true' becomes the return value of that program, and the whole
|
|
|
594167 |
thing apparently is not a conditional expression for the outer shell.
|
|
|
594167 |
|
|
|
594167 |
This is shorter, so let's just do this.
|
|
|
594167 |
|
|
|
594167 |
(cherry picked from commit d6c51c485abe0026a5da654fca5d6c1457c4587d)
|
|
|
594167 |
|
|
|
594167 |
Related: #2082131
|
|
|
594167 |
---
|
|
|
594167 |
test/test-systemctl-enable.sh | 76 ++++++++++++++++++-----------------
|
|
|
594167 |
1 file changed, 39 insertions(+), 37 deletions(-)
|
|
|
594167 |
|
|
|
594167 |
diff --git a/test/test-systemctl-enable.sh b/test/test-systemctl-enable.sh
|
|
|
594167 |
index 0f66af309a..ecb433380e 100644
|
|
|
594167 |
--- a/test/test-systemctl-enable.sh
|
|
|
594167 |
+++ b/test/test-systemctl-enable.sh
|
|
|
594167 |
@@ -20,7 +20,7 @@ islink() {
|
|
|
594167 |
}
|
|
|
594167 |
|
|
|
594167 |
: '------enable nonexistent------------------------------------'
|
|
|
594167 |
-"$systemctl" --root="$root" enable test1.service && { echo "Expected failure" >&2; exit 1; }
|
|
|
594167 |
+( ! "$systemctl" --root="$root" enable test1.service )
|
|
|
594167 |
|
|
|
594167 |
: '------basic enablement--------------------------------------'
|
|
|
594167 |
mkdir -p "$root/etc/systemd/system"
|
|
|
594167 |
@@ -86,7 +86,7 @@ Alias=test1-badalias.socket
|
|
|
594167 |
Alias=test1-goodalias2.service
|
|
|
594167 |
EOF
|
|
|
594167 |
|
|
|
594167 |
-"$systemctl" --root="$root" enable test1 && { echo "Expected failure" >&2; exit 1; }
|
|
|
594167 |
+( ! "$systemctl" --root="$root" enable test1 )
|
|
|
594167 |
test -h "$root/etc/systemd/system/default.target.wants/test1.service"
|
|
|
594167 |
test -h "$root/etc/systemd/system/special.target.requires/test1.service"
|
|
|
594167 |
test -e "$root/etc/systemd/system/test1-goodalias.service"
|
|
|
594167 |
@@ -98,7 +98,7 @@ test -e "$root/etc/systemd/system/test1-goodalias2.service"
|
|
|
594167 |
test -h "$root/etc/systemd/system/test1-goodalias2.service"
|
|
|
594167 |
|
|
|
594167 |
: '-------aliases in reeanble----------------------------------'
|
|
|
594167 |
-"$systemctl" --root="$root" reenable test1 && { echo "Expected failure" >&2; exit 1; }
|
|
|
594167 |
+( ! "$systemctl" --root="$root" reenable test1 )
|
|
|
594167 |
islink "$root/etc/systemd/system/default.target.wants/test1.service" "../test1.service"
|
|
|
594167 |
islink "$root/etc/systemd/system/test1-goodalias.service" "test1.service"
|
|
|
594167 |
|
|
|
594167 |
@@ -154,7 +154,7 @@ test ! -e "$root/etc/systemd/system/sockets.target.wants/test2.socket"
|
|
|
594167 |
: '-------link-------------------------------------------------'
|
|
|
594167 |
# File doesn't exist yet
|
|
|
594167 |
test ! -e "$root/link1.path"
|
|
|
594167 |
-"$systemctl" --root="$root" link '/link1.path' && { echo "Expected failure" >&2; exit 1; }
|
|
|
594167 |
+( ! "$systemctl" --root="$root" link '/link1.path' )
|
|
|
594167 |
test ! -e "$root/etc/systemd/system/link1.path"
|
|
|
594167 |
|
|
|
594167 |
cat >"$root/link1.path" <
|
|
|
594167 |
@@ -172,12 +172,12 @@ islink "$root/etc/systemd/system/link1.path" "/link1.path"
|
|
|
594167 |
: '-------link already linked different path-------------------'
|
|
|
594167 |
mkdir "$root/subdir"
|
|
|
594167 |
cp "$root/link1.path" "$root/subdir/"
|
|
|
594167 |
-"$systemctl" --root="$root" link '/subdir/link1.path' && { echo "Expected failure" >&2; exit 1; }
|
|
|
594167 |
+( ! "$systemctl" --root="$root" link '/subdir/link1.path' )
|
|
|
594167 |
islink "$root/etc/systemd/system/link1.path" "/link1.path"
|
|
|
594167 |
|
|
|
594167 |
: '-------link bad suffix--------------------------------------'
|
|
|
594167 |
cp "$root/link1.path" "$root/subdir/link1.suffix"
|
|
|
594167 |
-"$systemctl" --root="$root" link '/subdir/link1.suffix' && { echo "Expected failure" >&2; exit 1; }
|
|
|
594167 |
+( ! "$systemctl" --root="$root" link '/subdir/link1.suffix' )
|
|
|
594167 |
test ! -e "$root/etc/systemd/system/link1.suffix"
|
|
|
594167 |
|
|
|
594167 |
: '-------unlink by unit name----------------------------------'
|
|
|
594167 |
@@ -208,13 +208,13 @@ islink "$root/etc/systemd/system/link1.path" "/link1.path"
|
|
|
594167 |
islink "$root/etc/systemd/system/paths.target.wants/link1.path" "../link1.path"
|
|
|
594167 |
|
|
|
594167 |
: '-------enable already linked different path-----------------'
|
|
|
594167 |
-"$systemctl" --root="$root" enable '/subdir/link1.path' && { echo "Expected failure" >&2; exit 1; }
|
|
|
594167 |
+( ! "$systemctl" --root="$root" enable '/subdir/link1.path' )
|
|
|
594167 |
islink "$root/etc/systemd/system/link1.path" "/link1.path"
|
|
|
594167 |
islink "$root/etc/systemd/system/paths.target.wants/link1.path" "../link1.path"
|
|
|
594167 |
|
|
|
594167 |
: '-------enable bad suffix------------------------------------'
|
|
|
594167 |
cp "$root/link1.path" "$root/subdir/link1.suffix"
|
|
|
594167 |
-"$systemctl" --root="$root" enable '/subdir/link1.suffix' && { echo "Expected failure" >&2; exit 1; }
|
|
|
594167 |
+( ! "$systemctl" --root="$root" enable '/subdir/link1.suffix' )
|
|
|
594167 |
test ! -e "$root/etc/systemd/system/link1.suffix"
|
|
|
594167 |
test ! -e "$root/etc/systemd/system/paths.target.wants/link1.suffix"
|
|
|
594167 |
|
|
|
594167 |
@@ -264,14 +264,14 @@ test ! -h "$root/etc/systemd/system/services.target.wants/link3.service"
|
|
|
594167 |
|
|
|
594167 |
: '-------enable on masked-------------------------------------'
|
|
|
594167 |
ln -s "/dev/null" "$root/etc/systemd/system/masked.service"
|
|
|
594167 |
-"$systemctl" --root="$root" enable 'masked.service' && { echo "Expected failure" >&2; exit 1; }
|
|
|
594167 |
-"$systemctl" --root="$root" enable '/etc/systemd/system/masked.service' && { echo "Expected failure" >&2; exit 1; }
|
|
|
594167 |
+( ! "$systemctl" --root="$root" enable 'masked.service' )
|
|
|
594167 |
+( ! "$systemctl" --root="$root" enable '/etc/systemd/system/masked.service' )
|
|
|
594167 |
|
|
|
594167 |
: '-------enable on masked alias-------------------------------'
|
|
|
594167 |
test -h "$root/etc/systemd/system/masked.service"
|
|
|
594167 |
ln -s "masked.service" "$root/etc/systemd/system/masked-alias.service"
|
|
|
594167 |
-"$systemctl" --root="$root" enable 'masked-alias.service' && { echo "Expected failure" >&2; exit 1; }
|
|
|
594167 |
-"$systemctl" --root="$root" enable '/etc/systemd/system/masked-alias.service' && { echo "Expected failure" >&2; exit 1; }
|
|
|
594167 |
+( ! "$systemctl" --root="$root" enable 'masked-alias.service' )
|
|
|
594167 |
+( ! "$systemctl" --root="$root" enable '/etc/systemd/system/masked-alias.service' )
|
|
|
594167 |
|
|
|
594167 |
: '-------issue 22000: link in subdirectory--------------------'
|
|
|
594167 |
mkdir -p "$root/etc/systemd/system/myown.d"
|
|
|
594167 |
@@ -286,7 +286,7 @@ WantedBy=services.target
|
|
|
594167 |
Also=link5-also.service
|
|
|
594167 |
EOF
|
|
|
594167 |
|
|
|
594167 |
-"$systemctl" --root="$root" enable 'link5.service' && { echo "Expected failure" >&2; exit 1; }
|
|
|
594167 |
+( ! "$systemctl" --root="$root" enable 'link5.service' )
|
|
|
594167 |
test ! -h "$root/etc/systemd/system/services.target.wants/link5.service"
|
|
|
594167 |
test ! -h "$root/etc/systemd/system/services.target.wants/link5-also.service"
|
|
|
594167 |
|
|
|
594167 |
@@ -301,7 +301,7 @@ WantedBy=services.target
|
|
|
594167 |
EOF
|
|
|
594167 |
|
|
|
594167 |
# No instance here — this can't succeed.
|
|
|
594167 |
-"$systemctl" --root="$root" enable 'templ1@.service' && { echo "Expected failure" >&2; exit 1; }
|
|
|
594167 |
+( ! "$systemctl" --root="$root" enable 'templ1@.service' )
|
|
|
594167 |
test ! -h "$root/etc/systemd/system/services.target.wants/templ1@.service"
|
|
|
594167 |
|
|
|
594167 |
"$systemctl" --root="$root" enable 'templ1@one.service'
|
|
|
594167 |
@@ -428,7 +428,7 @@ Alias=link4alias.service
|
|
|
594167 |
Alias=link4alias2.service
|
|
|
594167 |
EOF
|
|
|
594167 |
|
|
|
594167 |
-"$systemctl" --root="$root" enable 'link4.service' && { echo "Expected failure" >&2; exit 1; }
|
|
|
594167 |
+( ! "$systemctl" --root="$root" enable 'link4.service' )
|
|
|
594167 |
test ! -h "$root/etc/systemd/system/link4.service" # this is our file
|
|
|
594167 |
test ! -h "$root/etc/systemd/system/link4@.service"
|
|
|
594167 |
test ! -h "$root/etc/systemd/system/link4@inst.service"
|
|
|
594167 |
@@ -571,12 +571,12 @@ check_alias a "$(uname -m | tr '_' '-')"
|
|
|
594167 |
test ! -e "$root/etc/os-release"
|
|
|
594167 |
test ! -e "$root/usr/lib/os-release"
|
|
|
594167 |
|
|
|
594167 |
-check_alias A '' && { echo "Expected failure" >&2; exit 1; }
|
|
|
594167 |
-check_alias B '' && { echo "Expected failure" >&2; exit 1; }
|
|
|
594167 |
-check_alias M '' && { echo "Expected failure" >&2; exit 1; }
|
|
|
594167 |
-check_alias o '' && { echo "Expected failure" >&2; exit 1; }
|
|
|
594167 |
-check_alias w '' && { echo "Expected failure" >&2; exit 1; }
|
|
|
594167 |
-check_alias W '' && { echo "Expected failure" >&2; exit 1; }
|
|
|
594167 |
+( ! check_alias A '' )
|
|
|
594167 |
+( ! check_alias B '' )
|
|
|
594167 |
+( ! check_alias M '' )
|
|
|
594167 |
+( ! check_alias o '' )
|
|
|
594167 |
+( ! check_alias w '' )
|
|
|
594167 |
+( ! check_alias W '' )
|
|
|
594167 |
|
|
|
594167 |
cat >"$root/etc/os-release" <
|
|
|
594167 |
# empty
|
|
|
594167 |
@@ -609,19 +609,19 @@ check_alias W 'right'
|
|
|
594167 |
check_alias b "$(systemd-id128 boot-id)"
|
|
|
594167 |
|
|
|
594167 |
# Specifiers not available for [Install]
|
|
|
594167 |
-check_alias C '' && { echo "Expected failure" >&2; exit 1; }
|
|
|
594167 |
-check_alias E '' && { echo "Expected failure" >&2; exit 1; }
|
|
|
594167 |
-check_alias f '' && { echo "Expected failure" >&2; exit 1; }
|
|
|
594167 |
-check_alias h '' && { echo "Expected failure" >&2; exit 1; }
|
|
|
594167 |
-check_alias I '' && { echo "Expected failure" >&2; exit 1; }
|
|
|
594167 |
-check_alias J '' && { echo "Expected failure" >&2; exit 1; }
|
|
|
594167 |
-check_alias L '' && { echo "Expected failure" >&2; exit 1; }
|
|
|
594167 |
-check_alias P '' && { echo "Expected failure" >&2; exit 1; }
|
|
|
594167 |
-check_alias s '' && { echo "Expected failure" >&2; exit 1; }
|
|
|
594167 |
-check_alias S '' && { echo "Expected failure" >&2; exit 1; }
|
|
|
594167 |
-check_alias t '' && { echo "Expected failure" >&2; exit 1; }
|
|
|
594167 |
-check_alias T '' && { echo "Expected failure" >&2; exit 1; }
|
|
|
594167 |
-check_alias V '' && { echo "Expected failure" >&2; exit 1; }
|
|
|
594167 |
+( ! check_alias C '' )
|
|
|
594167 |
+( ! check_alias E '' )
|
|
|
594167 |
+( ! check_alias f '' )
|
|
|
594167 |
+( ! check_alias h '' )
|
|
|
594167 |
+( ! check_alias I '' )
|
|
|
594167 |
+( ! check_alias J '' )
|
|
|
594167 |
+( ! check_alias L '' )
|
|
|
594167 |
+( ! check_alias P '' )
|
|
|
594167 |
+( ! check_alias s '' )
|
|
|
594167 |
+( ! check_alias S '' )
|
|
|
594167 |
+( ! check_alias t '' )
|
|
|
594167 |
+( ! check_alias T '' )
|
|
|
594167 |
+( ! check_alias V '' )
|
|
|
594167 |
|
|
|
594167 |
check_alias g root
|
|
|
594167 |
check_alias G 0
|
|
|
594167 |
@@ -635,7 +635,7 @@ check_alias j 'link6'
|
|
|
594167 |
check_alias l "$(uname -n | sed 's/\..*//')"
|
|
|
594167 |
|
|
|
594167 |
test ! -e "$root/etc/machine-id"
|
|
|
594167 |
-check_alias m '' && { echo "Expected failure" >&2; exit 1; }
|
|
|
594167 |
+( ! check_alias m '' )
|
|
|
594167 |
|
|
|
594167 |
systemd-id128 new >"$root/etc/machine-id"
|
|
|
594167 |
check_alias m "$(cat "$root/etc/machine-id")"
|
|
|
594167 |
@@ -647,9 +647,11 @@ check_alias p 'some-some-link6'
|
|
|
594167 |
|
|
|
594167 |
check_alias v "$(uname -r)"
|
|
|
594167 |
|
|
|
594167 |
-check_alias % '%' && { echo "Expected failure because % is not legal in unit name" >&2; exit 1; }
|
|
|
594167 |
+# % is not legal in unit name
|
|
|
594167 |
+( ! check_alias % '%' )
|
|
|
594167 |
|
|
|
594167 |
-check_alias z 'z' && { echo "Expected failure because %z is not known" >&2; exit 1; }
|
|
|
594167 |
+# %z is not defined
|
|
|
594167 |
+( ! check_alias z 'z' )
|
|
|
594167 |
|
|
|
594167 |
: '-------specifiers in WantedBy-------------------------------'
|
|
|
594167 |
# We don't need to repeat all the tests. Let's do a basic check that specifier
|