Move java_runtime tests to the toolchains directory. The tests for the `java_runtime` rule are now located in `test/java/toolchains/java_runtime_tests.bzl`, aligning with the location of the `java_runtime` rule itself. PiperOrigin-RevId: 870739029 Change-Id: I56d58653eb9e9b8ed700adad7a9fce7750ae1645
diff --git a/test/java/common/rules/BUILD b/test/java/common/rules/BUILD index 8a00159..2311a3f 100644 --- a/test/java/common/rules/BUILD +++ b/test/java/common/rules/BUILD
@@ -2,7 +2,6 @@ load(":java_import_tests.bzl", "java_import_tests") load(":java_library_tests.bzl", "java_library_tests") load(":java_plugin_tests.bzl", "java_plugin_tests") -load(":java_runtime_tests.bzl", "java_runtime_tests") load(":java_test_tests.bzl", "java_test_tests") load(":merge_attrs_tests.bzl", "merge_attrs_test_suite") @@ -18,6 +17,4 @@ java_import_tests(name = "java_import_tests") -java_runtime_tests(name = "java_runtime_tests") - java_test_tests(name = "java_test_tests")
diff --git a/test/java/common/rules/java_runtime_tests.bzl b/test/java/common/rules/java_runtime_tests.bzl deleted file mode 100644 index 454aa9c..0000000 --- a/test/java/common/rules/java_runtime_tests.bzl +++ /dev/null
@@ -1,158 +0,0 @@ -"""Tests for the java_runtime rule""" - -load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") -load("@rules_testing//lib:truth.bzl", "matching") -load("@rules_testing//lib:util.bzl", "util") -load("//java/toolchains:java_runtime.bzl", "java_runtime") -load("//test/java/testutil:java_runtime_info_subject.bzl", "java_runtime_info_subject") - -def _test_java_runtime_simple(name): - util.helper_target( - java_runtime, - name = name + "/jvm-foo", - srcs = [ - "foo/a", - "foo/b", - ], - java_home = "foo", - ) - - analysis_test( - name = name, - impl = _test_java_runtime_simple_impl, - target = name + "/jvm-foo", - ) - -def _test_java_runtime_simple_impl(env, target): - java_runtime_info_subject.from_target(env, target).files().contains_exactly([ - "{package}/foo/a", - "{package}/foo/b", - ]) - env.expect.that_target(target).data_runfiles().contains_exactly([ - "{workspace}/{package}/foo/a", - "{workspace}/{package}/foo/b", - ]) - -def _test_absolute_java_home_with_srcs(name): - util.helper_target( - java_runtime, - name = name + "/jvm", - srcs = ["dummy.txt"], - java_home = "/absolute/path", - ) - - analysis_test( - name = name, - impl = _test_absolute_java_home_with_srcs_impl, - target = name + "/jvm", - expect_failure = True, - ) - -def _test_absolute_java_home_with_srcs_impl(env, target): - env.expect.that_target(target).failures().contains_predicate( - matching.str_matches("'java_home' with an absolute path requires 'srcs' to be empty."), - ) - -def _test_absolute_java_home_with_java(name): - util.helper_target( - java_runtime, - name = name + "/jvm", - java = "bin/java", - java_home = "/absolute/path", - ) - - analysis_test( - name = name, - impl = _test_absolute_java_home_with_java_impl, - target = name + "/jvm", - expect_failure = True, - ) - -def _test_absolute_java_home_with_java_impl(env, target): - env.expect.that_target(target).failures().contains_predicate( - matching.str_matches("'java_home' with an absolute path requires 'java' to be empty."), - ) - -def _test_bin_java_path_name(name): - util.helper_target( - java_runtime, - name = name + "/jvm", - java = "java", - ) - - analysis_test( - name = name, - impl = _test_bin_java_path_name_impl, - target = name + "/jvm", - expect_failure = True, - ) - -def _test_bin_java_path_name_impl(env, target): - env.expect.that_target(target).failures().contains_predicate( - matching.str_matches("the path to 'java' must end in 'bin/java'."), - ) - -def _test_absolute_java_home(name): - util.helper_target( - java_runtime, - name = name + "/jvm", - java_home = "/absolute/path", - ) - - analysis_test( - name = name, - impl = _test_absolute_java_home_impl, - target = name + "/jvm", - ) - -def _test_absolute_java_home_impl(env, target): - java_runtime_info_subject.from_target(env, target).java_home().equals("/absolute/path") - -def _test_relative_java_home(name): - util.helper_target( - java_runtime, - name = name + "/jvm", - java_home = "b/c", - ) - - analysis_test( - name = name, - impl = _test_relative_java_home_impl, - target = name + "/jvm", - ) - -def _test_relative_java_home_impl(env, target): - java_runtime_info_subject.from_target(env, target).java_home().equals("{package}/b/c") - -def _test_java_home_with_invalid_make_variables(name): - util.helper_target( - java_runtime, - name = name + "/jvm", - java_home = "/opt/$(WTF)", - ) - - analysis_test( - name = name, - impl = _test_java_home_with_invalid_make_variables_impl, - target = name + "/jvm", - expect_failure = True, - ) - -def _test_java_home_with_invalid_make_variables_impl(env, target): - env.expect.that_target(target).failures().contains_predicate( - matching.str_matches("$(WTF) not defined"), - ) - -def java_runtime_tests(name): - test_suite( - name = name, - tests = [ - _test_java_runtime_simple, - _test_absolute_java_home_with_srcs, - _test_absolute_java_home_with_java, - _test_bin_java_path_name, - _test_absolute_java_home, - _test_relative_java_home, - _test_java_home_with_invalid_make_variables, - ], - )
diff --git a/test/java/toolchains/java_runtime_tests.bzl b/test/java/toolchains/java_runtime_tests.bzl index 2cc617b..a32c3a9 100644 --- a/test/java/toolchains/java_runtime_tests.bzl +++ b/test/java/toolchains/java_runtime_tests.bzl
@@ -1,6 +1,7 @@ """Tests for the java_runtime rule""" load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") +load("@rules_testing//lib:truth.bzl", "matching") load("@rules_testing//lib:util.bzl", "util") load("//java/common:java_semantics.bzl", "semantics") load("//java/toolchains:java_runtime.bzl", "java_runtime") @@ -151,6 +152,143 @@ env.expect.that_target(target).has_provider(platform_common.ToolchainInfo) env.expect.that_target(target).has_provider(platform_common.TemplateVariableInfo) +def _test_java_runtime_simple(name): + util.helper_target( + java_runtime, + name = name + "/jvm-foo", + srcs = [ + "foo/a", + "foo/b", + ], + java_home = "foo", + ) + + analysis_test( + name = name, + impl = _test_java_runtime_simple_impl, + target = name + "/jvm-foo", + ) + +def _test_java_runtime_simple_impl(env, target): + java_runtime_info_subject.from_target(env, target).files().contains_exactly([ + "{package}/foo/a", + "{package}/foo/b", + ]) + env.expect.that_target(target).data_runfiles().contains_exactly([ + "{workspace}/{package}/foo/a", + "{workspace}/{package}/foo/b", + ]) + +def _test_absolute_java_home_with_srcs(name): + util.helper_target( + java_runtime, + name = name + "/jvm", + srcs = ["dummy.txt"], + java_home = "/absolute/path", + ) + + analysis_test( + name = name, + impl = _test_absolute_java_home_with_srcs_impl, + target = name + "/jvm", + expect_failure = True, + ) + +def _test_absolute_java_home_with_srcs_impl(env, target): + env.expect.that_target(target).failures().contains_predicate( + matching.str_matches("'java_home' with an absolute path requires 'srcs' to be empty."), + ) + +def _test_absolute_java_home_with_java(name): + util.helper_target( + java_runtime, + name = name + "/jvm", + java = "bin/java", + java_home = "/absolute/path", + ) + + analysis_test( + name = name, + impl = _test_absolute_java_home_with_java_impl, + target = name + "/jvm", + expect_failure = True, + ) + +def _test_absolute_java_home_with_java_impl(env, target): + env.expect.that_target(target).failures().contains_predicate( + matching.str_matches("'java_home' with an absolute path requires 'java' to be empty."), + ) + +def _test_bin_java_path_name(name): + util.helper_target( + java_runtime, + name = name + "/jvm", + java = "java", + ) + + analysis_test( + name = name, + impl = _test_bin_java_path_name_impl, + target = name + "/jvm", + expect_failure = True, + ) + +def _test_bin_java_path_name_impl(env, target): + env.expect.that_target(target).failures().contains_predicate( + matching.str_matches("the path to 'java' must end in 'bin/java'."), + ) + +def _test_absolute_java_home(name): + util.helper_target( + java_runtime, + name = name + "/jvm", + java_home = "/absolute/path", + ) + + analysis_test( + name = name, + impl = _test_absolute_java_home_impl, + target = name + "/jvm", + ) + +def _test_absolute_java_home_impl(env, target): + java_runtime_info_subject.from_target(env, target).java_home().equals("/absolute/path") + +def _test_relative_java_home(name): + util.helper_target( + java_runtime, + name = name + "/jvm", + java_home = "b/c", + ) + + analysis_test( + name = name, + impl = _test_relative_java_home_impl, + target = name + "/jvm", + ) + +def _test_relative_java_home_impl(env, target): + java_runtime_info_subject.from_target(env, target).java_home().equals("{package}/b/c") + +def _test_java_home_with_invalid_make_variables(name): + util.helper_target( + java_runtime, + name = name + "/jvm", + java_home = "/opt/$(WTF)", + ) + + analysis_test( + name = name, + impl = _test_java_home_with_invalid_make_variables_impl, + target = name + "/jvm", + expect_failure = True, + ) + +def _test_java_home_with_invalid_make_variables_impl(env, target): + env.expect.that_target(target).failures().contains_predicate( + matching.str_matches("$(WTF) not defined"), + ) + def java_runtime_tests(name): test_suite( name = name, @@ -159,5 +297,12 @@ _test_with_hermetic_java_home, _test_with_generated_java_executable, _test_runtime_alias, + _test_java_runtime_simple, + _test_absolute_java_home_with_srcs, + _test_absolute_java_home_with_java, + _test_bin_java_path_name, + _test_absolute_java_home, + _test_relative_java_home, + _test_java_home_with_invalid_make_variables, ], )