aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/shell
diff options
context:
space:
mode:
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"