mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 14:40:06 +02:00
Add example tests (nu-plugin-test-support) for plugins in repo (#12281)
# Description Uses the new `nu-plugin-test-support` crate to test the examples of commands provided by plugins in the repo. Also fixed some of the examples to pass. # User-Facing Changes - Examples that are more guaranteed to work # Tests + Formatting - 🟢 `toolkit fmt` - 🟢 `toolkit clippy` - 🟢 `toolkit test` - 🟢 `toolkit test stdlib`
This commit is contained in:
@ -14,3 +14,6 @@ nu-plugin = { path = "../nu-plugin", version = "0.91.1" }
|
||||
nu-protocol = { path = "../nu-protocol", version = "0.91.1", features = ["plugin"] }
|
||||
serde = { workspace = true, default-features = false }
|
||||
typetag = "0.2"
|
||||
|
||||
[dev-dependencies]
|
||||
nu-plugin-test-support = { path = "../nu-plugin-test-support", version = "0.91.1" }
|
||||
|
@ -29,3 +29,11 @@ impl SimplePluginCommand for Generate {
|
||||
Ok(CoolCustomValue::new("abc").into_value(call.head))
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_examples() -> Result<(), nu_protocol::ShellError> {
|
||||
use nu_plugin_test_support::PluginTest;
|
||||
|
||||
PluginTest::new("custom_values", crate::CustomValuePlugin.into())?
|
||||
.test_command_examples(&Generate)
|
||||
}
|
||||
|
@ -54,3 +54,11 @@ impl SimplePluginCommand for Generate2 {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_examples() -> Result<(), nu_protocol::ShellError> {
|
||||
use nu_plugin_test_support::PluginTest;
|
||||
|
||||
PluginTest::new("custom_values", crate::CustomValuePlugin.into())?
|
||||
.test_command_examples(&Generate2)
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
use std::cmp::Ordering;
|
||||
|
||||
use nu_protocol::{CustomValue, ShellError, Span, Value};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct SecondCustomValue {
|
||||
pub(crate) something: String,
|
||||
}
|
||||
@ -59,6 +61,16 @@ impl CustomValue for SecondCustomValue {
|
||||
))
|
||||
}
|
||||
|
||||
fn partial_cmp(&self, other: &Value) -> Option<Ordering> {
|
||||
if let Value::CustomValue { val, .. } = other {
|
||||
val.as_any()
|
||||
.downcast_ref()
|
||||
.and_then(|other: &SecondCustomValue| PartialOrd::partial_cmp(self, other))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &dyn std::any::Any {
|
||||
self
|
||||
}
|
||||
|
@ -23,9 +23,9 @@ impl SimplePluginCommand for Update {
|
||||
result: Some(CoolCustomValue::new("abcxyz").into_value(Span::test_data())),
|
||||
},
|
||||
PluginExample {
|
||||
example: "custom-value generate | custom-value update".into(),
|
||||
example: "custom-value generate2 | custom-value update".into(),
|
||||
description: "Update a SecondCustomValue".into(),
|
||||
result: Some(CoolCustomValue::new("xyzabc").into_value(Span::test_data())),
|
||||
result: Some(SecondCustomValue::new("xyzabc").into_value(Span::test_data())),
|
||||
},
|
||||
])
|
||||
}
|
||||
@ -56,3 +56,11 @@ impl SimplePluginCommand for Update {
|
||||
.into())
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_examples() -> Result<(), nu_protocol::ShellError> {
|
||||
use nu_plugin_test_support::PluginTest;
|
||||
|
||||
PluginTest::new("custom_values", crate::CustomValuePlugin.into())?
|
||||
.test_command_examples(&Update)
|
||||
}
|
||||
|
Reference in New Issue
Block a user