Skip to content

Commit

Permalink
Rolling forward the change to open source JUnit integration tests.
Browse files Browse the repository at this point in the history
Fixed failures by removing the (expected) failing XML reports from the path, to stop Jenkins from reporting a failure despite passing tests.

After removing the XMLs I see jenkins passing where it was previously failing: http://ci.bazel.io/job/Gerrit-bazel-tests/419/ (caused by an un-clean version of this change https://bazel-review.googlesource.com/c/9039/)

<Rollback history below>

*** Original change description ***

Automated [] rollback of commit 9822151.

*** Reason for rollback ***

Jenkins reports the tests as failing. See bazelbuild#2554 for more details.

--
PiperOrigin-RevId: 148268951
MOS_MIGRATED_REVID=148268951
  • Loading branch information
kush-c authored and hermione521 committed Feb 23, 2017
1 parent 2997e25 commit 2bdf534
Show file tree
Hide file tree
Showing 9 changed files with 530 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ java_library(
],
)

java_binary(
name = "TestbedBinary",
testonly = 1,
main_class = "com.google.testing.junit.runner.BazelTestRunner",
runtime_deps = [
"//src/java_tools/junitrunner/java/com/google/testing/junit/runner:test_runner",
"//src/java_tools/junitrunner/javatests/com/google/testing/junit/runner/testbed",
],
)

# Tests
# =========================================================
java_test(
Expand All @@ -44,8 +54,81 @@ java_test(
runtime_deps = [":tests"],
)

# BazelTestRunner integration tests
sh_library(
name = "testenv",
srcs = ["testenv.sh"],
deps = ["//src/test/shell:bashunit"],
)

sh_test(
name = "junit4_testbridge_integration_test",
size = "medium",
srcs = ["junit4_testbridge_integration_tests.sh"],
args = [
"$(location :TestbedBinary)",
"bazel.test_suite",
],
data = [":TestbedBinary"],
shard_count = 0,
deps = [":testenv"],
)

sh_test(
name = "utf8_test_log_test",
size = "medium",
srcs = ["utf8_test_log_test.sh"],
args = [
"$(location :TestbedBinary)",
"bazel.test_suite",
],
data = [":TestbedBinary"],
shard_count = 0,
deps = [":testenv"],
)

sh_test(
name = "antxmlresultwriter_integration_test",
size = "medium",
srcs = ["antxmlresultwriter_integration_test.sh"],
args = [
"$(location :TestbedBinary)",
"$(location //src/java_tools/junitrunner/javatests/com/google/testing/junit/runner/testbed:XmlOutputExercises.ant.xml)",
"bazel.test_suite",
],
data = [
":TestbedBinary",
"//src/java_tools/junitrunner/javatests/com/google/testing/junit/runner/testbed:XmlOutputExercises.ant.xml",
],
shard_count = 0,
deps = [":testenv"],
)

sh_test(
name = "deploy_jar_integration_test",
size = "medium",
srcs = ["deploy_jar_integration_tests.sh"],
args = [
"$(JAVABASE)",
"$(location :TestbedBinary_deploy.jar)",
],
data = [
":TestbedBinary_deploy.jar",
"//tools/defaults:jdk",
],
shard_count = 0,
deps = [":testenv"],
)

filegroup(
name = "srcs",
srcs = glob(["**"]),
visibility = ["//src:__pkg__"],
)

exports_files([
"stack_trace_integration_tests.sh",
"junit4_testbridge_integration_tests.sh",
"utf8_test_log_test.sh",
"deploy_jar_integration_tests.sh",
])
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash
#
# Copyright 2015 The Bazel Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Integration testing of the AntXmlResultWriter.
#

DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)

TESTBED="${PWD}/$1"
XML_GOLDEN_OUTPUT_FILE="${PWD}/$2"
XML_OUTPUT_FILE="${TEST_TMPDIR}/test.xml"
SUITE_PARAMETER="$3"
SUITE="com.google.testing.junit.runner.testbed.XmlOutputExercises"
SUITE_FLAG="-D${SUITE_PARAMETER}=${SUITE}"

shift 3
source ${DIR}/testenv.sh || { echo "testenv.sh not found!" >&2; exit 1; }

