guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[shepherd] 03/03: tests: Correctly check for expected failures.


From: Ludovic Courtès
Subject: [shepherd] 03/03: tests: Correctly check for expected failures.
Date: Sat, 29 Apr 2023 16:41:17 -0400 (EDT)

civodul pushed a commit to branch master
in repository shepherd.

commit 6a2b36635d1588a07660403e137134fddf5b4923
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Sat Apr 29 22:33:58 2023 +0200

    tests: Correctly check for expected failures.
    
    The '! cmd' pattern was use to check for expected failures.  However,
    with 'set -e', a return status inverted with '!' does not cause the
    shell to exit immediately.
    
    See <https://issues.guix.gnu.org/62406>.
    
    * tests/basic.sh, tests/forking-service.sh, tests/inetd.sh,
    tests/respawn.sh, tests/services/monitoring.sh,
    tests/services/repl.sh, tests/starting-status.sh,
    tests/status-sexp.sh, tests/stopping-status.sh,
    tests/system-star.sh, tests/transient.sh: Replace ineffective "! cmd"
    pattern with "cmd && false" or "if cmd; then false; else true; fi" when
    in tail position.
---
 tests/basic.sh               | 10 +++++-----
 tests/forking-service.sh     |  2 +-
 tests/inetd.sh               | 15 +++++++++------
 tests/respawn.sh             |  4 ++--
 tests/services/monitoring.sh |  2 +-
 tests/services/repl.sh       |  7 ++++---
 tests/starting-status.sh     |  4 ++--
 tests/status-sexp.sh         |  2 +-
 tests/stopping-status.sh     |  4 ++--
 tests/system-star.sh         |  8 ++++----
 tests/transient.sh           |  4 ++--
 11 files changed, 33 insertions(+), 29 deletions(-)

diff --git a/tests/basic.sh b/tests/basic.sh
index cd1484b..94bda5d 100644
--- a/tests/basic.sh
+++ b/tests/basic.sh
@@ -94,7 +94,7 @@ test -f "$stamp"
 $herd status test | grep running
 
 $herd stop test
-! test -f "$stamp"
+test -f "$stamp" && false
 
 $herd log
 $herd log | grep "service test is running"
@@ -152,7 +152,7 @@ if $herd an-action-that-does-not-exist root
 then false; else true; fi
 
 # Check the behavior for a service whose 'start' method throws.
-! $herd start broken
+$herd start broken && false
 $herd status broken | grep "stopped"
 
 # Check 'make-system-constructor' and 'make-system-destructor'.
@@ -279,7 +279,7 @@ $herd start root | grep "already running"
 grep "already running" "$log"
 
 $herd stop root
-! kill -0 $shepherd_pid
+kill -0 $shepherd_pid && false
 
 test -f "$log"
 
@@ -307,12 +307,12 @@ test -f "$stamp"
 $herd status test | grep running
 
 $herd stop test
-! test -f "$stamp"
+test -f "$stamp" && false
 
 shepherd_pid="`cat $pid`"
 
 $herd stop root
-! kill -0 $shepherd_pid
+kill -0 $shepherd_pid && false
 
 rm -rf $confdir
 rm -rf $datadir
diff --git a/tests/forking-service.sh b/tests/forking-service.sh
index 1bf4c3c..8e07359 100644
--- a/tests/forking-service.sh
+++ b/tests/forking-service.sh
@@ -159,7 +159,7 @@ $herd status test3 | grep running
 child_pid="$($herd status test4 | grep Running | sed '-es/.*Running value is 
\([0-9]\+\)\./\1/g')"
 kill -0 "$child_pid"
 $herd stop test3               # this will also stop 'test4'
-! kill -0 "$child_pid"
+kill -0 "$child_pid" && false
 grep ignoring "$log"
 grep SIGKILL "$log"
 $herd status test3 | grep stopped
diff --git a/tests/inetd.sh b/tests/inetd.sh
index 9c43e8f..2affb71 100644
--- a/tests/inetd.sh
+++ b/tests/inetd.sh
@@ -128,12 +128,14 @@ do
 done
 
 # Unavailable on IPv6.
-! converse_with_echo_server \
-    "(make-socket-address AF_INET6 IN6ADDR_LOOPBACK $PORT)"
+converse_with_echo_server \
+    "(make-socket-address AF_INET6 IN6ADDR_LOOPBACK $PORT)" \
+     && false
 
 $herd stop test-inetd
-! converse_with_echo_server \
-  "(make-socket-address AF_INET INADDR_LOOPBACK $PORT)"
+converse_with_echo_server \
+  "(make-socket-address AF_INET INADDR_LOOPBACK $PORT)" \
+   && false
 
 if guile -c '(socket AF_INET6 SOCK_STREAM 0)'; then
     # Test IPv6 support.
@@ -180,8 +182,9 @@ do
 done
 
 $herd stop test-inetd-unix
-! converse_with_echo_server \
-  "(make-socket-address AF_UNIX \"$service_socket\")"
+converse_with_echo_server \
+  "(make-socket-address AF_UNIX \"$service_socket\")" \
+   && false
 
 # Check the maximum connection limit.
 $herd start test-inetd-unix
diff --git a/tests/respawn.sh b/tests/respawn.sh
index 28790a8..4a4d339 100644
--- a/tests/respawn.sh
+++ b/tests/respawn.sh
@@ -125,8 +125,8 @@ pid="`cat "$service1_pid"`"
 rm "$service1_pid"
 $herd stop test1
 $herd status test1 | grep stopped
