|
| 1 | +load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest") |
| 2 | +load("//src/main/starlark/core/options:opts.javac.bzl", "javac_options_to_flags") |
| 3 | +load("//src/main/starlark/core/options:opts.kotlinc.bzl", "kotlinc_options_to_flags") |
| 4 | + |
| 5 | +# x_backend_threads and x_optin require non-None values (map_value_to_flag fails with None) |
| 6 | +def _kopts(**kwargs): |
| 7 | + base = {"x_backend_threads": 1, "x_optin": []} |
| 8 | + base.update(kwargs) |
| 9 | + return struct(**base) |
| 10 | + |
| 11 | +def _kotlinc_flags_impl(ctx): |
| 12 | + env = unittest.begin(ctx) |
| 13 | + |
| 14 | + # map_value_to_flag path |
| 15 | + asserts.equals(env, ["-jvm-target=17"], kotlinc_options_to_flags(_kopts(jvm_target = "17"))) |
| 16 | + asserts.equals(env, ["-Xbackend-threads=4"], kotlinc_options_to_flags(_kopts(x_backend_threads = 4))) |
| 17 | + asserts.equals(env, ["-opt-in=A", "-opt-in=B"], kotlinc_options_to_flags(_kopts(x_optin = ["A", "B"]))) |
| 18 | + asserts.equals(env, ["-Xwarning-level=UNUSED:warning"], kotlinc_options_to_flags(_kopts(x_warning_level = {"UNUSED": "warning"}))) |
| 19 | + |
| 20 | + # value_to_flag dict path |
| 21 | + asserts.equals(env, ["-Werror"], kotlinc_options_to_flags(_kopts(warn = "error"))) |
| 22 | + asserts.equals(env, ["-nowarn"], kotlinc_options_to_flags(_kopts(warn = "off"))) |
| 23 | + asserts.equals(env, ["-no-stdlib"], kotlinc_options_to_flags(_kopts(include_stdlibs = "none"))) |
| 24 | + |
| 25 | + # derive.info path (repeated_values_for) |
| 26 | + asserts.equals(env, ["-Xsuppress-warning=SOME"], kotlinc_options_to_flags(_kopts(x_suppress_warning = ["SOME"]))) |
| 27 | + |
| 28 | + # defaults produce no flags; None provider is falsy |
| 29 | + asserts.equals(env, [], kotlinc_options_to_flags(_kopts())) |
| 30 | + asserts.true(env, not kotlinc_options_to_flags(None)) |
| 31 | + |
| 32 | + return unittest.end(env) |
| 33 | + |
| 34 | +kotlinc_flags_test = unittest.make(_kotlinc_flags_impl) |
| 35 | + |
| 36 | +def _javac_flags_impl(ctx): |
| 37 | + env = unittest.begin(ctx) |
| 38 | + |
| 39 | + # value_to_flag dict path |
| 40 | + asserts.equals(env, ["--release 17"], javac_options_to_flags(struct(release = "17"))) |
| 41 | + asserts.equals(env, ["-Werror"], javac_options_to_flags(struct(warn = "error"))) |
| 42 | + asserts.equals(env, ["-nowarn"], javac_options_to_flags(struct(warn = "off"))) |
| 43 | + |
| 44 | + # derive.repeated_values_for path |
| 45 | + asserts.equals(env, ["-Xlint:all", "-Xlint:cast"], javac_options_to_flags(struct(x_lint = ["all", "cast"]))) |
| 46 | + asserts.equals(env, ["--add-exports=java.base/sun.nio.ch"], javac_options_to_flags(struct(add_exports = ["java.base/sun.nio.ch"]))) |
| 47 | + |
| 48 | + # derive.format_key_value_for path |
| 49 | + asserts.equals(env, ["-Akey=v"], javac_options_to_flags(struct(annotation_processor_options = {"key": "v"}))) |
| 50 | + |
| 51 | + # None provider is falsy |
| 52 | + asserts.true(env, not javac_options_to_flags(None)) |
| 53 | + |
| 54 | + return unittest.end(env) |
| 55 | + |
| 56 | +javac_flags_test = unittest.make(_javac_flags_impl) |
| 57 | + |
| 58 | +def opts_test_suite(name): |
| 59 | + unittest.suite(name, kotlinc_flags_test, javac_flags_test) |
0 commit comments