]> git.proxmox.com Git - rustc.git/blame - 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
CommitLineData
dfeec247
XL
1use super::RPathConfig;
2use super::{get_rpath_relative_to_output, minimize_rpaths, rpaths_to_flags};
dc9dc135
XL
3use std::path::{Path, PathBuf};
4
5#[test]
6fn test_rpaths_to_flags() {
dfeec247
XL
7 let flags = rpaths_to_flags(&["path1".to_string(), "path2".to_string()]);
8 assert_eq!(flags, ["-Wl,-rpath,path1", "-Wl,-rpath,path2"]);
dc9dc135
XL
9}
10
11#[test]
12fn test_minimize1() {
dfeec247
XL
13 let res = minimize_rpaths(&["rpath1".to_string(), "rpath2".to_string(), "rpath1".to_string()]);
14 assert!(res == ["rpath1", "rpath2",]);
dc9dc135
XL
15}
16
17#[test]
18fn 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(),
dfeec247 29 "3".to_string(),
dc9dc135 30 ]);
dfeec247 31 assert!(res == ["1a", "2", "4a", "3",]);
dc9dc135
XL
32}
33
34#[test]
35fn test_rpath_relative() {
36 if cfg!(target_os = "macos") {
37 let config = &mut RPathConfig {
60c5eb7d 38 used_crates: &[],
dc9dc135
XL
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 };
dfeec247 45 let res = get_rpath_relative_to_output(config, Path::new("lib/libstd.so"));
dc9dc135
XL
46 assert_eq!(res, "@loader_path/../lib");
47 } else {
48 let config = &mut RPathConfig {
60c5eb7d 49 used_crates: &[],
dc9dc135
XL
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 };
dfeec247 56 let res = get_rpath_relative_to_output(config, Path::new("lib/libstd.so"));
dc9dc135
XL
57 assert_eq!(res, "$ORIGIN/../lib");
58 }
59}
60
61#[test]
62fn test_xlinker() {
dfeec247 63 let args = rpaths_to_flags(&["a/normal/path".to_string(), "a,comma,path".to_string()]);
dc9dc135 64
dfeec247
XL
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 );
dc9dc135 74}