Skip to content

stdlib: optimize test search and add better errors#8626

Merged
fdncred merged 7 commits intonushell:mainfrom
amtoine:feature/stdlib/add-completion-and-better-errors
Mar 26, 2023
Merged

stdlib: optimize test search and add better errors#8626
fdncred merged 7 commits intonushell:mainfrom
amtoine:feature/stdlib/add-completion-and-better-errors

Conversation

@amtoine
Copy link
Copy Markdown
Member

@amtoine amtoine commented Mar 26, 2023

the first part of this PR comes from a request from @presidento in #8525.
the second one is an improvement of the error support.

Description

this PR

  • computes module_search_pattern to only ls the selected modules => the goal is to save search time in the future with more tests
  • gives better errors when
    • the --path is invalid
    • the --module does not exist
    • the search is too strict

examples

>_ nu crates/nu-utils/standard_library/tests.nu --path does-not-exist
Error: 
  × directory_not_found
   ╭─[<commandline>:1:1]
 1 │ main --path does-not-exist
   ·             ───────┬──────
   ·                    ╰── no such directory
   ╰────
>_ nu crates/nu-utils/standard_library/tests.nu --module does-not-exist
Error: 
  × module_not_found
   ╭─[<commandline>:1:1]
 1 │ main --module does-not-exist
   ·               ───────┬──────
   ·                      ╰── no such module in /home/amtoine/.local/share/git/store/github.com/amtoine/nushell/crates/nu-utils/standard_library/
   ╰────
>_ nu crates/nu-utils/standard_library/tests.nu --command does_not_exist
Error: 
  × no test to run

instead of the previous

>_ nu crates/nu-utils/standard_library/tests.nu --path does-not-exist
Error: 
  × No matches found for /home/amtoine/.local/share/git/store/github.com/amtoine/nushell/does-not-exist/test_*.nu
    ╭─[/home/amtoine/.local/share/git/store/github.com/amtoine/nushell/crates/nu-utils/standard_library/tests.nu:32:1]
 32 │     let tests = (
 33 │         ls ($path | default $env.FILE_PWD | path join "test_*.nu")
    ·            ───────────────────────────┬───────────────────────────
    ·                                       ╰── Pattern, file or folder not found
 34 │         | each {|row| {file: $row.name name: ($row.name | path parse | get stem)}}
    ╰────
  help: no matches found
>_ nu crates/nu-utils/standard_library/tests.nu --module does-not-exist
Error: 
  × expected table from pipeline
    ╭─[/home/amtoine/.local/share/git/store/github.com/amtoine/nushell/crates/nu-utils/standard_library/tests.nu:59:1]
 59 │         $tests_to_run
 60 │         | group-by module
    ·           ────┬───
    ·               ╰── requires a table input
 61 │         | transpose name tests
    ╰────
>_ nu crates/nu-utils/standard_library/tests.nu --command does-not-exist
Error: 
  × expected table from pipeline
    ╭─[/home/amtoine/.local/share/git/store/github.com/amtoine/nushell/crates/nu-utils/standard_library/tests.nu:59:1]
 59 │         $tests_to_run
 60 │         | group-by module
    ·           ────┬───
    ·               ╰── requires a table input
 61 │         | transpose name tests
    ╰────

User-Facing Changes

$nothing

Tests + Formatting

$nothing

After Submitting

$nothing

@fdncred fdncred added the A:std-library Defining and improving the standard library written in Nu label Mar 26, 2023
@fdncred fdncred merged commit 332f119 into nushell:main Mar 26, 2023
@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Mar 26, 2023

Thanks

@amtoine amtoine deleted the feature/stdlib/add-completion-and-better-errors branch March 26, 2023 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:std-library Defining and improving the standard library written in Nu

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants