python313Packages.compliance-trestle: init at 3.7.0 (#377275)
[NixPkgs.git] / nixos / modules / system / activation / lib / test.sh
blob9b146383ad4b05a77f25141ca0152f50d227de3d
1 #!/usr/bin/env bash
3 # Run:
4 # ./test.sh
5 # or:
6 # nix-build -A nixosTests.activation-lib
8 cd "$(dirname "${BASH_SOURCE[0]}")"
9 set -euo pipefail
11 # report failure
12 onerr() {
13 set +e
14 # find failed statement
15 echo "call trace:"
16 local i=0
17 while t="$(caller $i)"; do
18 line="${t%% *}"
19 file="${t##* }"
20 echo " $file:$line" >&2
21 ((i++))
22 done
23 # red
24 printf "\033[1;31mtest failed\033[0m\n" >&2
25 exit 1
27 trap onerr ERR
29 source ./lib.sh
31 (warn hi, this works >/dev/null) 2>&1 | grep -E $'.*warning:.* hi, this works' >/dev/null
33 # green
34 printf "\033[1;32mok\033[0m\n"