aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/shell
diff options
context:
space:
mode:
authorGravatar Philipp Wollermann <philwo@google.com>2015-12-14 14:21:40 +0000
committerGravatar Dmitry Lomov <dslomov@google.com>2015-12-15 12:00:06 +0000
commita91198bd3c9b161334e80ca53f5ad02d09bb1169 (patch)
tree671da12d1f1c8a11d38e06cd81fb794bf06ef270 /src/test/shell
parentd69405e2351396f7c119fb7224aa21b54e1658d7 (diff)
Add unit tests for the new errexit feature in unittest.bash.
-- MOS_MIGRATED_REVID=110148583
Diffstat (limited to 'src/test/shell')
-rwxr-xr-xsrc/test/shell/unittest_test.sh34
1 files changed, 32 insertions, 2 deletions
diff --git a/src/test/shell/unittest_test.sh b/src/test/shell/unittest_test.sh
index 0a2864fc7a..9cbb8f36dc 100755
--- a/src/test/shell/unittest_test.sh
+++ b/src/test/shell/unittest_test.sh
@@ -59,7 +59,7 @@ function test_thing() {
run_suite "thing tests"
EOF
chmod +x thing.sh
- ./thing.sh &> $TEST_log || echo "thing.sh should fail"
+ ./thing.sh &> $TEST_log && fail "thing.sh should fail"
expect_not_log "__fail: No such file or directory"
assert_contains "I'm a failure." $XML_OUTPUT_FILE
}
@@ -77,9 +77,39 @@ function test_thing() {
run_suite "thing tests"
EOF
chmod +x thing.sh
- ./thing.sh &> $TEST_log || echo "thing.sh should fail"
+ ./thing.sh &> $TEST_log && fail "thing.sh should fail"
expect_not_log "__fail: No such file or directory"
assert_contains "No failure message" $XML_OUTPUT_FILE
}
+function test_errexit_prints_stack_trace() {
+ cd $TEST_TMPDIR
+ cat > thing.sh <<EOF
+#!/bin/bash
+source ${DIR}/unittest.bash
+
+enable_errexit
+
+function helper() {
+ echo before
+ false
+ echo after
+}
+
+function test_thing() {
+ helper
+}
+
+run_suite "thing tests"
+EOF
+ chmod +x thing.sh
+ ./thing.sh &> $TEST_log && fail "thing.sh should fail"
+ #cat $TEST_log
+
+ # Make sure the full stack trace is there.
+ expect_log "test_thing FAILED: terminated because this command returned a non-zero status:"
+ expect_log "./thing.sh:[0-9]*: in call to helper"
+ expect_log "./thing.sh:[0-9]*: in call to test_thing"
+}
+
run_suite "unittests Tests"