mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-11-11 10:16:01 +01:00
lib/test.nix relies on `fileset.toSource` which creates a source dir
with the files of interest. `testers.shellcheck` passes all the files in
the source dir to shellcheck. The issue is related to relative path
sourcing, i.e. `source ./lib.sh` where shellcheck cannot make any
assumptions about the working directory.
Options were:
1) Disable this warning with a directive
Prior disabling in the tree:
- pkgs/tools/nix/info/info.sh
- nixos/modules/testing/test-instrumentation.nix
2) Set source-path to SCRIPTDIR with a directive
https://github.com/koalaman/shellcheck/wiki/Directive#source-path
Even though we don't enable external script following for shellcheck
with `-x` flag given every file in the source dir is passed, this
directive seems to capture the intent to help shellcheck a bit
better.
Went with option 2.
36 lines
622 B
Bash
Executable file
36 lines
622 B
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
# Run:
|
|
# ./test.sh
|
|
# or:
|
|
# nix-build -A nixosTests.activation-lib
|
|
|
|
cd "$(dirname "${BASH_SOURCE[0]}")"
|
|
set -euo pipefail
|
|
|
|
# report failure
|
|
onerr() {
|
|
set +e
|
|
# find failed statement
|
|
echo "call trace:"
|
|
local i=0
|
|
while t="$(caller $i)"; do
|
|
line="${t%% *}"
|
|
file="${t##* }"
|
|
echo " $file:$line" >&2
|
|
((i++))
|
|
done
|
|
# red
|
|
printf "\033[1;31mtest failed\033[0m\n" >&2
|
|
exit 1
|
|
}
|
|
trap onerr ERR
|
|
|
|
# shellcheck source-path=SCRIPTDIR
|
|
source ./lib.sh
|
|
|
|
(warn hi, this works >/dev/null) 2>&1 | grep -E $'.*warning:.* hi, this works' >/dev/null
|
|
|
|
# green
|
|
printf "\033[1;32mok\033[0m\n"
|