1 | extern crate autocfg; |
---|---|
2 | |
3 | use std::env; |
4 | |
5 | /// Tests that autocfg uses the RUSTFLAGS or CARGO_ENCODED_RUSTFLAGS |
6 | /// environment variables when running rustc. |
7 | #[test] |
8 | fn test_with_sysroot() { |
9 | // Use the same path as this test binary. |
10 | let dir = env::current_exe().unwrap().parent().unwrap().to_path_buf(); |
11 | env::set_var("OUT_DIR", &format!( "{}", dir.display())); |
12 | |
13 | // If we have encoded rustflags, they take precedence, even if empty. |
14 | env::set_var("CARGO_ENCODED_RUSTFLAGS", ""); |
15 | env::set_var("RUSTFLAGS", &format!( "-L {}", dir.display())); |
16 | let ac = autocfg::AutoCfg::new().unwrap(); |
17 | assert!(ac.probe_sysroot_crate("std")); |
18 | assert!(!ac.probe_sysroot_crate("autocfg")); |
19 | |
20 | // Now try again with useful encoded args. |
21 | env::set_var( |
22 | "CARGO_ENCODED_RUSTFLAGS", |
23 | &format!("-L\x1f {}", dir.display()), |
24 | ); |
25 | let ac = autocfg::AutoCfg::new().unwrap(); |
26 | assert!(ac.probe_sysroot_crate("autocfg")); |
27 | |
28 | // Try the old-style RUSTFLAGS, ensuring HOST != TARGET. |
29 | env::remove_var("CARGO_ENCODED_RUSTFLAGS"); |
30 | env::set_var("HOST", "lol"); |
31 | let ac = autocfg::AutoCfg::new().unwrap(); |
32 | assert!(ac.probe_sysroot_crate("autocfg")); |
33 | } |
34 |
Definitions
Learn Rust with the experts
Find out more