nushell/tests/plugins/core_inc.rs

151 lines
3.9 KiB
Rust
Raw Normal View History

2019-12-17 19:54:39 +01:00
use nu_test_support::fs::Stub::FileWithContent;
use nu_test_support::nu_with_plugins;
2019-12-17 19:54:39 +01:00
use nu_test_support::playground::Playground;
use pretty_assertions::assert_eq;
2019-08-10 10:54:49 +02:00
#[test]
Restore `nu_with_plugins` test macro (#6065) * Updated nu_with_plugins to handle new nushell - Now it requires the plugin format and name to be passed in, because we can't really guess the format - It calls `register` with format and plugin path - It creates a temporary folder and in it an empty temporary plugin.nu so that the tests don't conflict with each other or with local copy of plugin.nu - Instead of passing the commands via stdin it passes them via the new --commands command line argument * Rename path to command for clarity * Enable core_inc tests Remove deprecated inc feature and replace with new plugin feature * Update core_inc tests for new nu_with_plugins syntax * Rework core_inc::can_only_apply_one The new inc plugin doesn't error if passed more than one but instead chooses the highest increment * Gate all plugin tests behind feature = "plugin" instead of one by one * Remove format!-like behavior from nu_with_plugins nu_with_plugins had format!-like behavior where it would allow calls such as this: ```rs nu_with_plugins!( cwd: "dir/", "open {} | get {}", "Cargo.toml", "package.version" ) ``` And although nifty it seems to have never been used before and the same can be achieved with a format! like so: ```rs nu_with_plugins!( cwd: "dir/", format!("open {} | get {}", "Cargo.toml", "package.version") ) ``` So I am removing it to keep the complexity of the macro in check * Add multi-plugin support to nu_with_plugins Useful for testing interactions between plugins * Alternative 1: run `cargo build` inside of tests * Handle Windows by canonicalizing paths and add .exe One VM install later and lots of learning about how command line arguments work and here we are
2022-07-22 06:14:37 +02:00
fn chooses_highest_increment_if_given_more_than_one() {
let actual = nu_with_plugins!(
2019-08-29 08:31:56 +02:00
cwd: "tests/fixtures/formats",
plugin: ("nu_plugin_inc"),
"open cargo_sample.toml | inc package.version --major --minor | get package.version"
2019-08-10 10:54:49 +02:00
);
Restore `nu_with_plugins` test macro (#6065) * Updated nu_with_plugins to handle new nushell - Now it requires the plugin format and name to be passed in, because we can't really guess the format - It calls `register` with format and plugin path - It creates a temporary folder and in it an empty temporary plugin.nu so that the tests don't conflict with each other or with local copy of plugin.nu - Instead of passing the commands via stdin it passes them via the new --commands command line argument * Rename path to command for clarity * Enable core_inc tests Remove deprecated inc feature and replace with new plugin feature * Update core_inc tests for new nu_with_plugins syntax * Rework core_inc::can_only_apply_one The new inc plugin doesn't error if passed more than one but instead chooses the highest increment * Gate all plugin tests behind feature = "plugin" instead of one by one * Remove format!-like behavior from nu_with_plugins nu_with_plugins had format!-like behavior where it would allow calls such as this: ```rs nu_with_plugins!( cwd: "dir/", "open {} | get {}", "Cargo.toml", "package.version" ) ``` And although nifty it seems to have never been used before and the same can be achieved with a format! like so: ```rs nu_with_plugins!( cwd: "dir/", format!("open {} | get {}", "Cargo.toml", "package.version") ) ``` So I am removing it to keep the complexity of the macro in check * Add multi-plugin support to nu_with_plugins Useful for testing interactions between plugins * Alternative 1: run `cargo build` inside of tests * Handle Windows by canonicalizing paths and add .exe One VM install later and lots of learning about how command line arguments work and here we are
2022-07-22 06:14:37 +02:00
assert_eq!(actual.out, "1.0.0");
let actual = nu_with_plugins!(
cwd: "tests/fixtures/formats",
plugin: ("nu_plugin_inc"),
Restore `nu_with_plugins` test macro (#6065) * Updated nu_with_plugins to handle new nushell - Now it requires the plugin format and name to be passed in, because we can't really guess the format - It calls `register` with format and plugin path - It creates a temporary folder and in it an empty temporary plugin.nu so that the tests don't conflict with each other or with local copy of plugin.nu - Instead of passing the commands via stdin it passes them via the new --commands command line argument * Rename path to command for clarity * Enable core_inc tests Remove deprecated inc feature and replace with new plugin feature * Update core_inc tests for new nu_with_plugins syntax * Rework core_inc::can_only_apply_one The new inc plugin doesn't error if passed more than one but instead chooses the highest increment * Gate all plugin tests behind feature = "plugin" instead of one by one * Remove format!-like behavior from nu_with_plugins nu_with_plugins had format!-like behavior where it would allow calls such as this: ```rs nu_with_plugins!( cwd: "dir/", "open {} | get {}", "Cargo.toml", "package.version" ) ``` And although nifty it seems to have never been used before and the same can be achieved with a format! like so: ```rs nu_with_plugins!( cwd: "dir/", format!("open {} | get {}", "Cargo.toml", "package.version") ) ``` So I am removing it to keep the complexity of the macro in check * Add multi-plugin support to nu_with_plugins Useful for testing interactions between plugins * Alternative 1: run `cargo build` inside of tests * Handle Windows by canonicalizing paths and add .exe One VM install later and lots of learning about how command line arguments work and here we are
2022-07-22 06:14:37 +02:00
// Regardless of order of arguments
"open cargo_sample.toml | inc package.version --minor --major | get package.version"
Restore `nu_with_plugins` test macro (#6065) * Updated nu_with_plugins to handle new nushell - Now it requires the plugin format and name to be passed in, because we can't really guess the format - It calls `register` with format and plugin path - It creates a temporary folder and in it an empty temporary plugin.nu so that the tests don't conflict with each other or with local copy of plugin.nu - Instead of passing the commands via stdin it passes them via the new --commands command line argument * Rename path to command for clarity * Enable core_inc tests Remove deprecated inc feature and replace with new plugin feature * Update core_inc tests for new nu_with_plugins syntax * Rework core_inc::can_only_apply_one The new inc plugin doesn't error if passed more than one but instead chooses the highest increment * Gate all plugin tests behind feature = "plugin" instead of one by one * Remove format!-like behavior from nu_with_plugins nu_with_plugins had format!-like behavior where it would allow calls such as this: ```rs nu_with_plugins!( cwd: "dir/", "open {} | get {}", "Cargo.toml", "package.version" ) ``` And although nifty it seems to have never been used before and the same can be achieved with a format! like so: ```rs nu_with_plugins!( cwd: "dir/", format!("open {} | get {}", "Cargo.toml", "package.version") ) ``` So I am removing it to keep the complexity of the macro in check * Add multi-plugin support to nu_with_plugins Useful for testing interactions between plugins * Alternative 1: run `cargo build` inside of tests * Handle Windows by canonicalizing paths and add .exe One VM install later and lots of learning about how command line arguments work and here we are
2022-07-22 06:14:37 +02:00
);
assert_eq!(actual.out, "1.0.0");
2019-08-10 10:54:49 +02:00
}
#[test]
2019-08-14 22:55:26 +02:00
fn by_one_with_field_passed() {
2019-08-29 02:32:42 +02:00
Playground::setup("plugin_inc_test_1", |dirs, sandbox| {
2019-09-11 16:36:50 +02:00
sandbox.with_files(vec![FileWithContent(
"sample.toml",
r#"
2019-08-29 02:32:42 +02:00
[package]
edition = "2018"
2019-09-11 16:36:50 +02:00
"#,
2019-08-29 02:32:42 +02:00
)]);
let actual = nu_with_plugins!(
2019-08-29 08:31:56 +02:00
cwd: dirs.test(),
plugin: ("nu_plugin_inc"),
"open sample.toml | inc package.edition | get package.edition"
2019-08-29 02:32:42 +02:00
);
assert_eq!(actual.out, "2019");
2019-08-29 02:32:42 +02:00
})
2019-08-10 10:54:49 +02:00
}
2019-08-14 22:55:26 +02:00
#[test]
fn by_one_with_no_field_passed() {
2019-08-29 02:32:42 +02:00
Playground::setup("plugin_inc_test_2", |dirs, sandbox| {
2019-09-11 16:36:50 +02:00
sandbox.with_files(vec![FileWithContent(
"sample.toml",
r#"
2019-08-29 02:32:42 +02:00
[package]
contributors = "2"
2019-09-11 16:36:50 +02:00
"#,
2019-08-29 02:32:42 +02:00
)]);
let actual = nu_with_plugins!(
2019-08-29 08:31:56 +02:00
cwd: dirs.test(),
plugin: ("nu_plugin_inc"),
"open sample.toml | get package.contributors | inc"
2019-08-29 02:32:42 +02:00
);
assert_eq!(actual.out, "3");
2019-08-29 02:32:42 +02:00
})
2019-08-14 22:55:26 +02:00
}
2019-08-10 10:54:49 +02:00
#[test]
fn semversion_major_inc() {
2019-08-29 02:32:42 +02:00
Playground::setup("plugin_inc_test_3", |dirs, sandbox| {
2019-09-11 16:36:50 +02:00
sandbox.with_files(vec![FileWithContent(
"sample.toml",
r#"
2019-08-29 02:32:42 +02:00
[package]
version = "0.1.3"
2019-09-11 16:36:50 +02:00
"#,
2019-08-29 02:32:42 +02:00
)]);
let actual = nu_with_plugins!(
2019-08-29 08:31:56 +02:00
cwd: dirs.test(),
plugin: ("nu_plugin_inc"),
"open sample.toml | inc package.version -M | get package.version"
2019-08-29 02:32:42 +02:00
);
assert_eq!(actual.out, "1.0.0");
2019-08-29 02:32:42 +02:00
})
2019-08-10 10:54:49 +02:00
}
#[test]
fn semversion_minor_inc() {
2019-08-29 02:32:42 +02:00
Playground::setup("plugin_inc_test_4", |dirs, sandbox| {
2019-09-11 16:36:50 +02:00
sandbox.with_files(vec![FileWithContent(
"sample.toml",
r#"
2019-08-29 02:32:42 +02:00
[package]
version = "0.1.3"
2019-09-11 16:36:50 +02:00
"#,
2019-08-29 02:32:42 +02:00
)]);
let actual = nu_with_plugins!(
2019-08-29 08:31:56 +02:00
cwd: dirs.test(),
plugin: ("nu_plugin_inc"),
"open sample.toml | inc package.version --minor | get package.version"
2019-08-29 02:32:42 +02:00
);
assert_eq!(actual.out, "0.2.0");
2019-08-29 02:32:42 +02:00
})
}
#[test]
fn semversion_patch_inc() {
2019-08-29 02:32:42 +02:00
Playground::setup("plugin_inc_test_5", |dirs, sandbox| {
2019-09-11 16:36:50 +02:00
sandbox.with_files(vec![FileWithContent(
"sample.toml",
r#"
2019-08-29 02:32:42 +02:00
[package]
version = "0.1.3"
2019-09-11 16:36:50 +02:00
"#,
2019-08-29 02:32:42 +02:00
)]);
let actual = nu_with_plugins!(
2019-08-29 08:31:56 +02:00
cwd: dirs.test(),
plugin: ("nu_plugin_inc"),
"open sample.toml | inc package.version --patch | get package.version"
2019-08-29 02:32:42 +02:00
);
assert_eq!(actual.out, "0.1.4");
2019-08-29 02:32:42 +02:00
})
}
#[test]
fn semversion_without_passing_field() {
2019-08-29 02:32:42 +02:00
Playground::setup("plugin_inc_test_6", |dirs, sandbox| {
2019-09-11 16:36:50 +02:00
sandbox.with_files(vec![FileWithContent(
"sample.toml",
r#"
2019-08-29 02:32:42 +02:00
[package]
version = "0.1.3"
2019-09-11 16:36:50 +02:00
"#,
2019-08-29 02:32:42 +02:00
)]);
let actual = nu_with_plugins!(
2019-08-29 08:31:56 +02:00
cwd: dirs.test(),
plugin: ("nu_plugin_inc"),
"open sample.toml | get package.version | inc --patch"
2019-08-29 02:32:42 +02:00
);
assert_eq!(actual.out, "0.1.4");
2019-08-29 02:32:42 +02:00
})
2019-08-26 20:19:05 +02:00
}