1 use super::AutoCfg;
2
3 impl AutoCfg {
core_std(&self, path: &str) -> String4 fn core_std(&self, path: &str) -> String {
5 let krate = if self.no_std { "core" } else { "std" };
6 format!("{}::{}", krate, path)
7 }
8
assert_std(&self, probe_result: bool)9 fn assert_std(&self, probe_result: bool) {
10 assert_eq!(!self.no_std, probe_result);
11 }
12
assert_min(&self, major: usize, minor: usize, probe_result: bool)13 fn assert_min(&self, major: usize, minor: usize, probe_result: bool) {
14 assert_eq!(self.probe_rustc_version(major, minor), probe_result);
15 }
16 }
17
18 #[test]
autocfg_version()19 fn autocfg_version() {
20 let ac = AutoCfg::with_dir("target").unwrap();
21 println!("version: {:?}", ac.rustc_version);
22 assert!(ac.probe_rustc_version(1, 0));
23 }
24
25 #[test]
version_cmp()26 fn version_cmp() {
27 use super::version::Version;
28 let v123 = Version::new(1, 2, 3);
29
30 assert!(Version::new(1, 0, 0) < v123);
31 assert!(Version::new(1, 2, 2) < v123);
32 assert!(Version::new(1, 2, 3) == v123);
33 assert!(Version::new(1, 2, 4) > v123);
34 assert!(Version::new(1, 10, 0) > v123);
35 assert!(Version::new(2, 0, 0) > v123);
36 }
37
38 #[test]
probe_add()39 fn probe_add() {
40 let ac = AutoCfg::with_dir("target").unwrap();
41 let add = ac.core_std("ops::Add");
42 let add_rhs = add.clone() + "<i32>";
43 let add_rhs_output = add.clone() + "<i32, Output = i32>";
44 let dyn_add_rhs_output = "dyn ".to_string() + &*add_rhs_output;
45 assert!(ac.probe_path(&add));
46 assert!(ac.probe_trait(&add));
47 assert!(ac.probe_trait(&add_rhs));
48 assert!(ac.probe_trait(&add_rhs_output));
49 ac.assert_min(1, 27, ac.probe_type(&dyn_add_rhs_output));
50 }
51
52 #[test]
probe_as_ref()53 fn probe_as_ref() {
54 let ac = AutoCfg::with_dir("target").unwrap();
55 let as_ref = ac.core_std("convert::AsRef");
56 let as_ref_str = as_ref.clone() + "<str>";
57 let dyn_as_ref_str = "dyn ".to_string() + &*as_ref_str;
58 assert!(ac.probe_path(&as_ref));
59 assert!(ac.probe_trait(&as_ref_str));
60 assert!(ac.probe_type(&as_ref_str));
61 ac.assert_min(1, 27, ac.probe_type(&dyn_as_ref_str));
62 }
63
64 #[test]
probe_i128()65 fn probe_i128() {
66 let ac = AutoCfg::with_dir("target").unwrap();
67 let i128_path = ac.core_std("i128");
68 ac.assert_min(1, 26, ac.probe_path(&i128_path));
69 ac.assert_min(1, 26, ac.probe_type("i128"));
70 }
71
72 #[test]
probe_sum()73 fn probe_sum() {
74 let ac = AutoCfg::with_dir("target").unwrap();
75 let sum = ac.core_std("iter::Sum");
76 let sum_i32 = sum.clone() + "<i32>";
77 let dyn_sum_i32 = "dyn ".to_string() + &*sum_i32;
78 ac.assert_min(1, 12, ac.probe_path(&sum));
79 ac.assert_min(1, 12, ac.probe_trait(&sum));
80 ac.assert_min(1, 12, ac.probe_trait(&sum_i32));
81 ac.assert_min(1, 12, ac.probe_type(&sum_i32));
82 ac.assert_min(1, 27, ac.probe_type(&dyn_sum_i32));
83 }
84
85 #[test]
probe_std()86 fn probe_std() {
87 let ac = AutoCfg::with_dir("target").unwrap();
88 ac.assert_std(ac.probe_sysroot_crate("std"));
89 }
90
91 #[test]
probe_alloc()92 fn probe_alloc() {
93 let ac = AutoCfg::with_dir("target").unwrap();
94 ac.assert_min(1, 36, ac.probe_sysroot_crate("alloc"));
95 }
96
97 #[test]
probe_bad_sysroot_crate()98 fn probe_bad_sysroot_crate() {
99 let ac = AutoCfg::with_dir("target").unwrap();
100 assert!(!ac.probe_sysroot_crate("doesnt_exist"));
101 }
102
103 #[test]
probe_no_std()104 fn probe_no_std() {
105 let ac = AutoCfg::with_dir("target").unwrap();
106 assert!(ac.probe_type("i32"));
107 assert!(ac.probe_type("[i32]"));
108 ac.assert_std(ac.probe_type("Vec<i32>"));
109 }
110
111 #[test]
probe_expression()112 fn probe_expression() {
113 let ac = AutoCfg::with_dir("target").unwrap();
114 assert!(ac.probe_expression(r#""test".trim_left()"#));
115 ac.assert_min(1, 30, ac.probe_expression(r#""test".trim_start()"#));
116 ac.assert_std(ac.probe_expression("[1, 2, 3].to_vec()"));
117 }
118
119 #[test]
probe_constant()120 fn probe_constant() {
121 let ac = AutoCfg::with_dir("target").unwrap();
122 assert!(ac.probe_constant("1 + 2 + 3"));
123 ac.assert_min(1, 33, ac.probe_constant("{ let x = 1 + 2 + 3; x * x }"));
124 ac.assert_min(1, 39, ac.probe_constant(r#""test".len()"#));
125 }
126