From 02269df1dc05ac9538d1c9fdcc4e2b32f38de5e9 Mon Sep 17 00:00:00 2001 From: Kristina Chodorow Date: Thu, 10 Dec 2015 15:25:31 +0000 Subject: Don't print an error message about cat if a test exits abnormally On calls to fail, the failure message is written to $TEST_TMPDIR/__fail. This is cat-ed to get the message, but if the test exited without calling fail then an annoying 'cat: blah/blah/blah/__fail: No such file or directory' message is printed. This throws out the error message if the cat fails. -- MOS_MIGRATED_REVID=109896051 --- src/test/shell/testenv.sh | 4 ++-- src/test/shell/unittest.bash | 4 ++-- src/test/shell/unittest_test.sh | 46 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 4 deletions(-) (limited to 'src/test/shell') diff --git a/src/test/shell/testenv.sh b/src/test/shell/testenv.sh index 0c42433801..acb5cdda9f 100755 --- a/src/test/shell/testenv.sh +++ b/src/test/shell/testenv.sh @@ -122,9 +122,9 @@ if [ -z "${TEST_TMPDIR:-}" ]; then fi if [ ! -e "${TEST_TMPDIR}" ]; then mkdir -p -m 0700 "${TEST_TMPDIR}" + # Clean TEST_TMPDIR on exit + atexit "rm -fr ${TEST_TMPDIR}" fi -# Clean TEST_TMPDIR on exit -atexit "rm -fr ${TEST_TMPDIR}" # Functions to compare the actual output of a test to the expected # (golden) output. diff --git a/src/test/shell/unittest.bash b/src/test/shell/unittest.bash index 6fecc4e6cc..92da1d3121 100644 --- a/src/test/shell/unittest.bash +++ b/src/test/shell/unittest.bash @@ -531,8 +531,8 @@ function run_suite() { timestamp >$TEST_TMPDIR/__ts_start set_up eval $TEST_name - timestamp >$TEST_TMPDIR/__ts_end tear_down + timestamp >$TEST_TMPDIR/__ts_end test $TEST_passed == true ) 2>&1 | tee $TEST_TMPDIR/__log # Note that tee will prevent the control flow continuing if the test @@ -570,7 +570,7 @@ function run_suite() { echo "FAILED: $TEST_name" >&2 # end marker in CDATA cannot be escaped, we need to split the CDATA sections log=$(cat $TEST_TMPDIR/__log | sed 's/]]>/]]>]]> /dev/null || echo "No failure message") testcase_tag="" fi $TEST_verbose && echo >&2 diff --git a/src/test/shell/unittest_test.sh b/src/test/shell/unittest_test.sh index f7d4f10da7..0a2864fc7a 100755 --- a/src/test/shell/unittest_test.sh +++ b/src/test/shell/unittest_test.sh @@ -20,6 +20,16 @@ DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) source ${DIR}/unittest.bash || { echo "Could not source unittest.sh" >&2; exit 1; } +function set_up() { + tmp_TEST_TMPDIR=$TEST_TMPDIR + TEST_TMPDIR=$TEST_TMPDIR/$TEST_name + mkdir -p $TEST_TMPDIR +} + +function tear_down() { + TEST_TMPDIR=$tmp_TEST_TMPDIR +} + function test_1() { echo "Everything is okay in test_1" } @@ -36,4 +46,40 @@ function test_timestamp() { assert_equals $time_diff 123.456 } +function test_failure_message() { + cd $TEST_TMPDIR + cat > thing.sh < $TEST_log || echo "thing.sh should fail" + expect_not_log "__fail: No such file or directory" + assert_contains "I'm a failure." $XML_OUTPUT_FILE +} + +function test_no_failure_message() { + cd $TEST_TMPDIR + cat > thing.sh < $TEST_log || echo "thing.sh should fail" + expect_not_log "__fail: No such file or directory" + assert_contains "No failure message" $XML_OUTPUT_FILE +} + run_suite "unittests Tests" -- cgit v1.2.3