2019-12-17 18:54:39 +00:00
|
|
|
use nu_test_support::fs::Stub::FileWithContent;
|
2020-09-14 14:07:02 +00:00
|
|
|
use nu_test_support::nu_with_plugins;
|
2019-12-17 18:54:39 +00:00
|
|
|
use nu_test_support::playground::Playground;
|
2019-08-10 08:54:49 +00:00
|
|
|
|
|
|
|
#[test]
|
2022-07-22 04:14:37 +00:00
|
|
|
fn chooses_highest_increment_if_given_more_than_one() {
|
2020-09-14 14:07:02 +00:00
|
|
|
let actual = nu_with_plugins!(
|
2019-08-29 06:31:56 +00:00
|
|
|
cwd: "tests/fixtures/formats",
|
2022-09-07 14:07:42 +00:00
|
|
|
plugin: ("nu_plugin_inc"),
|
2022-07-22 04:14:37 +00:00
|
|
|
"open cargo_sample.toml | first 1 | inc package.version --major --minor | get package.version"
|
2019-08-10 08:54:49 +00:00
|
|
|
);
|
|
|
|
|
2022-07-22 04:14:37 +00:00
|
|
|
assert_eq!(actual.out, "1.0.0");
|
|
|
|
|
|
|
|
let actual = nu_with_plugins!(
|
|
|
|
cwd: "tests/fixtures/formats",
|
2022-09-07 14:07:42 +00:00
|
|
|
plugin: ("nu_plugin_inc"),
|
2022-07-22 04:14:37 +00:00
|
|
|
// Regardless of order of arguments
|
|
|
|
"open cargo_sample.toml | first 1 | inc package.version --minor --major | get package.version"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "1.0.0");
|
2019-08-10 08:54:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-08-14 20:55:26 +00:00
|
|
|
fn by_one_with_field_passed() {
|
2019-08-29 00:32:42 +00:00
|
|
|
Playground::setup("plugin_inc_test_1", |dirs, sandbox| {
|
2019-09-11 14:36:50 +00:00
|
|
|
sandbox.with_files(vec![FileWithContent(
|
|
|
|
"sample.toml",
|
|
|
|
r#"
|
2019-08-29 00:32:42 +00:00
|
|
|
[package]
|
|
|
|
edition = "2018"
|
2019-09-11 14:36:50 +00:00
|
|
|
"#,
|
2019-08-29 00:32:42 +00:00
|
|
|
)]);
|
|
|
|
|
2020-09-14 14:07:02 +00:00
|
|
|
let actual = nu_with_plugins!(
|
2019-08-29 06:31:56 +00:00
|
|
|
cwd: dirs.test(),
|
2022-09-07 14:07:42 +00:00
|
|
|
plugin: ("nu_plugin_inc"),
|
2020-10-26 06:55:52 +00:00
|
|
|
"open sample.toml | inc package.edition | get package.edition"
|
2019-08-29 00:32:42 +00:00
|
|
|
);
|
|
|
|
|
2020-05-07 11:03:43 +00:00
|
|
|
assert_eq!(actual.out, "2019");
|
2019-08-29 00:32:42 +00:00
|
|
|
})
|
2019-08-10 08:54:49 +00:00
|
|
|
}
|
|
|
|
|
2019-08-14 20:55:26 +00:00
|
|
|
#[test]
|
|
|
|
fn by_one_with_no_field_passed() {
|
2019-08-29 00:32:42 +00:00
|
|
|
Playground::setup("plugin_inc_test_2", |dirs, sandbox| {
|
2019-09-11 14:36:50 +00:00
|
|
|
sandbox.with_files(vec![FileWithContent(
|
|
|
|
"sample.toml",
|
|
|
|
r#"
|
2019-08-29 00:32:42 +00:00
|
|
|
[package]
|
|
|
|
contributors = "2"
|
2019-09-11 14:36:50 +00:00
|
|
|
"#,
|
2019-08-29 00:32:42 +00:00
|
|
|
)]);
|
|
|
|
|
2020-09-14 14:07:02 +00:00
|
|
|
let actual = nu_with_plugins!(
|
2019-08-29 06:31:56 +00:00
|
|
|
cwd: dirs.test(),
|
2022-09-07 14:07:42 +00:00
|
|
|
plugin: ("nu_plugin_inc"),
|
2020-10-26 06:55:52 +00:00
|
|
|
"open sample.toml | get package.contributors | inc"
|
2019-08-29 00:32:42 +00:00
|
|
|
);
|
|
|
|
|
2020-05-07 11:03:43 +00:00
|
|
|
assert_eq!(actual.out, "3");
|
2019-08-29 00:32:42 +00:00
|
|
|
})
|
2019-08-14 20:55:26 +00:00
|
|
|
}
|
|
|
|
|
2019-08-10 08:54:49 +00:00
|
|
|
#[test]
|
2019-08-10 11:04:13 +00:00
|
|
|
fn semversion_major_inc() {
|
2019-08-29 00:32:42 +00:00
|
|
|
Playground::setup("plugin_inc_test_3", |dirs, sandbox| {
|
2019-09-11 14:36:50 +00:00
|
|
|
sandbox.with_files(vec![FileWithContent(
|
|
|
|
"sample.toml",
|
|
|
|
r#"
|
2019-08-29 00:32:42 +00:00
|
|
|
[package]
|
|
|
|
version = "0.1.3"
|
2019-09-11 14:36:50 +00:00
|
|
|
"#,
|
2019-08-29 00:32:42 +00:00
|
|
|
)]);
|
|
|
|
|
2020-09-14 14:07:02 +00:00
|
|
|
let actual = nu_with_plugins!(
|
2019-08-29 06:31:56 +00:00
|
|
|
cwd: dirs.test(),
|
2022-09-07 14:07:42 +00:00
|
|
|
plugin: ("nu_plugin_inc"),
|
2020-10-26 06:55:52 +00:00
|
|
|
"open sample.toml | inc package.version -M | get package.version"
|
2019-08-29 00:32:42 +00:00
|
|
|
);
|
|
|
|
|
2020-05-07 11:03:43 +00:00
|
|
|
assert_eq!(actual.out, "1.0.0");
|
2019-08-29 00:32:42 +00:00
|
|
|
})
|
2019-08-10 08:54:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-08-10 11:04:13 +00:00
|
|
|
fn semversion_minor_inc() {
|
2019-08-29 00:32:42 +00:00
|
|
|
Playground::setup("plugin_inc_test_4", |dirs, sandbox| {
|
2019-09-11 14:36:50 +00:00
|
|
|
sandbox.with_files(vec![FileWithContent(
|
|
|
|
"sample.toml",
|
|
|
|
r#"
|
2019-08-29 00:32:42 +00:00
|
|
|
[package]
|
|
|
|
version = "0.1.3"
|
2019-09-11 14:36:50 +00:00
|
|
|
"#,
|
2019-08-29 00:32:42 +00:00
|
|
|
)]);
|
|
|
|
|
2020-09-14 14:07:02 +00:00
|
|
|
let actual = nu_with_plugins!(
|
2019-08-29 06:31:56 +00:00
|
|
|
cwd: dirs.test(),
|
2022-09-07 14:07:42 +00:00
|
|
|
plugin: ("nu_plugin_inc"),
|
2020-10-26 06:55:52 +00:00
|
|
|
"open sample.toml | inc package.version --minor | get package.version"
|
2019-08-29 00:32:42 +00:00
|
|
|
);
|
|
|
|
|
2020-05-07 11:03:43 +00:00
|
|
|
assert_eq!(actual.out, "0.2.0");
|
2019-08-29 00:32:42 +00:00
|
|
|
})
|
2019-08-10 11:04:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn semversion_patch_inc() {
|
2019-08-29 00:32:42 +00:00
|
|
|
Playground::setup("plugin_inc_test_5", |dirs, sandbox| {
|
2019-09-11 14:36:50 +00:00
|
|
|
sandbox.with_files(vec![FileWithContent(
|
|
|
|
"sample.toml",
|
|
|
|
r#"
|
2019-08-29 00:32:42 +00:00
|
|
|
[package]
|
|
|
|
version = "0.1.3"
|
2019-09-11 14:36:50 +00:00
|
|
|
"#,
|
2019-08-29 00:32:42 +00:00
|
|
|
)]);
|
|
|
|
|
2020-09-14 14:07:02 +00:00
|
|
|
let actual = nu_with_plugins!(
|
2019-08-29 06:31:56 +00:00
|
|
|
cwd: dirs.test(),
|
2022-09-07 14:07:42 +00:00
|
|
|
plugin: ("nu_plugin_inc"),
|
2020-10-26 06:55:52 +00:00
|
|
|
"open sample.toml | inc package.version --patch | get package.version"
|
2019-08-29 00:32:42 +00:00
|
|
|
);
|
|
|
|
|
2020-05-07 11:03:43 +00:00
|
|
|
assert_eq!(actual.out, "0.1.4");
|
2019-08-29 00:32:42 +00:00
|
|
|
})
|
2019-08-10 11:04:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn semversion_without_passing_field() {
|
2019-08-29 00:32:42 +00:00
|
|
|
Playground::setup("plugin_inc_test_6", |dirs, sandbox| {
|
2019-09-11 14:36:50 +00:00
|
|
|
sandbox.with_files(vec![FileWithContent(
|
|
|
|
"sample.toml",
|
|
|
|
r#"
|
2019-08-29 00:32:42 +00:00
|
|
|
[package]
|
|
|
|
version = "0.1.3"
|
2019-09-11 14:36:50 +00:00
|
|
|
"#,
|
2019-08-29 00:32:42 +00:00
|
|
|
)]);
|
|
|
|
|
2020-09-14 14:07:02 +00:00
|
|
|
let actual = nu_with_plugins!(
|
2019-08-29 06:31:56 +00:00
|
|
|
cwd: dirs.test(),
|
2022-09-07 14:07:42 +00:00
|
|
|
plugin: ("nu_plugin_inc"),
|
2020-10-26 06:55:52 +00:00
|
|
|
"open sample.toml | get package.version | inc --patch"
|
2019-08-29 00:32:42 +00:00
|
|
|
);
|
|
|
|
|
2020-05-07 11:03:43 +00:00
|
|
|
assert_eq!(actual.out, "0.1.4");
|
2019-08-29 00:32:42 +00:00
|
|
|
})
|
2019-08-26 18:19:05 +00:00
|
|
|
}
|