mirror of
https://github.com/nushell/nushell
synced 2025-01-02 16:29:00 +00:00
6af59cb0ea
# Description this PR adds the `path add` command to `crates/nu-utils/standard_library/std.nu` - this comes from frequent questions over on the discord server, about how to add directories to the `PATH` - this is greatly inspired from the [original `path-add`](https://discord.com/channels/601130461678272522/615253963645911060/1081206660816699402) from @melMass - allows to prepend and append a variable number of directories to the `PATH` - i've added a description with an example - i've added tests in `crates/nu-utils/standard_library/tests.nu` that hopefully covers all the features # User-Facing Changes `path add` can now be used from `std.nu` # Tests + Formatting the tests pass with ```bash nu crates/nu-utils/standard_library/tests.nu ``` # After Submitting ```bash $nothing ```
70 lines
1.6 KiB
Text
70 lines
1.6 KiB
Text
use std.nu
|
|
|
|
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) }
|
|
}
|
|
|
|
def tests [] {
|
|
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)
|
|
}
|
|
|
|
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"]
|
|
}
|
|
}
|
|
|
|
def main [] {
|
|
test_assert
|
|
tests
|
|
test_path_add
|
|
}
|