about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/run-make/extern-flag-pathless/Makefile34
-rw-r--r--tests/run-make/extern-flag-pathless/rmake.rs40
2 files changed, 40 insertions, 34 deletions
diff --git a/tests/run-make/extern-flag-pathless/Makefile b/tests/run-make/extern-flag-pathless/Makefile
deleted file mode 100644
index 36b374e0d2e..00000000000
--- a/tests/run-make/extern-flag-pathless/Makefile
+++ /dev/null
@@ -1,34 +0,0 @@
-# ignore-cross-compile
-include ../tools.mk
-
-# Test mixing pathless --extern with paths.
-
-# Test for static linking by checking that the binary runs if the dylib
-# is removed and test for dynamic linking by checking that the binary
-# fails to run if the dylib is removed.
-
-all:
-	$(RUSTC) bar.rs --crate-type=rlib --crate-type=dylib -Cprefer-dynamic
-
-	# rlib preferred over dylib
-	$(RUSTC) foo.rs --extern bar
-	mv $(call DYLIB,bar) $(TMPDIR)/bar.tmp
-	$(call RUN,foo)
-	mv $(TMPDIR)/bar.tmp $(call DYLIB,bar)
-
-	$(RUSTC) foo.rs --extern bar=$(TMPDIR)/libbar.rlib --extern bar
-	mv $(call DYLIB,bar) $(TMPDIR)/bar.tmp
-	$(call RUN,foo)
-	mv $(TMPDIR)/bar.tmp $(call DYLIB,bar)
-
-	# explicit --extern overrides pathless
-	$(RUSTC) foo.rs --extern bar=$(call DYLIB,bar) --extern bar
-	mv $(call DYLIB,bar) $(TMPDIR)/bar.tmp
-	$(call FAIL,foo)
-	mv $(TMPDIR)/bar.tmp $(call DYLIB,bar)
-
-	# prefer-dynamic does what it says
-	$(RUSTC) foo.rs --extern bar -C prefer-dynamic
-	mv $(call DYLIB,bar) $(TMPDIR)/bar.tmp
-	$(call FAIL,foo)
-	mv $(TMPDIR)/bar.tmp $(call DYLIB,bar)
diff --git a/tests/run-make/extern-flag-pathless/rmake.rs b/tests/run-make/extern-flag-pathless/rmake.rs
new file mode 100644
index 00000000000..2f151136c33
--- /dev/null
+++ b/tests/run-make/extern-flag-pathless/rmake.rs
@@ -0,0 +1,40 @@
+// It is possible, since #64882, to use the --extern flag without an explicit
+// path. In the event of two --extern flags, the explicit one with a path will take
+// priority, but otherwise, it is a more concise way of fetching specific libraries.
+// This test checks that the default priority of explicit extern flags and rlibs is
+// respected.
+// See https://github.com/rust-lang/rust/pull/64882
+
+use run_make_support::{dynamic_lib_name, fs_wrapper, run, run_fail, rust_lib_name, rustc};
+
+fn main() {
+    rustc().input("bar.rs").crate_type("rlib").crate_type("dylib").arg("-Cprefer-dynamic").run();
+
+    // By default, the rlib has priority over the dylib.
+    rustc().input("foo.rs").arg("--extern").arg("bar").run();
+    fs_wrapper::rename(dynamic_lib_name("bar"), "bar.tmp");
+    run("foo");
+    fs_wrapper::rename("bar.tmp", dynamic_lib_name("bar"));
+
+    rustc().input("foo.rs").extern_("bar", rust_lib_name("bar")).arg("--extern").arg("bar").run();
+    fs_wrapper::rename(dynamic_lib_name("bar"), "bar.tmp");
+    run("foo");
+    fs_wrapper::rename("bar.tmp", dynamic_lib_name("bar"));
+
+    // The first explicit usage of extern overrides the second pathless --extern bar.
+    rustc()
+        .input("foo.rs")
+        .extern_("bar", dynamic_lib_name("bar"))
+        .arg("--extern")
+        .arg("bar")
+        .run();
+    fs_wrapper::rename(dynamic_lib_name("bar"), "bar.tmp");
+    run_fail("foo");
+    fs_wrapper::rename("bar.tmp", dynamic_lib_name("bar"));
+
+    // With prefer-dynamic, execution fails as it refuses to use the rlib.
+    rustc().input("foo.rs").arg("--extern").arg("bar").arg("-Cprefer-dynamic").run();
+    fs_wrapper::rename(dynamic_lib_name("bar"), "bar.tmp");
+    run_fail("foo");
+    fs_wrapper::rename("bar.tmp", dynamic_lib_name("bar"));
+}