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 Jul 31, 2024
1 parent 0b5eb7b commit 5a9a84d
Show file tree
Hide file tree
Showing 3 changed files with 71 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.

71 changes: 71 additions & 0 deletions tests/run-make/emit-to-stdout/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// 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);
}
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) {
let stderr_types = ["llvm-bc", "obj", "metadata", "link"];
if !stderr_types.contains(&emit_type) {
let mut initial_compile = rustc();
initial_compile.emit(&format!("{emit_type}=out/{emit_type}")).input("test.rs");
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");
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();
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 5a9a84d

Please sign in to comment.