From 0a2c8e4864dc30b6d1ed86a16793d37699707650 Mon Sep 17 00:00:00 2001 From: Erik Arvstedt Date: Sat, 6 Feb 2021 09:38:58 +0100 Subject: [PATCH] run-tests: add option --copy-src --- test/lib/copy-src.sh | 18 ++++++++++++++++++ test/run-tests.sh | 15 +++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 test/lib/copy-src.sh diff --git a/test/lib/copy-src.sh b/test/lib/copy-src.sh new file mode 100644 index 0000000..71bc3a2 --- /dev/null +++ b/test/lib/copy-src.sh @@ -0,0 +1,18 @@ +# Re-run run-tests.sh in a snapshot copy of the source. +# Maintain /tmp/nix-bitcoin-src as a source cache to minimize copies. + +tmp=$(mktemp -d '/tmp/nix-bitcoin-src.XXXXX') + +# Ignore errors from now on +set +e + +# Move source cache if it exists (atomic) +mv /tmp/nix-bitcoin-src $tmp/src 2>/dev/null + +rsync -a --delete --exclude='.git*' "$scriptDir/../" $tmp/src && \ + echo "Copied src" && \ + _nixBitcoinInCopySrc=1 $tmp/src/test/run-tests.sh "${args[@]}" + +# Set the current src as the source cache (atomic) +mv -T $tmp/src /tmp/nix-bitcoin-src 2>/dev/null +rm -rf $tmp diff --git a/test/run-tests.sh b/test/run-tests.sh index e59cc56..3f30408 100755 --- a/test/run-tests.sh +++ b/test/run-tests.sh @@ -42,12 +42,20 @@ # For now, creating NixOS containers requires root permissions. # See ./lib/make-container.sh for a complete documentation. # +# Run tests from a snapshot copy of the source files +# ./run-tests.sh --copy-src|-c ... +# +# This allows you to continue editing the nix-bitcoin sources while tests are running +# and reading source files. +# Files are copied to /tmp, a caching scheme helps minimizing copies. +# # To add custom scenarios, set the environment variable `scenarioOverridesFile`. set -eo pipefail scriptDir=$(cd "${BASH_SOURCE[0]%/*}" && pwd) +args=("$@") scenario= outLinkPrefix= ciBuild= @@ -77,6 +85,13 @@ while :; do shift ciBuild=1 ;; + --copy-src|-c) + shift + if [[ ! $_nixBitcoinInCopySrc ]]; then + . "$scriptDir/lib/copy-src.sh" + exit + fi + ;; *) break esac