about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOneirical <manchot@videotron.ca>2024-07-04 11:15:57 -0400
committerOneirical <manchot@videotron.ca>2024-07-04 11:38:24 -0400
commit5cddb156d114d77bb5f9ba3876fb2dada7ad9276 (patch)
tree8c5974e1a1e84304e923bbd581e661e91a14622c
parent1086affd98ad746e1bb02e187562b9a037e854e3 (diff)
rewrite target-specs to rmake
-rw-r--r--tests/run-make/target-specs/Makefile12
-rw-r--r--tests/run-make/target-specs/rmake.rs71
2 files changed, 71 insertions, 12 deletions
diff --git a/tests/run-make/target-specs/Makefile b/tests/run-make/target-specs/Makefile
deleted file mode 100644
index 161b6602185..00000000000
--- a/tests/run-make/target-specs/Makefile
+++ /dev/null
@@ -1,12 +0,0 @@
-include ../tools.mk
-all:
-	$(RUSTC) foo.rs --target=my-awesome-platform.json --crate-type=lib --emit=asm
-	$(CGREP) -v morestack < $(TMPDIR)/foo.s
-	$(RUSTC) foo.rs --target=my-invalid-platform.json 2>&1 | $(CGREP) "Error loading target specification"
-	$(RUSTC) foo.rs --target=my-incomplete-platform.json 2>&1 | $(CGREP) 'Field llvm-target'
-	RUST_TARGET_PATH=. $(RUSTC) foo.rs --target=my-awesome-platform --crate-type=lib --emit=asm
-	RUST_TARGET_PATH=. $(RUSTC) foo.rs --target=my-x86_64-unknown-linux-gnu-platform --crate-type=lib --emit=asm
-	$(RUSTC) -Z unstable-options --target=my-awesome-platform.json --print target-spec-json > $(TMPDIR)/test-platform.json && $(RUSTC) -Z unstable-options --target=$(TMPDIR)/test-platform.json --print target-spec-json | diff -q $(TMPDIR)/test-platform.json -
-	$(RUSTC) foo.rs --target=definitely-not-builtin-target 2>&1 | $(CGREP) 'may not set is_builtin'
-	$(RUSTC) foo.rs --target=endianness-mismatch 2>&1 | $(CGREP) '"data-layout" claims architecture is little-endian'
-	$(RUSTC) foo.rs --target=mismatching-data-layout --crate-type=lib 2>&1 | $(CGREP) 'data-layout for target'
diff --git a/tests/run-make/target-specs/rmake.rs b/tests/run-make/target-specs/rmake.rs
new file mode 100644
index 00000000000..10c2fa29830
--- /dev/null
+++ b/tests/run-make/target-specs/rmake.rs
@@ -0,0 +1,71 @@
+// Target-specific compilation in rustc used to have case-by-case peculiarities in 2014,
+// with the compiler having redundant target types and unspecific names. An overarching rework
+// in #161156 changed the way the target flag functions, and this test attempts compilation
+// with the target flag's bundle of new features to check that compilation either succeeds while
+// using them correctly, or fails with the right error message when using them improperly.
+// See https://github.com/rust-lang/rust/pull/16156
+
+use run_make_support::{diff, fs_wrapper, rustc};
+
+fn main() {
+    rustc().input("foo.rs").target("my-awesome-platform.json").crate_type("lib").emit("asm").run();
+    assert!(!fs_wrapper::read_to_string("foo.s").contains("morestack"));
+    rustc()
+        .input("foo.rs")
+        .target("my-invalid-platform.json")
+        .run_fail()
+        .assert_stderr_contains("Error loading target specification");
+    rustc()
+        .input("foo.rs")
+        .target("my-incomplete-platform.json")
+        .run_fail()
+        .assert_stderr_contains("Field llvm-target");
+    rustc()
+        .env("RUST_TARGET_PATH", ".")
+        .input("foo.rs")
+        .target("my-awesome-platform")
+        .crate_type("lib")
+        .emit("asm")
+        .run();
+    rustc()
+        .env("RUST_TARGET_PATH", ".")
+        .input("foo.rs")
+        .target("my-x86_64-unknown-linux-gnu-platform")
+        .crate_type("lib")
+        .emit("asm")
+        .run();
+    let test_platform = rustc()
+        .arg("-Zunstable-options")
+        .target("my-awesome-platform.json")
+        .print("target-spec-json")
+        .run()
+        .stdout_utf8();
+    fs_wrapper::create_file("test-platform.json");
+    fs_wrapper::write("test-platform.json", test_platform.as_bytes());
+    let test_platform_2 = rustc()
+        .arg("-Zunstable-options")
+        .target("test-platform.json")
+        .print("target-spec-json")
+        .run()
+        .stdout_utf8();
+    diff()
+        .expected_file("test-platform.json")
+        .actual_text("test-platform-2", test_platform_2)
+        .run();
+    rustc()
+        .input("foo.rs")
+        .target("definitely-not-builtin-target")
+        .run_fail()
+        .assert_stderr_contains("may not set is_builtin");
+    rustc()
+        .input("foo.rs")
+        .target("endianness-mismatch")
+        .run_fail()
+        .assert_stderr_contains(r#""data-layout" claims architecture is little-endian"#);
+    rustc()
+        .input("foo.rs")
+        .target("mismatching-data-layout")
+        .crate_type("lib")
+        .run_fail()
+        .assert_stderr_contains("data-layout for target");
+}