MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / specify_env

Function specify_env

tests/all/cli_tests.rs:461–511  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

459
460#[test]
461fn specify_env() -> Result<()> {
462 // By default no env is inherited
463 let output = get_wasmtime_command()?
464 .args(&["run", "tests/all/cli_tests/print_env.wat"])
465 .env("THIS_WILL_NOT", "show up in the output")
466 .output()?;
467 assert!(output.status.success());
468 assert_eq!(String::from_utf8_lossy(&output.stdout), "");
469
470 // Specify a single env var
471 let output = get_wasmtime_command()?
472 .args(&[
473 "run",
474 "--env",
475 "FOO=bar",
476 "tests/all/cli_tests/print_env.wat",
477 ])
478 .output()?;
479 assert!(output.status.success());
480 assert_eq!(String::from_utf8_lossy(&output.stdout), "FOO=bar\n");
481
482 // Inherit a single env var
483 let output = get_wasmtime_command()?
484 .args(&["run", "--env", "FOO", "tests/all/cli_tests/print_env.wat"])
485 .env("FOO", "bar")
486 .output()?;
487 assert!(output.status.success());
488 assert_eq!(String::from_utf8_lossy(&output.stdout), "FOO=bar\n");
489
490 // Inherit a nonexistent env var
491 let output = get_wasmtime_command()?
492 .args(&[
493 "run",
494 "--env",
495 "SURELY_THIS_ENV_VAR_DOES_NOT_EXIST_ANYWHERE_RIGHT",
496 "tests/all/cli_tests/print_env.wat",
497 ])
498 .output()?;
499 assert!(output.status.success());
500
501 // Inherit all env vars
502 let output = get_wasmtime_command()?
503 .args(&["run", "-Sinherit-env", "tests/all/cli_tests/print_env.wat"])
504 .env("FOO", "bar")
505 .output()?;
506 assert!(output.status.success());
507 let stdout = String::from_utf8_lossy(&output.stdout);
508 assert!(stdout.contains("FOO=bar"), "bad output: {stdout}");
509
510 Ok(())
511}
512
513#[cfg(unix)]
514#[test]

Callers

nothing calls this directly

Calls 5

get_wasmtime_commandFunction · 0.85
OkFunction · 0.85
outputMethod · 0.80
envMethod · 0.45
argsMethod · 0.45

Tested by

no test coverage detected