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.
This commit is contained in:
Erik Arvstedt 2022-12-12 11:57:08 +01:00
parent da612fe84f
commit a51f7b419e
No known key found for this signature in database
GPG Key ID: 33312B944DD97846
1 changed files with 15 additions and 3 deletions

View File

@ -57,7 +57,8 @@
# and reading source files. # and reading source files.
# Files are copied to /tmp, a caching scheme helps minimizing copies. # 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 set -eo pipefail
@ -66,6 +67,7 @@ scriptDir=$(cd "${BASH_SOURCE[0]%/*}" && pwd)
args=("$@") args=("$@")
scenario= scenario=
outLinkPrefix= outLinkPrefix=
scenarioOverridesFile=
while :; do while :; do
case $1 in case $1 in
--scenario|-s) --scenario|-s)
@ -88,6 +90,16 @@ while :; do
exit 1 exit 1
fi fi
;; ;;
--extra-scenarios)
if [[ $2 ]]; then
scenarioOverridesFile=$2
shift
shift
else
>&2 echo "Error: $1 requires an argument."
exit 1
fi
;;
--copy-src|-c) --copy-src|-c)
shift shift
if [[ ! $_nixBitcoinInCopiedSrc ]]; then if [[ ! $_nixBitcoinInCopiedSrc ]]; then
@ -113,7 +125,7 @@ makeTmpDir() {
# Support explicit scenario definitions # Support explicit scenario definitions
if [[ $scenario = *' '* ]]; then if [[ $scenario = *' '* ]]; then
makeTmpDir makeTmpDir
export scenarioOverridesFile=$tmpDir/scenario-overrides.nix scenarioOverridesFile=$tmpDir/scenario-overrides.nix
echo "{ scenarios, pkgs, lib, nix-bitcoin }: with lib; { tmp = $scenario; }" > "$scenarioOverridesFile" echo "{ scenarios, pkgs, lib, nix-bitcoin }: with lib; { tmp = $scenario; }" > "$scenarioOverridesFile"
scenario=tmp scenario=tmp
fi fi
@ -195,7 +207,7 @@ buildTests() {
nixInstantiateTest() { nixInstantiateTest() {
local attr=$1 local attr=$1
shift shift
if [[ ${scenarioOverridesFile:-} ]]; then if [[ $scenarioOverridesFile ]]; then
local file="extraScenariosFile = \"$scenarioOverridesFile\";" local file="extraScenariosFile = \"$scenarioOverridesFile\";"
else else
local file= local file=