• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""Tests for the bootclasspath rule."""
2
3load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite")
4load("@rules_testing//lib:truth.bzl", "subjects")
5load("//java/common:java_common.bzl", "java_common")
6
7def _test_utf_8_environment(name):
8    analysis_test(
9        name = name,
10        impl = _test_utf_8_environment_impl,
11        target = Label("//toolchains:platformclasspath"),
12    )
13
14def _test_utf_8_environment_impl(env, target):
15    for action in target.actions:
16        env_subject = env.expect.where(action = action).that_dict(action.env)
17        env_subject.keys().contains("LC_CTYPE")
18        env_subject.get("LC_CTYPE", factory = subjects.str).contains("UTF-8")
19
20def _test_incompatible_language_version_bootclasspath_disabled(name):
21    analysis_test(
22        name = name,
23        impl = _test_incompatible_language_version_bootclasspath_disabled_impl,
24        target = Label("//toolchains:platformclasspath"),
25        config_settings = {
26            "//command_line_option:java_language_version": "11",
27            "//command_line_option:java_runtime_version": "remotejdk_17",
28            str(Label("//toolchains:incompatible_language_version_bootclasspath")): False,
29        },
30    )
31
32def _test_incompatible_language_version_bootclasspath_disabled_impl(env, target):
33    system_path = target[java_common.BootClassPathInfo]._system_path
34    env.expect.that_str(system_path).contains("remotejdk17_")
35
36def _test_incompatible_language_version_bootclasspath_enabled_versioned(name):
37    analysis_test(
38        name = name,
39        impl = _test_incompatible_language_version_bootclasspath_enabled_versioned_impl,
40        target = Label("//toolchains:platformclasspath"),
41        config_settings = {
42            "//command_line_option:java_language_version": "11",
43            "//command_line_option:java_runtime_version": "remotejdk_17",
44            str(Label("//toolchains:incompatible_language_version_bootclasspath")): True,
45        },
46    )
47
48def _test_incompatible_language_version_bootclasspath_enabled_versioned_impl(env, target):
49    system_path = target[java_common.BootClassPathInfo]._system_path
50    env.expect.that_str(system_path).contains("remotejdk11_")
51
52def _test_incompatible_language_version_bootclasspath_enabled_unversioned(name):
53    analysis_test(
54        name = name,
55        impl = _test_incompatible_language_version_bootclasspath_enabled_unversioned_impl,
56        target = Label("//toolchains:platformclasspath"),
57        config_settings = {
58            "//command_line_option:java_language_version": "11",
59            "//command_line_option:java_runtime_version": "local_jdk",
60            str(Label("//toolchains:incompatible_language_version_bootclasspath")): True,
61        },
62    )
63
64def _test_incompatible_language_version_bootclasspath_enabled_unversioned_impl(env, target):
65    system_path = target[java_common.BootClassPathInfo]._system_path
66    env.expect.that_str(system_path).contains("local_jdk")
67
68def bootclasspath_tests(name):
69    test_suite(
70        name = name,
71        tests = [
72            _test_utf_8_environment,
73            _test_incompatible_language_version_bootclasspath_disabled,
74            _test_incompatible_language_version_bootclasspath_enabled_versioned,
75            _test_incompatible_language_version_bootclasspath_enabled_unversioned,
76        ],
77    )
78