Skip to content

Commit

Permalink
Add tests for --env usage with tracked_env::var
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Dec 11, 2023
1 parent 5967ceb commit 453ff1e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/ui/proc-macro/auxiliary/env.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// force-host
// no-prefer-dynamic

#![crate_type = "proc-macro"]
#![feature(proc_macro_tracked_env)]

extern crate proc_macro;

use proc_macro::TokenStream;
use proc_macro::tracked_env::var;

#[proc_macro]
pub fn generate_const(input: TokenStream) -> TokenStream {
let the_const = match var("THE_CONST") {
Ok(x) if x == "12" => {
"const THE_CONST: u32 = 12;"
}
_ => {
"const THE_CONST: u32 = 0;"
}
};
let another = if var("ANOTHER").is_ok() {
"const ANOTHER: u32 = 1;"
} else {
"const ANOTHER: u32 = 2;"
};
format!("{the_const}{another}").parse().unwrap()
}
17 changes: 17 additions & 0 deletions tests/ui/proc-macro/env.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// aux-build:env.rs
// run-pass
// rustc-env: THE_CONST=1
// compile-flags: -Zunstable-options --env THE_CONST=12 --env ANOTHER=4

#![crate_name = "foo"]

extern crate env;

use env::generate_const;

generate_const!();

fn main() {
assert_eq!(THE_CONST, 12);
assert_eq!(ANOTHER, 1);
}

0 comments on commit 453ff1e

Please sign in to comment.