2023-01-04 13:42:34 -07:00
|
|
|
#!/usr/bin/env bats
|
2023-01-25 06:37:21 -07:00
|
|
|
# shellcheck disable=SC2164
|
2023-01-04 13:42:34 -07:00
|
|
|
|
|
|
|
load test_helpers
|
|
|
|
|
|
|
|
setup() {
|
2023-01-24 06:15:23 -07:00
|
|
|
cd "$(dirname "$BATS_TEST_DIRNAME")"
|
2023-01-06 07:43:15 -07:00
|
|
|
|
|
|
|
if ! command -v nu; then
|
|
|
|
skip "Nu is not installed"
|
|
|
|
fi
|
2023-01-04 13:42:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
cleaned_path() {
|
2023-01-22 16:36:47 -07:00
|
|
|
echo "$PATH" | tr ':' '\n' | grep -v "asdf" | tr '\n' ':'
|
2023-01-04 13:42:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "exports ASDF_DIR" {
|
2023-01-24 06:15:23 -07:00
|
|
|
run nu -c "
|
2023-01-04 13:42:34 -07:00
|
|
|
hide-env -i asdf
|
|
|
|
hide-env -i ASDF_DIR
|
|
|
|
let-env PATH = ( '$(cleaned_path)' | split row ':' )
|
|
|
|
let-env ASDF_NU_DIR = '$PWD'
|
|
|
|
|
2023-01-06 07:43:15 -07:00
|
|
|
source asdf.nu
|
2023-01-04 13:42:34 -07:00
|
|
|
|
2023-01-24 06:15:23 -07:00
|
|
|
echo \$env.ASDF_DIR"
|
2023-01-04 13:42:34 -07:00
|
|
|
|
2023-01-24 06:15:23 -07:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
result=$(echo "$output" | grep "asdf")
|
|
|
|
[ "$result" = "$PWD" ]
|
2023-01-04 13:42:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "adds asdf dirs to PATH" {
|
2023-01-24 06:15:23 -07:00
|
|
|
run nu -c "
|
2023-01-04 13:42:34 -07:00
|
|
|
hide-env -i asdf
|
|
|
|
hide-env -i ASDF_DIR
|
|
|
|
let-env PATH = ( '$(cleaned_path)' | split row ':' )
|
|
|
|
let-env ASDF_NU_DIR = '$PWD'
|
|
|
|
|
2023-01-06 07:43:15 -07:00
|
|
|
source asdf.nu
|
|
|
|
|
2023-01-04 13:42:34 -07:00
|
|
|
|
2023-01-24 06:15:23 -07:00
|
|
|
\$env.PATH | to text"
|
|
|
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
output_bin=$(echo "$output" | grep "asdf/bin")
|
2023-01-14 06:18:44 -07:00
|
|
|
[ "$output_bin" = "$PWD/bin" ]
|
2023-01-24 06:15:23 -07:00
|
|
|
|
|
|
|
output_shims=$(echo "$output" | grep "/shims")
|
2023-01-14 06:18:44 -07:00
|
|
|
[ "$output_shims" = "$HOME/.asdf/shims" ]
|
2023-01-04 13:42:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "does not add paths to PATH more than once" {
|
2023-01-24 06:15:23 -07:00
|
|
|
run nu -c "
|
2023-01-04 13:42:34 -07:00
|
|
|
hide-env -i asdf
|
|
|
|
hide-env -i ASDF_DIR
|
|
|
|
let-env PATH = ( '$(cleaned_path)' | split row ':' )
|
|
|
|
let-env ASDF_NU_DIR = '$PWD'
|
|
|
|
|
2023-01-06 07:43:15 -07:00
|
|
|
source asdf.nu
|
|
|
|
source asdf.nu
|
2023-01-04 13:42:34 -07:00
|
|
|
|
2023-01-24 06:15:23 -07:00
|
|
|
echo \$env.PATH"
|
|
|
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
result=$(echo "$output" | tr ' ' '\n' | grep "asdf" | sort | uniq -d)
|
|
|
|
[ "$result" = "" ]
|
2023-01-04 13:42:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "retains ASDF_DIR" {
|
2023-01-24 06:15:23 -07:00
|
|
|
run nu -c "
|
2023-01-04 13:42:34 -07:00
|
|
|
hide-env -i asdf
|
|
|
|
let-env ASDF_DIR = ( pwd )
|
|
|
|
let-env PATH = ( '$(cleaned_path)' | split row ':' )
|
|
|
|
let-env ASDF_NU_DIR = '$PWD'
|
|
|
|
|
2023-01-06 07:43:15 -07:00
|
|
|
source asdf.nu
|
2023-01-04 13:42:34 -07:00
|
|
|
|
2023-01-24 06:15:23 -07:00
|
|
|
echo \$env.ASDF_DIR"
|
2023-01-04 13:42:34 -07:00
|
|
|
|
2023-01-24 06:15:23 -07:00
|
|
|
[ "$status" -eq 0 ]
|
2023-01-04 13:42:34 -07:00
|
|
|
[ "$output" = "$PWD" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "defines the asdf function" {
|
2023-01-24 06:15:23 -07:00
|
|
|
run nu -c "
|
2023-01-04 13:42:34 -07:00
|
|
|
hide-env -i asdf
|
|
|
|
hide-env -i ASDF_DIR
|
|
|
|
let-env PATH = ( '$(cleaned_path)' | split row ':' )
|
|
|
|
let-env ASDF_NU_DIR = '$PWD'
|
|
|
|
|
2023-01-06 07:43:15 -07:00
|
|
|
source asdf.nu
|
2023-01-24 06:15:23 -07:00
|
|
|
which asdf | get path | to text"
|
|
|
|
|
|
|
|
[ "$status" -eq 0 ]
|
2023-01-04 13:42:34 -07:00
|
|
|
[[ "$output" =~ "command" ]]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "function calls asdf command" {
|
2023-01-24 06:15:23 -07:00
|
|
|
run nu -c "
|
2023-01-04 13:42:34 -07:00
|
|
|
hide-env -i asdf
|
|
|
|
hide-env -i ASDF_DIR
|
|
|
|
let-env PATH = ( '$(cleaned_path)' | split row ':' )
|
|
|
|
let-env ASDF_NU_DIR = '$PWD'
|
|
|
|
|
2023-01-06 07:43:15 -07:00
|
|
|
source asdf.nu
|
2023-01-24 06:15:23 -07:00
|
|
|
asdf info"
|
|
|
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
result=$(echo "$output" | grep "ASDF INSTALLED PLUGINS:")
|
|
|
|
[ "$result" != "" ]
|
2023-01-04 13:42:34 -07:00
|
|
|
}
|