Skip to content

Commit 5dc276c

Browse files
committed
compiletest: properly handle revisioned run-rustfix tests
1 parent fc1a4c5 commit 5dc276c

File tree

4 files changed

+53
-1
lines changed

4 files changed

+53
-1
lines changed

src/tools/compiletest/src/runtest.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -4252,14 +4252,34 @@ impl<'test> TestCx<'test> {
42524252
if self.props.run_rustfix && self.config.compare_mode.is_none() {
42534253
// And finally, compile the fixed code and make sure it both
42544254
// succeeds and has no diagnostics.
4255-
let rustc = self.make_compile_args(
4255+
let mut rustc = self.make_compile_args(
42564256
&self.expected_output_path(UI_FIXED),
42574257
TargetLocation::ThisFile(self.make_exe_name()),
42584258
emit_metadata,
42594259
AllowUnused::No,
42604260
LinkToAux::Yes,
42614261
Vec::new(),
42624262
);
4263+
4264+
// If a test is revisioned, it's fixed source file can be named "a.foo.fixed", which,
4265+
// well, "a.foo" isn't a valid crate name. So we explicitly mangle the test name
4266+
// (including the revision) here to avoid the test writer having to manually specify a
4267+
// `#![crate_name = "..."]` as a workaround. This is okay since we're only checking if
4268+
// the fixed code is compilable.
4269+
if self.revision.is_some() {
4270+
let crate_name =
4271+
self.testpaths.file.file_stem().expect("test must have a file stem");
4272+
// crate name must be alphanumeric or `_`.
4273+
let crate_name =
4274+
crate_name.to_str().expect("crate name implies file name must be valid UTF-8");
4275+
// replace `a.foo` -> `a__foo` for crate name purposes.
4276+
// replace `revision-name-with-dashes` -> `revision_name_with_underscore`
4277+
let crate_name = crate_name.replace(".", "__");
4278+
let crate_name = crate_name.replace("-", "_");
4279+
rustc.arg("--crate-name");
4280+
rustc.arg(crate_name);
4281+
}
4282+
42634283
let res = self.compose_and_run_compiler(rustc, None);
42644284
if !res.status.success() {
42654285
self.fatal_proc_rec("failed to compile fixed code", &res);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Check that revisioned `run-rustfix` does not fail with issues related to `.` in crate name.
2+
//@ revisions: foo
3+
//@[foo] run-rustfix
4+
#![deny(unused_variables)]
5+
6+
fn main() {
7+
let _x = 0usize;
8+
//~^ ERROR unused variable: `x`
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: unused variable: `x`
2+
--> $DIR/run-rustfix-revisions.rs:7:9
3+
|
4+
LL | let x = 0usize;
5+
| ^ help: if this is intentional, prefix it with an underscore: `_x`
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/run-rustfix-revisions.rs:4:9
9+
|
10+
LL | #![deny(unused_variables)]
11+
| ^^^^^^^^^^^^^^^^
12+
13+
error: aborting due to 1 previous error
14+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Check that revisioned `run-rustfix` does not fail with issues related to `.` in crate name.
2+
//@ revisions: foo
3+
//@[foo] run-rustfix
4+
#![deny(unused_variables)]
5+
6+
fn main() {
7+
let x = 0usize;
8+
//~^ ERROR unused variable: `x`
9+
}

0 commit comments

Comments
 (0)