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:
Devyn Cairns
2024-03-25 19:20:35 -07:00
committed by GitHub
parent efe1c99a3b
commit 2ae4408ced
19 changed files with 139 additions and 6 deletions

View File

@ -53,6 +53,7 @@ pub fn examples() -> Vec<PluginExample> {
example: "'From: test@email.com
Subject: Welcome
To: someone@somewhere.com
Test' | from eml"
.into(),
result: Some(Value::test_record(record! {
@ -73,6 +74,7 @@ Test' | from eml"
example: "'From: test@email.com
Subject: Welcome
To: someone@somewhere.com
Test' | from eml -b 1"
.into(),
result: Some(Value::test_record(record! {
@ -164,3 +166,10 @@ fn from_eml(input: &Value, body_preview: usize, head: Span) -> Result<Value, Lab
Ok(Value::record(collected.into_iter().collect(), head))
}
#[test]
fn test_examples() -> Result<(), nu_protocol::ShellError> {
use nu_plugin_test_support::PluginTest;
PluginTest::new("formats", crate::FromCmds.into())?.test_command_examples(&FromEml)
}

View File

@ -75,8 +75,9 @@ impl SimplePluginCommand for FromIcs {
pub fn examples() -> Vec<PluginExample> {
vec![PluginExample {
example: "'BEGIN:VCALENDAR
END:VCALENDAR' | from ics"
example: "
'BEGIN:VCALENDAR
END:VCALENDAR' | from ics"
.into(),
description: "Converts ics formatted string to table".into(),
result: Some(Value::test_list(vec![Value::test_record(record! {
@ -263,3 +264,10 @@ fn params_to_value(params: Vec<(String, Vec<String>)>, span: Span) -> Value {
Value::record(row.into_iter().collect(), span)
}
#[test]
fn test_examples() -> Result<(), nu_protocol::ShellError> {
use nu_plugin_test_support::PluginTest;
PluginTest::new("formats", crate::FromCmds.into())?.test_command_examples(&FromIcs)
}

View File

@ -89,3 +89,10 @@ b=2' | from ini"
})),
}]
}
#[test]
fn test_examples() -> Result<(), nu_protocol::ShellError> {
use nu_plugin_test_support::PluginTest;
PluginTest::new("formats", crate::FromCmds.into())?.test_command_examples(&FromIni)
}

View File

@ -153,3 +153,10 @@ fn params_to_value(params: Vec<(String, Vec<String>)>, span: Span) -> Value {
Value::record(row.into_iter().collect(), span)
}
#[test]
fn test_examples() -> Result<(), nu_protocol::ShellError> {
use nu_plugin_test_support::PluginTest;
PluginTest::new("formats", crate::FromCmds.into())?.test_command_examples(&FromVcf)
}