nushell/crates/nu-utils/standard_library/tests.nu
Máté FARKAS d74a260883
stdlib: add test discovery, extract test files (#8443)
# Description

Was original asked here:
https://github.com/nushell/nushell/pull/8405#issuecomment-1465062652
Make it easier to extend standard library with submodules.
(For a new submodule called `xx.nu` the tests can be written in
`test_xx.nu`).
Test discovery is implemented.

# User-Facing Changes

There are no user-facing changes.

# Tests + Formatting

Tests are updated.
There is no `nufmt` now.

---------

Co-authored-by: Mate Farkas <Mate.Farkas@oneidentity.com>
2023-03-16 13:23:29 -05:00

20 lines
699 B
Plaintext

def main [] {
for test_file in (ls ($env.FILE_PWD | path join "test_*.nu") -f | get name) {
let $module_name = ($test_file | path parse).stem
echo $"(ansi default)INFO Run tests in ($module_name)(ansi reset)"
let tests = (
nu -c $'use ($test_file) *; $nu.scope.commands | to nuon'
| from nuon
| where module_name == $module_name
| where ($it.name | str starts-with "test_")
| get name
)
for test_case in $tests {
echo $"(ansi default_dimmed)DEBUG Run test ($module_name)/($test_case)(ansi reset)"
nu -c $'use ($test_file) ($test_case); ($test_case)'
}
}
}