Skip to content

Commit c6b4625

Browse files
author
Tamas Vajk
committed
Add test for rustfmt with generated compile_data
Add a test case with an intentionally unformatted source file and generated compile_data. This triggers transform_sources to symlink sources into bazel-out, exercising the fix in _find_rustfmtable_srcs. Without the fix, rustfmt silently passes (sources are skipped). With the fix, rustfmt correctly detects the formatting issue.
1 parent 1f30678 commit c6b4625

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

test/rustfmt/rustfmt_failure_tester.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ EOF
8686
check_build_result $TEST_OK ${variant}_formatted_2015_test
8787
check_build_result $TEST_OK ${variant}_formatted_2018_test
8888
check_build_result $TEST_OK ${variant}_generated_test
89+
check_build_result $TEST_FAILED ${variant}_compile_data_generated_test
8990
done
9091

9192
# Format a specific target
@@ -99,6 +100,7 @@ EOF
99100
check_build_result $TEST_OK ${variant}_formatted_2015_test
100101
check_build_result $TEST_OK ${variant}_formatted_2018_test
101102
check_build_result $TEST_OK ${variant}_generated_test
103+
check_build_result $TEST_OK ${variant}_compile_data_generated_test
102104
done
103105

104106
# Format all targets

test/rustfmt/rustfmt_integration_test_suite.bzl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Test definitions for rustfmt test rules"""
22

3+
load("@bazel_skylib//rules:write_file.bzl", "write_file")
34
load(
45
"@rules_rust//rust:defs.bzl",
56
"rust_binary",
@@ -101,12 +102,36 @@ def rustfmt_integration_test_suite(name, **kwargs):
101102
targets = [":{}_generated".format(variant)],
102103
)
103104

105+
#
106+
# Test targets with generated compile_data (triggers transform_sources
107+
# to symlink hand-written sources into bazel-out)
108+
#
109+
write_file(
110+
name = "{}_compile_data_gen".format(variant),
111+
out = "{}_generated_data.txt".format(variant),
112+
content = ["generated"],
113+
)
114+
115+
rust_rule(
116+
name = "{}_compile_data_generated".format(variant),
117+
srcs = ["srcs/compile_data_generated/lib.rs"],
118+
compile_data = [":{}_compile_data_gen".format(variant)],
119+
edition = "2021",
120+
)
121+
122+
rustfmt_test(
123+
name = "{}_compile_data_generated_test".format(variant),
124+
tags = ["manual"],
125+
targets = [":{}_compile_data_generated".format(variant)],
126+
)
127+
104128
tests.extend([
105129
"{}_formatted_2015_test".format(variant),
106130
"{}_formatted_2018_test".format(variant),
107131
"{}_unformatted_2015_test".format(variant),
108132
"{}_unformatted_2018_test".format(variant),
109133
"{}_generated_test".format(variant),
134+
"{}_compile_data_generated_test".format(variant),
110135
])
111136

112137
native.test_suite(
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pub fn main()
2+
{
3+
println!(
4+
"compile_data_generated"
5+
);
6+
}

0 commit comments

Comments
 (0)