diff options
author | Robert Hensing | 2024-08-12 13:36:13 +0200 |
---|---|---|
committer | Robert Hensing | 2024-08-12 13:48:25 +0200 |
commit | 7f838d4c54891ad1d9c2eb7ed8065c840fb21924 (patch) | |
tree | 27a5fa9567dba813efdf34f7baab2af17c79472f /lib | |
parent | 6fa24da815b755e7a521cd7e6808956480af3613 (diff) |
lib/tests/modules.sh: Improve failure log format
- Clear separation between failures - Move error regex close to error message, which is at the bottom of a fairly long trace - Move most relevant and consistent info to bottom of terminal: the location of the failure. Some editors including vscode heuristically resolve file paths on Ctrl+click. - Less wordy - easy to glance - Capitalized prefixes to distinguish from Nix's own logging
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/tests/modules.sh | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index e7c7f881338b..3a23766a17f5 100755 --- a/lib/tests/modules.sh +++ b/lib/tests/modules.sh @@ -35,6 +35,22 @@ loc() { echo "${caller[2]}:${caller[0]}" } +line() { + echo "----------------------------------------" +} +logStartFailure() { + line +} +logEndFailure() { + line + echo +} + +logFailure() { + # bold red + printf '\033[1;31mTEST FAILED\033[0m at %s\n' "$(loc 2)" +} + evalConfig() { local attr=$1 shift @@ -57,9 +73,12 @@ checkConfigOutput() { if evalConfig "$@" 2>/dev/null | grep -E --silent "$outputContains" ; then ((++pass)) else - echo "test failure at $(loc):" - echo "error: Expected result matching '$outputContains', while evaluating" + logStartFailure + echo "ACTUAL:" reportFailure "$@" + echo "EXPECTED: result matching '$outputContains'" + logFailure + logEndFailure fi } @@ -68,16 +87,22 @@ checkConfigError() { local err="" shift if err="$(evalConfig "$@" 2>&1 >/dev/null)"; then - echo "test failure at $(loc):" - echo "error: Expected error code, got exit code 0, while evaluating" + logStartFailure + echo "ACTUAL: exit code 0, output:" reportFailure "$@" + echo "EXPECTED: non-zero exit code" + logFailure + logEndFailure else if echo "$err" | grep -zP --silent "$errorContains" ; then ((++pass)) else - echo "test failure at $(loc):" - echo "error: Expected error matching '$errorContains', while evaluating" + logStartFailure + echo "ACTUAL:" reportFailure "$@" + echo "EXPECTED: error matching '$errorContains'" + logFailure + logEndFailure fi fi } |