about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--tests/ui/proc-macro/auxiliary/env.rs28
-rw-r--r--tests/ui/proc-macro/env.rs17
2 files changed, 45 insertions, 0 deletions
diff --git a/tests/ui/proc-macro/auxiliary/env.rs b/tests/ui/proc-macro/auxiliary/env.rs
new file mode 100644
index 00000000000..58bcb08bf06
--- /dev/null
+++ b/tests/ui/proc-macro/auxiliary/env.rs
@@ -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()
+}
diff --git a/tests/ui/proc-macro/env.rs b/tests/ui/proc-macro/env.rs
new file mode 100644
index 00000000000..1b1d1873eb3
--- /dev/null
+++ b/tests/ui/proc-macro/env.rs
@@ -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);
+}