Debian Codegraph @

.cargo/vendor/autocfg/tests/wrappers.rs

raw
1 extern crate autocfg;
2
3 use std::env;
4
5 /// Tests that autocfg uses the RUSTC_WRAPPER and/or RUSTC_WORKSPACE_WRAPPER
6 /// environment variables when running rustc.
7 #[test]
8 #[cfg(unix)] // we're using system binaries as wrappers
9 fn test_wrappers() {
10 fn set(name: &str, value: Option<bool>) {
11 match value {
12 Some(true) => env::set_var(name, "/usr/bin/env"),
13 Some(false) => env::set_var(name, "/bin/false"),
14 None => env::remove_var(name),
15 }
16 }
17
18 // Use the same path as this test binary.
19 let dir = env::current_exe().unwrap().parent().unwrap().to_path_buf();
20 env::set_var("OUT_DIR", &format!("{}", dir.display()));
21
22 // This is used as a heuristic to detect rust-lang/cargo#9601.
23 env::set_var("CARGO_ENCODED_RUSTFLAGS", "");
24
25 // No wrapper, a good pass-through wrapper, and a bad wrapper.
26 let variants = [None, Some(true), Some(false)];
27
28 for &workspace in &variants {
29 for &rustc in &variants {
30 set("RUSTC_WRAPPER", rustc);
31 set("RUSTC_WORKSPACE_WRAPPER", workspace);
32
33 let ac = autocfg::AutoCfg::new().unwrap();
34 if rustc == Some(false) || workspace == Some(false) {
35 // Everything should fail with bad wrappers.
36 assert!(!ac.probe_type("usize"));
37 } else {
38 // Try known good and bad types for the wrapped rustc.
39 assert!(ac.probe_type("usize"));
40 assert!(!ac.probe_type("mesize"));
41 }
42 // Either way, we should have found the inner rustc version.
43 assert!(ac.probe_rustc_version(1, 0));
44 }
45 }
46
47 // Finally, make sure that `RUSTC_WRAPPER` is applied outermost
48 // by using something that doesn't pass through at all.
49 env::set_var("RUSTC_WRAPPER", "./tests/wrap_ignored");
50 env::set_var("RUSTC_WORKSPACE_WRAPPER", "/bin/false");
51 let ac = autocfg::AutoCfg::new().unwrap();
52 assert!(ac.probe_type("mesize")); // anything goes!
53
54 // Make sure we also got the version from that wrapper.
55 assert!(ac.probe_rustc_version(12345, 6789));
56 }