aboutsummaryrefslogtreecommitdiff
path: root/tests/common
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2023-03-16 16:00:20 -0400
committerJohn Ericson <John.Ericson@Obsidian.Systems>2023-03-16 18:43:03 -0400
commitbfb9eb87fe98f96969188df9df866e15800bd55b (patch)
tree1bb94f3b5aa283e9fd2c294a7bbd458eb6ba3950 /tests/common
parent7f46ebcf90432a54f5fdec1931d87e5130e68190 (diff)
Cleanup test skipping
- Try not to put cryptic "99" in many places Factor out `exit 99` into `skipTest` function - Alows make sure skipping a test is done with a reason `skipTest` takes a mandatory argument - Separate pure conditionals vs side-effectful test skipping. "require daemon" already had this, but "sandbox support" did not.
Diffstat (limited to 'tests/common')
-rw-r--r--tests/common/vars-and-functions.sh.in25
1 files changed, 16 insertions, 9 deletions
diff --git a/tests/common/vars-and-functions.sh.in b/tests/common/vars-and-functions.sh.in
index e4a773f34..a9e6c802f 100644
--- a/tests/common/vars-and-functions.sh.in
+++ b/tests/common/vars-and-functions.sh.in
@@ -152,21 +152,29 @@ isDaemonNewer () {
[[ $(nix eval --expr "builtins.compareVersions ''$daemonVersion'' ''$requiredVersion''") -ge 0 ]]
}
+skipTest () {
+ echo "$1, skipping this test..." >&2
+ exit 99
+}
+
requireDaemonNewerThan () {
- isDaemonNewer "$1" || exit 99
+ isDaemonNewer "$1" || skipTest "Daemon is too old"
}
canUseSandbox() {
- if [[ ! ${_canUseSandbox-} ]]; then
- echo "Sandboxing not supported, skipping this test..."
- return 1
- fi
+ [[ ${_canUseSandbox-} ]]
+}
- return 0
+requireSandboxSupport () {
+ canUseSandbox || skipTest "Sandboxing not supported"
+}
+
+requireGit() {
+ [[ $(type -p git) ]] || skipTest "Git not installed"
}
fail() {
- echo "$1"
+ echo "$1" >&2
exit 1
}
@@ -209,8 +217,7 @@ expectStderr() {
needLocalStore() {
if [[ "$NIX_REMOTE" == "daemon" ]]; then
- echo "Can’t run through the daemon ($1), skipping this test..."
- return 99
+ skipTest "Can’t run through the daemon ($1)"
fi
}