nushell/tests/plugins/nu_plugin_nu_example.rs
Devyn Cairns fac2f43aa4
Add an example Nushell plugin written in Nushell itself (#12574)
# Description

As suggested by @fdncred.

It's neat that this is possible, but the particularly useful part of
this is that we can actually
test it because it doesn't have any external dependencies, unlike the
python plugin.

Right now this just implements exactly the same behavior as the python
plugin, but we could have it
exercise a few more things.

Also fixes a couple of bugs:

- `.nu` plugins were not run with `nu --stdin`, so they couldn't take
input.
- `register` couldn't be called if `--no-config-file` was set, because
it would error on trying to
  update the plugin file.

# User-Facing Changes

- `nu_plugin_nu_example` plugin added.
- `register` now works in `--no-config-file` mode.

# Tests + Formatting
Tests added for `nu_plugin_nu_example`.

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# After Submitting

- [ ] Add the version bump to the release script just like for python
2024-04-19 09:53:30 +03:00

27 lines
716 B
Rust

use nu_test_support::nu;
#[test]
fn register() {
let out = nu!("register crates/nu_plugin_nu_example/nu_plugin_nu_example.nu");
assert!(out.status.success());
assert!(out.out.trim().is_empty());
assert!(out.err.trim().is_empty());
}
#[test]
fn call() {
let out = nu!(r#"
register crates/nu_plugin_nu_example/nu_plugin_nu_example.nu
nu_plugin_nu_example 4242 teststring
"#);
assert!(out.status.success());
assert!(out.err.contains("name: nu_plugin_nu_example"));
assert!(out.err.contains("4242"));
assert!(out.err.contains("teststring"));
assert!(out.out.contains("one"));
assert!(out.out.contains("two"));
assert!(out.out.contains("three"));
}