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