diff options
author | 2017-03-08 15:30:59 +0000 | |
---|---|---|
committer | 2017-03-09 10:27:29 +0000 | |
commit | 4baedc7bf96bd06b36c4af241b7423d21b6ba424 (patch) | |
tree | c17272f6e4f49c539f708b0b79517b543622f76e /src/main | |
parent | cb8a5e25382cb67a80449ac1fb78ae9680650b92 (diff) |
Create ExperimentalTestRunner which is just the same as BazelTestRunner, but a testbed of upcoming changes, without breaking existing test targets.
To use the alternate test runner a java test should add the tag "experimental_testrunner" and depend on "@bazel_tools//tools/jdk:ExperimentalTestRunner_deploy.jar" (instead of @bazel_tools//tools/jdk:TestRunner_deploy.jar)
--
PiperOrigin-RevId: 149536298
MOS_MIGRATED_REVID=149536298
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaRuleClasses.java | 13 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaSemantics.java | 18 |
2 files changed, 29 insertions, 2 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaRuleClasses.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaRuleClasses.java index 2946b297a1..87a02bb547 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaRuleClasses.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaRuleClasses.java @@ -60,6 +60,8 @@ public class BazelJavaRuleClasses { PackageNameConstraint.ANY_SEGMENT, "java", "javatests"); protected static final String JUNIT_TESTRUNNER = "//tools/jdk:TestRunner_deploy.jar"; + protected static final String EXPERIMENTAL_TESTRUNNER = + "//tools/jdk:ExperimentalTestRunner_deploy.jar"; public static final ImplicitOutputsFunction JAVA_BINARY_IMPLICIT_OUTPUTS = fromFunctions( @@ -391,6 +393,17 @@ public class BazelJavaRuleClasses { : null; } })) + .add( + attr("$experimental_testsupport", LABEL) + .value( + new Attribute.ComputedDefault("use_testrunner") { + @Override + public Object getDefault(AttributeMap rule) { + return rule.get("use_testrunner", Type.BOOLEAN) + ? env.getToolsLabel(EXPERIMENTAL_TESTRUNNER) + : null; + } + })) /* <!-- #BLAZE_RULE($base_java_binary).ATTRIBUTE(deploy_manifest_lines) --> A list of lines to add to the <code>META-INF/manifest.mf</code> file generated for the <code>*_deploy.jar</code> target. The contents of this attribute are <em>not</em> subject diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaSemantics.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaSemantics.java index f5fa1ff7ae..d4156ba4f3 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaSemantics.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaSemantics.java @@ -80,6 +80,11 @@ public class BazelJavaSemantics implements JavaSemantics { private static final String JACOCO_COVERAGE_RUNNER_MAIN_CLASS = "com.google.testing.coverage.JacocoCoverageRunner"; + private static final String BAZEL_TEST_RUNNER_MAIN_CLASS = + "com.google.testing.junit.runner.BazelTestRunner"; + private static final String EXPERIMENTAL_TEST_RUNNER_MAIN_CLASS = + "com.google.testing.junit.runner.ExperimentalTestRunner"; + private static final String EXPERIMENTAL_TESTRUNNER_TAG = "experimental_testrunner"; private BazelJavaSemantics() { } @@ -120,13 +125,20 @@ public class BazelJavaSemantics implements JavaSemantics { if (mainClass.isEmpty()) { if (ruleContext.attributes().get("use_testrunner", Type.BOOLEAN) && !useLegacyJavaTest(ruleContext)) { - return "com.google.testing.junit.runner.BazelTestRunner"; + return useExperimentalTestRunner(ruleContext) + ? EXPERIMENTAL_TEST_RUNNER_MAIN_CLASS + : BAZEL_TEST_RUNNER_MAIN_CLASS; } mainClass = JavaCommon.determinePrimaryClass(ruleContext, sources); } return mainClass; } + private static boolean useExperimentalTestRunner(RuleContext ruleContext) { + List<String> tags = ruleContext.attributes().get("tags", Type.STRING_LIST); + return tags.contains(EXPERIMENTAL_TESTRUNNER_TAG); + } + private void checkMainClass(RuleContext ruleContext, ImmutableList<Artifact> sources) { boolean createExecutable = ruleContext.attributes().get("create_executable", Type.BOOLEAN); String mainClass = getMainClassInternal(ruleContext, sources); @@ -294,7 +306,9 @@ public class BazelJavaSemantics implements JavaSemantics { boolean createExecutable = ruleContext.attributes().get("create_executable", Type.BOOLEAN); if (createExecutable && ruleContext.attributes().get("use_testrunner", Type.BOOLEAN)) { - return Iterables.getOnlyElement(ruleContext.getPrerequisites("$testsupport", Mode.TARGET)); + String testSupport = + useExperimentalTestRunner(ruleContext) ? "$experimental_testsupport" : "$testsupport"; + return Iterables.getOnlyElement(ruleContext.getPrerequisites(testSupport, Mode.TARGET)); } else { return null; } |