diff options
author | Philipp Wollermann <philwo@google.com> | 2015-12-11 14:53:26 +0000 |
---|---|---|
committer | David Chen <dzc@google.com> | 2015-12-11 17:08:40 +0000 |
commit | 9ee7c311f7231b1801b965f52de75fa95e47aec3 (patch) | |
tree | d54c2311f96cd853bed9436e43ee43cc0eb03ed6 /src/test/shell | |
parent | 6089e5be0d8f84ea3c96b5f46bf2387491fe7178 (diff) |
unittest.bash: Make it clear that true / false are strings and treat them as such.
--
MOS_MIGRATED_REVID=109991616
Diffstat (limited to 'src/test/shell')
-rw-r--r-- | src/test/shell/unittest.bash | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/src/test/shell/unittest.bash b/src/test/shell/unittest.bash index 92da1d3121..dd31839c95 100644 --- a/src/test/shell/unittest.bash +++ b/src/test/shell/unittest.bash @@ -92,7 +92,7 @@ TEST_log=$TEST_TMPDIR/log # The log file over which the # be absolute to be robust against # tests invoking 'cd'! -TEST_passed=true # The result of the current test; +TEST_passed="true" # The result of the current test; # failed assertions cause this to # become false. @@ -113,7 +113,7 @@ if [ $# -gt 0 ]; then fi fi -TEST_verbose=true # Whether or not to be verbose. A +TEST_verbose="true" # Whether or not to be verbose. A # command; "true" or "false" are # acceptable. The default is: true. @@ -183,7 +183,7 @@ function fail() { __show_log >&2 echo "$TEST_name FAILED: $1." >&2 echo "$1" >$TEST_TMPDIR/__fail - TEST_passed=false + TEST_passed="false" __show_stack # Cleanup as we are leaving the subshell now tear_down @@ -406,7 +406,7 @@ function __update_shards() { function __test_terminated() { __show_log >&2 echo "$TEST_name FAILED: terminated by signal $1." >&2 - TEST_passed=false + TEST_passed="false" __show_stack timeout exit 1 @@ -513,10 +513,12 @@ function run_suite() { for TEST_name in ${TESTS[@]}; do >$TEST_log # Reset the log. - TEST_passed=true + TEST_passed="true" total=$(($total + 1)) - $TEST_verbose && __pad $TEST_name '*' >&2 + if [[ "$TEST_verbose" == "true" ]]; then + __pad $TEST_name '*' >&2 + fi local run_time="0.0" @@ -533,7 +535,7 @@ function run_suite() { eval $TEST_name tear_down timestamp >$TEST_TMPDIR/__ts_end - test $TEST_passed == true + test $TEST_passed == "true" ) 2>&1 | tee $TEST_TMPDIR/__log # Note that tee will prevent the control flow continuing if the test # spawned any processes which are still running and have not closed @@ -541,7 +543,7 @@ function run_suite() { test_subshell_status=${PIPESTATUS[0]} if [ "$test_subshell_status" != 0 ]; then - TEST_passed=false + TEST_passed="false" # Ensure that an end time is recorded in case the test subshell # terminated prematurely. [ -f $TEST_TMPDIR/__ts_end ] || timestamp >$TEST_TMPDIR/__ts_end @@ -562,8 +564,11 @@ function run_suite() { fi local testcase_tag="" - if $TEST_passed; then - $TEST_verbose && echo "PASSED: $TEST_name" >&2 + + if [[ "$TEST_passed" == "true" ]]; then + if [[ "$TEST_verbose" == "true" ]]; then + echo "PASSED: $TEST_name" >&2 + fi passed=$(($passed + 1)) testcase_tag="<testcase name=\"$TEST_name\" status=\"run\" time=\"$run_time\" classname=\"\"></testcase>" else @@ -573,8 +578,11 @@ function run_suite() { fail_msg=$(cat $TEST_TMPDIR/__fail 2> /dev/null || echo "No failure message") testcase_tag="<testcase name=\"$TEST_name\" status=\"run\" time=\"$run_time\" classname=\"\"><error message=\"$fail_msg\"><![CDATA[$log]]></error></testcase>" fi - $TEST_verbose && echo >&2 - __log_to_test_report "<\/testsuite>" "$testcase_tag" + + if [[ "$TEST_verbose" == "true" ]]; then + echo >&2 + fi + __log_to_test_report "<\/testsuite>" "$testcase_tag" done __finish_test_report $total $passed |