1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-09 12:03:55 +02:00

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.
This commit is contained in:
John Ericson 2023-03-16 16:00:20 -04:00
parent 7f46ebcf90
commit bfb9eb87fe
15 changed files with 33 additions and 49 deletions

View file

@ -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 "Cant run through the daemon ($1), skipping this test..."
return 99
skipTest "Cant run through the daemon ($1)"
fi
}