mirror of
https://github.com/nushell/nushell.git
synced 2024-12-25 08:29:07 +01:00
092d496ff5
# Description #11492 fixed flags for builtin commands but I missed that plugins don't use the same `has_flag` that builtins do. This PR addresses this. Unfortunately this means that return value of `has_flag` needs to change from `bool` to `Result<bool, ShellError>` to produce an error when explicit value is not a boolean (just like in case of `has_flag` for builtin commands. It is not possible to check this in `EvaluatedCall::try_from_call` because # User-Facing Changes Passing explicit values to flags of plugin commands (like `--flag=true` `--flag=false`) should work now. BREAKING: changed return value of `EvaluatedCall::has_flag` method from `bool` to `Result<bool, ShellError>` # Tests + Formatting Added tests and updated documentation and examples
164 lines
4.2 KiB
Rust
164 lines
4.2 KiB
Rust
use nu_test_support::fs::Stub::FileWithContent;
|
|
use nu_test_support::nu_with_plugins;
|
|
use nu_test_support::playground::Playground;
|
|
use pretty_assertions::assert_eq;
|
|
|
|
#[test]
|
|
fn chooses_highest_increment_if_given_more_than_one() {
|
|
let actual = nu_with_plugins!(
|
|
cwd: "tests/fixtures/formats",
|
|
plugin: ("nu_plugin_inc"),
|
|
"open cargo_sample.toml | inc package.version --major --minor | get package.version"
|
|
);
|
|
|
|
assert_eq!(actual.out, "1.0.0");
|
|
|
|
let actual = nu_with_plugins!(
|
|
cwd: "tests/fixtures/formats",
|
|
plugin: ("nu_plugin_inc"),
|
|
// Regardless of order of arguments
|
|
"open cargo_sample.toml | inc package.version --minor --major | get package.version"
|
|
);
|
|
|
|
assert_eq!(actual.out, "1.0.0");
|
|
}
|
|
|
|
#[test]
|
|
fn by_one_with_field_passed() {
|
|
Playground::setup("plugin_inc_test_1", |dirs, sandbox| {
|
|
sandbox.with_files(vec![FileWithContent(
|
|
"sample.toml",
|
|
r#"
|
|
[package]
|
|
edition = "2018"
|
|
"#,
|
|
)]);
|
|
|
|
let actual = nu_with_plugins!(
|
|
cwd: dirs.test(),
|
|
plugin: ("nu_plugin_inc"),
|
|
"open sample.toml | inc package.edition | get package.edition"
|
|
);
|
|
|
|
assert_eq!(actual.out, "2019");
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn by_one_with_no_field_passed() {
|
|
Playground::setup("plugin_inc_test_2", |dirs, sandbox| {
|
|
sandbox.with_files(vec![FileWithContent(
|
|
"sample.toml",
|
|
r#"
|
|
[package]
|
|
contributors = "2"
|
|
"#,
|
|
)]);
|
|
|
|
let actual = nu_with_plugins!(
|
|
cwd: dirs.test(),
|
|
plugin: ("nu_plugin_inc"),
|
|
"open sample.toml | get package.contributors | inc"
|
|
);
|
|
|
|
assert_eq!(actual.out, "3");
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn semversion_major_inc() {
|
|
Playground::setup("plugin_inc_test_3", |dirs, sandbox| {
|
|
sandbox.with_files(vec![FileWithContent(
|
|
"sample.toml",
|
|
r#"
|
|
[package]
|
|
version = "0.1.3"
|
|
"#,
|
|
)]);
|
|
|
|
let actual = nu_with_plugins!(
|
|
cwd: dirs.test(),
|
|
plugin: ("nu_plugin_inc"),
|
|
"open sample.toml | inc package.version -M | get package.version"
|
|
);
|
|
|
|
assert_eq!(actual.out, "1.0.0");
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn semversion_minor_inc() {
|
|
Playground::setup("plugin_inc_test_4", |dirs, sandbox| {
|
|
sandbox.with_files(vec![FileWithContent(
|
|
"sample.toml",
|
|
r#"
|
|
[package]
|
|
version = "0.1.3"
|
|
"#,
|
|
)]);
|
|
|
|
let actual = nu_with_plugins!(
|
|
cwd: dirs.test(),
|
|
plugin: ("nu_plugin_inc"),
|
|
"open sample.toml | inc package.version --minor | get package.version"
|
|
);
|
|
|
|
assert_eq!(actual.out, "0.2.0");
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn semversion_patch_inc() {
|
|
Playground::setup("plugin_inc_test_5", |dirs, sandbox| {
|
|
sandbox.with_files(vec![FileWithContent(
|
|
"sample.toml",
|
|
r#"
|
|
[package]
|
|
version = "0.1.3"
|
|
"#,
|
|
)]);
|
|
|
|
let actual = nu_with_plugins!(
|
|
cwd: dirs.test(),
|
|
plugin: ("nu_plugin_inc"),
|
|
"open sample.toml | inc package.version --patch | get package.version"
|
|
);
|
|
|
|
assert_eq!(actual.out, "0.1.4");
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn semversion_without_passing_field() {
|
|
Playground::setup("plugin_inc_test_6", |dirs, sandbox| {
|
|
sandbox.with_files(vec![FileWithContent(
|
|
"sample.toml",
|
|
r#"
|
|
[package]
|
|
version = "0.1.3"
|
|
"#,
|
|
)]);
|
|
|
|
let actual = nu_with_plugins!(
|
|
cwd: dirs.test(),
|
|
plugin: ("nu_plugin_inc"),
|
|
"open sample.toml | get package.version | inc --patch"
|
|
);
|
|
|
|
assert_eq!(actual.out, "0.1.4");
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn explicit_flag() {
|
|
Playground::setup("plugin_inc_test_6", |dirs, _| {
|
|
let actual = nu_with_plugins!(
|
|
cwd: dirs.test(),
|
|
plugin: ("nu_plugin_inc"),
|
|
"'0.1.2' | inc --major=false --minor=true --patch=false"
|
|
);
|
|
|
|
assert_eq!(actual.out, "0.2.0");
|
|
})
|
|
}
|