about summary refs log tree commit diff
diff options
context:
space:
mode:
author许杰友 Jieyou Xu (Joe) <jieyouxu@outlook.com>2024-04-07 16:33:56 +0000
committer许杰友 Jieyou Xu (Joe) <jieyouxu@outlook.com>2024-04-07 17:06:15 +0000
commit5dc276c0da0a79bb84e3b67db677da29db989d92 (patch)
tree7d3bd4cc2cfd57b902f8f242803431359361d342
parentfc1a4c5cc9308c4b5980c64a73fd344a59c10601 (diff)
downloadrust-5dc276c0da0a79bb84e3b67db677da29db989d92.tar.gz
rust-5dc276c0da0a79bb84e3b67db677da29db989d92.zip
compiletest: properly handle revisioned run-rustfix tests
-rw-r--r--src/tools/compiletest/src/runtest.rs22
-rw-r--r--tests/ui/compiletest-self-test/run-rustfix-revisions.foo.fixed9
-rw-r--r--tests/ui/compiletest-self-test/run-rustfix-revisions.foo.stderr14
-rw-r--r--tests/ui/compiletest-self-test/run-rustfix-revisions.rs9
4 files changed, 53 insertions, 1 deletions
diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs
index 689fdc5dfeb..bb8509fe413 100644
--- a/src/tools/compiletest/src/runtest.rs
+++ b/src/tools/compiletest/src/runtest.rs
@@ -4252,7 +4252,7 @@ impl<'test> TestCx<'test> {
         if self.props.run_rustfix && self.config.compare_mode.is_none() {
             // And finally, compile the fixed code and make sure it both
             // succeeds and has no diagnostics.
-            let rustc = self.make_compile_args(
+            let mut rustc = self.make_compile_args(
                 &self.expected_output_path(UI_FIXED),
                 TargetLocation::ThisFile(self.make_exe_name()),
                 emit_metadata,
@@ -4260,6 +4260,26 @@ impl<'test> TestCx<'test> {
                 LinkToAux::Yes,
                 Vec::new(),
             );
+
+            // If a test is revisioned, it's fixed source file can be named "a.foo.fixed", which,
+            // well, "a.foo" isn't a valid crate name. So we explicitly mangle the test name
+            // (including the revision) here to avoid the test writer having to manually specify a
+            // `#![crate_name = "..."]` as a workaround. This is okay since we're only checking if
+            // the fixed code is compilable.
+            if self.revision.is_some() {
+                let crate_name =
+                    self.testpaths.file.file_stem().expect("test must have a file stem");
+                // crate name must be alphanumeric or `_`.
+                let crate_name =
+                    crate_name.to_str().expect("crate name implies file name must be valid UTF-8");
+                // replace `a.foo` -> `a__foo` for crate name purposes.
+                // replace `revision-name-with-dashes` -> `revision_name_with_underscore`
+                let crate_name = crate_name.replace(".", "__");
+                let crate_name = crate_name.replace("-", "_");
+                rustc.arg("--crate-name");
+                rustc.arg(crate_name);
+            }
+
             let res = self.compose_and_run_compiler(rustc, None);
             if !res.status.success() {
                 self.fatal_proc_rec("failed to compile fixed code", &res);
diff --git a/tests/ui/compiletest-self-test/run-rustfix-revisions.foo.fixed b/tests/ui/compiletest-self-test/run-rustfix-revisions.foo.fixed
new file mode 100644
index 00000000000..0fa6ac1dd99
--- /dev/null
+++ b/tests/ui/compiletest-self-test/run-rustfix-revisions.foo.fixed
@@ -0,0 +1,9 @@
+// Check that revisioned `run-rustfix` does not fail with issues related to `.` in crate name.
+//@ revisions: foo
+//@[foo] run-rustfix
+#![deny(unused_variables)]
+
+fn main() {
+    let _x = 0usize;
+    //~^ ERROR unused variable: `x`
+}
diff --git a/tests/ui/compiletest-self-test/run-rustfix-revisions.foo.stderr b/tests/ui/compiletest-self-test/run-rustfix-revisions.foo.stderr
new file mode 100644
index 00000000000..74384ef24af
--- /dev/null
+++ b/tests/ui/compiletest-self-test/run-rustfix-revisions.foo.stderr
@@ -0,0 +1,14 @@
+error: unused variable: `x`
+  --> $DIR/run-rustfix-revisions.rs:7:9
+   |
+LL |     let x = 0usize;
+   |         ^ help: if this is intentional, prefix it with an underscore: `_x`
+   |
+note: the lint level is defined here
+  --> $DIR/run-rustfix-revisions.rs:4:9
+   |
+LL | #![deny(unused_variables)]
+   |         ^^^^^^^^^^^^^^^^
+
+error: aborting due to 1 previous error
+
diff --git a/tests/ui/compiletest-self-test/run-rustfix-revisions.rs b/tests/ui/compiletest-self-test/run-rustfix-revisions.rs
new file mode 100644
index 00000000000..84c5b7a2d0a
--- /dev/null
+++ b/tests/ui/compiletest-self-test/run-rustfix-revisions.rs
@@ -0,0 +1,9 @@
+// Check that revisioned `run-rustfix` does not fail with issues related to `.` in crate name.
+//@ revisions: foo
+//@[foo] run-rustfix
+#![deny(unused_variables)]
+
+fn main() {
+    let x = 0usize;
+    //~^ ERROR unused variable: `x`
+}