From 5003a26dc03bb8f6a67e5b6f776053655810913c Mon Sep 17 00:00:00 2001 From: Oneirical Date: Fri, 28 Jun 2024 16:25:12 -0400 Subject: [PATCH 1/3] rewrite output-type-permutations to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - .../output-type-permutations/Makefile | 147 --------------- .../output-type-permutations/rmake.rs | 178 ++++++++++++++++++ 3 files changed, 178 insertions(+), 148 deletions(-) delete mode 100644 tests/run-make/output-type-permutations/Makefile create mode 100644 tests/run-make/output-type-permutations/rmake.rs diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 276d2d694cda0..fe3b1eeae23d7 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -107,7 +107,6 @@ run-make/no-duplicate-libs/Makefile run-make/obey-crate-type-flag/Makefile run-make/optimization-remarks-dir-pgo/Makefile run-make/optimization-remarks-dir/Makefile -run-make/output-type-permutations/Makefile run-make/panic-abort-eh_frame/Makefile run-make/pass-linker-flags-flavor/Makefile run-make/pass-linker-flags-from-dep/Makefile diff --git a/tests/run-make/output-type-permutations/Makefile b/tests/run-make/output-type-permutations/Makefile deleted file mode 100644 index 035033b9fddd3..0000000000000 --- a/tests/run-make/output-type-permutations/Makefile +++ /dev/null @@ -1,147 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -all: - $(RUSTC) foo.rs --crate-type=rlib,dylib,staticlib - $(call REMOVE_RLIBS,bar) - $(call REMOVE_DYLIBS,bar) - rm $(call STATICLIB,bar) - rm -f $(TMPDIR)/{lib,}bar.{dll.exp,dll.lib,pdb,dll.a} - # Check that $(TMPDIR) is empty. - [ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ] - - $(RUSTC) foo.rs --crate-type=bin - rm $(TMPDIR)/$(call BIN,bar) - rm -f $(TMPDIR)/bar.pdb - [ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ] - - $(RUSTC) foo.rs --emit=asm,llvm-ir,llvm-bc,obj,link - rm $(TMPDIR)/bar.ll - rm $(TMPDIR)/bar.bc - rm $(TMPDIR)/bar.s - rm $(TMPDIR)/bar.o - rm $(TMPDIR)/$(call BIN,bar) - rm -f $(TMPDIR)/bar.pdb - [ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ] - - $(RUSTC) foo.rs --emit asm -o $(TMPDIR)/foo - rm $(TMPDIR)/foo - $(RUSTC) foo.rs --emit asm=$(TMPDIR)/foo - rm $(TMPDIR)/foo - $(RUSTC) foo.rs --emit=asm=$(TMPDIR)/foo - rm $(TMPDIR)/foo - [ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ] - - $(RUSTC) foo.rs --emit llvm-bc -o $(TMPDIR)/foo - rm $(TMPDIR)/foo - $(RUSTC) foo.rs --emit llvm-bc=$(TMPDIR)/foo - rm $(TMPDIR)/foo - $(RUSTC) foo.rs --emit=llvm-bc=$(TMPDIR)/foo - rm $(TMPDIR)/foo - [ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ] - - $(RUSTC) foo.rs --emit llvm-ir -o $(TMPDIR)/foo - rm $(TMPDIR)/foo - $(RUSTC) foo.rs --emit llvm-ir=$(TMPDIR)/foo - rm $(TMPDIR)/foo - $(RUSTC) foo.rs --emit=llvm-ir=$(TMPDIR)/foo - rm $(TMPDIR)/foo - [ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ] - - $(RUSTC) foo.rs --emit obj -o $(TMPDIR)/foo - rm $(TMPDIR)/foo - $(RUSTC) foo.rs --emit obj=$(TMPDIR)/foo - rm $(TMPDIR)/foo - $(RUSTC) foo.rs --emit=obj=$(TMPDIR)/foo - rm $(TMPDIR)/foo - [ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ] - - $(RUSTC) foo.rs --emit link -o $(TMPDIR)/$(call BIN,foo) - rm $(TMPDIR)/$(call BIN,foo) - $(RUSTC) foo.rs --emit link=$(TMPDIR)/$(call BIN,foo) - rm $(TMPDIR)/$(call BIN,foo) - $(RUSTC) foo.rs --emit=link=$(TMPDIR)/$(call BIN,foo) - rm $(TMPDIR)/$(call BIN,foo) - rm -f $(TMPDIR)/foo.pdb - [ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ] - - $(RUSTC) foo.rs --crate-type=rlib -o $(TMPDIR)/foo - rm $(TMPDIR)/foo - $(RUSTC) foo.rs --crate-type=rlib --emit link=$(TMPDIR)/foo - rm $(TMPDIR)/foo - $(RUSTC) foo.rs --crate-type=rlib --emit=link=$(TMPDIR)/foo - rm $(TMPDIR)/foo - [ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ] - - $(RUSTC) foo.rs --crate-type=dylib -o $(TMPDIR)/$(call BIN,foo) - rm $(TMPDIR)/$(call BIN,foo) - $(RUSTC) foo.rs --crate-type=dylib --emit link=$(TMPDIR)/$(call BIN,foo) - rm $(TMPDIR)/$(call BIN,foo) - $(RUSTC) foo.rs --crate-type=dylib --emit=link=$(TMPDIR)/$(call BIN,foo) - rm $(TMPDIR)/$(call BIN,foo) - rm -f $(TMPDIR)/{lib,}foo.{dll.exp,dll.lib,pdb,dll.a,exe.a} - [ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ] || (ls -1 $(TMPDIR) && exit 1) - - $(RUSTC) foo.rs --crate-type=staticlib -o $(TMPDIR)/foo - rm $(TMPDIR)/foo - $(RUSTC) foo.rs --crate-type=staticlib --emit link=$(TMPDIR)/foo - rm $(TMPDIR)/foo - $(RUSTC) foo.rs --crate-type=staticlib --emit=link=$(TMPDIR)/foo - rm $(TMPDIR)/foo - [ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ] - - $(RUSTC) foo.rs --crate-type=bin -o $(TMPDIR)/$(call BIN,foo) - rm $(TMPDIR)/$(call BIN,foo) - $(RUSTC) foo.rs --crate-type=bin --emit link=$(TMPDIR)/$(call BIN,foo) - rm $(TMPDIR)/$(call BIN,foo) - $(RUSTC) foo.rs --crate-type=bin --emit=link=$(TMPDIR)/$(call BIN,foo) - rm $(TMPDIR)/$(call BIN,foo) - rm -f $(TMPDIR)/foo.pdb - [ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ] - - $(RUSTC) foo.rs --emit llvm-ir=$(TMPDIR)/ir \ - --emit link \ - --crate-type=rlib - rm $(TMPDIR)/ir - rm $(TMPDIR)/libbar.rlib - [ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ] - - $(RUSTC) foo.rs --emit asm=$(TMPDIR)/asm \ - --emit llvm-ir=$(TMPDIR)/ir \ - --emit llvm-bc=$(TMPDIR)/bc \ - --emit obj=$(TMPDIR)/obj \ - --emit link=$(TMPDIR)/link \ - --crate-type=staticlib - rm $(TMPDIR)/asm - rm $(TMPDIR)/ir - rm $(TMPDIR)/bc - rm $(TMPDIR)/obj - rm $(TMPDIR)/link - $(RUSTC) foo.rs --emit=asm=$(TMPDIR)/asm \ - --emit llvm-ir=$(TMPDIR)/ir \ - --emit=llvm-bc=$(TMPDIR)/bc \ - --emit obj=$(TMPDIR)/obj \ - --emit=link=$(TMPDIR)/link \ - --crate-type=staticlib - rm $(TMPDIR)/asm - rm $(TMPDIR)/ir - rm $(TMPDIR)/bc - rm $(TMPDIR)/obj - rm $(TMPDIR)/link - [ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ] - - $(RUSTC) foo.rs --emit=asm,llvm-ir,llvm-bc,obj,link --crate-type=staticlib - rm $(TMPDIR)/bar.ll - rm $(TMPDIR)/bar.s - rm $(TMPDIR)/bar.o - rm $(call STATICLIB,bar) - mv $(TMPDIR)/bar.bc $(TMPDIR)/foo.bc - # Don't check that the $(TMPDIR) is empty - we left `foo.bc` for later - # comparison. - - $(RUSTC) foo.rs --emit=llvm-bc,link --crate-type=rlib - cmp $(TMPDIR)/foo.bc $(TMPDIR)/bar.bc - rm $(TMPDIR)/bar.bc - rm $(TMPDIR)/foo.bc - $(call REMOVE_RLIBS,bar) - [ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ] diff --git a/tests/run-make/output-type-permutations/rmake.rs b/tests/run-make/output-type-permutations/rmake.rs new file mode 100644 index 0000000000000..69af1274c68a1 --- /dev/null +++ b/tests/run-make/output-type-permutations/rmake.rs @@ -0,0 +1,178 @@ +// In 2014, rustc's output flags were reworked to be a lot more modular. +// This test uses these output flags in an expansive variety of combinations +// and syntax styles, checking that compilation is successful and that no unexpected +// files are created. +// The assert_eq! checks that "1 file remains" at the end of each part of the test, +// because foo.rs counts as a file, and should be the only remaining one. +// See https://github.com/rust-lang/rust/pull/12020 + +use run_make_support::{ + bin_name, cwd, dynamic_lib_name, fs_wrapper, rust_lib_name, rustc, static_lib_name, +}; + +fn remove_artifacts() { + std::fs::remove_file("libbar.ddl.exp").unwrap_or_default(); + std::fs::remove_file("libbar.dll.lib").unwrap_or_default(); + std::fs::remove_file("libbar.pdb").unwrap_or_default(); + std::fs::remove_file("libbar.dll.a").unwrap_or_default(); + std::fs::remove_file("libbar.exe.a").unwrap_or_default(); + std::fs::remove_file("bar.ddl.exp").unwrap_or_default(); + std::fs::remove_file("bar.dll.lib").unwrap_or_default(); + std::fs::remove_file("bar.pdb").unwrap_or_default(); + std::fs::remove_file("bar.dll.a").unwrap_or_default(); + std::fs::remove_file("bar.exe.a").unwrap_or_default(); +} + +fn main() { + rustc().input("foo.rs").crate_type("rlib,dylib,staticlib").run(); + fs_wrapper::remove_file(rust_lib_name("bar")); + fs_wrapper::remove_file(dynamic_lib_name("bar")); + fs_wrapper::remove_file(static_lib_name("bar")); + remove_artifacts(); + assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1); + + rustc().input("foo.rs").crate_type("bin").run(); + fs_wrapper::remove_file(bin_name("bar")); + std::fs::remove_file("bar.pdb").unwrap_or_default(); + assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1); + + rustc().input("foo.rs").emit("asm,llvm-ir,llvm-bc,obj,link").run(); + fs_wrapper::remove_file("bar.ll"); + fs_wrapper::remove_file("bar.bc"); + fs_wrapper::remove_file("bar.s"); + fs_wrapper::remove_file("bar.o"); + fs_wrapper::remove_file(bin_name("bar")); + std::fs::remove_file("bar.pdb").unwrap_or_default(); + assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1); + + rustc().input("foo.rs").emit("asm").output("foo").run(); + fs_wrapper::remove_file("foo"); + rustc().input("foo.rs").emit("asm=foo").run(); + fs_wrapper::remove_file("foo"); + rustc().input("foo.rs").arg("--emit=asm=foo").run(); + fs_wrapper::remove_file("foo"); + assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1); + + rustc().input("foo.rs").emit("llvm-bc").output("foo").run(); + fs_wrapper::remove_file("foo"); + rustc().input("foo.rs").emit("llvm-bc=foo").run(); + fs_wrapper::remove_file("foo"); + rustc().input("foo.rs").arg("--emit=llvm-bc=foo").run(); + fs_wrapper::remove_file("foo"); + assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1); + + rustc().input("foo.rs").emit("llvm-ir").output("foo").run(); + fs_wrapper::remove_file("foo"); + rustc().input("foo.rs").emit("llvm-ir=foo").run(); + fs_wrapper::remove_file("foo"); + rustc().input("foo.rs").arg("--emit=llvm-ir=foo").run(); + fs_wrapper::remove_file("foo"); + assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1); + + rustc().input("foo.rs").emit("obj").output("foo").run(); + fs_wrapper::remove_file("foo"); + rustc().input("foo.rs").emit("obj=foo").run(); + fs_wrapper::remove_file("foo"); + rustc().input("foo.rs").arg("--emit=obj=foo").run(); + fs_wrapper::remove_file("foo"); + assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1); + + let bin_foo = bin_name("foo"); + rustc().input("foo.rs").emit("link").output(&bin_foo).run(); + fs_wrapper::remove_file(&bin_foo); + rustc().input("foo.rs").emit(&format!("link={bin_foo}")).run(); + fs_wrapper::remove_file(&bin_foo); + rustc().input("foo.rs").arg(&format!("--emit=link={bin_foo}")).run(); + fs_wrapper::remove_file(&bin_foo); + std::fs::remove_file("foo.pdb").unwrap_or_default(); + assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1); + + rustc().input("foo.rs").crate_type("rlib").output("foo").run(); + fs_wrapper::remove_file("foo"); + rustc().input("foo.rs").crate_type("rlib").emit("link=foo").run(); + fs_wrapper::remove_file("foo"); + rustc().input("foo.rs").crate_type("rlib").arg("--emit=link=foo").run(); + fs_wrapper::remove_file("foo"); + assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1); + + rustc().input("foo.rs").crate_type("dylib").output(&bin_foo).run(); + fs_wrapper::remove_file(&bin_foo); + rustc().input("foo.rs").crate_type("dylib").emit(&format!("link={bin_foo}")).run(); + fs_wrapper::remove_file(&bin_foo); + rustc().input("foo.rs").crate_type("dylib").arg(&format!("--emit=link={bin_foo}")).run(); + fs_wrapper::remove_file(&bin_foo); + remove_artifacts(); + assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1); + + rustc().input("foo.rs").crate_type("staticlib").emit("link").output("foo").run(); + fs_wrapper::remove_file("foo"); + rustc().input("foo.rs").crate_type("staticlib").emit("link=foo").run(); + fs_wrapper::remove_file("foo"); + rustc().input("foo.rs").crate_type("staticlib").arg("--emit=link=foo").run(); + fs_wrapper::remove_file("foo"); + assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1); + + rustc().input("foo.rs").crate_type("bin").output(&bin_foo).run(); + fs_wrapper::remove_file(&bin_foo); + rustc().input("foo.rs").crate_type("bin").emit(&format!("link={bin_foo}")).run(); + fs_wrapper::remove_file(&bin_foo); + rustc().input("foo.rs").crate_type("bin").arg(&format!("--emit=link={bin_foo}")).run(); + fs_wrapper::remove_file(&bin_foo); + std::fs::remove_file("foo.pdb").unwrap_or_default(); + assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1); + + rustc().input("foo.rs").emit("llvm-ir=ir").emit("link").crate_type("rlib").run(); + fs_wrapper::remove_file("ir"); + fs_wrapper::remove_file(rust_lib_name("bar")); + assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1); + + rustc() + .input("foo.rs") + .emit("asm=asm") + .emit("llvm-ir=ir") + .emit("llvm-bc=bc") + .emit("obj=obj") + .emit("link=link") + .crate_type("staticlib") + .run(); + fs_wrapper::remove_file("asm"); + fs_wrapper::remove_file("ir"); + fs_wrapper::remove_file("bc"); + fs_wrapper::remove_file("obj"); + fs_wrapper::remove_file("link"); + assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1); + + rustc() + .input("foo.rs") + .arg("--emit=asm=asm") + .arg("--emit") + .arg("llvm-ir=ir") + .arg("--emit=llvm-bc=bc") + .arg("--emit") + .arg("obj=obj") + .arg("--emit=link=link") + .crate_type("staticlib") + .run(); + fs_wrapper::remove_file("asm"); + fs_wrapper::remove_file("ir"); + fs_wrapper::remove_file("bc"); + fs_wrapper::remove_file("obj"); + fs_wrapper::remove_file("link"); + assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1); + + rustc().input("foo.rs").emit("asm,llvm-ir,llvm-bc,obj,link").crate_type("staticlib").run(); + fs_wrapper::remove_file("bar.ll"); + fs_wrapper::remove_file("bar.s"); + fs_wrapper::remove_file("bar.o"); + fs_wrapper::remove_file(static_lib_name("bar")); + fs_wrapper::rename("bar.bc", "foo.bc"); + // Don't check that no files except foo.rs remain - we left `foo.bc` for later + // comparison. + + rustc().input("foo.rs").emit("llvm-bc,link").crate_type("rlib").run(); + assert_eq!(fs_wrapper::read("foo.bc"), fs_wrapper::read("bar.bc")); + fs_wrapper::remove_file("bar.bc"); + fs_wrapper::remove_file("foo.bc"); + fs_wrapper::remove_file(rust_lib_name("bar")); + assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1); +} From da50aaefbc3d003bd4936557e02c7dc9f7338a0a Mon Sep 17 00:00:00 2001 From: Oneirical Date: Tue, 2 Jul 2024 15:25:26 -0400 Subject: [PATCH 2/3] add shallow_find_files helper to run_make_support --- src/tools/run-make-support/src/lib.rs | 34 ++ .../output-type-permutations/rmake.rs | 447 +++++++++++------- 2 files changed, 314 insertions(+), 167 deletions(-) diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index 294dae109425f..71543902efb8c 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -261,6 +261,40 @@ pub fn test_while_readonly, F: FnOnce() + std::panic::UnwindSafe> success.unwrap(); } +/// Browse the directory `path` non-recursively and return all files which respect the parameters +/// outlined by `closure`. +#[track_caller] +pub fn shallow_find_files, F: Fn(&PathBuf) -> bool>( + path: P, + closure: F, +) -> Vec { + let mut matching_files = Vec::new(); + for entry in fs_wrapper::read_dir(path) { + let entry = entry.expect("failed to read directory entry."); + let path = entry.path(); + + if path.is_file() && closure(&path) { + matching_files.push(path); + } + } + matching_files +} + +/// Returns true if the filename at `path` starts with `prefix`. +pub fn has_prefix>(path: P, prefix: &str) -> bool { + path.as_ref().file_name().is_some_and(|name| name.to_str().unwrap().starts_with(prefix)) +} + +/// Returns true if the filename at `path` has the extension `extension`. +pub fn has_extension>(path: P, extension: &str) -> bool { + path.as_ref().extension().is_some_and(|ext| ext == extension) +} + +/// Returns true if the filename at `path` is not in `expected`. +pub fn name_not_among>(path: P, expected: &[&'static str]) -> bool { + path.as_ref().file_name().is_some_and(|name| !expected.contains(&name.to_str().unwrap())) +} + /// Use `cygpath -w` on a path to get a Windows path string back. This assumes that `cygpath` is /// available on the platform! #[track_caller] diff --git a/tests/run-make/output-type-permutations/rmake.rs b/tests/run-make/output-type-permutations/rmake.rs index 69af1274c68a1..eb166307f6800 100644 --- a/tests/run-make/output-type-permutations/rmake.rs +++ b/tests/run-make/output-type-permutations/rmake.rs @@ -1,178 +1,291 @@ // In 2014, rustc's output flags were reworked to be a lot more modular. // This test uses these output flags in an expansive variety of combinations -// and syntax styles, checking that compilation is successful and that no unexpected -// files are created. -// The assert_eq! checks that "1 file remains" at the end of each part of the test, -// because foo.rs counts as a file, and should be the only remaining one. +// and syntax styles, checking that compilation is successful and that output +// files are exactly what is expected, no more, no less. // See https://github.com/rust-lang/rust/pull/12020 use run_make_support::{ - bin_name, cwd, dynamic_lib_name, fs_wrapper, rust_lib_name, rustc, static_lib_name, + bin_name, cwd, dynamic_lib_name, fs_wrapper, name_not_among, rust_lib_name, rustc, + shallow_find_files, static_lib_name, }; -fn remove_artifacts() { - std::fs::remove_file("libbar.ddl.exp").unwrap_or_default(); - std::fs::remove_file("libbar.dll.lib").unwrap_or_default(); - std::fs::remove_file("libbar.pdb").unwrap_or_default(); - std::fs::remove_file("libbar.dll.a").unwrap_or_default(); - std::fs::remove_file("libbar.exe.a").unwrap_or_default(); - std::fs::remove_file("bar.ddl.exp").unwrap_or_default(); - std::fs::remove_file("bar.dll.lib").unwrap_or_default(); - std::fs::remove_file("bar.pdb").unwrap_or_default(); - std::fs::remove_file("bar.dll.a").unwrap_or_default(); - std::fs::remove_file("bar.exe.a").unwrap_or_default(); +// Each test takes 4 arguments: +// `must_exist`: output files which must be found - if any are absent, the test fails +// `can_exist`: optional output files which will not trigger a failure +// `dir`: the name of the directory where the test happens +// `rustc_invocation`: the rustc command being tested +// Any unexpected output files not listed in `must_exist` or `can_exist` will cause a failure. +fn assert_expected_output_files( + must_exist: &[&'static str], + can_exist: &[&'static str], + dir: &str, + rustc_invocation: impl Fn(), +) { + fs_wrapper::create_dir(dir); + rustc_invocation(); + for file in must_exist { + fs_wrapper::remove_file(dir.to_owned() + "/" + file); + } + let actual_output_files = shallow_find_files(dir, |path| name_not_among(path, can_exist)); + if !&actual_output_files.is_empty() { + dbg!(&actual_output_files); + panic!("unexpected output artifacts detected"); + } } fn main() { - rustc().input("foo.rs").crate_type("rlib,dylib,staticlib").run(); - fs_wrapper::remove_file(rust_lib_name("bar")); - fs_wrapper::remove_file(dynamic_lib_name("bar")); - fs_wrapper::remove_file(static_lib_name("bar")); - remove_artifacts(); - assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1); - - rustc().input("foo.rs").crate_type("bin").run(); - fs_wrapper::remove_file(bin_name("bar")); - std::fs::remove_file("bar.pdb").unwrap_or_default(); - assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1); - - rustc().input("foo.rs").emit("asm,llvm-ir,llvm-bc,obj,link").run(); - fs_wrapper::remove_file("bar.ll"); - fs_wrapper::remove_file("bar.bc"); - fs_wrapper::remove_file("bar.s"); - fs_wrapper::remove_file("bar.o"); - fs_wrapper::remove_file(bin_name("bar")); - std::fs::remove_file("bar.pdb").unwrap_or_default(); - assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1); - - rustc().input("foo.rs").emit("asm").output("foo").run(); - fs_wrapper::remove_file("foo"); - rustc().input("foo.rs").emit("asm=foo").run(); - fs_wrapper::remove_file("foo"); - rustc().input("foo.rs").arg("--emit=asm=foo").run(); - fs_wrapper::remove_file("foo"); - assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1); - - rustc().input("foo.rs").emit("llvm-bc").output("foo").run(); - fs_wrapper::remove_file("foo"); - rustc().input("foo.rs").emit("llvm-bc=foo").run(); - fs_wrapper::remove_file("foo"); - rustc().input("foo.rs").arg("--emit=llvm-bc=foo").run(); - fs_wrapper::remove_file("foo"); - assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1); - - rustc().input("foo.rs").emit("llvm-ir").output("foo").run(); - fs_wrapper::remove_file("foo"); - rustc().input("foo.rs").emit("llvm-ir=foo").run(); - fs_wrapper::remove_file("foo"); - rustc().input("foo.rs").arg("--emit=llvm-ir=foo").run(); - fs_wrapper::remove_file("foo"); - assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1); - - rustc().input("foo.rs").emit("obj").output("foo").run(); - fs_wrapper::remove_file("foo"); - rustc().input("foo.rs").emit("obj=foo").run(); - fs_wrapper::remove_file("foo"); - rustc().input("foo.rs").arg("--emit=obj=foo").run(); - fs_wrapper::remove_file("foo"); - assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1); - - let bin_foo = bin_name("foo"); - rustc().input("foo.rs").emit("link").output(&bin_foo).run(); - fs_wrapper::remove_file(&bin_foo); - rustc().input("foo.rs").emit(&format!("link={bin_foo}")).run(); - fs_wrapper::remove_file(&bin_foo); - rustc().input("foo.rs").arg(&format!("--emit=link={bin_foo}")).run(); - fs_wrapper::remove_file(&bin_foo); - std::fs::remove_file("foo.pdb").unwrap_or_default(); - assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1); - - rustc().input("foo.rs").crate_type("rlib").output("foo").run(); - fs_wrapper::remove_file("foo"); - rustc().input("foo.rs").crate_type("rlib").emit("link=foo").run(); - fs_wrapper::remove_file("foo"); - rustc().input("foo.rs").crate_type("rlib").arg("--emit=link=foo").run(); - fs_wrapper::remove_file("foo"); - assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1); - - rustc().input("foo.rs").crate_type("dylib").output(&bin_foo).run(); - fs_wrapper::remove_file(&bin_foo); - rustc().input("foo.rs").crate_type("dylib").emit(&format!("link={bin_foo}")).run(); - fs_wrapper::remove_file(&bin_foo); - rustc().input("foo.rs").crate_type("dylib").arg(&format!("--emit=link={bin_foo}")).run(); - fs_wrapper::remove_file(&bin_foo); - remove_artifacts(); - assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1); - - rustc().input("foo.rs").crate_type("staticlib").emit("link").output("foo").run(); - fs_wrapper::remove_file("foo"); - rustc().input("foo.rs").crate_type("staticlib").emit("link=foo").run(); - fs_wrapper::remove_file("foo"); - rustc().input("foo.rs").crate_type("staticlib").arg("--emit=link=foo").run(); - fs_wrapper::remove_file("foo"); - assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1); - - rustc().input("foo.rs").crate_type("bin").output(&bin_foo).run(); - fs_wrapper::remove_file(&bin_foo); - rustc().input("foo.rs").crate_type("bin").emit(&format!("link={bin_foo}")).run(); - fs_wrapper::remove_file(&bin_foo); - rustc().input("foo.rs").crate_type("bin").arg(&format!("--emit=link={bin_foo}")).run(); - fs_wrapper::remove_file(&bin_foo); - std::fs::remove_file("foo.pdb").unwrap_or_default(); - assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1); - - rustc().input("foo.rs").emit("llvm-ir=ir").emit("link").crate_type("rlib").run(); - fs_wrapper::remove_file("ir"); - fs_wrapper::remove_file(rust_lib_name("bar")); - assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1); - - rustc() - .input("foo.rs") - .emit("asm=asm") - .emit("llvm-ir=ir") - .emit("llvm-bc=bc") - .emit("obj=obj") - .emit("link=link") - .crate_type("staticlib") - .run(); - fs_wrapper::remove_file("asm"); - fs_wrapper::remove_file("ir"); - fs_wrapper::remove_file("bc"); - fs_wrapper::remove_file("obj"); - fs_wrapper::remove_file("link"); - assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1); - - rustc() - .input("foo.rs") - .arg("--emit=asm=asm") - .arg("--emit") - .arg("llvm-ir=ir") - .arg("--emit=llvm-bc=bc") - .arg("--emit") - .arg("obj=obj") - .arg("--emit=link=link") - .crate_type("staticlib") - .run(); - fs_wrapper::remove_file("asm"); - fs_wrapper::remove_file("ir"); - fs_wrapper::remove_file("bc"); - fs_wrapper::remove_file("obj"); - fs_wrapper::remove_file("link"); - assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1); - - rustc().input("foo.rs").emit("asm,llvm-ir,llvm-bc,obj,link").crate_type("staticlib").run(); - fs_wrapper::remove_file("bar.ll"); - fs_wrapper::remove_file("bar.s"); - fs_wrapper::remove_file("bar.o"); - fs_wrapper::remove_file(static_lib_name("bar")); - fs_wrapper::rename("bar.bc", "foo.bc"); - // Don't check that no files except foo.rs remain - we left `foo.bc` for later - // comparison. - - rustc().input("foo.rs").emit("llvm-bc,link").crate_type("rlib").run(); - assert_eq!(fs_wrapper::read("foo.bc"), fs_wrapper::read("bar.bc")); - fs_wrapper::remove_file("bar.bc"); - fs_wrapper::remove_file("foo.bc"); - fs_wrapper::remove_file(rust_lib_name("bar")); - assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1); + let bin_foo = Box::leak(Box::new(bin_name("foo"))); + let bin_bar = Box::leak(Box::new(bin_name("bar"))); + let static_bar = Box::leak(Box::new(static_lib_name("bar"))); + let dynamic_bar = Box::leak(Box::new(dynamic_lib_name("bar"))); + let rust_bar = Box::leak(Box::new(rust_lib_name("bar"))); + + assert_expected_output_files( + &[static_bar, dynamic_bar, rust_bar], + &[ + "libbar.ddl.exp", + "libbar.dll.lib", + "libbar.pdb", + "libbar.dll.a", + "libbar.exe.a", + "bar.ddl.exp", + "bar.dll.lib", + "bar.pdb", + "bar.dll.a", + "bar.exe.a", + ], + "three-crates", + || { + rustc() + .input("foo.rs") + .out_dir("three-crates") + .crate_type("rlib,dylib,staticlib") + .run(); + }, + ); + + assert_expected_output_files(&[bin_bar], &["bar.pdb"], "bin-crate", || { + rustc().input("foo.rs").crate_type("bin").out_dir("bin-crate").run(); + }); + + assert_expected_output_files( + &["bar.ll", "bar.bc", "bar.s", "bar.o", bin_bar], + &["bar.pdb"], + "all-emit", + || { + rustc().input("foo.rs").emit("asm,llvm-ir,llvm-bc,obj,link").out_dir("all-emit").run(); + }, + ); + + assert_expected_output_files(&["foo"], &[], "asm-emit", || { + rustc().input("foo.rs").emit("asm").output("asm-emit/foo").run(); + }); + assert_expected_output_files(&["foo"], &[], "asm-emit2", || { + rustc().input("foo.rs").emit("asm=asm-emit2/foo").run(); + }); + assert_expected_output_files(&["foo"], &[], "asm-emit3", || { + rustc().input("foo.rs").arg("--emit=asm=asm-emit3/foo").run(); + }); + + assert_expected_output_files(&["foo"], &[], "llvm-ir-emit", || { + rustc().input("foo.rs").emit("llvm-ir").output("llvm-ir-emit/foo").run(); + }); + assert_expected_output_files(&["foo"], &[], "llvm-ir-emit2", || { + rustc().input("foo.rs").emit("llvm-ir=llvm-ir-emit2/foo").run(); + }); + assert_expected_output_files(&["foo"], &[], "llvm-ir-emit3", || { + rustc().input("foo.rs").arg("--emit=llvm-ir=llvm-ir-emit3/foo").run(); + }); + + assert_expected_output_files(&["foo"], &[], "llvm-bc-emit", || { + rustc().input("foo.rs").emit("llvm-bc").output("llvm-bc-emit/foo").run(); + }); + assert_expected_output_files(&["foo"], &[], "llvm-bc-emit2", || { + rustc().input("foo.rs").emit("llvm-bc=llvm-bc-emit2/foo").run(); + }); + assert_expected_output_files(&["foo"], &[], "llvm-bc-emit3", || { + rustc().input("foo.rs").arg("--emit=llvm-bc=llvm-bc-emit3/foo").run(); + }); + + assert_expected_output_files(&["foo"], &[], "obj-emit", || { + rustc().input("foo.rs").emit("obj").output("obj-emit/foo").run(); + }); + assert_expected_output_files(&["foo"], &[], "obj-emit2", || { + rustc().input("foo.rs").emit("obj=obj-emit2/foo").run(); + }); + assert_expected_output_files(&["foo"], &[], "obj-emit3", || { + rustc().input("foo.rs").arg("--emit=obj=obj-emit3/foo").run(); + }); + + assert_expected_output_files(&[bin_foo], &[], "link-emit", || { + rustc().input("foo.rs").emit("link").output("link-emit/".to_owned() + bin_foo).run(); + }); + assert_expected_output_files(&[bin_foo], &[], "link-emit2", || { + rustc().input("foo.rs").emit(&format!("link=link-emit2/{bin_foo}")).run(); + }); + assert_expected_output_files(&[bin_foo], &[], "link-emit3", || { + rustc().input("foo.rs").arg(&format!("--emit=link=link-emit3/{bin_foo}")).run(); + }); + + assert_expected_output_files(&["foo"], &[], "rlib", || { + rustc().crate_type("rlib").input("foo.rs").output("rlib/foo").run(); + }); + assert_expected_output_files(&["foo"], &[], "rlib2", || { + rustc().crate_type("rlib").input("foo.rs").emit("link=rlib2/foo").run(); + }); + assert_expected_output_files(&["foo"], &[], "rlib3", || { + rustc().crate_type("rlib").input("foo.rs").arg("--emit=link=rlib3/foo").run(); + }); + + assert_expected_output_files( + &[bin_foo], + &[ + "libbar.ddl.exp", + "libbar.dll.lib", + "libbar.pdb", + "libbar.dll.a", + "libbar.exe.a", + "bar.ddl.exp", + "bar.dll.lib", + "bar.pdb", + "bar.dll.a", + "bar.exe.a", + ], + "dylib", + || { + rustc().crate_type("dylib").input("foo.rs").output("dylib/".to_owned() + bin_foo).run(); + }, + ); + assert_expected_output_files( + &[bin_foo], + &[ + "libbar.ddl.exp", + "libbar.dll.lib", + "libbar.pdb", + "libbar.dll.a", + "libbar.exe.a", + "bar.ddl.exp", + "bar.dll.lib", + "bar.pdb", + "bar.dll.a", + "bar.exe.a", + ], + "dylib2", + || { + rustc() + .crate_type("dylib") + .input("foo.rs") + .emit(&format!("link=dylib2/{bin_foo}")) + .run(); + }, + ); + assert_expected_output_files( + &[bin_foo], + &[ + "libbar.ddl.exp", + "libbar.dll.lib", + "libbar.pdb", + "libbar.dll.a", + "libbar.exe.a", + "bar.ddl.exp", + "bar.dll.lib", + "bar.pdb", + "bar.dll.a", + "bar.exe.a", + ], + "dylib3", + || { + rustc() + .crate_type("dylib") + .input("foo.rs") + .arg(&format!("--emit=link=dylib3/{bin_foo}")) + .run(); + }, + ); + + assert_expected_output_files(&["foo"], &[], "staticlib", || { + rustc().crate_type("staticlib").input("foo.rs").output("staticlib/foo").run(); + }); + assert_expected_output_files(&["foo"], &[], "staticlib2", || { + rustc().crate_type("staticlib").input("foo.rs").emit("link=staticlib2/foo").run(); + }); + assert_expected_output_files(&["foo"], &[], "staticlib3", || { + rustc().crate_type("staticlib").input("foo.rs").arg("--emit=link=staticlib3/foo").run(); + }); + + assert_expected_output_files(&["foo"], &["foo.pdb"], "bincrate", || { + rustc().crate_type("bin").input("foo.rs").output("bincrate/".to_owned() + bin_foo).run(); + }); + assert_expected_output_files(&["foo"], &["foo.pdb"], "bincrate2", || { + rustc().crate_type("bin").input("foo.rs").emit(&format!("link=bincrate2/{bin_foo}")).run(); + }); + assert_expected_output_files(&["foo"], &["foo.pdb"], "bincrate3", || { + rustc() + .crate_type("bin") + .input("foo.rs") + .arg(&format!("--emit=link=bincrate3/{bin_foo}")) + .run(); + }); + + assert_expected_output_files(&["ir", rust_bar], &[], "rlib-ir", || { + rustc() + .input("foo.rs") + .emit("llvm-ir=rlib-ir/ir") + .emit("link") + .crate_type("rlib") + .out_dir("rlib-ir") + .run(); + }); + + assert_expected_output_files(&["ir", "asm", "bc", "obj", "link"], &[], "staticlib-all", || { + rustc() + .input("foo.rs") + .emit("asm=staticlib-all/asm") + .emit("llvm-ir=staticlib-all/ir") + .emit("llvm-bc=staticlib-all/bc") + .emit("obj=staticlib-all/obj") + .emit("link=staticlib-all/link") + .crate_type("staticlib") + .run(); + }); + assert_expected_output_files( + &["ir", "asm", "bc", "obj", "link"], + &[], + "staticlib-all2", + || { + rustc() + .input("foo.rs") + .arg("--emit=asm=staticlib-all2/asm") + .arg("--emit") + .arg("llvm-ir=staticlib-all2/ir") + .arg("--emit=llvm-bc=staticlib-all2/bc") + .arg("--emit") + .arg("obj=staticlib-all2/obj") + .arg("--emit=link=staticlib-all2/link") + .crate_type("staticlib") + .run(); + }, + ); + + assert_expected_output_files( + &["bar.ll", "bar.s", "bar.o", static_bar], + &["bar.bc"], // keep this one for the next test + "staticlib-all3", + || { + rustc() + .input("foo.rs") + .emit("asm,llvm-ir,llvm-bc,obj,link") + .crate_type("staticlib") + .out_dir("staticlib-all3") + .run(); + }, + ); + + // the .bc file from the previous test should be equivalent to this one, despite the difference + // in crate type + assert_expected_output_files(&["bar.bc", rust_bar, "foo.bc"], &[], "rlib-emits", || { + fs_wrapper::rename("staticlib-all3/bar.bc", "rlib-emits/foo.bc"); + rustc().input("foo.rs").emit("llvm-bc,link").crate_type("rlib").out_dir("rlib-emits").run(); + assert_eq!(fs_wrapper::read("rlib-emits/foo.bc"), fs_wrapper::read("rlib-emits/bar.bc")); + }); } From db010c6242359d8b9b58ba5ac47f71cd702ca43b Mon Sep 17 00:00:00 2001 From: Oneirical Date: Wed, 3 Jul 2024 11:48:19 -0400 Subject: [PATCH 3/3] Expectations struct for output-type-permutations --- src/tools/run-make-support/src/lib.rs | 10 +- .../output-type-permutations/rmake.rs | 630 ++++++++++++------ 2 files changed, 446 insertions(+), 194 deletions(-) diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index 71543902efb8c..5a0d4bd923b57 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -266,14 +266,14 @@ pub fn test_while_readonly, F: FnOnce() + std::panic::UnwindSafe> #[track_caller] pub fn shallow_find_files, F: Fn(&PathBuf) -> bool>( path: P, - closure: F, + filter: F, ) -> Vec { let mut matching_files = Vec::new(); for entry in fs_wrapper::read_dir(path) { let entry = entry.expect("failed to read directory entry."); let path = entry.path(); - if path.is_file() && closure(&path) { + if path.is_file() && filter(&path) { matching_files.push(path); } } @@ -291,8 +291,10 @@ pub fn has_extension>(path: P, extension: &str) -> bool { } /// Returns true if the filename at `path` is not in `expected`. -pub fn name_not_among>(path: P, expected: &[&'static str]) -> bool { - path.as_ref().file_name().is_some_and(|name| !expected.contains(&name.to_str().unwrap())) +pub fn filename_not_in_denylist>(path: P, expected: &[String]) -> bool { + path.as_ref() + .file_name() + .is_some_and(|name| !expected.contains(&name.to_str().unwrap().to_owned())) } /// Use `cygpath -w` on a path to get a Windows path string back. This assumes that `cygpath` is diff --git a/tests/run-make/output-type-permutations/rmake.rs b/tests/run-make/output-type-permutations/rmake.rs index eb166307f6800..e5830314de996 100644 --- a/tests/run-make/output-type-permutations/rmake.rs +++ b/tests/run-make/output-type-permutations/rmake.rs @@ -5,7 +5,7 @@ // See https://github.com/rust-lang/rust/pull/12020 use run_make_support::{ - bin_name, cwd, dynamic_lib_name, fs_wrapper, name_not_among, rust_lib_name, rustc, + bin_name, dynamic_lib_name, filename_not_in_denylist, fs_wrapper, rust_lib_name, rustc, shallow_find_files, static_lib_name, }; @@ -15,46 +15,69 @@ use run_make_support::{ // `dir`: the name of the directory where the test happens // `rustc_invocation`: the rustc command being tested // Any unexpected output files not listed in `must_exist` or `can_exist` will cause a failure. -fn assert_expected_output_files( - must_exist: &[&'static str], - can_exist: &[&'static str], - dir: &str, - rustc_invocation: impl Fn(), -) { - fs_wrapper::create_dir(dir); +fn assert_expected_output_files(expectations: Expectations, rustc_invocation: impl Fn()) { + let must_exist = expectations.expected_files; + let can_exist = expectations.allowed_files; + let dir = expectations.test_dir; + + fs_wrapper::create_dir(&dir); rustc_invocation(); for file in must_exist { - fs_wrapper::remove_file(dir.to_owned() + "/" + file); + fs_wrapper::remove_file(dir.to_owned() + "/" + &file); } - let actual_output_files = shallow_find_files(dir, |path| name_not_among(path, can_exist)); + let actual_output_files = + shallow_find_files(dir, |path| filename_not_in_denylist(path, &can_exist)); if !&actual_output_files.is_empty() { dbg!(&actual_output_files); panic!("unexpected output artifacts detected"); } } +struct Expectations { + /// Output files which must be found. The test fails if any are absent. + expected_files: Vec, + /// Allowed output files which will not trigger a failure. + allowed_files: Vec, + /// Name of the directory where the test happens. + test_dir: String, +} + +macro_rules! s { + ( $( $x:expr ),* ) => { + { + let mut temp_vec = Vec::new(); + $( + temp_vec.push($x.to_string()); + )* + temp_vec + } + }; +} + fn main() { - let bin_foo = Box::leak(Box::new(bin_name("foo"))); - let bin_bar = Box::leak(Box::new(bin_name("bar"))); - let static_bar = Box::leak(Box::new(static_lib_name("bar"))); - let dynamic_bar = Box::leak(Box::new(dynamic_lib_name("bar"))); - let rust_bar = Box::leak(Box::new(rust_lib_name("bar"))); + let bin_foo = bin_name("foo"); assert_expected_output_files( - &[static_bar, dynamic_bar, rust_bar], - &[ - "libbar.ddl.exp", - "libbar.dll.lib", - "libbar.pdb", - "libbar.dll.a", - "libbar.exe.a", - "bar.ddl.exp", - "bar.dll.lib", - "bar.pdb", - "bar.dll.a", - "bar.exe.a", - ], - "three-crates", + Expectations { + expected_files: s![ + static_lib_name("bar"), + dynamic_lib_name("bar"), + rust_lib_name("bar") + ], + allowed_files: s![ + "libbar.dll.exp", + "libbar.dll.lib", + "libbar.pdb", + "libbar.dll.a", + "libbar.exe.a", + "bar.dll.exp", + "bar.dll.lib", + "bar.pdb", + "bar.dll.a", + "bar.exe.a" + ], + test_dir: "three-crates".to_string(), + }, || { rustc() .input("foo.rs") @@ -64,113 +87,256 @@ fn main() { }, ); - assert_expected_output_files(&[bin_bar], &["bar.pdb"], "bin-crate", || { - rustc().input("foo.rs").crate_type("bin").out_dir("bin-crate").run(); - }); + assert_expected_output_files( + Expectations { + expected_files: s![bin_name("bar")], + allowed_files: s!["bar.pdb"], + test_dir: "bin-crate".to_string(), + }, + || { + rustc().input("foo.rs").crate_type("bin").out_dir("bin-crate").run(); + }, + ); assert_expected_output_files( - &["bar.ll", "bar.bc", "bar.s", "bar.o", bin_bar], - &["bar.pdb"], - "all-emit", + Expectations { + expected_files: s!["bar.ll", "bar.bc", "bar.s", "bar.o", bin_name("bar")], + allowed_files: s!["bar.pdb"], + test_dir: "all-emit".to_string(), + }, || { rustc().input("foo.rs").emit("asm,llvm-ir,llvm-bc,obj,link").out_dir("all-emit").run(); }, ); - assert_expected_output_files(&["foo"], &[], "asm-emit", || { - rustc().input("foo.rs").emit("asm").output("asm-emit/foo").run(); - }); - assert_expected_output_files(&["foo"], &[], "asm-emit2", || { - rustc().input("foo.rs").emit("asm=asm-emit2/foo").run(); - }); - assert_expected_output_files(&["foo"], &[], "asm-emit3", || { - rustc().input("foo.rs").arg("--emit=asm=asm-emit3/foo").run(); - }); + assert_expected_output_files( + Expectations { + expected_files: s!["foo"], + allowed_files: s![], + test_dir: "asm-emit".to_string(), + }, + || { + rustc().input("foo.rs").emit("asm").output("asm-emit/foo").run(); + }, + ); + assert_expected_output_files( + Expectations { + expected_files: s!["foo"], + allowed_files: s![], + test_dir: "asm-emit2".to_string(), + }, + || { + rustc().input("foo.rs").emit("asm=asm-emit2/foo").run(); + }, + ); + assert_expected_output_files( + Expectations { + expected_files: s!["foo"], + allowed_files: s![], + test_dir: "asm-emit3".to_string(), + }, + || { + rustc().input("foo.rs").arg("--emit=asm=asm-emit3/foo").run(); + }, + ); - assert_expected_output_files(&["foo"], &[], "llvm-ir-emit", || { - rustc().input("foo.rs").emit("llvm-ir").output("llvm-ir-emit/foo").run(); - }); - assert_expected_output_files(&["foo"], &[], "llvm-ir-emit2", || { - rustc().input("foo.rs").emit("llvm-ir=llvm-ir-emit2/foo").run(); - }); - assert_expected_output_files(&["foo"], &[], "llvm-ir-emit3", || { - rustc().input("foo.rs").arg("--emit=llvm-ir=llvm-ir-emit3/foo").run(); - }); + assert_expected_output_files( + Expectations { + expected_files: s!["foo"], + allowed_files: s![], + test_dir: "llvm-ir-emit".to_string(), + }, + || { + rustc().input("foo.rs").emit("llvm-ir").output("llvm-ir-emit/foo").run(); + }, + ); + assert_expected_output_files( + Expectations { + expected_files: s!["foo"], + allowed_files: s![], + test_dir: "llvm-ir-emit2".to_string(), + }, + || { + rustc().input("foo.rs").emit("llvm-ir=llvm-ir-emit2/foo").run(); + }, + ); + assert_expected_output_files( + Expectations { + expected_files: s!["foo"], + allowed_files: s![], + test_dir: "llvm-ir-emit3".to_string(), + }, + || { + rustc().input("foo.rs").arg("--emit=llvm-ir=llvm-ir-emit3/foo").run(); + }, + ); - assert_expected_output_files(&["foo"], &[], "llvm-bc-emit", || { - rustc().input("foo.rs").emit("llvm-bc").output("llvm-bc-emit/foo").run(); - }); - assert_expected_output_files(&["foo"], &[], "llvm-bc-emit2", || { - rustc().input("foo.rs").emit("llvm-bc=llvm-bc-emit2/foo").run(); - }); - assert_expected_output_files(&["foo"], &[], "llvm-bc-emit3", || { - rustc().input("foo.rs").arg("--emit=llvm-bc=llvm-bc-emit3/foo").run(); - }); + assert_expected_output_files( + Expectations { + expected_files: s!["foo"], + allowed_files: s![], + test_dir: "llvm-bc-emit".to_string(), + }, + || { + rustc().input("foo.rs").emit("llvm-bc").output("llvm-bc-emit/foo").run(); + }, + ); + assert_expected_output_files( + Expectations { + expected_files: s!["foo"], + allowed_files: s![], + test_dir: "llvm-bc-emit2".to_string(), + }, + || { + rustc().input("foo.rs").emit("llvm-bc=llvm-bc-emit2/foo").run(); + }, + ); + assert_expected_output_files( + Expectations { + expected_files: s!["foo"], + allowed_files: s![], + test_dir: "llvm-bc-emit3".to_string(), + }, + || { + rustc().input("foo.rs").arg("--emit=llvm-bc=llvm-bc-emit3/foo").run(); + }, + ); - assert_expected_output_files(&["foo"], &[], "obj-emit", || { - rustc().input("foo.rs").emit("obj").output("obj-emit/foo").run(); - }); - assert_expected_output_files(&["foo"], &[], "obj-emit2", || { - rustc().input("foo.rs").emit("obj=obj-emit2/foo").run(); - }); - assert_expected_output_files(&["foo"], &[], "obj-emit3", || { - rustc().input("foo.rs").arg("--emit=obj=obj-emit3/foo").run(); - }); + assert_expected_output_files( + Expectations { + expected_files: s!["foo"], + allowed_files: s![], + test_dir: "obj-emit".to_string(), + }, + || { + rustc().input("foo.rs").emit("obj").output("obj-emit/foo").run(); + }, + ); + assert_expected_output_files( + Expectations { + expected_files: s!["foo"], + allowed_files: s![], + test_dir: "obj-emit2".to_string(), + }, + || { + rustc().input("foo.rs").emit("obj=obj-emit2/foo").run(); + }, + ); + assert_expected_output_files( + Expectations { + expected_files: s!["foo"], + allowed_files: s![], + test_dir: "obj-emit3".to_string(), + }, + || { + rustc().input("foo.rs").arg("--emit=obj=obj-emit3/foo").run(); + }, + ); - assert_expected_output_files(&[bin_foo], &[], "link-emit", || { - rustc().input("foo.rs").emit("link").output("link-emit/".to_owned() + bin_foo).run(); - }); - assert_expected_output_files(&[bin_foo], &[], "link-emit2", || { - rustc().input("foo.rs").emit(&format!("link=link-emit2/{bin_foo}")).run(); - }); - assert_expected_output_files(&[bin_foo], &[], "link-emit3", || { - rustc().input("foo.rs").arg(&format!("--emit=link=link-emit3/{bin_foo}")).run(); - }); + assert_expected_output_files( + Expectations { + expected_files: s![&bin_foo], + allowed_files: s!["foo.pdb"], + test_dir: "link-emit".to_string(), + }, + || { + rustc().input("foo.rs").emit("link").output("link-emit/".to_owned() + &bin_foo).run(); + }, + ); + assert_expected_output_files( + Expectations { + expected_files: s![&bin_foo], + allowed_files: s!["foo.pdb"], + test_dir: "link-emit2".to_string(), + }, + || { + rustc().input("foo.rs").emit(&format!("link=link-emit2/{bin_foo}")).run(); + }, + ); + assert_expected_output_files( + Expectations { + expected_files: s![&bin_foo], + allowed_files: s!["foo.pdb"], + test_dir: "link-emit3".to_string(), + }, + || { + rustc().input("foo.rs").arg(&format!("--emit=link=link-emit3/{bin_foo}")).run(); + }, + ); - assert_expected_output_files(&["foo"], &[], "rlib", || { - rustc().crate_type("rlib").input("foo.rs").output("rlib/foo").run(); - }); - assert_expected_output_files(&["foo"], &[], "rlib2", || { - rustc().crate_type("rlib").input("foo.rs").emit("link=rlib2/foo").run(); - }); - assert_expected_output_files(&["foo"], &[], "rlib3", || { - rustc().crate_type("rlib").input("foo.rs").arg("--emit=link=rlib3/foo").run(); - }); + assert_expected_output_files( + Expectations { + expected_files: s!["foo"], + allowed_files: s![], + test_dir: "rlib".to_string(), + }, + || { + rustc().crate_type("rlib").input("foo.rs").output("rlib/foo").run(); + }, + ); + assert_expected_output_files( + Expectations { + expected_files: s!["foo"], + allowed_files: s![], + test_dir: "rlib2".to_string(), + }, + || { + rustc().crate_type("rlib").input("foo.rs").emit("link=rlib2/foo").run(); + }, + ); + assert_expected_output_files( + Expectations { + expected_files: s!["foo"], + allowed_files: s![], + test_dir: "rlib3".to_string(), + }, + || { + rustc().crate_type("rlib").input("foo.rs").arg("--emit=link=rlib3/foo").run(); + }, + ); assert_expected_output_files( - &[bin_foo], - &[ - "libbar.ddl.exp", - "libbar.dll.lib", - "libbar.pdb", - "libbar.dll.a", - "libbar.exe.a", - "bar.ddl.exp", - "bar.dll.lib", - "bar.pdb", - "bar.dll.a", - "bar.exe.a", - ], - "dylib", - || { - rustc().crate_type("dylib").input("foo.rs").output("dylib/".to_owned() + bin_foo).run(); - }, - ); - assert_expected_output_files( - &[bin_foo], - &[ - "libbar.ddl.exp", - "libbar.dll.lib", - "libbar.pdb", - "libbar.dll.a", - "libbar.exe.a", - "bar.ddl.exp", - "bar.dll.lib", - "bar.pdb", - "bar.dll.a", - "bar.exe.a", - ], - "dylib2", + Expectations { + expected_files: s![bin_foo], + allowed_files: s![ + "libfoo.dll.exp", + "libfoo.dll.lib", + "libfoo.pdb", + "libfoo.dll.a", + "libfoo.exe.a", + "foo.dll.exp", + "foo.dll.lib", + "foo.pdb", + "foo.dll.a", + "foo.exe.a" + ], + test_dir: "dylib".to_string(), + }, + || { + rustc() + .crate_type("dylib") + .input("foo.rs") + .output("dylib/".to_owned() + &bin_foo) + .run(); + }, + ); + assert_expected_output_files( + Expectations { + expected_files: s![bin_foo], + allowed_files: s![ + "libfoo.dll.exp", + "libfoo.dll.lib", + "libfoo.pdb", + "libfoo.dll.a", + "libfoo.exe.a", + "foo.dll.exp", + "foo.dll.lib", + "foo.pdb", + "foo.dll.a", + "foo.exe.a" + ], + test_dir: "dylib2".to_string(), + }, || { rustc() .crate_type("dylib") @@ -180,20 +346,22 @@ fn main() { }, ); assert_expected_output_files( - &[bin_foo], - &[ - "libbar.ddl.exp", - "libbar.dll.lib", - "libbar.pdb", - "libbar.dll.a", - "libbar.exe.a", - "bar.ddl.exp", - "bar.dll.lib", - "bar.pdb", - "bar.dll.a", - "bar.exe.a", - ], - "dylib3", + Expectations { + expected_files: s![bin_foo], + allowed_files: s![ + "libfoo.dll.exp", + "libfoo.dll.lib", + "libfoo.pdb", + "libfoo.dll.a", + "libfoo.exe.a", + "foo.dll.exp", + "foo.dll.lib", + "foo.pdb", + "foo.dll.a", + "foo.exe.a" + ], + test_dir: "dylib3".to_string(), + }, || { rustc() .crate_type("dylib") @@ -203,55 +371,121 @@ fn main() { }, ); - assert_expected_output_files(&["foo"], &[], "staticlib", || { - rustc().crate_type("staticlib").input("foo.rs").output("staticlib/foo").run(); - }); - assert_expected_output_files(&["foo"], &[], "staticlib2", || { - rustc().crate_type("staticlib").input("foo.rs").emit("link=staticlib2/foo").run(); - }); - assert_expected_output_files(&["foo"], &[], "staticlib3", || { - rustc().crate_type("staticlib").input("foo.rs").arg("--emit=link=staticlib3/foo").run(); - }); + assert_expected_output_files( + Expectations { + expected_files: s!["foo"], + allowed_files: s![], + test_dir: "staticlib".to_string(), + }, + || { + rustc().crate_type("staticlib").input("foo.rs").output("staticlib/foo").run(); + }, + ); + assert_expected_output_files( + Expectations { + expected_files: s!["foo"], + allowed_files: s![], + test_dir: "staticlib2".to_string(), + }, + || { + rustc().crate_type("staticlib").input("foo.rs").emit("link=staticlib2/foo").run(); + }, + ); + assert_expected_output_files( + Expectations { + expected_files: s!["foo"], + allowed_files: s![], + test_dir: "staticlib3".to_string(), + }, + || { + rustc().crate_type("staticlib").input("foo.rs").arg("--emit=link=staticlib3/foo").run(); + }, + ); - assert_expected_output_files(&["foo"], &["foo.pdb"], "bincrate", || { - rustc().crate_type("bin").input("foo.rs").output("bincrate/".to_owned() + bin_foo).run(); - }); - assert_expected_output_files(&["foo"], &["foo.pdb"], "bincrate2", || { - rustc().crate_type("bin").input("foo.rs").emit(&format!("link=bincrate2/{bin_foo}")).run(); - }); - assert_expected_output_files(&["foo"], &["foo.pdb"], "bincrate3", || { - rustc() - .crate_type("bin") - .input("foo.rs") - .arg(&format!("--emit=link=bincrate3/{bin_foo}")) - .run(); - }); + assert_expected_output_files( + Expectations { + expected_files: s![bin_foo], + allowed_files: s!["foo.pdb"], + test_dir: "bincrate".to_string(), + }, + || { + rustc() + .crate_type("bin") + .input("foo.rs") + .output("bincrate/".to_owned() + &bin_foo) + .run(); + }, + ); + assert_expected_output_files( + Expectations { + expected_files: s![bin_foo], + allowed_files: s!["foo.pdb"], + test_dir: "bincrate2".to_string(), + }, + || { + rustc() + .crate_type("bin") + .input("foo.rs") + .emit(&format!("link=bincrate2/{bin_foo}")) + .run(); + }, + ); + assert_expected_output_files( + Expectations { + expected_files: s![bin_foo], + allowed_files: s!["foo.pdb"], + test_dir: "bincrate3".to_string(), + }, + || { + rustc() + .crate_type("bin") + .input("foo.rs") + .arg(&format!("--emit=link=bincrate3/{bin_foo}")) + .run(); + }, + ); - assert_expected_output_files(&["ir", rust_bar], &[], "rlib-ir", || { - rustc() - .input("foo.rs") - .emit("llvm-ir=rlib-ir/ir") - .emit("link") - .crate_type("rlib") - .out_dir("rlib-ir") - .run(); - }); + assert_expected_output_files( + Expectations { + expected_files: s!["ir", rust_lib_name("bar")], + allowed_files: s![], + test_dir: "rlib-ir".to_string(), + }, + || { + rustc() + .input("foo.rs") + .emit("llvm-ir=rlib-ir/ir") + .emit("link") + .crate_type("rlib") + .out_dir("rlib-ir") + .run(); + }, + ); - assert_expected_output_files(&["ir", "asm", "bc", "obj", "link"], &[], "staticlib-all", || { - rustc() - .input("foo.rs") - .emit("asm=staticlib-all/asm") - .emit("llvm-ir=staticlib-all/ir") - .emit("llvm-bc=staticlib-all/bc") - .emit("obj=staticlib-all/obj") - .emit("link=staticlib-all/link") - .crate_type("staticlib") - .run(); - }); - assert_expected_output_files( - &["ir", "asm", "bc", "obj", "link"], - &[], - "staticlib-all2", + assert_expected_output_files( + Expectations { + expected_files: s!["ir", "asm", "bc", "obj", "link"], + allowed_files: s![], + test_dir: "staticlib-all".to_string(), + }, + || { + rustc() + .input("foo.rs") + .emit("asm=staticlib-all/asm") + .emit("llvm-ir=staticlib-all/ir") + .emit("llvm-bc=staticlib-all/bc") + .emit("obj=staticlib-all/obj") + .emit("link=staticlib-all/link") + .crate_type("staticlib") + .run(); + }, + ); + assert_expected_output_files( + Expectations { + expected_files: s!["ir", "asm", "bc", "obj", "link"], + allowed_files: s![], + test_dir: "staticlib-all2".to_string(), + }, || { rustc() .input("foo.rs") @@ -268,9 +502,10 @@ fn main() { ); assert_expected_output_files( - &["bar.ll", "bar.s", "bar.o", static_bar], - &["bar.bc"], // keep this one for the next test - "staticlib-all3", + Expectations{ expected_files: + s!["bar.ll", "bar.s", "bar.o", static_lib_name("bar")], + allowed_files: s!["bar.bc"], test_dir: // keep this one for the next test + "staticlib-all3".to_string()}, || { rustc() .input("foo.rs") @@ -283,9 +518,24 @@ fn main() { // the .bc file from the previous test should be equivalent to this one, despite the difference // in crate type - assert_expected_output_files(&["bar.bc", rust_bar, "foo.bc"], &[], "rlib-emits", || { - fs_wrapper::rename("staticlib-all3/bar.bc", "rlib-emits/foo.bc"); - rustc().input("foo.rs").emit("llvm-bc,link").crate_type("rlib").out_dir("rlib-emits").run(); - assert_eq!(fs_wrapper::read("rlib-emits/foo.bc"), fs_wrapper::read("rlib-emits/bar.bc")); - }); + assert_expected_output_files( + Expectations { + expected_files: s!["bar.bc", rust_lib_name("bar"), "foo.bc"], + allowed_files: s![], + test_dir: "rlib-emits".to_string(), + }, + || { + fs_wrapper::rename("staticlib-all3/bar.bc", "rlib-emits/foo.bc"); + rustc() + .input("foo.rs") + .emit("llvm-bc,link") + .crate_type("rlib") + .out_dir("rlib-emits") + .run(); + assert_eq!( + fs_wrapper::read("rlib-emits/foo.bc"), + fs_wrapper::read("rlib-emits/bar.bc") + ); + }, + ); }