aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar John Cater <jcater@google.com>2017-07-25 22:51:09 +0200
committerGravatar Jakob Buchgraber <buchgr@google.com>2017-07-26 10:35:02 +0200
commit31ed852788767e17315818cefa989bd191c1d30b (patch)
treeba9406cbd91f743caca233d671a5977e80d114a8 /src
parent6ab1d669563c4ae9483ebd6b55e20255cd2a2ec2 (diff)
Fix bash unit tests to include the test suite name in the XML output.
Fixes https://github.com/bazelbuild/continuous-integration/issues/103. Change-Id: Icbf62514baf0f581ca2bc5c115da1f3633ef7828 PiperOrigin-RevId: 163117605
Diffstat (limited to 'src')
-rw-r--r--src/test/shell/unittest.bash28
1 files changed, 21 insertions, 7 deletions
diff --git a/src/test/shell/unittest.bash b/src/test/shell/unittest.bash
index ed2b7c5aa1..ab03b6587f 100644
--- a/src/test/shell/unittest.bash
+++ b/src/test/shell/unittest.bash
@@ -560,7 +560,13 @@ function assert_not_contains() {
local pattern=$1
local file=$2
local message=${3:-Expected regexp "$pattern" found in "$file"}
- grep -sq -- "$pattern" "$file" || return 0
+
+ if [[ -f "$file" ]]; then
+ grep -sq -- "$pattern" "$file" || return 0
+ else
+ fail "$file is not a file: $message"
+ return 1
+ fi
cat "$file" >&2
fail "$message"
@@ -660,16 +666,19 @@ close FILE" "$block"
# Usage: <total> <passed>
# Adds the test summaries to the xml nodes.
function __finish_test_report() {
- local total=$1
- local passed=$2
+ local suite_name="$1"
+ local total="$2"
+ local passed="$3"
local failed=$((total - passed))
+ # Update the xml output with the suite name and total number of
+ # passed/failed tests.
cat $XML_OUTPUT_FILE | \
sed \
"s/<testsuites>/<testsuites tests=\"$total\" failures=\"0\" errors=\"$failed\">/" | \
sed \
- "s/<testsuite>/<testsuite tests=\"$total\" failures=\"0\" errors=\"$failed\">/" \
- > $XML_OUTPUT_FILE.bak
+ "s/<testsuite>/<testsuite name=\"${suite_name}\" tests=\"$total\" failures=\"0\" errors=\"$failed\">/" \
+ > $XML_OUTPUT_FILE.bak
rm -f $XML_OUTPUT_FILE
mv $XML_OUTPUT_FILE.bak $XML_OUTPUT_FILE
@@ -699,8 +708,13 @@ function get_run_time() {
# Must be called from the end of the user's test suite.
# Calls exit with zero on success, non-zero otherwise.
function run_suite() {
+ local message="$1"
+ # The name of the suite should be the script being run, under Bazel that
+ # will be the filename with the ".sh" extension removed.
+ local suite_name="$(basename $0)"
+
echo >&2
- echo "$1" >&2
+ echo "$message" >&2
echo >&2
__log_to_test_report "<\/testsuites>" "<testsuite></testsuite>"
@@ -801,7 +815,7 @@ function run_suite() {
__log_to_test_report "<\/testsuite>" "$testcase_tag"
done
- __finish_test_report $total $passed
+ __finish_test_report "$suite_name" $total $passed
__pad "$passed / $total tests passed." '*' >&2
[ $total = $passed ] || {
__pad "There were errors." '*'