test(logging): keep helper output free of diagnostics
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
# Tests for colors.sh - run with: bats tests/test_colors.bats
|
# Tests for colors.sh - run with: bats tests/test_colors.bats
|
||||||
|
|
||||||
setup() {
|
setup() {
|
||||||
|
bats_require_minimum_version 1.5.0
|
||||||
load '../lib/colors.sh'
|
load '../lib/colors.sh'
|
||||||
TEST_LOG=$(mktemp)
|
TEST_LOG=$(mktemp)
|
||||||
}
|
}
|
||||||
@@ -39,3 +40,33 @@ teardown() {
|
|||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
echo "$output" | grep -q "Test Title"
|
echo "$output" | grep -q "Test Title"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "diagnostics use stderr without contaminating helper return values" {
|
||||||
|
local source_file
|
||||||
|
for source_file in lib/colors.sh unleash-standalone.sh; do
|
||||||
|
run --separate-stderr bash -u -c '
|
||||||
|
source <(sed "/^error_exit()/,\$d" "$1")
|
||||||
|
volume_path() {
|
||||||
|
log INFO "Locating Data volume"
|
||||||
|
log OK "Data volume found"
|
||||||
|
printf "%s\n" "/Volumes/Work Data"
|
||||||
|
}
|
||||||
|
result=$(volume_path)
|
||||||
|
printf "%s\n" "$result"
|
||||||
|
' bash "$BATS_TEST_DIRNAME/../$source_file"
|
||||||
|
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[ "$output" = "/Volumes/Work Data" ]
|
||||||
|
[[ "$stderr" == *"Locating Data volume"* ]]
|
||||||
|
[[ "$stderr" == *"Data volume found"* ]]
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "diagnostics still reach the log file when stdout is captured" {
|
||||||
|
LOG_FILE="$TEST_LOG"
|
||||||
|
local result
|
||||||
|
result=$(log WARN "Review the selected volume" 2>/dev/null)
|
||||||
|
|
||||||
|
[ -z "$result" ]
|
||||||
|
grep -q 'Review the selected volume' "$TEST_LOG"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user