Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Bats assertion libraries #1534

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ repository
.vagrant
keyrings
/tmp
/node_modules
27 changes: 27 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "asdf",
"private": true,
"devDependencies": {
"@hyperupcall/bats-all": "^5.1.1"
}
}
26 changes: 13 additions & 13 deletions test/asdf_elvish.bats
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ cleaned_path() {
use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
echo \$E:ASDF_DIR"

[ "$status" -eq 0 ]
[ "$output" = "$HOME/.asdf" ]
assert_success
assert_output -- "$HOME/.asdf"
}

@test "retains ASDF_DIR" {
Expand All @@ -44,8 +44,8 @@ cleaned_path() {
use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
echo \$E:ASDF_DIR"

[ "$status" -eq 0 ]
[ "$output" = "/path/to/asdf" ]
assert_success
assert_output "/path/to/asdf"
}

@test "retains ASDF_DATA_DIR" {
Expand All @@ -55,8 +55,8 @@ cleaned_path() {
use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
echo \$E:ASDF_DATA_DIR"

[ "$status" -eq 0 ]
[ "$output" = "/path/to/asdf-data" ]
assert_success
assert_output "/path/to/asdf-data"
}

@test "adds asdf dirs to PATH" {
Expand All @@ -66,7 +66,7 @@ cleaned_path() {
use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
echo \$E:PATH"

[ "$status" -eq 0 ]
assert_success

result=$(echo "$output" | grep "asdf")
[ "$result" != "" ]
Expand All @@ -79,8 +79,8 @@ cleaned_path() {
use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
pprint \$_asdf:"

[ "$status" -eq 0 ]
[[ "$output" =~ "<ns " ]]
assert_success
assert_output -p "<ns "
}

@test "does not add paths to PATH more than once" {
Expand All @@ -92,7 +92,7 @@ cleaned_path() {
use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
echo \$E:PATH"

[ "$status" -eq 0 ]
assert_success

result=$(echo "$result" | tr ':' '\n' | grep "asdf" | sort | uniq -d)
[ "$result" = "" ]
Expand All @@ -105,8 +105,8 @@ cleaned_path() {
use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
pprint \$asdf~"

[ "$status" -eq 0 ]
[[ "$output" =~ "<closure " ]]
assert_success
assert_output -p "<closure "
}

@test "function calls asdf command" {
Expand All @@ -116,7 +116,7 @@ cleaned_path() {
use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
asdf info"

[ "$status" -eq 0 ]
assert_success

result=$(echo "$output" | grep "ASDF INSTALLED PLUGINS:")
[ "$result" != "" ]
Expand Down
14 changes: 7 additions & 7 deletions test/asdf_fish.bats
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ cleaned_path() {
. asdf.fish
echo \$ASDF_DIR"

[ "$status" -eq 0 ]
[ "$output" != "" ]
assert_success
refute_output ''
}

@test "adds asdf dirs to PATH" {
Expand All @@ -39,7 +39,7 @@ cleaned_path() {
. (pwd)/asdf.fish # if the full path is not passed, status -f will return the relative path
echo \$PATH"

[ "$status" -eq 0 ]
assert_success

result=$(echo "$output" | grep "asdf")
[ "$result" != "" ]
Expand All @@ -56,7 +56,7 @@ cleaned_path() {
. asdf.fish
echo \$PATH"

[ "$status" -eq 0 ]
assert_success

result=$(echo "$output" | tr ' ' '\n' | grep "asdf" | sort | uniq -d)
[ "$result" = "" ]
Expand All @@ -71,8 +71,8 @@ cleaned_path() {
. asdf.fish
type asdf"

[ "$status" -eq 0 ]
[[ "$output" =~ "is a function" ]]
assert_success
assert_line "asdf is a function with definition"
}

@test "function calls asdf command" {
Expand All @@ -84,7 +84,7 @@ cleaned_path() {
. asdf.fish
asdf info"

[ "$status" -eq 0 ]
assert_success

result=$(echo "$output" | grep "ASDF INSTALLED PLUGINS:")
[ "$result" != "" ]
Expand Down
36 changes: 18 additions & 18 deletions test/asdf_nu.bats
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,26 @@ run_nushell() {
@test "exports ASDF_DIR" {
run_nushell "echo \$env.ASDF_DIR"

[ "$status" -eq 0 ]
assert_success
result=$(echo "$output" | grep "asdf")
[ "$result" = "$PWD" ]
}

@test "adds asdf dirs to PATH" {
run_nushell "\$env.PATH | to text"

[ "$status" -eq 0 ]
assert_success

[[ "$output" == *"$PWD/bin"* ]]
[[ "$output" == *"$HOME/.asdf/shims"* ]]
assert_output -p "$PWD/bin"
assert_output -p "$HOME/.asdf/shims"
}

@test "does not add paths to PATH more than once" {
run_nushell "
source asdf.nu
echo \$env.PATH"

[ "$status" -eq 0 ]
assert_success

result=$(echo "$output" | tr ' ' '\n' | grep "asdf" | sort | uniq -d)
[ "$result" = "" ]
Expand All @@ -71,20 +71,20 @@ run_nushell() {

echo \$env.ASDF_DIR"

[ "$status" -eq 0 ]
[ "$output" = "$PWD" ]
assert_success
assert_output -- "$PWD"
}

@test "defines the asdf or main function" {
run_nushell "which asdf | get path | to text"

[ "$status" -eq 0 ]
assert_success
}

@test "function calls asdf command" {
run_nushell "asdf info"

[ "$status" -eq 0 ]
assert_success

result=$(echo "$output" | grep "ASDF INSTALLED PLUGINS:")
[ "$result" != "" ]
Expand All @@ -95,8 +95,8 @@ run_nushell() {
install_dummy_plugin
run_nushell "asdf plugin list | to csv -n"

[ "$status" -eq 0 ]
[ "$output" = "dummy" ]
assert_success
assert_output "dummy"
}

@test "parses the output of asdf plugin list --urls" {
Expand All @@ -106,12 +106,12 @@ run_nushell() {

run_nushell "asdf plugin list --urls | to csv -n"

[ "$status" -eq 0 ]
assert_success

local repo_url
repo_url=$(get_plugin_remote_url "dummy")

[ "$output" = "dummy,$repo_url" ]
assert_output "dummy,$repo_url"
}

@test "parses the output of asdf plugin list --refs" {
Expand All @@ -121,13 +121,13 @@ run_nushell() {

run_nushell "asdf plugin list --refs | to csv -n"

[ "$status" -eq 0 ]
assert_success

local branch gitref
branch=$(get_plugin_remote_branch "dummy")
gitref=$(get_plugin_remote_gitref "dummy")

[ "$output" = "dummy,$branch,$gitref" ]
assert_output "dummy,$branch,$gitref"
}

@test "parses the output of asdf plugin list --urls --refs" {
Expand All @@ -137,22 +137,22 @@ run_nushell() {

run_nushell "asdf plugin list --urls --refs | to csv -n"

[ "$status" -eq 0 ]
assert_success

local repo_url branch gitref
repo_url=$(get_plugin_remote_url "dummy")
branch=$(get_plugin_remote_branch "dummy")
gitref=$(get_plugin_remote_gitref "dummy")

[ "$output" = "dummy,$repo_url,$branch,$gitref" ]
assert_output "dummy,$repo_url,$branch,$gitref"
}

@test "parses the output of asdf plugin list all" {
setup_repo
install_dummy_plugin
run_nushell "asdf plugin list all | to csv -n"

[ "$status" -eq 0 ]
assert_success
[ "$output" = "\
bar,false,http://example.com/bar
dummy,true,http://example.com/dummy
Expand Down
14 changes: 7 additions & 7 deletions test/asdf_pwsh.bats
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ cleaned_path() {
. ./asdf.ps1
Write-Output \"\$env:ASDF_DIR\""

[ "$status" -eq 0 ]
[ "$output" != "" ]
assert_success
refute_output ''
}

@test "adds asdf dirs to PATH" {
Expand All @@ -41,7 +41,7 @@ cleaned_path() {
. ./asdf.ps1
Write-Output \$Env:PATH"

[ "$status" -eq 0 ]
assert_success
result=$(echo "$output" | grep "asdf")
[ "$result" != "" ]
}
Expand All @@ -58,7 +58,7 @@ cleaned_path() {
. ./asdf.ps1
Write-Output \$Env:PATH"

[ "$status" -eq 0 ]
assert_success

result=$(echo "$output" | tr ' ' '\n' | grep "asdf" | sort | uniq -d)
[ "$result" = "" ]
Expand All @@ -75,8 +75,8 @@ cleaned_path() {
./ asdf.ps1
\$(Get-Command -CommandType asdf).Name"

[ "$status" -eq 0 ]
[[ "$output" =~ "asdf" ]]
assert_success
assert_output -p "asdf"
}

@test "function calls asdf command" {
Expand All @@ -90,7 +90,7 @@ cleaned_path() {
. ./asdf.ps1
asdf info"

[ "$status" -eq 0 ]
assert_success
result=$(echo "$output" | grep "ASDF INSTALLED PLUGINS:")
[ "$result" != "" ]
}
6 changes: 3 additions & 3 deletions test/asdf_sh.bats
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ cleaned_path() {
}

@test "defines the asdf function" {
output=$(
result=$(
unset -f asdf
unset ASDF_DIR
PATH=$(cleaned_path)
Expand All @@ -79,7 +79,7 @@ cleaned_path() {
type asdf
)

[[ "$output" =~ "is a function" ]]
[[ "$result" == "asdf is a function"* ]]
}

@test "function calls asdf command" {
Expand All @@ -93,5 +93,5 @@ cleaned_path() {
)

output=$(echo "$result" | grep "ASDF INSTALLED PLUGINS:")
[ "$output" != "" ]
refute_output ''
}
4 changes: 2 additions & 2 deletions test/banned_commands.bats
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ teardown() {
fi

[ "$status" -eq 1 ]
[ "" = "$output" ]
assert_output ''
done

for cmd in "${banned_commands_regex[@]}"; do
Expand All @@ -96,6 +96,6 @@ teardown() {
fi

[ "$status" -eq 1 ]
[ "" = "$output" ]
assert_output ''
done
}
Loading