aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/shell
diff options
context:
space:
mode:
authorGravatar Kristina Chodorow <kchodorow@google.com>2015-12-10 15:25:31 +0000
committerGravatar Kristina Chodorow <kchodorow@google.com>2015-12-10 20:15:41 +0000
commit02269df1dc05ac9538d1c9fdcc4e2b32f38de5e9 (patch)
tree41c8af27ed2c7c325cf873da901d0e149223a6de /src/test/shell
parent20262fdf40be0ba7fc74cb03d552cadebd76af6d (diff)
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
Diffstat (limited to 'src/test/shell')
-rwxr-xr-xsrc/test/shell/testenv.sh4
-rw-r--r--src/test/shell/unittest.bash4
-rwxr-xr-xsrc/test/shell/unittest_test.sh46
3 files changed, 50 insertions, 4 deletions
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/]]>/]]>]]&gt;<![CDATA[/g')
- fail_msg=$(cat $TEST_TMPDIR/__fail || echo "No failure message")
+ 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
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 <<EOF
+#!/bin/bash
+source ${DIR}/unittest.bash
+
+function test_thing() {
+ fail "I'm a failure"
+}
+
+run_suite "thing tests"
+EOF
+ chmod +x thing.sh
+ ./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 <<EOF
+#!/bin/bash
+source ${DIR}/unittest.bash
+
+function test_thing() {
+ TEST_passed=blorp
+}
+
+run_suite "thing tests"
+EOF
+ chmod +x thing.sh
+ ./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"