2024-03-12 12:34:32 +01:00
|
|
|
use nu_test_support::nu_with_plugins;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn get_env_by_name() {
|
|
|
|
let result = nu_with_plugins!(
|
|
|
|
cwd: ".",
|
|
|
|
plugin: ("nu_plugin_example"),
|
|
|
|
r#"
|
2024-07-31 01:55:22 +02:00
|
|
|
$env.FOO = 'bar'
|
2024-03-19 18:36:46 +01:00
|
|
|
example env FOO | print
|
2024-07-31 01:55:22 +02:00
|
|
|
$env.FOO = 'baz'
|
2024-03-19 18:36:46 +01:00
|
|
|
example env FOO | print
|
2024-03-12 12:34:32 +01:00
|
|
|
"#
|
|
|
|
);
|
|
|
|
assert!(result.status.success());
|
|
|
|
assert_eq!("barbaz", result.out);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn get_envs() {
|
|
|
|
let result = nu_with_plugins!(
|
|
|
|
cwd: ".",
|
|
|
|
plugin: ("nu_plugin_example"),
|
2024-07-31 01:55:22 +02:00
|
|
|
"$env.BAZ = 'foo'; example env | get BAZ"
|
2024-03-12 12:34:32 +01:00
|
|
|
);
|
|
|
|
assert!(result.status.success());
|
|
|
|
assert_eq!("foo", result.out);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn get_current_dir() {
|
|
|
|
let cwd = std::env::current_dir()
|
|
|
|
.expect("failed to get current dir")
|
|
|
|
.join("tests")
|
|
|
|
.to_string_lossy()
|
|
|
|
.into_owned();
|
|
|
|
let result = nu_with_plugins!(
|
|
|
|
cwd: ".",
|
|
|
|
plugin: ("nu_plugin_example"),
|
2024-03-19 18:36:46 +01:00
|
|
|
"cd tests; example env --cwd"
|
2024-03-12 12:34:32 +01:00
|
|
|
);
|
|
|
|
assert!(result.status.success());
|
|
|
|
assert_eq!(cwd, result.out);
|
|
|
|
}
|
2024-03-15 12:45:45 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn set_env() {
|
|
|
|
let result = nu_with_plugins!(
|
|
|
|
cwd: ".",
|
|
|
|
plugin: ("nu_plugin_example"),
|
2024-03-19 18:36:46 +01:00
|
|
|
"example env NUSHELL_OPINION --set=rocks; $env.NUSHELL_OPINION"
|
2024-03-15 12:45:45 +01:00
|
|
|
);
|
|
|
|
assert!(result.status.success());
|
|
|
|
assert_eq!("rocks", result.out);
|
|
|
|
}
|