@@ -5,26 +5,49 @@ load("//kotlin/compiler:kapt.bzl", "kapt_compiler_plugin")
55load ("//src/test/starlark:case.bzl" , "Want" , "suite" )
66load ("//src/test/starlark:truth.bzl" , "flags_and_values_of" )
77
8+ def _normalize_path_with_cfg (file ):
9+ """Attempts to normalize the file to standard configs.
10+
11+ This turns out to be necessary due to multiple transitions with testing.analysis_test.
12+ """
13+ prefix = file .path .removesuffix (file .short_path )
14+ segments = prefix .split ("/" )
15+ if segments [0 ] == "external" :
16+ return "(source) " + file .short_path
17+ if segments [0 ] == "bazel-out" :
18+ # not exactly reliable, but the current test rules perform several transitions making it
19+ # difficult to validate if a file is actually where it should be.
20+ if "exec" in segments [1 ]:
21+ return "(exec) " + file .short_path
22+ return "(target) " + file .short_path
23+
824def _action (env , got ):
925 got_target = env .expect .that_target (got )
1026
11- inputs = []
27+ want_inputs = {}
1228 for i in env .ctx .attr .exec_inputs :
1329 if JavaInfo in i :
1430 for jo in i [JavaInfo ].java_outputs :
15- inputs . append (jo .compile_jar )
31+ want_inputs [ _normalize_path_with_cfg (jo .compile_jar )] = True
1632 else :
17- inputs .extend (i [DefaultInfo ].files .to_list ())
33+ for f in i [DefaultInfo ].files .to_list ():
34+ want_inputs [_normalize_path_with_cfg (f )] = True
1835 for i in env .ctx .attr .target_inputs :
1936 if JavaInfo in i :
2037 for jo in i [JavaInfo ].java_outputs :
21- inputs . append (jo .compile_jar )
38+ want_inputs [ _normalize_path_with_cfg (jo .compile_jar )] = True
2239 else :
23- inputs .extend (i [DefaultInfo ].files .to_list ())
40+ for f in i [DefaultInfo ].files .to_list ():
41+ want_inputs [_normalize_path_with_cfg (f )] = True
2442
2543 compile = got_target .action_named (env .ctx .attr .mnemonic )
2644
27- compile .contains_at_least_inputs (inputs )
45+ got_inputs = {
46+ _normalize_path_with_cfg (f ): True
47+ for f in compile .actual .inputs .to_list ()
48+ }
49+
50+ env .expect .that_collection (got_inputs .keys ()).contains_at_least (want_inputs .keys ())
2851
2952 got_target .runfiles ().contains_at_least ([
3053 "/" .join ((env .ctx .workspace_name , f .short_path ))
@@ -90,7 +113,7 @@ def _apoptions_to_kotlinc(rule_under_test, **kwargs):
90113 value = [],
91114 ),
92115 "exec_inputs" : Want (
93- attr = attr .label_list (allow_empty = True , allow_files = True , cfg = "exec " ),
116+ attr = attr .label_list (allow_empty = True , allow_files = True , cfg = "target " ),
94117 value = [dep_jar ],
95118 ),
96119 "target_inputs" : Want (
0 commit comments