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

@ -1,5 +1,5 @@
if ! canUseSandbox; then exit 99; fi requireSandboxSupport
if ! [[ $busybox =~ busybox ]]; then exit 99; fi [[ $busybox =~ busybox ]] || skipTest "no busybox"
unset NIX_STORE_DIR unset NIX_STORE_DIR
unset NIX_STATE_DIR unset NIX_STATE_DIR

View File

@ -152,21 +152,29 @@ isDaemonNewer () {
[[ $(nix eval --expr "builtins.compareVersions ''$daemonVersion'' ''$requiredVersion''") -ge 0 ]] [[ $(nix eval --expr "builtins.compareVersions ''$daemonVersion'' ''$requiredVersion''") -ge 0 ]]
} }
skipTest () {
echo "$1, skipping this test..." >&2
exit 99
}
requireDaemonNewerThan () { requireDaemonNewerThan () {
isDaemonNewer "$1" || exit 99 isDaemonNewer "$1" || skipTest "Daemon is too old"
} }
canUseSandbox() { canUseSandbox() {
if [[ ! ${_canUseSandbox-} ]]; then [[ ${_canUseSandbox-} ]]
echo "Sandboxing not supported, skipping this test..." }
return 1
fi
return 0 requireSandboxSupport () {
canUseSandbox || skipTest "Sandboxing not supported"
}
requireGit() {
[[ $(type -p git) ]] || skipTest "Git not installed"
} }
fail() { fail() {
echo "$1" echo "$1" >&2
exit 1 exit 1
} }
@ -209,8 +217,7 @@ expectStderr() {
needLocalStore() { needLocalStore() {
if [[ "$NIX_REMOTE" == "daemon" ]]; then if [[ "$NIX_REMOTE" == "daemon" ]]; then
echo "Cant run through the daemon ($1), skipping this test..." skipTest "Cant run through the daemon ($1)"
return 99
fi fi
} }

View File

@ -1,13 +1,13 @@
# Test that we can successfully migrate from an older db schema # Test that we can successfully migrate from an older db schema
source common.sh
# Only run this if we have an older Nix available # Only run this if we have an older Nix available
# XXX: This assumes that the `daemon` package is older than the `client` one # XXX: This assumes that the `daemon` package is older than the `client` one
if [[ -z "${NIX_DAEMON_PACKAGE-}" ]]; then if [[ -z "${NIX_DAEMON_PACKAGE-}" ]]; then
exit 99 skipTest "not using the Nix daemon"
fi fi
source common.sh
killDaemon killDaemon
# Fill the db using the older Nix # Fill the db using the older Nix

View File

@ -1,9 +1,6 @@
source common.sh source common.sh
if [[ -z $(type -p git) ]]; then requireGit
echo "Git not installed; skipping Git tests"
exit 99
fi
clearStore clearStore

View File

@ -1,9 +1,6 @@
source common.sh source common.sh
if [[ -z $(type -p git) ]]; then requireGit
echo "Git not installed; skipping Git tests"
exit 99
fi
clearStore clearStore

View File

@ -2,10 +2,7 @@ source common.sh
set -u set -u
if [[ -z $(type -p git) ]]; then requireGit
echo "Git not installed; skipping Git submodule tests"
exit 99
fi
clearStore clearStore

View File

@ -1,9 +1,6 @@
source common.sh source common.sh
if [[ -z $(type -p hg) ]]; then [[ $(type -p hq) ]] || skipTest "Mercurial not installed"
echo "Mercurial not installed; skipping Mercurial tests"
exit 99
fi
clearStore clearStore

View File

@ -2,13 +2,6 @@ source ../common.sh
registry=$TEST_ROOT/registry.json registry=$TEST_ROOT/registry.json
requireGit() {
if [[ -z $(type -p git) ]]; then
echo "Git not installed; skipping flake tests"
exit 99
fi
}
writeSimpleFlake() { writeSimpleFlake() {
local flakeDir="$1" local flakeDir="$1"
cat > $flakeDir/flake.nix <<EOF cat > $flakeDir/flake.nix <<EOF

View File

@ -1,9 +1,6 @@
source ./common.sh source ./common.sh
if [[ -z $(type -p hg) ]]; then [[ $(type -p hq) ]] || skipTest "Mercurial not installed"
echo "Mercurial not installed; skipping"
exit 99
fi
flake1Dir=$TEST_ROOT/flake-hg1 flake1Dir=$TEST_ROOT/flake-hg1
mkdir -p $flake1Dir mkdir -p $flake1Dir

View File

@ -4,7 +4,7 @@ case $system in
*linux*) *linux*)
;; ;;
*) *)
exit 99; skipTest "Not running Linux";
esac esac
set -m # enable job control, needed for kill set -m # enable job control, needed for kill

