nushell/crates/nu-std/tests/test_std.nu
Yethal 0bdc362e13
std: refactor test-runner to no longer require tests to be exported (#9355)
# Description
Test runner now performs following actions in order to run tests:
* Module file is opened
* Public function with random name is added to the source code, this
function calls user-specified private function
* Modified module file is saved under random name in $nu.temp-path
* Modified module file is imported in subprocess, injected function is
called by the test runner
# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->
* Test functions no longer need to be exported
* test functions no longer need to reside in separate test_ files
* setup and teardown renamed to before-each and after-each respectively
* before-all and after-all functions added that run before all tests in
given module. This matches the behavior of test runners used by other
languages such as JUnit/TestNG or Mocha
# Tests + Formatting

# After Submitting

---------

Co-authored-by: Kamil <skelly37@protonmail.com>
Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-10 20:16:17 +02:00

41 lines
1011 B
Plaintext

use std
def test_path_add [] {
use std assert
let path_name = if "PATH" in $env { "PATH" } else { "Path" }
with-env [$path_name []] {
def get_path [] { $env | get $path_name }
assert equal (get_path) []
std path add "/foo/"
assert equal (get_path) ["/foo/"]
std path add "/bar/" "/baz/"
assert equal (get_path) ["/bar/", "/baz/", "/foo/"]
let-env $path_name = []
std path add "foo"
std path add "bar" "baz" --append
assert equal (get_path) ["foo", "bar", "baz"]
assert equal (std path add "fooooo" --ret) ["fooooo", "foo", "bar", "baz"]
assert equal (get_path) ["fooooo", "foo", "bar", "baz"]
let-env $path_name = []
let target_paths = {linux: "foo", windows: "bar", macos: "baz"}
std path add $target_paths
assert equal (get_path) [($target_paths | get $nu.os-info.name)]
}
}
def test_banner [] {
std assert ((std banner | lines | length) == 15)
}