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 }
9 
10 #[test]
autocfg_version()11 fn autocfg_version() {
12     let ac = AutoCfg::with_dir("target").unwrap();
13     println!("version: {:?}", ac.rustc_version);
14     assert!(ac.probe_rustc_version(1, 0));
15 }
16 
17 #[test]
version_cmp()18 fn version_cmp() {
19     use super::version::Version;
20     let v123 = Version::new(1, 2, 3);
21 
22     assert!(Version::new(1, 0, 0) < v123);
23     assert!(Version::new(1, 2, 2) < v123);
24     assert!(Version::new(1, 2, 3) == v123);
25     assert!(Version::new(1, 2, 4) > v123);
26     assert!(Version::new(1, 10, 0) > v123);
27     assert!(Version::new(2, 0, 0) > v123);
28 }
29 
30 #[test]
probe_add()31 fn probe_add() {
32     let ac = AutoCfg::with_dir("target").unwrap();
33     let add = ac.core_std("ops::Add");
34     let add_rhs = ac.core_std("ops::Add<i32>");
35     let add_rhs_output = ac.core_std("ops::Add<i32, Output = i32>");
36     assert!(ac.probe_path(&add));
37     assert!(ac.probe_trait(&add));
38     assert!(ac.probe_trait(&add_rhs));
39     assert!(ac.probe_trait(&add_rhs_output));
40     assert!(ac.probe_type(&add_rhs_output));
41 }
42 
43 #[test]
probe_as_ref()44 fn probe_as_ref() {
45     let ac = AutoCfg::with_dir("target").unwrap();
46     let as_ref = ac.core_std("convert::AsRef");
47     let as_ref_str = ac.core_std("convert::AsRef<str>");
48     assert!(ac.probe_path(&as_ref));
49     assert!(ac.probe_trait(&as_ref_str));
50     assert!(ac.probe_type(&as_ref_str));
51 }
52 
53 #[test]
probe_i128()54 fn probe_i128() {
55     let ac = AutoCfg::with_dir("target").unwrap();
56     let missing = !ac.probe_rustc_version(1, 26);
57     let i128_path = ac.core_std("i128");
58     assert!(missing ^ ac.probe_path(&i128_path));
59     assert!(missing ^ ac.probe_type("i128"));
60 }
61 
62 #[test]
probe_sum()63 fn probe_sum() {
64     let ac = AutoCfg::with_dir("target").unwrap();
65     let missing = !ac.probe_rustc_version(1, 12);
66     let sum = ac.core_std("iter::Sum");
67     let sum_i32 = ac.core_std("iter::Sum<i32>");
68     assert!(missing ^ ac.probe_path(&sum));
69     assert!(missing ^ ac.probe_trait(&sum));
70     assert!(missing ^ ac.probe_trait(&sum_i32));
71     assert!(missing ^ ac.probe_type(&sum_i32));
72 }
73 
74 #[test]
probe_std()75 fn probe_std() {
76     let ac = AutoCfg::with_dir("target").unwrap();
77     assert_eq!(ac.probe_sysroot_crate("std"), !ac.no_std);
78 }
79 
80 #[test]
probe_alloc()81 fn probe_alloc() {
82     let ac = AutoCfg::with_dir("target").unwrap();
83     let missing = !ac.probe_rustc_version(1, 36);
84     assert!(missing ^ ac.probe_sysroot_crate("alloc"));
85 }
86 
87 #[test]
probe_bad_sysroot_crate()88 fn probe_bad_sysroot_crate() {
89     let ac = AutoCfg::with_dir("target").unwrap();
90     assert!(!ac.probe_sysroot_crate("doesnt_exist"));
91 }
92 
93 #[test]
probe_no_std()94 fn probe_no_std() {
95     let ac = AutoCfg::with_dir("target").unwrap();
96     assert!(ac.probe_type("i32"));
97     assert!(ac.probe_type("[i32]"));
98     assert_eq!(ac.probe_type("Vec<i32>"), !ac.no_std);
99 }
100