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

@ -51,3 +51,9 @@ impl PluginCommand for CollectExternal {
})
}
}
#[test]
fn test_examples() -> Result<(), nu_protocol::ShellError> {
use nu_plugin_test_support::PluginTest;
PluginTest::new("example", Example.into())?.test_command_examples(&CollectExternal)
}

View File

@ -45,3 +45,9 @@ impl PluginCommand for ForEach {
Ok(PipelineData::Empty)
}
}
#[test]
fn test_examples() -> Result<(), nu_protocol::ShellError> {
use nu_plugin_test_support::PluginTest;
PluginTest::new("example", Example.into())?.test_command_examples(&ForEach)
}

View File

@ -76,3 +76,12 @@ impl PluginCommand for Generate {
.into_pipeline_data(None))
}
}
#[test]
fn test_examples() -> Result<(), nu_protocol::ShellError> {
use nu_cmd_lang::If;
use nu_plugin_test_support::PluginTest;
PluginTest::new("example", Example.into())?
.add_decl(Box::new(If))?
.test_command_examples(&Generate)
}

View File

@ -41,3 +41,9 @@ impl SimplePluginCommand for One {
Ok(Value::nothing(call.head))
}
}
#[test]
fn test_examples() -> Result<(), nu_protocol::ShellError> {
use nu_plugin_test_support::PluginTest;
PluginTest::new("example", Example.into())?.test_command_examples(&One)
}

View File

@ -46,3 +46,9 @@ impl PluginCommand for Seq {
Ok(PipelineData::ListStream(list_stream, None))
}
}
#[test]
fn test_examples() -> Result<(), nu_protocol::ShellError> {
use nu_plugin_test_support::PluginTest;
PluginTest::new("example", Example.into())?.test_command_examples(&Seq)
}

View File

@ -20,7 +20,7 @@ impl PluginCommand for Sum {
(Type::List(Type::Float.into()), Type::Float),
])
.plugin_examples(vec![PluginExample {
example: "seq 1 5 | example sum".into(),
example: "example seq 1 5 | example sum".into(),
description: "sum values from 1 to 5".into(),
result: Some(Value::test_int(15)),
}])
@ -88,3 +88,9 @@ impl IntOrFloat {
}
}
}
#[test]
fn test_examples() -> Result<(), nu_protocol::ShellError> {
use nu_plugin_test_support::PluginTest;
PluginTest::new("example", Example.into())?.test_command_examples(&Sum)
}