nushell/crates/nu-utils/standard_library/test_std.nu
Antoine Stevan 14bf0b000e
standard library: fix the tests for the new closure parsing of 0.77.2 (#8504)
# Description
as closures now need to have explicit parameters, this PR adds the empty
`||` to the two closure of the `std match` test.

# User-Facing Changes
```
$nothing
```

# Tests + Formatting
```
nu crates/nu-utils/standard_library/tests.nu
```
does not give the following anymore
```
Error: nu::parser::closure_missing_pipe

  × Missing || inside closure
    ╭─[/home/amtoine/.local/share/git/store/github.com/amtoine/nushell/crates/nu-utils/standard_library/test_std.nu:29:1]
 29 │     let branches = {
 30 │         1: { -1 }
    ·            ───┬──
    ·               ╰── Parsing as a closure, but || is missing
 31 │         2: { -2 }
    ╰────
  help: Try add || to the beginning of closure

Error: nu:🐚:only_supports_this_input_type

  × Input type not supported.
    ╭─[/home/amtoine/.local/share/git/store/github.com/amtoine/nushell/crates/nu-utils/standard_library/tests.nu:7:1]
  7 │             nu -c $'use ($test_file) *; $nu.scope.commands | to nuon'
  8 │             | from nuon
    ·               ────┬────
    ·                   ╰── input type: nothing
  9 │             | where module_name == $module_name
    ·               ──┬──
    ·                 ╰── only list, binary, raw data or range input data is supported
 10 │             | where ($it.name | str starts-with "test_")
    ╰────
```

# After Submitting
```
$nothing
```
2023-03-18 08:52:08 +13:00

65 lines
1.5 KiB
Plaintext

use std.nu
export def test_assert [] {
def test_failing [code: closure] {
let code_did_run = (try { do $code; true } catch { false })
if $code_did_run {
error make {msg: (view source $code)}
}
}
std assert true
std assert (1 + 2 == 3)
test_failing { std assert false }
test_failing { std assert (1 + 2 == 4) }
std assert eq (1 + 2) 3
test_failing { std assert eq 1 "foo" }
test_failing { std assert eq (1 + 2) 4) }
std assert ne (1 + 2) 4
test_failing { std assert ne 1 "foo" }
test_failing { std assert ne (1 + 2) 3) }
}
export def test_match [] {
use std.nu assert
let branches = {
1: {|| -1 }
2: {|| -2 }
}
assert ((std match 1 $branches) == -1)
assert ((std match 2 $branches) == -2)
assert ((std match 3 $branches) == $nothing)
assert ((std match 1 $branches { 0 }) == -1)
assert ((std match 2 $branches { 0 }) == -2)
assert ((std match 3 $branches { 0 }) == 0)
}
export def test_path_add [] {
use std.nu "assert eq"
with-env [PATH []] {
assert eq $env.PATH []
std path add "/foo/"
assert eq $env.PATH ["/foo/"]
std path add "/bar/" "/baz/"
assert eq $env.PATH ["/bar/", "/baz/", "/foo/"]
let-env PATH = []
std path add "foo"
std path add "bar" "baz" --append
assert eq $env.PATH ["foo", "bar", "baz"]
assert eq (std path add "fooooo" --ret) ["fooooo", "foo", "bar", "baz"]
assert eq $env.PATH ["fooooo", "foo", "bar", "baz"]
}
}