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 committed by Greg Shuflin
parent d119c207b9
commit c237f1302f
1 changed files with 15 additions and 3 deletions

View File

@ -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=