Skip to content

Add test support crate for plugin developers - #12259

Merged
fdncred merged 7 commits into
nushell:mainfrom
devyn:plugin-test
Mar 23, 2024
Merged

fdncred merged 7 commits into
nushell:mainfrom
devyn:plugin-test

Conversation

@devyn

@devyn devyn commented Mar 22, 2024 •

Copy link
Copy Markdown
Contributor

Description

Adds a nu-plugin-test-support crate with an interface that supports testing plugins.

Unlike in reality, these plugins run in the same process on separate threads. This will allow
testing aspects of the plugin internal state and handling serialized plugin custom values easily.
We still serialize their custom values and all of the engine to plugin logic is still in play, so
from a logical perspective this should still expose any bugs that would have been caused by that.
The only difference is that it doesn't run in a different process, and doesn't try to serialize
everything to the final wire format for stdin/stdout.

TODO still:

  • Clean up warnings about private types exposed in trait definition
  • Automatically deserialize plugin custom values in the result so they can be inspected
  • Automatic plugin examples test function
  • Write a bit more documentation
  • More tests
  • Add MIT License file to new crate

User-Facing Changes

Plugin developers get a nice way to test their plugins.

Tests + Formatting

Run the tests with cargo test -p nu-plugin-test-support -- --show-output to see some examples of what the failing test output for examples can look like. I used the difference crate (MIT licensed) to make it look nice.

  • 🟢 toolkit fmt
  • 🟢 toolkit clippy
  • 🟢 toolkit test
  • 🟢 toolkit test stdlib

After Submitting

  • Add a section to the book about testing
  • Test some of the example plugins this way
  • Add example tests to nu_plugin_template so plugin developers have something to start with

@devyn
devyn marked this pull request as ready for review March 23, 2024 07:49
@devyn

devyn commented Mar 23, 2024

Copy link
Copy Markdown
Contributor Author

I think this is ready to go! @ayax79 see if you're happy with this. The basic idea for testing examples is:

#[test]
fn test_into_u32_examples() -> Result<(), ShellError> {
    // you can also pass them directly with .test_examples()
    PluginTest::new("custom_u32", CustomU32Plugin.into())?.test_command_examples(&IntoU32)
}

and yeah, it works with custom values.

There's also APIs for just directly evaluating stuff with or without input, and getting the PipelineData.

@fdncred

fdncred commented Mar 23, 2024

Copy link
Copy Markdown
Contributor

wow, this seems very cool!

@ayax79

ayax79 commented Mar 23, 2024

Copy link
Copy Markdown
Contributor

Look perfect Thanks!

@fdncred
fdncred merged commit c79c43d into nushell:main Mar 23, 2024
@fdncred

fdncred commented Mar 23, 2024

Copy link
Copy Markdown
Contributor

Thanks again @devyn!

@fdncred fdncred added deprecated:pr-plugins Deprecated: use the A:plugins label instead api-change This PR should be mentioned in #api-updates channel on Discord labels Mar 23, 2024
@devyn
devyn deleted the plugin-test branch March 23, 2024 19:27
@hustcer hustcer added this to the v0.92.0 milestone Mar 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-change This PR should be mentioned in #api-updates channel on Discord deprecated:pr-plugins Deprecated: use the A:plugins label instead

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants