Skip to content

Commit

Permalink
rewrite emit-to-stdout to rmake
Browse files Browse the repository at this point in the history
  • Loading branch information
Oneirical committed Aug 26, 2024
1 parent 0b5eb7b commit 73560f5
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 52 deletions.
1 change: 0 additions & 1 deletion src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ run-make/cross-lang-lto/Makefile
run-make/dep-info-doesnt-run-much/Makefile
run-make/dep-info-spaces/Makefile
run-make/dep-info/Makefile
run-make/emit-to-stdout/Makefile
run-make/extern-fn-reachable/Makefile
run-make/fmt-write-bloat/Makefile
run-make/foreign-double-unwind/Makefile
Expand Down
51 changes: 0 additions & 51 deletions tests/run-make/emit-to-stdout/Makefile

This file was deleted.

79 changes: 79 additions & 0 deletions tests/run-make/emit-to-stdout/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// If `-o -` or `--emit KIND=-` is provided, output should be written
// to stdout instead. Binary output (`obj`, `llvm-bc`, `link` and
// `metadata`) being written this way will result in an error unless
// stdout is not a tty. Multiple output types going to stdout will
// trigger an error too, as they will all be mixed together.
// See https://github.com/rust-lang/rust/pull/111626

use run_make_support::{diff, rfs, rustc};

fn main() {
rfs::create_dir("out");
let tests = ["asm", "llvm-ir", "dep-info", "mir", "llvm-bc", "obj", "metadata", "link"];
for test in tests {
test_emit(test);
}
// These two last tests, which combine multiple emit types, should be done separately.
diff()
.expected_file("emit-multiple-types.stderr")
.actual_text(
"actual",
rustc()
.output("-")
.emit("asm=-")
.emit("llvm-ir=-")
.emit("dep-info=-")
.emit("mir=-")
.input("test.rs")
.run_fail()
.stderr_utf8(),
)
.run();
diff()
.expected_file("emit-multiple-types.stderr")
.actual_text(
"actual",
rustc()
.output("-")
.emit("asm,llvm-ir,dep-info,mir")
.input("test.rs")
.run_fail()
.stderr_utf8(),
)
.run();
}

fn test_emit(emit_type: &str) {
// Emitting these types will cause a compilation failure, which should be compared to a
// blessed stderr file for differences.
let stderr_types = ["llvm-bc", "obj", "metadata", "link"];
// Successful types (not in stderr_types) should start by outputting one emit file.
if !stderr_types.contains(&emit_type) {
let mut initial_compile = rustc();
initial_compile.emit(&format!("{emit_type}=out/{emit_type}")).input("test.rs");
// dep-info requires an extra unstable argument.
if emit_type == "dep-info" {
initial_compile.arg("-Zdep-info-omit-d-target=yes");
}
initial_compile.run();
}
let mut compile = rustc();
compile.emit(&format!("{emit_type}=-")).input("test.rs");
// Check if compilation should succeed or fail depending on the emit type.
let compile =
if stderr_types.contains(&emit_type) { compile.run_fail() } else { compile.run() };
let emit = if stderr_types.contains(&emit_type) {
compile.stderr_utf8()
} else {
compile.stdout_utf8()
};
let mut diff = diff();
// Compare the output with either an emit file or stderr file, depending on success
// or failure.
if stderr_types.contains(&emit_type) {
diff.expected_file(&format!("emit-{emit_type}.stderr"));
} else {
diff.expected_file(&format!("out/{emit_type}"));
}
diff.actual_text("actual", &emit).run();
}

0 comments on commit 73560f5

Please sign in to comment.