Skip to content

Commit 31766c6

Browse files
committed
Test that env! works with incremental compilation
This currently works because it's part of expansion, and that isn't yet tracked by the query system. But we want to ensure it continues working, even if that is changed.
1 parent 46e8d20 commit 31766c6

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

tests/incremental/env/env_macro.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Check that changes to environment variables are propagated to `env!`.
2+
//
3+
// This test is intentionally written to not use any `#[cfg(rpass*)]`, to
4+
// _really_ test that we re-compile if the environment variable changes.
5+
6+
//@ revisions: cfail1 rpass2 rpass3 cfail4
7+
//@ [cfail1]unset-rustc-env:EXAMPLE_ENV
8+
//@ [rpass2]rustc-env:EXAMPLE_ENV=one
9+
//@ [rpass2]exec-env:EXAMPLE_ENV=one
10+
//@ [rpass3]rustc-env:EXAMPLE_ENV=two
11+
//@ [rpass3]exec-env:EXAMPLE_ENV=two
12+
//@ [cfail4]unset-rustc-env:EXAMPLE_ENV
13+
14+
fn main() {
15+
assert_eq!(env!("EXAMPLE_ENV"), std::env::var("EXAMPLE_ENV").unwrap());
16+
//[cfail1]~^ ERROR environment variable `EXAMPLE_ENV` not defined at compile time
17+
//[cfail4]~^^ ERROR environment variable `EXAMPLE_ENV` not defined at compile time
18+
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Check that changes to environment variables are propagated to `option_env!`.
2+
//
3+
// This test is intentionally written to not use any `#[cfg(rpass*)]`, to
4+
// _really_ test that we re-compile if the environment variable changes.
5+
6+
//@ revisions: rpass1 rpass2 rpass3 rpass4
7+
//@ [rpass1]unset-rustc-env:EXAMPLE_ENV
8+
//@ [rpass1]unset-exec-env:EXAMPLE_ENV
9+
//@ [rpass2]rustc-env:EXAMPLE_ENV=one
10+
//@ [rpass2]exec-env:EXAMPLE_ENV=one
11+
//@ [rpass3]rustc-env:EXAMPLE_ENV=two
12+
//@ [rpass3]exec-env:EXAMPLE_ENV=two
13+
//@ [rpass4]unset-rustc-env:EXAMPLE_ENV
14+
//@ [rpass4]unset-exec-env:EXAMPLE_ENV
15+
16+
fn main() {
17+
assert_eq!(option_env!("EXAMPLE_ENV"), std::env::var("EXAMPLE_ENV").ok().as_deref());
18+
}

0 commit comments

Comments
 (0)