about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOneirical <manchot@videotron.ca>2024-06-26 11:44:23 -0400
committerOneirical <manchot@videotron.ca>2024-06-26 11:44:23 -0400
commit53109d5d6e284da313617be95e31ff4152d317f0 (patch)
treef98150d3c764d8aa30c650b6622095f7162ab9c9
parent722ae2243ece024797c006d1812c6abd3158f720 (diff)
downloadrust-53109d5d6e284da313617be95e31ff4152d317f0.tar.gz
rust-53109d5d6e284da313617be95e31ff4152d317f0.zip
rewrite libtest-padding to rmake
-rw-r--r--tests/run-make/libtest-padding/Makefile14
-rw-r--r--tests/run-make/libtest-padding/rmake.rs46
2 files changed, 46 insertions, 14 deletions
diff --git a/tests/run-make/libtest-padding/Makefile b/tests/run-make/libtest-padding/Makefile
deleted file mode 100644
index c8e2fc01f67..00000000000
--- a/tests/run-make/libtest-padding/Makefile
+++ /dev/null
@@ -1,14 +0,0 @@
-# ignore-cross-compile because we run the compiled code
-# needs-unwind because #[bench] and -Cpanic=abort requires -Zpanic-abort-tests
-include ../tools.mk
-
-NORMALIZE=sed 's%[0-9,\.]\{1,\} ns/iter (+/- [0-9,\.]\{1,\})%?? ns/iter (+/- ??)%' | sed 's%finished in [0-9\.]\{1,\}%finished in ??%'
-
-all:
-	$(RUSTC) --test tests.rs
-
-	$(call RUN,tests) --test-threads=1 | $(NORMALIZE) > "$(TMPDIR)"/test.stdout
-	$(RUSTC_TEST_OP) "$(TMPDIR)"/test.stdout test.stdout
-
-	$(call RUN,tests) --test-threads=1 --bench | $(NORMALIZE) > "$(TMPDIR)"/bench.stdout
-	$(RUSTC_TEST_OP) "$(TMPDIR)"/bench.stdout bench.stdout
diff --git a/tests/run-make/libtest-padding/rmake.rs b/tests/run-make/libtest-padding/rmake.rs
new file mode 100644
index 00000000000..4b17ba19bf7
--- /dev/null
+++ b/tests/run-make/libtest-padding/rmake.rs
@@ -0,0 +1,46 @@
+// Benchmarks, when ran as tests, would cause strange indentations
+// to appear in the output. This was because padding formatting was
+// applied before the conversion from bench to test, and not afterwards.
+// Now that this bug has been fixed in #118548, this test checks that it
+// does not make a resurgence by comparing the output of --bench with an
+// example stdout file.
+// See https://github.com/rust-lang/rust/issues/104092
+
+//@ ignore-cross-compile
+// Reason: the compiled code is ran
+//@ needs-unwind
+// Reason: #[bench] requires -Z panic-abort-tests
+
+use run_make_support::{diff, run_with_args, rustc};
+
+fn main() {
+    rustc().arg("--test").input("tests.rs").run();
+    let out = run_with_args("tests", &["--test-threads=1"]).stdout_utf8();
+    diff()
+        .expected_file("test.stdout")
+        .actual_text("actual-test-stdout", out)
+        .normalize(
+            // Replace all instances of (arbitrary numbers)
+            // [1.2345 ns/iter (+/- 0.1234)]
+            // with
+            // [?? ns/iter (+/- ??)]
+            r#"(\d+(?:[.,]\d+)*)\s*ns/iter\s*\(\+/-\s*(\d+(?:[.,]\d+)*)\)"#,
+            "?? ns/iter (+/- ??)",
+        )
+        // Replace all instances of (arbitrary numbers)
+        // finished in 8.0000 s
+        // with
+        // finished in ??
+        .normalize(r#"finished\s+in\s+(\d+(?:\.\d+)*)"#, "finished in ??")
+        .run();
+    let out = run_with_args("tests", &["--test-threads=1", "--bench"]).stdout_utf8();
+    diff()
+        .expected_file("bench.stdout")
+        .actual_text("actual-bench-stdout", out)
+        .normalize(
+            r#"(\d+(?:[.,]\d+)*)\s*ns/iter\s*\(\+/-\s*(\d+(?:[.,]\d+)*)\)"#,
+            "?? ns/iter (+/- ??)",
+        )
+        .normalize(r#"finished\s+in\s+(\d+(?:\.\d+)*)"#, "finished in ??")
+        .run();
+}