]> git.proxmox.com Git - rustc.git/blob - src/librustc_codegen_ssa/back/rpath/tests.rs
New upstream version 1.47.0+dfsg1
[rustc.git] / src / librustc_codegen_ssa / 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 used_crates: &[],
39 has_rpath: true,
40 is_like_osx: true,
41 linker_is_gnu: false,
42 out_filename: PathBuf::from("bin/rustc"),
43 get_install_prefix_lib_path: &mut || panic!(),
44 };
45 let res = get_rpath_relative_to_output(config, Path::new("lib/libstd.so"));
46 assert_eq!(res, "@loader_path/../lib");
47 } else {
48 let config = &mut RPathConfig {
49 used_crates: &[],
50 out_filename: PathBuf::from("bin/rustc"),
51 get_install_prefix_lib_path: &mut || panic!(),
52 has_rpath: true,
53 is_like_osx: false,
54 linker_is_gnu: true,
55 };
56 let res = get_rpath_relative_to_output(config, Path::new("lib/libstd.so"));
57 assert_eq!(res, "$ORIGIN/../lib");
58 }
59 }
60
61 #[test]
62 fn test_xlinker() {
63 let args = rpaths_to_flags(&["a/normal/path".to_string(), "a,comma,path".to_string()]);
64
65 assert_eq!(
66 args,
67 vec![
68 "-Wl,-rpath,a/normal/path".to_string(),
69 "-Wl,-rpath".to_string(),
70 "-Xlinker".to_string(),
71 "a,comma,path".to_string()
72 ]
73 );
74 }