function test_XmlOutputExercises() {
cd $TEST_TMPDIR

$TESTBED --jvm_flag=${SUITE_FLAG} || true # Test failures

# Remove timestamps and test runtime from the XML files as they will always differ and cause a
# mismatch.
sed -i.bak -E "s/(time[^=]*)='[^']*/\1='/g" $XML_OUTPUT_FILE \
|| fail "sed to remove timestamps failed"

# Removes the stacktrace from the XML files, it can vary between JDK versions.
sed -i.bak -E '/\w*at [a-zA-Z0-9\$\.]+\([a-zA-Z0-9 \.]*(:[0-9]+)?\)$/d' \
"${XML_OUTPUT_FILE}" || fail "sed to remove stacktraces failed"

diff -wu $XML_GOLDEN_OUTPUT_FILE $XML_OUTPUT_FILE \
|| fail "Did not expect a diff between the golden file and the generated XML output."
}

run_suite "antxmlresultwriter"
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash
#
# Copyright 2012 The Bazel Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Integration testing of _deploy.jar behavior. Not using the runfiles wrapper
# can create a few puzzling hazards. This verifies that we warn the user for
# the most obvious ones.
#
# These tests operate by executing test methods in a testbed deploy.jar program
# and checking the output.
#

DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)

unset TEST_PREMATURE_EXIT_FILE
JAVA_HOME="$1"
TESTBED_JAR="${PWD}/$2"

shift 2
source ${DIR}/testenv.sh || { echo "testenv.sh not found!" >&2; exit 1; }

#######################

# Test that we see a warning about missing the test suite Java system property
function test_Warning() {
test_pid=""
${JAVA_HOME}/bin/java -jar $TESTBED_JAR >& $TEST_log && test_pid=$!

expect_log "The test suite Java system property .* is required but missing"

wait $test_pid || fail "Expected process to finish successfully"
}

run_suite "deploy_jar"
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/bin/bash
#
# Copyright 2015 The Bazel Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Integration testing of the test bridge protocol for JUnit4 tests.
# This is a test filter passed by "bazel test --test_filter".
#
# These tests operate by executing test methods in a testbed program
# and checking the output.
#

DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)

TESTBED="${PWD}/$1"
SUITE_PARAMETER="$2"
SUITE_FLAG="-D${SUITE_PARAMETER}=com.google.testing.junit.runner.testbed.JUnit4TestbridgeExercises"
XML_OUTPUT_FILE="${TEST_TMPDIR}/test.xml"

shift 2
source ${DIR}/testenv.sh || { echo "testenv.sh not found!" >&2; exit 1; }

#######################

function set_up() {
# By default, the environment flag is unset.
declare +x TESTBRIDGE_TEST_ONLY
}

# Test that we respond to TESTBRIDGE_TEST_ONLY in JUnit4 tests.
function test_Junit4() {
cd $TEST_TMPDIR

# Run the test without environment flag; it should fail.
declare +x TESTBRIDGE_TEST_ONLY
$TESTBED --jvm_flag=${SUITE_FLAG} >& $TEST_log && fail "Expected failure"
expect_log 'Failures: 1'

# Run the test with environment flag.
declare -x TESTBRIDGE_TEST_ONLY="doRun"
$TESTBED --jvm_flag=${SUITE_FLAG} >& $TEST_log || fail "Expected success"
expect_log 'OK.*1 test'

# Finally, run the test once again without environment flag; it should fail.
declare +x TESTBRIDGE_TEST_ONLY
$TESTBED --jvm_flag=${SUITE_FLAG} >& $TEST_log && fail "Expected failure again"
expect_log 'Failures: 1'

# Remove the XML output with failures, so it does not get picked up to
# indicate a failure.
rm -rf "${XML_OUTPUT_FILE}" || fail "failed to remove XML output"
}

# Test that TESTBRIDGE_TEST_ONLY is overridden by a direct flag.
function test_Junit4FlagOverridesEnv() {
cd $TEST_TMPDIR

# Run the test with both environment and command line flags.
declare -x TESTBRIDGE_TEST_ONLY="doNotRun"
$TESTBED --jvm_flag=${SUITE_FLAG} --test_filter doRun >& $TEST_log || \
fail "Expected success"
expect_log 'OK.*1 test'

declare -x TESTBRIDGE_TEST_ONLY="doRun"
$TESTBED --jvm_flag=${SUITE_FLAG} --test_filter doNotRun >& $TEST_log && \
fail "Expected failure"
expect_log 'Failures: 1'
}

run_suite "testbridge_test_only"
Loading

0 comments on commit 2bdf534

Please sign in to comment.