2023-04-08 14:35:16 +02:00
|
|
|
use std
|
2023-03-16 19:23:29 +01:00
|
|
|
|
2023-07-02 10:41:33 +02:00
|
|
|
#[test]
|
|
|
|
def path_add [] {
|
2023-05-27 14:45:04 +02:00
|
|
|
use std assert
|
2023-03-16 19:23:29 +01:00
|
|
|
|
2023-05-18 01:55:46 +02:00
|
|
|
let path_name = if "PATH" in $env { "PATH" } else { "Path" }
|
|
|
|
|
|
|
|
with-env [$path_name []] {
|
|
|
|
def get_path [] { $env | get $path_name }
|
2023-06-10 20:16:17 +02:00
|
|
|
|
2023-05-18 01:55:46 +02:00
|
|
|
assert equal (get_path) []
|
2023-03-16 19:23:29 +01:00
|
|
|
|
|
|
|
std path add "/foo/"
|
2023-10-25 16:43:27 +02:00
|
|
|
assert equal (get_path) (["/foo/"] | path expand)
|
2023-03-16 19:23:29 +01:00
|
|
|
|
|
|
|
std path add "/bar/" "/baz/"
|
2023-10-25 16:43:27 +02:00
|
|
|
assert equal (get_path) (["/bar/", "/baz/", "/foo/"] | path expand)
|
2023-03-16 19:23:29 +01:00
|
|
|
|
2023-06-30 21:57:51 +02:00
|
|
|
load-env {$path_name: []}
|
2023-03-16 19:23:29 +01:00
|
|
|
|
|
|
|
std path add "foo"
|
|
|
|
std path add "bar" "baz" --append
|
2023-10-25 16:43:27 +02:00
|
|
|
assert equal (get_path) (["foo", "bar", "baz"] | path expand)
|
2023-03-16 19:23:29 +01:00
|
|
|
|
2023-10-25 16:43:27 +02:00
|
|
|
assert equal (std path add "fooooo" --ret) (["fooooo", "foo", "bar", "baz"] | path expand)
|
|
|
|
assert equal (get_path) (["fooooo", "foo", "bar", "baz"] | path expand)
|
2023-05-26 09:24:53 +02:00
|
|
|
|
2023-06-30 21:57:51 +02:00
|
|
|
load-env {$path_name: []}
|
Fix unit tests on Android (#10224)
# Description
* The path to the binaries for tests is slightly incorrect. It is
missing the build target when it is set with the `CARGO_BUILD_TARGET`
environment variable. For example, when `CARGO_BUILD_TARGET` is set to
`aarch64-linux-android`, the path to the `nu` binary is:
`./target/aarch64-linux-android/debug/nu`
rather than
`./target/debug/nu`
This is common on Termux since the default target that rustc detects can
cause problems on some projects, such as [python's `cryptography`
package](https://github.com/pyca/cryptography/issues/7248).
This technically isn't a problem specific to Android, but is more likely
to happen on Android due to the latter.
* Additionally, the existing variable named `NUSHELL_CARGO_TARGET` is in
fact the profile, not the build target, so this was renamed to
`NUSHELL_CARGO_PROFILE`. This change is included because without the
rename, the build system would be using `CARGO_BUILD_TARGET` for the
build target and `NUSHELL_CARGO_TARGET` for the build profile, which is
confusing.
* `std path add` tests were missing `android` test
# User-Facing Changes
For those who would like to build nushell on Termux, the unit tests will
pass now.
2023-09-05 10:17:34 +02:00
|
|
|
|
|
|
|
let target_paths = {
|
|
|
|
linux: "foo",
|
|
|
|
windows: "bar",
|
|
|
|
macos: "baz",
|
|
|
|
android: "quux",
|
|
|
|
}
|
2023-06-10 20:16:17 +02:00
|
|
|
|
2023-05-26 09:24:53 +02:00
|
|
|
std path add $target_paths
|
2023-10-25 16:43:27 +02:00
|
|
|
assert equal (get_path) ([($target_paths | get $nu.os-info.name)] | path expand)
|
|
|
|
|
|
|
|
load-env {$path_name: [$"/foo(char esep)/bar"]}
|
|
|
|
std path add "~/foo"
|
|
|
|
assert equal (get_path) (["~/foo", "/foo", "/bar"] | path expand)
|
2023-03-16 19:23:29 +01:00
|
|
|
}
|
|
|
|
}
|
2023-05-10 14:05:01 +02:00
|
|
|
|
2023-07-02 10:41:33 +02:00
|
|
|
#[test]
|
|
|
|
def banner [] {
|
2023-05-10 14:05:01 +02:00
|
|
|
std assert ((std banner | lines | length) == 15)
|
|
|
|
}
|
2023-09-12 21:59:31 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
def repeat_things [] {
|
|
|
|
std assert error { "foo" | std repeat -1 }
|
|
|
|
|
|
|
|
for x in ["foo", [1 2], {a: 1}] {
|
|
|
|
std assert equal ($x | std repeat 0) []
|
|
|
|
std assert equal ($x | std repeat 1) [$x]
|
|
|
|
std assert equal ($x | std repeat 2) [$x $x]
|
|
|
|
}
|
|
|
|
}
|