-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
476: fix bug in wasi::environ_get, fix off by one error in env_size_get r=MarkMcCaskey a=MarkMcCaskey adds `--env` flag (resolves #475) fixes other wasi env bugs adds wasi envvar test Co-authored-by: Mark McCaskey <[email protected]>
- Loading branch information
Showing
28 changed files
with
176 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#[test] | ||
fn test_envvar() { | ||
assert_wasi_output!( | ||
"../../wasitests/envvar.wasm", | ||
"envvar", | ||
vec![], | ||
vec![], | ||
"../../wasitests/envvar.out" | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ fn test_hello() { | |
"../../wasitests/hello.wasm", | ||
"hello", | ||
vec![], | ||
vec![], | ||
"../../wasitests/hello.out" | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ fn test_mapdir() { | |
"../../wasitests/mapdir.wasm", | ||
"mapdir", | ||
vec![], | ||
vec![], | ||
"../../wasitests/mapdir.out" | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ fn test_quine() { | |
"../../wasitests/quine.wasm", | ||
"quine", | ||
vec![], | ||
vec![], | ||
"../../wasitests/quine.out" | ||
); | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Env vars: | ||
CAT=2 | ||
DOG=1 | ||
DOG Ok("1") | ||
DOG_TYPE Err(NotPresent) | ||
SET VAR Ok("HELLO") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Args: | ||
// env: DOG=1 | ||
// env: CAT=2 | ||
|
||
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()]; | ||
#[cfg(target = "wasi")] | ||
let mut env_vars = env::vars() | ||
.map(|(key, value)| format!("{}={}", key, value)) | ||
.collect::<Vec<String>>(); | ||
|
||
env_vars.sort(); | ||
|
||
println!("Env vars:"); | ||
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 not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.