shellcheck: fix lint of scripts in tests

This commit is contained in:
Otto Sabart 2022-08-16 21:00:00 +02:00 committed by Erik Arvstedt
parent a59c3b4b8a
commit f184bb34e6
No known key found for this signature in database
GPG key ID: 33312B944DD97846
14 changed files with 82 additions and 59 deletions

View file

@ -4,15 +4,18 @@
tmp=$(mktemp -d '/tmp/nix-bitcoin-src.XXXXX')
# Move source cache if it exists (atomic)
mv /tmp/nix-bitcoin-src $tmp/src 2>/dev/null || true
mv /tmp/nix-bitcoin-src "$tmp/src" 2>/dev/null || true
atExit() {
# Set the current src as the source cache (atomic)
mv -T $tmp/src /tmp/nix-bitcoin-src 2>/dev/null || true
rm -rf $tmp
mv -T "$tmp/src" /tmp/nix-bitcoin-src 2>/dev/null || true
rm -rf "$tmp"
}
trap "atExit" EXIT
rsync -a --delete --exclude='.git*' "$scriptDir/../" $tmp/src
# shellcheck disable=SC2154
rsync -a --delete --exclude='.git*' "$scriptDir/../" "$tmp/src"
echo "Copied src"
_nixBitcoinInCopiedSrc=1 $tmp/src/test/run-tests.sh "${args[@]}"
# shellcheck disable=SC2154
_nixBitcoinInCopiedSrc=1 "$tmp/src/test/run-tests.sh" "${args[@]}"

View file

@ -1,13 +1,15 @@
# Create and maintain a minimal git repo at the root of the copied src
(
# shellcheck disable=SC2154,SC2164
cd "$scriptDir/.."
amend=--amend
if [[ ! -e .git ]]; then
git init
amend=
fi
git add .
if ! git diff --quiet --cached; then
git commit -a $amend -m -
git commit -a "$amend" -m -
fi
) >/dev/null

View file

@ -57,6 +57,8 @@ if [[ $EUID != 0 ]]; then
# NixOS containers require root permissions.
# By using sudo here and not at the user's call-site extra-container can detect if it is running
# inside an existing shell session (by checking an internal environment variable).
#
# shellcheck disable=SC2154
exec sudo scenario="$scenario" scriptDir="$scriptDir" NIX_PATH="$NIX_PATH" PATH="$PATH" \
scenarioOverridesFile="${scenarioOverridesFile:-}" "$scriptDir/lib/make-container.sh" "$@"
fi
@ -64,7 +66,7 @@ fi
export containerName=nb-test
containerCommand=shell
while [[ $# > 0 ]]; do
while [[ $# -gt 0 ]]; do
case $1 in
--command|-c)
shift
@ -77,14 +79,14 @@ while [[ $# > 0 ]]; do
done
containerBin=$(type -P extra-container) || true
if [[ ! ($containerBin && $(realpath $containerBin) == *extra-container-0.10*) ]]; then
if [[ ! ($containerBin && $(realpath "$containerBin") == *extra-container-0.10*) ]]; then
echo "Building extra-container. Skip this step by adding extra-container 0.10 to PATH."
nix-build --out-link /tmp/extra-container "$scriptDir"/../pkgs \
-A pinned.extra-container >/dev/null
export PATH="/tmp/extra-container/bin${PATH:+:}$PATH"
fi
read -d '' src <<EOF || true
read -rd '' src <<EOF || true
((import "$scriptDir/tests.nix" {}).getTest "$scenario").container
EOF
exec extra-container $containerCommand -E "$src" "$@"
exec extra-container "$containerCommand" -E "$src" "$@"

View file

@ -16,9 +16,9 @@ let
fixedTest = test.overrideAttrs (_: {
# See `runTests` in nixpkgs/nixos/lib/testing-python.nix for the original definition of `buildCommand`
buildCommand = ''
mkdir $out
mkdir "$out"
LOGFILE=$out/output.xml tests='exec(os.environ["testScript"])' ${test.driver}/bin/nixos-test-driver
ln -s ${test.driver} $out/driver
ln -s ${test.driver} "$out/driver"
'';
});
in