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

View File

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

View File

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