Skip to content

Commit 1ff3c04

Browse files
committed
Added additional tests
1 parent 90e11bd commit 1ff3c04

1 file changed

Lines changed: 88 additions & 0 deletions

File tree

test/unit/compile_data/compile_data_test.bzl

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,52 @@ def _transitive_data_not_in_compile_inputs_test_impl(ctx):
7979

8080
return analysistest.end(env)
8181

82+
def _transitive_compile_data_not_in_compile_inputs_test_impl(ctx):
83+
env = analysistest.begin(ctx)
84+
target = analysistest.target_under_test(env)
85+
86+
rustc_action = None
87+
for action in target.actions:
88+
if action.mnemonic == "Rustc":
89+
rustc_action = action
90+
break
91+
92+
asserts.false(env, rustc_action == None, "Expected a Rustc action")
93+
94+
compile_data_inputs = [i for i in rustc_action.inputs.to_list() if "transitive_compile_data_dep.txt" in i.path]
95+
asserts.equals(
96+
env,
97+
0,
98+
len(compile_data_inputs),
99+
"Expected transitive compile_data dep file to NOT appear in Rustc action inputs, but found: " +
100+
str([i.path for i in compile_data_inputs]),
101+
)
102+
103+
return analysistest.end(env)
104+
105+
def _data_propagates_to_runfiles_test_impl(ctx):
106+
env = analysistest.begin(ctx)
107+
target = analysistest.target_under_test(env)
108+
109+
runfiles = target[DefaultInfo].default_runfiles
110+
runfile_paths = [f.short_path for f in runfiles.files.to_list()]
111+
112+
asserts.true(
113+
env,
114+
any([p for p in runfile_paths if "transitive_data_dep.txt" in p]),
115+
"Expected transitive data dep file to appear in runfiles, but got: " +
116+
str(runfile_paths),
117+
)
118+
119+
return analysistest.end(env)
120+
82121
compile_data_propagates_to_crate_info_test = analysistest.make(_compile_data_propagates_to_crate_info_test_impl)
83122
wrapper_rule_propagates_to_crate_info_test = analysistest.make(_wrapper_rule_propagates_to_crate_info_test_impl)
84123
wrapper_rule_propagates_and_joins_compile_data_test = analysistest.make(_wrapper_rule_propagates_and_joins_compile_data_test_impl)
85124
compile_data_propagates_to_rust_doc_test = analysistest.make(_compile_data_propagates_to_rust_doc_test_impl)
86125
transitive_data_not_in_compile_inputs_test = analysistest.make(_transitive_data_not_in_compile_inputs_test_impl)
126+
transitive_compile_data_not_in_compile_inputs_test = analysistest.make(_transitive_compile_data_not_in_compile_inputs_test_impl)
127+
data_propagates_to_runfiles_test = analysistest.make(_data_propagates_to_runfiles_test_impl)
87128

88129
def _define_test_targets():
89130
rust_library(
@@ -193,6 +234,41 @@ def _define_test_targets():
193234
edition = "2021",
194235
)
195236

237+
write_file(
238+
name = "transitive_compile_data_dep_file",
239+
out = "transitive_compile_data_dep.txt",
240+
content = ["transitive compile data dep", ""],
241+
newline = "unix",
242+
)
243+
244+
write_file(
245+
name = "lib_with_compile_data_src",
246+
out = "lib_with_compile_data.rs",
247+
content = ["pub fn hello() {}", ""],
248+
newline = "unix",
249+
)
250+
251+
rust_library(
252+
name = "lib_with_compile_data",
253+
srcs = [":lib_with_compile_data.rs"],
254+
compile_data = [":transitive_compile_data_dep.txt"],
255+
edition = "2021",
256+
)
257+
258+
write_file(
259+
name = "lib_depending_on_compile_data_src",
260+
out = "lib_depending_on_compile_data.rs",
261+
content = ["extern crate lib_with_compile_data;", ""],
262+
newline = "unix",
263+
)
264+
265+
rust_library(
266+
name = "lib_depending_on_compile_data",
267+
srcs = [":lib_depending_on_compile_data.rs"],
268+
deps = [":lib_with_compile_data"],
269+
edition = "2021",
270+
)
271+
196272
def compile_data_test_suite(name):
197273
"""Entry-point macro called from the BUILD file.
198274
@@ -227,6 +303,16 @@ def compile_data_test_suite(name):
227303
target_under_test = ":lib_depending_on_data",
228304
)
229305

306+
transitive_compile_data_not_in_compile_inputs_test(
307+
name = "transitive_compile_data_not_in_compile_inputs_test",
308+
target_under_test = ":lib_depending_on_compile_data",
309+
)
310+
311+
data_propagates_to_runfiles_test(
312+
name = "data_propagates_to_runfiles_test",
313+
target_under_test = ":lib_depending_on_data",
314+
)
315+
230316
native.test_suite(
231317
name = name,
232318
tests = [
@@ -235,5 +321,7 @@ def compile_data_test_suite(name):
235321
":wrapper_rule_propagates_and_joins_compile_data_test",
236322
":compile_data_propagates_to_rust_doc_test",
237323
":transitive_data_not_in_compile_inputs_test",
324+
":transitive_compile_data_not_in_compile_inputs_test",
325+
":data_propagates_to_runfiles_test",
238326
],
239327
)

0 commit comments

Comments
 (0)