From 91697b1427d4deb6d41dccd5561e3939e076814d Mon Sep 17 00:00:00 2001 From: Erik Arvstedt Date: Fri, 21 Aug 2020 22:36:13 +0200 Subject: [PATCH] test: allow for testing all scenarios Test all scenarios by default when running 'build' (which happens when the script is called without arguments). Default to scenario 'default' in other test commands like 'debug'. --- test/run-tests.sh | 61 ++++++++++++++++++++++------------------------- test/test.nix | 1 + 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/test/run-tests.sh b/test/run-tests.sh index def34be..9099d09 100755 --- a/test/run-tests.sh +++ b/test/run-tests.sh @@ -4,51 +4,34 @@ # The test (./test.nix) uses the NixOS testing framework and is executed in a VM. # # Usage: -# Run test +# Run all tests +# ./run-tests.sh +# +# Test specific scenario # ./run-tests.sh --scenario # # Run test and save result to avoid garbage collection -# ./run-tests.sh --scenario build --out-link /tmp/nix-bitcoin-test +# ./run-tests.sh [--scenario ] build --out-link /tmp/nix-bitcoin-test # # Run interactive test debugging -# ./run-tests.sh --scenario debug +# ./run-tests.sh [--scenario ] debug # # This starts the testing VM and drops you into a Python REPL where you can # manually execute the tests from ./test-script.py set -eo pipefail -die() { - printf '%s\n' "$1" >&2 - exit 1 -} - -# Initialize all the option variables. -# This ensures we are not contaminated by variables from the environment. scenario= -while :; do - case $1 in - --scenario) - if [ "$2" ]; then - scenario=$2 +if [[ $1 == --scenario ]]; then + if [[ $2 ]]; then + scenario=$2 shift - else - die 'ERROR: "--scenario" requires a non-empty option argument.' - fi - ;; - -?*) - printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2 - ;; - *) - break - esac - - shift -done - -if [[ -z $scenario ]]; then - die 'ERROR: "--scenario" is required' + shift + else + >&2 echo 'Error: "--scenario" requires an argument.' + exit 1 + fi fi numCPUs=${numCPUs:-$(nproc)} @@ -108,7 +91,7 @@ debug() { } # Run the test by building the test derivation -build() { +buildTest() { vmTestNixExpr | nix-build --no-out-link "$@" - } @@ -137,4 +120,18 @@ vmTestNixExpr() { EOF } +build() { + if [[ $scenario ]]; then + buildTest "$@" + else + scenario=default buildTest "$@" + scenario=withnetns buildTest "$@" + fi +} + +# Set default scenario for all actions other than 'build' +if [[ $1 && $1 != build ]]; then + : ${scenario:=default} +fi + eval "${@:-build}" diff --git a/test/test.nix b/test/test.nix index c54312e..5de981b 100644 --- a/test/test.nix +++ b/test/test.nix @@ -1,5 +1,6 @@ # Integration test, can be run without internet access. +# Make sure to update build() in ./run-tests.sh when adding new scenarios { scenario ? "default" }: import ./make-test.nix rec {