-! test -f "$service1_pid"
-! kill -0 "$pid"
+test -f "$service1_pid" && false
+kill -0 "$pid" && false
 
 cat $service2_pid
 $herd stop root
diff --git a/tests/services/monitoring.sh b/tests/services/monitoring.sh
index 80e1f47..faffb6d 100644
--- a/tests/services/monitoring.sh
+++ b/tests/services/monitoring.sh
@@ -57,7 +57,7 @@ $herd log monitoring
 $herd log monitoring | grep "heap:"
 $herd log monitoring | grep "service names: 3"
 $herd period monitoring 1
-! $herd period monitoring not-a-number
+$herd period monitoring not-a-number && false
 
 $herd stop monitoring
 $herd status monitoring | grep "stopped"
diff --git a/tests/services/repl.sh b/tests/services/repl.sh
index c0e37d7..597858a 100644
--- a/tests/services/repl.sh
+++ b/tests/services/repl.sh
@@ -63,7 +63,7 @@ test $($herd status | grep '^ ' | wc -l) = 3
 # Make sure 'repl-client-1' gets stopped as soon as the client disappears.
 kill $child_pid
 while test $($herd status | grep '^ ' | wc -l) -ne 2; do $herd status && sleep 
1 ;done
-! $herd status repl-client-1
+$herd status repl-client-1 && false
 
 guile -c '
 (use-modules (ice-9 rdelim))
@@ -124,5 +124,6 @@ $herd stop repl
 $herd status repl | grep "stopped"
 
 # Now we can't connect anymore.
-! guile -c '(let ((sock (socket AF_UNIX SOCK_STREAM 0)))
-              (connect sock PF_UNIX "'$repl_socket'"))'
+if guile -c '(let ((sock (socket AF_UNIX SOCK_STREAM 0)))
+                (connect sock PF_UNIX "'$repl_socket'"))'
+then false; else true; fi
diff --git a/tests/starting-status.sh b/tests/starting-status.sh
index 8e011e9..81e371c 100644
--- a/tests/starting-status.sh
+++ b/tests/starting-status.sh
@@ -99,7 +99,7 @@ while : ; do
 done
 
 $herd stop test
-! test -f "$stamp"
+test -f "$stamp" && false
 
 test $(grep "Starting service test" "$log" | wc -l) = 1
 
@@ -135,7 +135,7 @@ $herd status test | grep stopped
 
 
 $herd stop root
-! kill -0 $shepherd_pid
+kill -0 $shepherd_pid && false
 
 rm -rf "$confdir"
 rm -rf "$datadir"
diff --git a/tests/status-sexp.sh b/tests/status-sexp.sh
index b7a16c2..0d1270a 100644
--- a/tests/status-sexp.sh
+++ b/tests/status-sexp.sh
@@ -160,6 +160,6 @@ $define_reset_timestamps
             (error #f) (messages ()))))"
 
 $herd stop root
-! kill -0 $shepherd_pid
+kill -0 $shepherd_pid && false
 
 test -f "$log"
diff --git a/tests/stopping-status.sh b/tests/stopping-status.sh
index df2f0a4..7b2c224 100644
--- a/tests/stopping-status.sh
+++ b/tests/stopping-status.sh
@@ -103,7 +103,7 @@ while : ; do
 done
 
 $herd stop test
-! test -f "$stamp"
+test -f "$stamp" && false
 
 test $(grep "Stopping service test" "$log" | wc -l) = 1
 
@@ -147,7 +147,7 @@ $herd status test | grep stopped
 
 
 $herd stop root
-! kill -0 $shepherd_pid
+kill -0 $shepherd_pid && false
 
 rm -rf "$confdir"
 rm -rf "$datadir"
diff --git a/tests/system-star.sh b/tests/system-star.sh
index b3cb933..0320df2 100755
--- a/tests/system-star.sh
+++ b/tests/system-star.sh
@@ -98,11 +98,11 @@ $herd status test | grep running
 $herd status test | grep "exit-code 123"
 
 $herd stop test
-! test -f "$stamp"
+test -f "$stamp" && false
 grep "STOPPING" "$log"
 
 # This service uses 'system*' but the command is not found.
-! $herd start test-command-not-found
+$herd start test-command-not-found && false
 $herd status test-command-not-found
 $herd status test-command-not-found | grep "stopped"
 
@@ -123,11 +123,11 @@ $herd stop test-with-respawn
 # What happens when we cause the process monitor to throw an exception while
 # trying to fork?  The process monitor fiber should remain alive.
 $herd eval root "(setrlimit 'nproc 1 1)"
-! $herd start test
+$herd start test && false
 $herd status test
 $herd status test | grep "stopped"
 
 $herd stop root
 
 # Make sure 'shutdown-services' did its job.
-! test -f "$stamp"
+if test -f "$stamp"; then false; else true; fi
diff --git a/tests/transient.sh b/tests/transient.sh
index 50434c9..f61bb46 100644
--- a/tests/transient.sh
+++ b/tests/transient.sh
@@ -55,11 +55,11 @@ $herd start transient-test2
 # Stop the service and make sure it gets unregistered.
 $herd status transient-test1 | grep "transient, running"
 $herd stop transient-test1
-! $herd status transient-test1
+$herd status transient-test1 && false
 
 # Terminate the service and make sure it gets unregistered.
 $herd status transient-test2 | grep "transient, running"
 kill $($herd status transient-test2 | grep Running | sed -e's/^.* 
\([0-9]\+\).*$/\1/g')
-! $herd status transient-test2
+$herd status transient-test2 && false
 
 test $($herd status | grep transient-test | wc -l) -eq 0



reply via email to

[Prev in Thread] Current Thread [Next in Thread]