From d273ce89df3e801c4d8afbc99af11a71451478c5 Mon Sep 17 00:00:00 2001 From: Piepmatz Date: Wed, 16 Apr 2025 23:20:04 +0200 Subject: [PATCH] Add `--plugins` flag to `nu-std/testing.nu` (#15552) # Description In this PR I added the flag `--plugins` to the `testing.nu` file inside of `crates/nu-std`. This allows running tests with active plugins. While I did not use it here in this repo, it allows testing in [nushell/plugin-examples](https://github.com/nushell/plugin-examples) with plugins. # User-Facing Changes None, just the additional flag. # Tests + Formatting - :green_circle: `toolkit fmt` - :green_circle: `toolkit clippy` - :green_circle: `toolkit test` - :green_circle: `toolkit test stdlib` (nothing broke \o/) # After Submitting --- crates/nu-std/testing.nu | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/crates/nu-std/testing.nu b/crates/nu-std/testing.nu index b8ee4b3329..92aa5c1d52 100644 --- a/crates/nu-std/testing.nu +++ b/crates/nu-std/testing.nu @@ -132,6 +132,7 @@ def show-pretty-test [indent: int = 4] { # * Modified file is removed def run-test [ test: record + plugins: list ] { let test_file_name = (random chars --length 10) let test_function_name = (random chars --length 10) @@ -155,8 +156,9 @@ export def ($test_function_name) [] { | str join (char lsep) | save $rendered_module_path + let plugins = $plugins | to json -r let result = ( - ^$nu.current-exe --no-config-file -c $"use ($rendered_module_path) *; ($test_function_name)|to nuon" + ^$nu.current-exe --no-config-file --plugins $plugins -c $"use ($rendered_module_path) *; ($test_function_name)|to nuon" | complete ) @@ -175,6 +177,7 @@ export def ($test_function_name) [] { def run-tests-for-module [ module: record threads: int + plugins: list ]: nothing -> table { let global_context = if not ($module.before-all|is-empty) { log info $"Running before-all for module ($module.name)" @@ -183,7 +186,7 @@ def run-tests-for-module [ before-each: 'let context = {}', after-each: '', test: $module.before-all - } + } $plugins | if $in.exit_code == 0 { $in.stdout } else { @@ -233,7 +236,7 @@ def run-tests-for-module [ log debug $"Global context is ($global_context)" $test|insert result {|x| - run-test $test + run-test $test $plugins | if $in.exit_code == 0 { 'pass' } else { @@ -253,7 +256,7 @@ def run-tests-for-module [ before-each: $"let context = ($global_context)", after-each: '', test: $module.after-all - } + } $plugins } return $tests } @@ -278,6 +281,7 @@ export def run-tests [ --exclude-module: string, # Pattern to use to exclude test modules. Default: No modules are excluded --list, # list the selected tests without running them. --threads: int@"nu-complete threads", # Amount of threads to use for parallel execution. Default: All threads are utilized + --plugins: list, # Plugins to load while running tests. ] { let available_threads = (sys cpu | length) @@ -356,7 +360,7 @@ export def run-tests [ let results = ( $modules | par-each --threads $threads {|module| - run-tests-for-module $module $threads + run-tests-for-module $module $threads ($plugins | default []) } | flatten )