|
| 1 | +load("@rules_testing//lib:analysis_test.bzl", "analysis_test") |
| 2 | +load("@rules_testing//lib:test_suite.bzl", "test_suite") |
| 3 | +load("@rules_testing//lib:util.bzl", "util") |
| 4 | +load("//kotlin:jvm.bzl", "kt_jvm_binary") |
| 5 | + |
| 6 | +def _kt_jvm_binary_env_test_impl(env, target): |
| 7 | + """Test that kt_jvm_binary sets RunEnvironmentInfo correctly.""" |
| 8 | + |
| 9 | + # Check that RunEnvironmentInfo is present |
| 10 | + env.expect.that_target(target).has_provider(RunEnvironmentInfo) |
| 11 | + |
| 12 | + # Get the RunEnvironmentInfo provider |
| 13 | + run_env_info = target[RunEnvironmentInfo] |
| 14 | + |
| 15 | + # Verify the environment variables |
| 16 | + env.expect.that_dict(run_env_info.environment).contains_exactly({ |
| 17 | + "FOO": "bar", |
| 18 | + "BAZ": "qux", |
| 19 | + }) |
| 20 | + |
| 21 | + # Verify the inherited environment variables |
| 22 | + env.expect.that_collection(run_env_info.inherited_environment).contains_exactly([ |
| 23 | + "HOME", |
| 24 | + "PATH", |
| 25 | + ]) |
| 26 | + |
| 27 | +def _kt_jvm_binary_env_test(name): |
| 28 | + """Creates a test that verifies env and env_inherit attributes work.""" |
| 29 | + kt_jvm_binary( |
| 30 | + name = name + "_subject", |
| 31 | + srcs = [util.empty_file(name + "_Main.kt")], |
| 32 | + main_class = "test.Main", |
| 33 | + env = { |
| 34 | + "FOO": "bar", |
| 35 | + "BAZ": "qux", |
| 36 | + }, |
| 37 | + env_inherit = ["HOME", "PATH"], |
| 38 | + tags = ["manual"], |
| 39 | + ) |
| 40 | + |
| 41 | + analysis_test( |
| 42 | + name = name, |
| 43 | + impl = _kt_jvm_binary_env_test_impl, |
| 44 | + target = name + "_subject", |
| 45 | + ) |
| 46 | + |
| 47 | +def _kt_jvm_binary_empty_env_test_impl(env, target): |
| 48 | + """Test that kt_jvm_binary works with no env attributes.""" |
| 49 | + |
| 50 | + # Check that RunEnvironmentInfo is present |
| 51 | + env.expect.that_target(target).has_provider(RunEnvironmentInfo) |
| 52 | + |
| 53 | + # Get the RunEnvironmentInfo provider |
| 54 | + run_env_info = target[RunEnvironmentInfo] |
| 55 | + |
| 56 | + # Verify the environment is empty |
| 57 | + env.expect.that_dict(run_env_info.environment).contains_exactly({}) |
| 58 | + |
| 59 | + # Verify no inherited environment variables |
| 60 | + env.expect.that_collection(run_env_info.inherited_environment).contains_exactly([]) |
| 61 | + |
| 62 | +def _kt_jvm_binary_empty_env_test(name): |
| 63 | + """Creates a test that verifies default env behavior.""" |
| 64 | + kt_jvm_binary( |
| 65 | + name = name + "_subject", |
| 66 | + srcs = [util.empty_file(name + "_Main.kt")], |
| 67 | + main_class = "test.Main", |
| 68 | + tags = ["manual"], |
| 69 | + ) |
| 70 | + |
| 71 | + analysis_test( |
| 72 | + name = name, |
| 73 | + impl = _kt_jvm_binary_empty_env_test_impl, |
| 74 | + target = name + "_subject", |
| 75 | + ) |
| 76 | + |
| 77 | +def kt_jvm_binary_env_test_suite(name): |
| 78 | + """Test suite for kt_jvm_binary env support.""" |
| 79 | + test_suite( |
| 80 | + name = name, |
| 81 | + tests = [ |
| 82 | + _kt_jvm_binary_env_test, |
| 83 | + _kt_jvm_binary_empty_env_test, |
| 84 | + ], |
| 85 | + ) |
0 commit comments