chore: Fix ShellCheck errors in tests (#1451)

This commit is contained in:
Edwin Kofler 2023-01-24 05:15:23 -08:00 committed by GitHub
parent 28b348a041
commit 720fd17200
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 127 additions and 124 deletions

View File

@ -22,96 +22,97 @@ cleaned_path() {
}
@test "exports ASDF_DIR" {
output=$(elvish -norc -c "
run elvish -norc -c "
unset-env ASDF_DIR
set paths = [$(cleaned_path)]
use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
echo \$E:ASDF_DIR
")
[ "$?" -eq 0 ]
echo \$E:ASDF_DIR"
[ "$status" -eq 0 ]
[ "$output" = "$HOME/.asdf" ]
}
@test "retains ASDF_DIR" {
output=$(elvish -norc -c "
set-env ASDF_DIR "/path/to/asdf"
run elvish -norc -c "
set-env ASDF_DIR \"/path/to/asdf\"
set paths = [$(cleaned_path)]
use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
echo \$E:ASDF_DIR
")
[ "$?" -eq 0 ]
echo \$E:ASDF_DIR"
[ "$status" -eq 0 ]
[ "$output" = "/path/to/asdf" ]
}
@test "retains ASDF_DATA_DIR" {
output=$(elvish -norc -c "
set-env ASDF_DATA_DIR "/path/to/asdf-data"
run elvish -norc -c "
set-env ASDF_DATA_DIR \"/path/to/asdf-data\"
set paths = [$(cleaned_path)]
use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
echo \$E:ASDF_DATA_DIR
")
[ "$?" -eq 0 ]
echo \$E:ASDF_DATA_DIR"
[ "$status" -eq 0 ]
[ "$output" = "/path/to/asdf-data" ]
}
@test "adds asdf dirs to PATH" {
result=$(elvish -norc -c "
run elvish -norc -c "
unset-env ASDF_DIR
set paths = [$(cleaned_path)]
use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
echo \$E:PATH
")
[ "$?" -eq 0 ]
echo "$result"
output=$(echo "$result" | grep "asdf")
[ "$output" != "" ]
echo \$E:PATH"
[ "$status" -eq 0 ]
result=$(echo "$output" | grep "asdf")
[ "$result" != "" ]
}
@test "defines the _asdf namespace" {
output=$(elvish -norc -c "
run elvish -norc -c "
unset-env ASDF_DIR
set paths = [$(cleaned_path)]
use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
pprint \$_asdf:
")
[ "$?" -eq 0 ]
pprint \$_asdf:"
[ "$status" -eq 0 ]
[[ "$output" =~ "<ns " ]]
}
@test "does not add paths to PATH more than once" {
result=$(elvish -norc -c "
run elvish -norc -c "
unset-env ASDF_DIR
set paths = [$(cleaned_path)]
use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
echo \$E:PATH
")
[ "$?" -eq 0 ]
output=$(echo $result | tr ':' '\n' | grep "asdf" | sort | uniq -d)
[ "$output" = "" ]
echo \$E:PATH"
[ "$status" -eq 0 ]
result=$(echo "$result" | tr ':' '\n' | grep "asdf" | sort | uniq -d)
[ "$result" = "" ]
}
@test "defines the asdf function" {
output=$(elvish -norc -c "
run elvish -norc -c "
unset-env ASDF_DIR
set paths = [$(cleaned_path)]
use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
pprint \$asdf~
")
[ "$?" -eq 0 ]
echo "$output"
pprint \$asdf~"
[ "$status" -eq 0 ]
[[ "$output" =~ "<closure " ]]
}
@test "function calls asdf command" {
result=$(elvish -norc -c "
run elvish -norc -c "
set-env ASDF_DIR $(pwd) # checkstyle-ignore
set paths = [$(cleaned_path)]
use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
asdf info
")
[ "$?" -eq 0 ]
output=$(echo "$result" | grep "ASDF INSTALLED PLUGINS:")
[ "$output" != "" ]
asdf info"
[ "$status" -eq 0 ]
result=$(echo "$output" | grep "ASDF INSTALLED PLUGINS:")
[ "$result" != "" ]
}

View File

@ -3,7 +3,7 @@
load test_helpers
setup() {
cd $(dirname "$BATS_TEST_DIRNAME")
cd "$(dirname "$BATS_TEST_DIRNAME")"
}
cleaned_path() {
@ -11,36 +11,37 @@ cleaned_path() {
}
@test "exports ASDF_DIR" {
output=$(fish -c "
run fish -c "
set -e asdf
set -e ASDF_DIR
set -e ASDF_DATA_DIR
set PATH $(cleaned_path)
. asdf.fish
echo \$ASDF_DIR
")
[ "$?" -eq 0 ]
echo \$ASDF_DIR"
[ "$status" -eq 0 ]
[ "$output" != "" ]
}
@test "adds asdf dirs to PATH" {
result=$(fish -c "
run fish -c "
set -e asdf
set -e ASDF_DIR
set -e ASDF_DATA_DIR
set PATH $(cleaned_path)
. (pwd)/asdf.fish # if the full path is not passed, status -f will return the relative path
echo \$PATH
")
[ "$?" -eq 0 ]
output=$(echo "$result" | grep "asdf")
[ "$output" != "" ]
echo \$PATH"
[ "$status" -eq 0 ]
result=$(echo "$output" | grep "asdf")
[ "$result" != "" ]
}
@test "does not add paths to PATH more than once" {
result=$(fish -c "
run fish -c "
set -e asdf
set -e ASDF_DIR
set -e ASDF_DATA_DIR
@ -48,36 +49,38 @@ cleaned_path() {
. asdf.fish
. asdf.fish
echo \$PATH
")
[ "$?" -eq 0 ]
output=$(echo $result | tr ' ' '\n' | grep "asdf" | sort | uniq -d)
[ "$output" = "" ]
echo \$PATH"
[ "$status" -eq 0 ]
result=$(echo "$output" | tr ' ' '\n' | grep "asdf" | sort | uniq -d)
[ "$result" = "" ]
}
@test "defines the asdf function" {
output=$(fish -c "
run fish -c "
set -e asdf
set -e ASDF_DIR
set PATH $(cleaned_path)
. asdf.fish
type asdf
")
[ "$?" -eq 0 ]
type asdf"
[ "$status" -eq 0 ]
[[ "$output" =~ "is a function" ]]
}
@test "function calls asdf command" {
result=$(fish -c "
run fish -c "
set -e asdf
set -x ASDF_DIR $(pwd) # checkstyle-ignore
set PATH $(cleaned_path)
. asdf.fish
asdf info
")
[ "$?" -eq 0 ]
output=$(echo "$result" | grep "ASDF INSTALLED PLUGINS:")
[ "$output" != "" ]
asdf info"
[ "$status" -eq 0 ]
result=$(echo "$output" | grep "ASDF INSTALLED PLUGINS:")
[ "$result" != "" ]
}

View File

@ -3,7 +3,7 @@
load test_helpers
setup() {
cd $(dirname "$BATS_TEST_DIRNAME")
cd "$(dirname "$BATS_TEST_DIRNAME")"
if ! command -v nu; then
skip "Nu is not installed"
@ -15,7 +15,7 @@ cleaned_path() {
}
@test "exports ASDF_DIR" {
result=$(nu -c "
run nu -c "
hide-env -i asdf
hide-env -i ASDF_DIR
let-env PATH = ( '$(cleaned_path)' | split row ':' )
@ -23,16 +23,16 @@ cleaned_path() {
source asdf.nu
echo \$env.ASDF_DIR
")
echo \$env.ASDF_DIR"
[ "$?" -eq 0 ]
output=$(echo "$result" | grep "asdf")
[ "$output" = $PWD ]
[ "$status" -eq 0 ]
result=$(echo "$output" | grep "asdf")
[ "$result" = "$PWD" ]
}
@test "adds asdf dirs to PATH" {
result=$(nu -c "
run nu -c "
hide-env -i asdf
hide-env -i ASDF_DIR
let-env PATH = ( '$(cleaned_path)' | split row ':' )
@ -41,17 +41,19 @@ cleaned_path() {
source asdf.nu
\$env.PATH | to text
")
[ "$?" -eq 0 ]
output_bin=$(echo "$result" | grep "asdf/bin")
\$env.PATH | to text"
[ "$status" -eq 0 ]
output_bin=$(echo "$output" | grep "asdf/bin")
[ "$output_bin" = "$PWD/bin" ]
output_shims=$(echo "$result" | grep "/shims")
output_shims=$(echo "$output" | grep "/shims")
[ "$output_shims" = "$HOME/.asdf/shims" ]
}
@test "does not add paths to PATH more than once" {
result=$(nu -c "
run nu -c "
hide-env -i asdf
hide-env -i ASDF_DIR
let-env PATH = ( '$(cleaned_path)' | split row ':' )
@ -60,15 +62,16 @@ cleaned_path() {
source asdf.nu
source asdf.nu
echo \$env.PATH
")
[ "$?" -eq 0 ]
output=$(echo $result | tr ' ' '\n' | grep "asdf" | sort | uniq -d)
[ "$output" = "" ]
echo \$env.PATH"
[ "$status" -eq 0 ]
result=$(echo "$output" | tr ' ' '\n' | grep "asdf" | sort | uniq -d)
[ "$result" = "" ]
}
@test "retains ASDF_DIR" {
output=$(nu -c "
run nu -c "
hide-env -i asdf
let-env ASDF_DIR = ( pwd )
let-env PATH = ( '$(cleaned_path)' | split row ':' )
@ -76,38 +79,38 @@ cleaned_path() {
source asdf.nu
echo \$env.ASDF_DIR
")
echo \$env.ASDF_DIR"
[ "$?" -eq 0 ]
[ "$status" -eq 0 ]
[ "$output" = "$PWD" ]
}
@test "defines the asdf function" {
output=$(nu -c "
run nu -c "
hide-env -i asdf
hide-env -i ASDF_DIR
let-env PATH = ( '$(cleaned_path)' | split row ':' )
let-env ASDF_NU_DIR = '$PWD'
source asdf.nu
which asdf | get path | to text
")
[ "$?" -eq 0 ]
which asdf | get path | to text"
[ "$status" -eq 0 ]
[[ "$output" =~ "command" ]]
}
@test "function calls asdf command" {
result=$(nu -c "
run nu -c "
hide-env -i asdf
hide-env -i ASDF_DIR
let-env PATH = ( '$(cleaned_path)' | split row ':' )
let-env ASDF_NU_DIR = '$PWD'
source asdf.nu
asdf info
")
[ "$?" -eq 0 ]
output=$(echo "$result" | grep "ASDF INSTALLED PLUGINS:")
[ "$output" != "" ]
asdf info"
[ "$status" -eq 0 ]
result=$(echo "$output" | grep "ASDF INSTALLED PLUGINS:")
[ "$result" != "" ]
}

View File

@ -4,7 +4,7 @@ load test_helpers
# Helper function to handle sourcing of asdf.sh
source_asdf_sh() {
. $(dirname "$BATS_TEST_DIRNAME")/asdf.sh
. "$(dirname "$BATS_TEST_DIRNAME")/asdf.sh"
}
cleaned_path() {
@ -12,65 +12,61 @@ cleaned_path() {
}
@test "exports ASDF_DIR" {
result=$(
output=$(
unset -f asdf
unset ASDF_DIR
PATH=$(cleaned_path)
source_asdf_sh
echo $ASDF_DIR
echo "$ASDF_DIR"
)
output=$(echo "$result" | grep "asdf")
[ "$?" -eq 0 ]
[ "$output" != "" ]
result=$(echo "$output" | grep "asdf")
[ "$result" != "" ]
}
@test "does not error if nounset is enabled" {
result=$(
output=$(
unset -f asdf
unset ASDF_DIR
PATH=$(cleaned_path)
set -o nounset
source_asdf_sh
echo $ASDF_DIR
echo "$ASDF_DIR"
)
output=$(echo "$result" | grep "asdf")
[ "$?" -eq 0 ]
[ "$output" != "" ]
result=$(echo "$output" | grep "asdf")
[ "$result" != "" ]
}
@test "adds asdf dirs to PATH" {
result=$(
output=$(
unset -f asdf
unset ASDF_DIR
PATH=$(cleaned_path)
source_asdf_sh
echo $PATH
echo "$PATH"
)
output=$(echo "$result" | grep "asdf")
[ "$?" -eq 0 ]
[ "$output" != "" ]
result=$(echo "$output" | grep "asdf")
[ "$result" != "" ]
}
@test "does not add paths to PATH more than once" {
result=$(
output=$(
unset -f asdf
unset ASDF_DIR
PATH=$(cleaned_path)
source_asdf_sh
source_asdf_sh
echo $PATH
echo "$PATH"
)
output=$(echo $result | tr ':' '\n' | grep "asdf" | sort | uniq -d)
[ "$?" -eq 0 ]
[ "$output" = "" ]
result=$(echo "$output" | tr ':' '\n' | grep "asdf" | sort | uniq -d)
[ "$result" = "" ]
}
@test "defines the asdf function" {
@ -95,7 +91,7 @@ cleaned_path() {
source_asdf_sh
asdf info
)
[ "$?" -eq 0 ]
output=$(echo "$result" | grep "ASDF INSTALLED PLUGINS:")
[ "$output" != "" ]
}