View File

@ -4,13 +4,13 @@ needLocalStore "the sandbox only runs on the builder side, so it makes no sense
clearStore clearStore
if ! canUseSandbox; then exit 99; fi requireSandboxSupport
# Note: we need to bind-mount $SHELL into the chroot. Currently we # Note: we need to bind-mount $SHELL into the chroot. Currently we
# only support the case where $SHELL is in the Nix store, because # only support the case where $SHELL is in the Nix store, because
# otherwise things get complicated (e.g. if it's in /bin, do we need # otherwise things get complicated (e.g. if it's in /bin, do we need
# /lib as well?). # /lib as well?).
if [[ ! $SHELL =~ /nix/store ]]; then exit 99; fi if [[ ! $SHELL =~ /nix/store ]]; then skipTest "Shell is not from Nix store"; fi
chmod -R u+w $TEST_ROOT/store0 || true chmod -R u+w $TEST_ROOT/store0 || true
rm -rf $TEST_ROOT/store0 rm -rf $TEST_ROOT/store0

View File

@ -1,8 +1,7 @@
source common.sh source common.sh
if [[ $BUILD_SHARED_LIBS != 1 ]]; then if [[ $BUILD_SHARED_LIBS != 1 ]]; then
echo "plugins are not supported" skipTest "Plugins are not supported"
exit 99
fi fi
res=$(nix --option setting-set true --option plugin-files $PWD/plugins/libplugintest* eval --expr builtins.anotherNull) res=$(nix --option setting-set true --option plugin-files $PWD/plugins/libplugintest* eval --expr builtins.anotherNull)

View File

@ -4,7 +4,7 @@ sed -i 's/experimental-features .*/& recursive-nix/' "$NIX_CONF_DIR"/nix.conf
restartDaemon restartDaemon
# FIXME # FIXME
if [[ $(uname) != Linux ]]; then exit 99; fi if [[ $(uname) != Linux ]]; then skipTest "Not running Linux"; fi
clearStore clearStore

View File

@ -10,7 +10,7 @@ nix shell -f shell-hello.nix hello -c hello NixOS | grep 'Hello NixOS'
nix shell -f shell-hello.nix hello^dev -c hello2 | grep 'Hello2' nix shell -f shell-hello.nix hello^dev -c hello2 | grep 'Hello2'
nix shell -f shell-hello.nix 'hello^*' -c hello2 | grep 'Hello2' nix shell -f shell-hello.nix 'hello^*' -c hello2 | grep 'Hello2'
if ! canUseSandbox; then exit 99; fi requireSandboxSupport
chmod -R u+w $TEST_ROOT/store0 || true chmod -R u+w $TEST_ROOT/store0 || true
rm -rf $TEST_ROOT/store0 rm -rf $TEST_ROOT/store0

View File

@ -4,7 +4,7 @@
source common.sh source common.sh
if isDaemonNewer "2.4pre20211005"; then if isDaemonNewer "2.4pre20211005"; then
exit 99 skipTest "Daemon is too new"
fi fi