Test sorting of native library paths
authorKornel <kornel@geekhood.net>
Sat, 20 Jan 2018 17:57:17 +0000 (17:57 +0000)
committerKornel <kornel@geekhood.net>
Tue, 23 Jan 2018 17:21:25 +0000 (17:21 +0000)
tests/run.rs

index efa107c4b91b046fa7311d6e1a3606edfffa3929..96a7bb02dede221f554c76e2f8d4663164091716 100644 (file)
@@ -784,6 +784,49 @@ fn run_with_library_paths() {
     assert_that(p.cargo("run"), execs().with_status(0));
 }
 
+#[test]
+fn library_paths_sorted_alphabetically() {
+    let p = project("foo");
+
+    let mut dir1 = p.target_debug_dir();
+    dir1.push("zzzzzzz");
+
+    let mut dir2 = p.target_debug_dir();
+    dir2.push("BBBBBBB");
+
+    let mut dir3 = p.target_debug_dir();
+    dir3.push("aaaaaaa");
+
+    let p = p
+        .file("Cargo.toml", r#"
+            [project]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+            build = "build.rs"
+        "#)
+        .file("build.rs", &format!(r##"
+            fn main() {{
+                println!(r#"cargo:rustc-link-search=native={}"#);
+                println!(r#"cargo:rustc-link-search=native={}"#);
+                println!(r#"cargo:rustc-link-search=native={}"#);
+            }}
+        "##, dir1.display(), dir2.display(), dir3.display()))
+        .file("src/main.rs", &format!(r##"
+            fn main() {{
+                let search_path = std::env::var_os("{}").unwrap();
+                let paths = std::env::split_paths(&search_path).collect::<Vec<_>>();
+                // ASCII case-sensitive sort
+                assert_eq!("BBBBBBB", paths[0].file_name().unwrap().to_string_lossy());
+                assert_eq!("aaaaaaa", paths[1].file_name().unwrap().to_string_lossy());
+                assert_eq!("zzzzzzz", paths[2].file_name().unwrap().to_string_lossy());
+            }}
+        "##, dylib_path_envvar()))
+        .build();
+
+    assert_that(p.cargo("run"), execs().with_status(0));
+}
+
 #[test]
 fn fail_no_extra_verbose() {
     let p = project("foo")