Skip to content

Commit 177a067

Browse files
authored
Merge pull request NixOS#12372 from roberth/test-characterisation-log-to-stderr
tests/functional/characterisation/framework: Log to stderr
2 parents cfe9329 + a5de2dd commit 177a067

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

tests/functional/characterisation/framework.sh

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# shellcheck shell=bash
22

3+
badTestNames=()
4+
35
# Golden test support
46
#
57
# Test that the output of the given test matches what is expected. If
@@ -18,10 +20,11 @@ function diffAndAcceptInner() {
1820
fi
1921

2022
# Diff so we get a nice message
21-
if ! diff --color=always --unified "$expectedOrEmpty" "$got"; then
22-
echo "FAIL: evaluation result of $testName not as expected"
23+
if ! diff >&2 --color=always --unified "$expectedOrEmpty" "$got"; then
24+
echo >&2 "FAIL: evaluation result of $testName not as expected"
2325
# shellcheck disable=SC2034
2426
badDiff=1
27+
badTestNames+=("$testName")
2528
fi
2629

2730
# Update expected if `_NIX_TEST_ACCEPT` is non-empty.
@@ -42,14 +45,14 @@ function characterisationTestExit() {
4245
if test -n "${_NIX_TEST_ACCEPT-}"; then
4346
if (( "$badDiff" )); then
4447
set +x
45-
echo 'Output did mot match, but accepted output as the persisted expected output.'
46-
echo 'That means the next time the tests are run, they should pass.'
48+
echo >&2 'Output did mot match, but accepted output as the persisted expected output.'
49+
echo >&2 'That means the next time the tests are run, they should pass.'
4750
set -x
4851
else
4952
set +x
50-
echo 'NOTE: Environment variable _NIX_TEST_ACCEPT is defined,'
51-
echo 'indicating the unexpected output should be accepted as the expected output going forward,'
52-
echo 'but no tests had unexpected output so there was no expected output to update.'
53+
echo >&2 'NOTE: Environment variable _NIX_TEST_ACCEPT is defined,'
54+
echo >&2 'indicating the unexpected output should be accepted as the expected output going forward,'
55+
echo >&2 'but no tests had unexpected output so there was no expected output to update.'
5356
set -x
5457
fi
5558
if (( "$badExitCode" )); then
@@ -60,16 +63,21 @@ function characterisationTestExit() {
6063
else
6164
if (( "$badDiff" )); then
6265
set +x
63-
echo ''
64-
echo 'You can rerun this test with:'
65-
echo ''
66-
echo " _NIX_TEST_ACCEPT=1 make tests/functional/${TEST_NAME}.sh.test"
67-
echo ''
68-
echo 'to regenerate the files containing the expected output,'
69-
echo 'and then view the git diff to decide whether a change is'
70-
echo 'good/intentional or bad/unintentional.'
71-
echo 'If the diff contains arbitrary or impure information,'
72-
echo 'please improve the normalization that the test applies to the output.'
66+
echo >&2 ''
67+
echo >&2 'The following tests had unexpected output:'
68+
for testName in "${badTestNames[@]}"; do
69+
echo >&2 " $testName"
70+
done
71+
echo >&2 ''
72+
echo >&2 'You can rerun this test with:'
73+
echo >&2 ''
74+
echo >&2 " _NIX_TEST_ACCEPT=1 meson test ${TEST_NAME}"
75+
echo >&2 ''
76+
echo >&2 'to regenerate the files containing the expected output,'
77+
echo >&2 'and then view the git diff to decide whether a change is'
78+
echo >&2 'good/intentional or bad/unintentional.'
79+
echo >&2 'If the diff contains arbitrary or impure information,'
80+
echo >&2 'please improve the normalization that the test applies to the output.'
7381
set -x
7482
fi
7583
exit $(( "$badExitCode" + "$badDiff" ))

0 commit comments

Comments
 (0)