Skip to content

Commit

Permalink
improve wasi envvar test
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark McCaskey committed May 30, 2019
1 parent 2a94a69 commit 6a9515d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/wasi/wasitests/envvar.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Env vars:
CAT=2
DOG=1
DOG Ok("1")
DOG_TYPE Err(NotPresent)
SET VAR Ok("HELLO")
17 changes: 17 additions & 0 deletions lib/wasi/wasitests/envvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@

use std::env;

fn get_env_var(var_name: &str) -> Result<String, env::VarError> {
#[cfg(not(target = "wasi"))]
match var_name {
"DOG" => Ok("1".to_string()),
"CAT" => Ok("2".to_string()),
_ => Err(env::VarError::NotPresent),
}
#[cfg(target = "wasi")]
env::var(var_name)
}

fn main() {
#[cfg(not(target = "wasi"))]
let mut env_vars = vec!["DOG=1".to_string(), "CAT=2".to_string()];
Expand All @@ -18,4 +29,10 @@ fn main() {
for e in env_vars {
println!("{}", e);
}

env::set_var("WASI_ENVVAR_TEST", "HELLO");

println!("DOG {:?}", get_env_var("DOG"));
println!("DOG_TYPE {:?}", get_env_var("DOG_TYPE"));
println!("SET VAR {:?}", env::var("WASI_ENVVAR_TEST"));
}
Binary file modified lib/wasi/wasitests/envvar.wasm
Binary file not shown.

0 comments on commit 6a9515d

Please sign in to comment.