mirror of
https://github.com/nushell/nushell.git
synced 2025-05-21 02:10:47 +02:00
Add --plugins
flag to nu-std/testing.nu
(#15552)
<!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> 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 <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> None, just the additional flag. # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> - 🟢 `toolkit fmt` - 🟢 `toolkit clippy` - 🟢 `toolkit test` - 🟢 `toolkit test stdlib` (nothing broke \o/) # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
This commit is contained in:
parent
2dc5c19b71
commit
d273ce89df
@ -132,6 +132,7 @@ def show-pretty-test [indent: int = 4] {
|
|||||||
# * Modified file is removed
|
# * Modified file is removed
|
||||||
def run-test [
|
def run-test [
|
||||||
test: record
|
test: record
|
||||||
|
plugins: list<string>
|
||||||
] {
|
] {
|
||||||
let test_file_name = (random chars --length 10)
|
let test_file_name = (random chars --length 10)
|
||||||
let test_function_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)
|
| str join (char lsep)
|
||||||
| save $rendered_module_path
|
| save $rendered_module_path
|
||||||
|
|
||||||
|
let plugins = $plugins | to json -r
|
||||||
let result = (
|
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
|
| complete
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -175,6 +177,7 @@ export def ($test_function_name) [] {
|
|||||||
def run-tests-for-module [
|
def run-tests-for-module [
|
||||||
module: record<file: path name: string before-each: string after-each: string before-all: string after-all: string test: list test-skip: list>
|
module: record<file: path name: string before-each: string after-each: string before-all: string after-all: string test: list test-skip: list>
|
||||||
threads: int
|
threads: int
|
||||||
|
plugins: list<string>
|
||||||
]: nothing -> table<file: path, name: string, test: string, result: string> {
|
]: nothing -> table<file: path, name: string, test: string, result: string> {
|
||||||
let global_context = if not ($module.before-all|is-empty) {
|
let global_context = if not ($module.before-all|is-empty) {
|
||||||
log info $"Running before-all for module ($module.name)"
|
log info $"Running before-all for module ($module.name)"
|
||||||
@ -183,7 +186,7 @@ def run-tests-for-module [
|
|||||||
before-each: 'let context = {}',
|
before-each: 'let context = {}',
|
||||||
after-each: '',
|
after-each: '',
|
||||||
test: $module.before-all
|
test: $module.before-all
|
||||||
}
|
} $plugins
|
||||||
| if $in.exit_code == 0 {
|
| if $in.exit_code == 0 {
|
||||||
$in.stdout
|
$in.stdout
|
||||||
} else {
|
} else {
|
||||||
@ -233,7 +236,7 @@ def run-tests-for-module [
|
|||||||
log debug $"Global context is ($global_context)"
|
log debug $"Global context is ($global_context)"
|
||||||
|
|
||||||
$test|insert result {|x|
|
$test|insert result {|x|
|
||||||
run-test $test
|
run-test $test $plugins
|
||||||
| if $in.exit_code == 0 {
|
| if $in.exit_code == 0 {
|
||||||
'pass'
|
'pass'
|
||||||
} else {
|
} else {
|
||||||
@ -253,7 +256,7 @@ def run-tests-for-module [
|
|||||||
before-each: $"let context = ($global_context)",
|
before-each: $"let context = ($global_context)",
|
||||||
after-each: '',
|
after-each: '',
|
||||||
test: $module.after-all
|
test: $module.after-all
|
||||||
}
|
} $plugins
|
||||||
}
|
}
|
||||||
return $tests
|
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
|
--exclude-module: string, # Pattern to use to exclude test modules. Default: No modules are excluded
|
||||||
--list, # list the selected tests without running them.
|
--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
|
--threads: int@"nu-complete threads", # Amount of threads to use for parallel execution. Default: All threads are utilized
|
||||||
|
--plugins: list<string>, # Plugins to load while running tests.
|
||||||
] {
|
] {
|
||||||
let available_threads = (sys cpu | length)
|
let available_threads = (sys cpu | length)
|
||||||
|
|
||||||
@ -356,7 +360,7 @@ export def run-tests [
|
|||||||
let results = (
|
let results = (
|
||||||
$modules
|
$modules
|
||||||
| par-each --threads $threads {|module|
|
| par-each --threads $threads {|module|
|
||||||
run-tests-for-module $module $threads
|
run-tests-for-module $module $threads ($plugins | default [])
|
||||||
}
|
}
|
||||||
| flatten
|
| flatten
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user