From c237f1302fc967f2ee0222a0712d41eda03e84cd Mon Sep 17 00:00:00 2001 From: Erik Arvstedt Date: Mon, 12 Dec 2022 11:57:08 +0100 Subject: [PATCH] run-tests: use arg instead of env var for scenario overrides This removes a source of implicit state and guarantees that regular calls to `run-tests.sh` always run the builtin tests. --- test/run-tests.sh | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/test/run-tests.sh b/test/run-tests.sh index 13eb647..f6c75f3 100755 --- a/test/run-tests.sh +++ b/test/run-tests.sh @@ -57,7 +57,8 @@ # and reading source files. # Files are copied to /tmp, a caching scheme helps minimizing copies. # -# To add custom scenarios, set the environment variable `scenarioOverridesFile`. +# Add custom scenarios from a file +# ./run-tests.sh --extra-scenarios ~/my/scenarios.nix ... set -eo pipefail @@ -66,6 +67,7 @@ scriptDir=$(cd "${BASH_SOURCE[0]%/*}" && pwd) args=("$@") scenario= outLinkPrefix= +scenarioOverridesFile= while :; do case $1 in --scenario|-s) @@ -88,6 +90,16 @@ while :; do exit 1 fi ;; + --extra-scenarios) + if [[ $2 ]]; then + scenarioOverridesFile=$2 + shift + shift + else + >&2 echo "Error: $1 requires an argument." + exit 1 + fi + ;; --copy-src|-c) shift if [[ ! $_nixBitcoinInCopiedSrc ]]; then @@ -113,7 +125,7 @@ makeTmpDir() { # Support explicit scenario definitions if [[ $scenario = *' '* ]]; then makeTmpDir - export scenarioOverridesFile=$tmpDir/scenario-overrides.nix + scenarioOverridesFile=$tmpDir/scenario-overrides.nix echo "{ scenarios, pkgs, lib, nix-bitcoin }: with lib; { tmp = $scenario; }" > "$scenarioOverridesFile" scenario=tmp fi @@ -195,7 +207,7 @@ buildTests() { nixInstantiateTest() { local attr=$1 shift - if [[ ${scenarioOverridesFile:-} ]]; then + if [[ $scenarioOverridesFile ]]; then local file="extraScenariosFile = \"$scenarioOverridesFile\";" else local file=