Debian Codegraph @

.cargo/vendor/autocfg/tests/no_std.rs

raw
1 extern crate autocfg;
2
3 use std::env;
4
5 /// Tests that we can control the use of `#![no_std]`.
6 #[test]
7 fn no_std() {
8 // Clear the CI `TARGET`, if any, so we're just dealing with the
9 // host target which always has `std` available.
10 env::remove_var("TARGET");
11
12 // Use the same path as this test binary.
13 let dir = env::current_exe().unwrap().parent().unwrap().to_path_buf();
14 env::set_var("OUT_DIR", &format!("{}", dir.display()));
15
16 let mut ac = autocfg::AutoCfg::new().unwrap();
17 assert!(!ac.no_std());
18 assert!(ac.probe_path("std::mem"));
19
20 // `#![no_std]` was stabilized in Rust 1.6
21 if ac.probe_rustc_version(1, 6) {
22 ac.set_no_std(true);
23 assert!(ac.no_std());
24 assert!(!ac.probe_path("std::mem"));
25 assert!(ac.probe_path("core::mem"));
26 }
27 }