]> git.lizzy.rs Git - rust.git/blob - tests/pass/env.rs
make tests pass again
[rust.git] / tests / pass / env.rs
1 use std::env;
2
3 fn main() {
4     // Test that miri environment is isolated when communication is disabled.
5     // (`MIRI_ENV_VAR_TEST` is set by the test harness.)
6     assert_eq!(env::var("MIRI_ENV_VAR_TEST"), Err(env::VarError::NotPresent));
7
8     // Test base state.
9     println!("{:#?}", env::vars().collect::<Vec<_>>());
10     assert_eq!(env::var("MIRI_TEST"), Err(env::VarError::NotPresent));
11
12     // Set the variable.
13     env::set_var("MIRI_TEST", "the answer");
14     assert_eq!(env::var("MIRI_TEST"), Ok("the answer".to_owned()));
15     println!("{:#?}", env::vars().collect::<Vec<_>>());
16
17     // Change the variable.
18     env::set_var("MIRI_TEST", "42");
19     assert_eq!(env::var("MIRI_TEST"), Ok("42".to_owned()));
20     println!("{:#?}", env::vars().collect::<Vec<_>>());
21
22     // Remove the variable.
23     env::remove_var("MIRI_TEST");
24     assert_eq!(env::var("MIRI_TEST"), Err(env::VarError::NotPresent));
25     println!("{:#?}", env::vars().collect::<Vec<_>>());
26 }