]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_codegen_ssa/src/back/rpath/tests.rs
Auto merge of #104535 - mikebenfield:discr-fix, r=pnkfelix
[rust.git] / compiler / rustc_codegen_ssa / src / back / rpath / tests.rs
1 use super::RPathConfig;
2 use super::{get_rpath_relative_to_output, minimize_rpaths, rpaths_to_flags};
3 use std::path::{Path, PathBuf};
4
5 #[test]
6 fn test_rpaths_to_flags() {
7     let flags = rpaths_to_flags(&["path1".to_string(), "path2".to_string()]);
8     assert_eq!(flags, ["-Wl,-rpath,path1", "-Wl,-rpath,path2"]);
9 }
10
11 #[test]
12 fn test_minimize1() {
13     let res = minimize_rpaths(&["rpath1".to_string(), "rpath2".to_string(), "rpath1".to_string()]);
14     assert!(res == ["rpath1", "rpath2",]);
15 }
16
17 #[test]
18 fn test_minimize2() {
19     let res = minimize_rpaths(&[
20         "1a".to_string(),
21         "2".to_string(),
22         "2".to_string(),
23         "1a".to_string(),
24         "4a".to_string(),
25         "1a".to_string(),
26         "2".to_string(),
27         "3".to_string(),
28         "4a".to_string(),
29         "3".to_string(),
30     ]);
31     assert!(res == ["1a", "2", "4a", "3",]);
32 }
33
34 #[test]
35 fn test_rpath_relative() {
36     if cfg!(target_os = "macos") {
37         let config = &mut RPathConfig {
38             libs: &[],
39             has_rpath: true,
40             is_like_osx: true,
41             linker_is_gnu: false,
42             out_filename: PathBuf::from("bin/rustc"),
43         };
44         let res = get_rpath_relative_to_output(config, Path::new("lib/libstd.so"));
45         assert_eq!(res, "@loader_path/../lib");
46     } else {
47         let config = &mut RPathConfig {
48             libs: &[],
49             out_filename: PathBuf::from("bin/rustc"),
50             has_rpath: true,
51             is_like_osx: false,
52             linker_is_gnu: true,
53         };
54         let res = get_rpath_relative_to_output(config, Path::new("lib/libstd.so"));
55         assert_eq!(res, "$ORIGIN/../lib");
56     }
57 }
58
59 #[test]
60 fn test_xlinker() {
61     let args = rpaths_to_flags(&["a/normal/path".to_string(), "a,comma,path".to_string()]);
62
63     assert_eq!(
64         args,
65         vec![
66             "-Wl,-rpath,a/normal/path".to_string(),
67             "-Wl,-rpath".to_string(),
68             "-Xlinker".to_string(),
69             "a,comma,path".to_string()
70         ]
71     );
72 }