2022-07-25 18:32:56 +02:00
|
|
|
use nu_test_support::nu_with_plugins;
|
2023-04-08 20:52:37 +02:00
|
|
|
use pretty_assertions::assert_eq;
|
2022-07-25 18:32:56 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn can_get_custom_value_from_plugin_and_instantly_collapse_it() {
|
|
|
|
let actual = nu_with_plugins!(
|
|
|
|
cwd: "tests",
|
2022-09-07 16:07:42 +02:00
|
|
|
plugin: ("nu_plugin_custom_values"),
|
2022-07-25 18:32:56 +02:00
|
|
|
"custom-value generate"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "I used to be a custom value! My data was (abc)");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn can_get_custom_value_from_plugin_and_pass_it_over() {
|
|
|
|
let actual = nu_with_plugins!(
|
|
|
|
cwd: "tests",
|
2022-09-07 16:07:42 +02:00
|
|
|
plugin: ("nu_plugin_custom_values"),
|
2022-07-25 18:32:56 +02:00
|
|
|
"custom-value generate | custom-value update"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
actual.out,
|
|
|
|
"I used to be a custom value! My data was (abcxyz)"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-02-25 23:32:50 +01:00
|
|
|
#[test]
|
|
|
|
fn can_get_custom_value_from_plugin_and_pass_it_over_as_an_argument() {
|
|
|
|
let actual = nu_with_plugins!(
|
|
|
|
cwd: "tests",
|
|
|
|
plugin: ("nu_plugin_custom_values"),
|
|
|
|
"custom-value update-arg (custom-value generate)"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
actual.out,
|
|
|
|
"I used to be a custom value! My data was (abcxyz)"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-07-25 18:32:56 +02:00
|
|
|
#[test]
|
|
|
|
fn can_generate_and_updated_multiple_types_of_custom_values() {
|
|
|
|
let actual = nu_with_plugins!(
|
|
|
|
cwd: "tests",
|
2022-09-07 16:07:42 +02:00
|
|
|
plugin: ("nu_plugin_custom_values"),
|
2022-07-25 18:32:56 +02:00
|
|
|
"custom-value generate2 | custom-value update"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
actual.out,
|
|
|
|
"I used to be a DIFFERENT custom value! (xyzabc)"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn can_get_describe_plugin_custom_values() {
|
|
|
|
let actual = nu_with_plugins!(
|
|
|
|
cwd: "tests",
|
2022-09-07 16:07:42 +02:00
|
|
|
plugin: ("nu_plugin_custom_values"),
|
2022-07-25 18:32:56 +02:00
|
|
|
"custom-value generate | describe"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "CoolCustomValue");
|
|
|
|
}
|
|
|
|
|
|
|
|
// There are currently no custom values defined by the engine that aren't hidden behind an extra
|
|
|
|
// feature, both database and dataframes are hidden behind --features=extra so we need to guard
|
|
|
|
// this test
|
2022-11-23 01:58:11 +01:00
|
|
|
#[cfg(feature = "sqlite")]
|
2022-07-25 18:32:56 +02:00
|
|
|
#[test]
|
|
|
|
fn fails_if_passing_engine_custom_values_to_plugins() {
|
|
|
|
let actual = nu_with_plugins!(
|
|
|
|
cwd: "tests/fixtures/formats",
|
2022-09-07 16:07:42 +02:00
|
|
|
plugin: ("nu_plugin_custom_values"),
|
2022-11-09 23:14:48 +01:00
|
|
|
"open sample.db | custom-value update"
|
2022-07-25 18:32:56 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
assert!(actual
|
|
|
|
.err
|
2024-02-25 23:32:50 +01:00
|
|
|
.contains("`SQLiteDatabase` cannot be sent to plugin"));
|
|
|
|
assert!(actual
|
|
|
|
.err
|
|
|
|
.contains("the `custom_values` plugin does not support this kind of value"));
|
2022-07-25 18:32:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fails_if_passing_custom_values_across_plugins() {
|
|
|
|
let actual = nu_with_plugins!(
|
|
|
|
cwd: "tests",
|
|
|
|
plugins: [
|
2022-09-07 16:07:42 +02:00
|
|
|
("nu_plugin_custom_values"),
|
|
|
|
("nu_plugin_inc")
|
2022-07-25 18:32:56 +02:00
|
|
|
],
|
|
|
|
"custom-value generate | inc --major"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert!(actual
|
|
|
|
.err
|
2024-02-25 23:32:50 +01:00
|
|
|
.contains("`CoolCustomValue` cannot be sent to plugin"));
|
|
|
|
assert!(actual
|
|
|
|
.err
|
|
|
|
.contains("the `inc` plugin does not support this kind of value"));
|
2022-07-25 18:32:56 +02:00
|
|
|
}
|