test-lib: Always print output differences, not just in verbose mode.
Differences in the expected and actual todo.sh output are critical to analyzing the error, so they should always be printed, not just when the -verbose argument is given. This refactoring moves the test_cmp call from the command under test (as seen from test-lib's perspective) into a new assertion test_expect_output, derived from test_expect_success.
This commit is contained in:
@@ -180,7 +180,7 @@ test_failure_ () {
|
||||
test_failure=$(($test_failure + 1))
|
||||
say_color error "FAIL $test_count: $1"
|
||||
shift
|
||||
echo "$@" | sed -e 's/^/ /'
|
||||
echo "$@"
|
||||
test "$immediate" = "" || { trap - EXIT; exit 1; }
|
||||
}
|
||||
|
||||
@@ -260,6 +260,30 @@ test_expect_success () {
|
||||
echo >&3 ""
|
||||
}
|
||||
|
||||
test_expect_output () {
|
||||
test "$#" = 2 ||
|
||||
error "bug in the test script: not 2 parameters to test-expect-output"
|
||||
if ! test_skip "$@"
|
||||
then
|
||||
say >&3 "expecting success and output: $2"
|
||||
test_run_ "$2"
|
||||
if [ "$?" = 0 -a "$eval_ret" = 0 ]
|
||||
then
|
||||
cmp_output=$(test_cmp expect output)
|
||||
if [ "$?" = 0 ]
|
||||
then
|
||||
test_ok_ "$1"
|
||||
else
|
||||
test_failure_ "$@" "
|
||||
$cmp_output"
|
||||
fi
|
||||
else
|
||||
test_failure_ "$@"
|
||||
fi
|
||||
fi
|
||||
echo >&3 ""
|
||||
}
|
||||
|
||||
test_expect_code () {
|
||||
test "$#" = 3 ||
|
||||
error "bug in the test script: not 3 parameters to test-expect-code"
|
||||
@@ -542,9 +566,9 @@ test_todo_session () {
|
||||
"")
|
||||
if [ ! -z "$cmd" ]; then
|
||||
if [ $status = 0 ]; then
|
||||
test_expect_success "$1 $subnum" "$cmd > output && test_cmp expect output"
|
||||
test_expect_output "$1 $subnum" "$cmd > output"
|
||||
else
|
||||
test_expect_success "$1 $subnum" "$cmd > output ; test \$? = $status && test_cmp expect output"
|
||||
test_expect_output "$1 $subnum" "$cmd > output ; test \$? = $status"
|
||||
fi
|
||||
|
||||
subnum=$(($subnum + 1))
|
||||
@@ -560,9 +584,9 @@ test_todo_session () {
|
||||
done
|
||||
if [ ! -z "$cmd" ]; then
|
||||
if [ $status = 0 ]; then
|
||||
test_expect_success "$1 $subnum" "$cmd > output && test_cmp expect output"
|
||||
test_expect_output "$1 $subnum" "$cmd > output"
|
||||
else
|
||||
test_expect_success "$1 $subnum" "$cmd > output ; test \$? = $status && test_cmp expect output"
|
||||
test_expect_output "$1 $subnum" "$cmd > output ; test \$? = $status"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user