Migrate the `javaTestInvalidTestClassAtRootPackage` test to Starlark The test is removed from Bazel and added to rules_java (ignore-relnotes) PiperOrigin-RevId: 911323913 Change-Id: Ie7cd3da252158916945911ef1cf59099a098e4e0
diff --git a/BUILD b/BUILD index 9f0e223..2fbbbd6 100644 --- a/BUILD +++ b/BUILD
@@ -1,4 +1,5 @@ load("@rules_license//rules:license.bzl", "license") +load("//java:java_test.bzl", "java_test") package(default_applicable_licenses = [":license"]) @@ -27,3 +28,17 @@ name = "license", package_name = "rules_java", ) + +# For exercising root-package behavior in tests +java_test( + name = "invalid_test_at_repo_root", + srcs = ["SomeTest.java"], + tags = [ + "manual", + "nobuilder", + "notap", + ], + visibility = [ + "//test/java/bazel/rules:__pkg__", + ], +)
diff --git a/test/java/bazel/rules/java_test_tests.bzl b/test/java/bazel/rules/java_test_tests.bzl index 9ee618d..5c76b0e 100644 --- a/test/java/bazel/rules/java_test_tests.bzl +++ b/test/java/bazel/rules/java_test_tests.bzl
@@ -35,10 +35,25 @@ matching.str_matches("-Dbazel.test_suite=bazel.rules.test_deduced_test_class.foo"), ) +# regression test for https://github.com/bazelbuild/bazel/issues/20378 +def _test_invalid_test_class_at_repo_root(name): + analysis_test( + name = name, + impl = _test_invalid_test_class_at_repo_root_impl, + target = "//:invalid_test_at_repo_root", + expect_failure = True, + ) + +def _test_invalid_test_class_at_repo_root_impl(env, target): + env.expect.that_target(target).failures().contains_predicate( + matching.str_matches("cannot determine test class."), + ) + def java_test_tests(name): test_suite( name = name, tests = [ _test_deduced_test_class, + _test_invalid_test_class_at_repo_root, ], )