diff options
author | Kush Chakraborty <kush@google.com> | 2017-03-23 17:42:14 +0000 |
---|---|---|
committer | Yue Gan <yueg@google.com> | 2017-03-23 17:55:32 +0000 |
commit | 0248dbb92e54b411b24166abda64f3f57f3eab35 (patch) | |
tree | cb621a1c16c4c1fa67ebd3c57db52357a839c21c /src/test/shell | |
parent | 12b98fb6003abbe55c69a0ea1c282fb990c88971 (diff) |
Stop adding the TestRunner's JAR as part of the compile time classpath, when experimental_testrunner is invoked. This has the unintended side effect of accidentally supplying dependencies such as JUnit and hamcrest, when bazel should enforce the target to specify those dependencies explicitly.
We should eventually make this the default behaviour of bazel instead of hiding it behind the experimental_testrunner flag.
This is another partial rollforward of commit 786cfa2ed980e278c42ee474408844f7e3720385
--
PiperOrigin-RevId: 151022781
MOS_MIGRATED_REVID=151022781
Diffstat (limited to 'src/test/shell')
-rwxr-xr-x | src/test/shell/bazel/bazel_java_test.sh | 51 | ||||
-rwxr-xr-x | src/test/shell/bazel/bazel_sandboxing_test.sh | 4 | ||||
-rwxr-xr-x | src/test/shell/bazel/persistent_test_runner_test.sh | 7 |
3 files changed, 61 insertions, 1 deletions
diff --git a/src/test/shell/bazel/bazel_java_test.sh b/src/test/shell/bazel/bazel_java_test.sh index 1709ff3262..691511c041 100755 --- a/src/test/shell/bazel/bazel_java_test.sh +++ b/src/test/shell/bazel/bazel_java_test.sh @@ -322,6 +322,7 @@ EOF } function test_java_test_main_class() { + setup_javatest_support mkdir -p java/testrunners || fail "mkdir failed" cat > java/testrunners/TestRunner.java <<EOF package testrunners; @@ -361,6 +362,7 @@ java_library(name = "test_runner", java_test(name = "Tests", srcs = ['Tests.java'], + deps = ['//third_party:junit4'], main_class = "testrunners.TestRunner", runtime_deps = [':test_runner'] ) @@ -574,6 +576,7 @@ EOF } function test_java_test_java_sandwich() { + setup_javatest_support mkdir -p java/com/google/sandwich cd java/com/google/sandwich @@ -586,7 +589,10 @@ java_test( name = "MainTest", size = "small", srcs = ["MainTest.java"], - deps = [":custom"] + deps = [ + ":custom", + "//third_party:junit4", + ], ) java_custom_library( @@ -650,5 +656,48 @@ EOF expect_log "Test message" } +function test_junit_deps_enforced_with_experimental_testrunner() { + setup_javatest_support + mkdir -p java/testrunners || fail "mkdir failed" + + cat > java/testrunners/Tests.java <<EOF +package testrunners; + +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +import org.junit.Test; + +@RunWith(JUnit4.class) +public class Tests { + + @Test + public void testTest() { + System.out.println("testTest was run"); + } +} +EOF + + # With experimental_testrunner, we fail without explicitly specifying the JUnit deps. + cat > java/testrunners/BUILD <<EOF +java_test(name = "Tests", + srcs = ['Tests.java'], + tags = ['experimental_testrunner'], +) +EOF + bazel test --test_output=streamed //java/testrunners:Tests &> "$TEST_log" && fail "Expected Failure" || true + expect_log "cannot find symbol" + + # We start passing again with experimental_testrunner once we explicitly specify the deps. + cat > java/testrunners/BUILD <<EOF +java_test(name = "Tests", + srcs = ['Tests.java'], + tags = ['experimental_testrunner'], + deps = ['//third_party:junit4'], +) +EOF + bazel test --test_output=streamed //java/testrunners:Tests &> "$TEST_log" || fail "Expected success" + expect_log "testTest was run" +} + run_suite "Java integration tests" diff --git a/src/test/shell/bazel/bazel_sandboxing_test.sh b/src/test/shell/bazel/bazel_sandboxing_test.sh index c5e75f048f..8e393d86ec 100755 --- a/src/test/shell/bazel/bazel_sandboxing_test.sh +++ b/src/test/shell/bazel/bazel_sandboxing_test.sh @@ -378,6 +378,7 @@ EOF } function test_sandbox_can_resolve_own_hostname() { + setup_javatest_support mkdir -p src/test/java/com/example cat > src/test/java/com/example/HostNameTest.java <<'EOF' package com.example; @@ -400,6 +401,7 @@ EOF java_test( name = "HostNameTest", srcs = ["HostNameTest.java"], + deps = ['//third_party:junit4'], ) EOF @@ -408,6 +410,7 @@ EOF } function test_hostname_inside_sandbox_is_localhost_when_using_sandbox_fake_hostname_flag() { + setup_javatest_support mkdir -p src/test/java/com/example cat > src/test/java/com/example/HostNameIsLocalhostTest.java <<'EOF' package com.example; @@ -430,6 +433,7 @@ EOF java_test( name = "HostNameIsLocalhostTest", srcs = ["HostNameIsLocalhostTest.java"], + deps = ['//third_party:junit4'], ) EOF diff --git a/src/test/shell/bazel/persistent_test_runner_test.sh b/src/test/shell/bazel/persistent_test_runner_test.sh index 7e92151246..0b82694c1b 100755 --- a/src/test/shell/bazel/persistent_test_runner_test.sh +++ b/src/test/shell/bazel/persistent_test_runner_test.sh @@ -23,6 +23,7 @@ source "${CURRENT_DIR}/../integration_test_setup.sh" \ || { echo "integration_test_setup.sh not found!" >&2; exit 1; } function test_simple_scenario() { + setup_javatest_support mkdir -p java/testrunners || fail "mkdir failed" cat > java/testrunners/TestsPass.java <<EOF @@ -63,11 +64,13 @@ EOF cat > java/testrunners/BUILD <<EOF java_test(name = "TestsPass", srcs = ['TestsPass.java'], + deps = ['//third_party:junit4'], tags = ["experimental_testrunner"], ) java_test(name = "TestsFail", srcs = ['TestsFail.java'], + deps = ['//third_party:junit4'], tags = ["experimental_testrunner"], ) EOF @@ -82,6 +85,7 @@ EOF # TODO(kush): Enable this test once we're able to reload modified classes in persistent test runner. function DISABLED_test_reload_modified_classes() { + setup_javatest_support mkdir -p java/testrunners || fail "mkdir failed" # Create a passing test. @@ -105,6 +109,7 @@ EOF cat > java/testrunners/BUILD <<EOF java_test(name = "Tests", srcs = ['Tests.java'], + deps = ['//third_party:junit4'], ) EOF @@ -169,6 +174,7 @@ EOF } function test_fail_without_experimental_testrunner() { + setup_javatest_support mkdir -p java/testrunners || fail "mkdir failed" cat > java/testrunners/Tests.java <<EOF @@ -191,6 +197,7 @@ EOF cat > java/testrunners/BUILD <<EOF java_test(name = "Tests", srcs = ['Tests.java'], + deps = ['//third_party:junit4'], ) EOF |