Adding base tests for all scripts (#44)

This commit is contained in:
Alex Epstein 2017-07-09 02:02:30 -04:00 committed by GitHub
parent a5f3f076ec
commit 1901224d86
15 changed files with 353 additions and 2 deletions

9
.travis.yml Normal file
View File

@ -0,0 +1,9 @@
language: bash
before_install:
- sudo ./install.sh all
- sudo add-apt-repository ppa:duggan/bats --yes
- sudo apt-get update -qq
- sudo apt-get install -qq bats
- sudo apt-get install -qq vlc
script:
- bats tests

View File

@ -229,8 +229,10 @@ elif [[ $1 == "help" || $1 == ":help" ]];then ## shows the help and prevents the
else
if [[ $arg1 != $arg2 ]];then ## if they equal each other that means there was no arg 2 supplied
getCheatSheet $arg1 $arg2
exit 0
else
getCheatSheet $arg1
exit 0
fi
exit 0

View File

@ -61,7 +61,7 @@ usage() {
# Displays version number
version() {
echo $currentVersion;
echo "Version $currentVersion";
}
# Fetches WAN ip address

44
tests/cheat.bats Executable file
View File

@ -0,0 +1,44 @@
#!/bin/env bats
@test "Testing cheat tool" {
echo cheat
}
@test "Check for latest version of bash-snippets on update" {
run cheat update
[ "$status" -eq 0 ]
[ "$output" = "Bash-Snippets is already the latest version" ]
}
@test "No arguments prints usage instructions" {
run cheat
[ "$status" -eq 0 ]
[ "${lines[0]}" = "Cheat" ]
}
@test "The -h option should print usage" {
run cheat -h
[ "$status" -eq 0 ]
[ "${lines[0]}" = "Cheat" ]
}
@test "Grabbing information on a programming language (rust)" {
run cheat rust
[ "$status" -eq 0 ]
result=$( echo $(cheat rust) | grep -Eo "Rust is a systems" )
[ "$result" = "Rust is a systems" ]
}
@test "Testing unkown topic due to misspelling" {
result=$( echo $(cheat go operators) | grep -Eo "Unknown" )
[ "$result" = "Unknown" ]
}
@test "Get the tools version with -v" {
run cheat -v
[ "$status" -eq 0 ]
result=$( echo $(cheat -v) | grep -Eo "Version")
[ "$result" = "Version" ]
}

24
tests/cloudup.bats Executable file
View File

@ -0,0 +1,24 @@
#!/bin/env bats
@test "Testing cloudup tool" {
echo cloudup
}
@test "Check for latest version of bash-snippets on update" {
run cloudup update
[ "$status" -eq 0 ]
[ "$output" = "Bash-Snippets is already the latest version" ]
}
@test "The -h option should print usage" {
run cloudup -h
[ "$status" -eq 0 ]
[ "${lines[0]}" = "Cloudup" ]
}
@test "Get the tools version with -v" {
run cloudup -v
[ "$status" -eq 0 ]
result=$( echo $(cloudup -v) | grep -Eo "Version")
[ "$result" = "Version" ]
}

24
tests/currency.bats Executable file
View File

@ -0,0 +1,24 @@
#!/bin/env bats
@test "Testing currency tool" {
echo currency
}
@test "Check for latest version of bash-snippets on update" {
run currency update
[ "$status" -eq 0 ]
[ "$output" = "Bash-Snippets is already the latest version" ]
}
@test "The -h option should print usage" {
run currency -h
[ "$status" -eq 0 ]
[ "${lines[0]}" = "Currency" ]
}
@test "Get the tools version with -v" {
run currency -v
[ "$status" -eq 0 ]
result=$( echo $(currency -v) | grep -Eo "Version")
[ "$result" = "Version" ]
}

24
tests/geo.bats Executable file
View File

@ -0,0 +1,24 @@
#!/bin/env bats
@test "Testing geo tool" {
echo geo
}
@test "Check for latest version of bash-snippets on update" {
run geo update
[ "$status" -eq 0 ]
[ "$output" = "Bash-Snippets is already the latest version" ]
}
@test "The -h option should print usage" {
run geo -h
[ "$status" -eq 0 ]
[ "${lines[0]}" = "Geo" ]
}
@test "Get the tools version with -v" {
run geo -v
[ "$status" -eq 0 ]
result=$( echo $(geo -v) | grep -Eo "Version")
[ "$result" = "Version" ]
}

39
tests/movies.bats Executable file
View File

@ -0,0 +1,39 @@
#!/bin/env bats
@test "Testing movies tool" {
echo movies
}
@test "Check for latest version of bash-snippets on update" {
run movies update
[ "$status" -eq 0 ]
[ "$output" = "Bash-Snippets is already the latest version" ]
}
@test "The -h option should print usage" {
run movies -h
[ "$status" -eq 0 ]
[ "${lines[0]}" = "Movies" ]
}
@test "No arguments prints usage instructions" {
run movies
[ "$status" -eq 0 ]
[ "${lines[0]}" = "Movies" ]
}
@test "Get information on a single movie" {
run movies Argo
[ "$status" -eq 0 ]
[ "${lines[0]}" = "==================================================" ]
[ "${lines[1]}" = "| Title: Argo" ]
}
@test "Get the tools version with -v" {
run movies -v
[ "$status" -eq 0 ]
result=$( echo $(movies -v) | grep -Eo "Version")
[ "$result" = "Version" ]
}

30
tests/qrify.bats Executable file
View File

@ -0,0 +1,30 @@
#!/bin/env bats
@test "Testing qrify tool" {
echo qrify
}
@test "Check for latest version of bash-snippets on update" {
run qrify update
[ "$status" -eq 0 ]
[ "$output" = "Bash-Snippets is already the latest version" ]
}
@test "The -h option should print usage" {
run qrify -h
[ "$status" -eq 0 ]
[ "${lines[0]}" = "Qrify" ]
}
@test "No arguments prints usage instructions" {
run qrify
[ "$status" -eq 0 ]
[ "${lines[0]}" = "Qrify" ]
}
@test "Get the tools version with -v" {
run qrify -v
[ "$status" -eq 0 ]
result=$( echo $(qrify -v) | grep -Eo "Version")
[ "$result" = "Version" ]
}

30
tests/short.bats Executable file
View File

@ -0,0 +1,30 @@
#!/bin/env bats
@test "Testing short tool" {
echo short
}
@test "Check for latest version of bash-snippets on update" {
run short update
[ "$status" -eq 0 ]
[ "$output" = "Bash-Snippets is already the latest version" ]
}
@test "The -h option should print usage" {
run short -h
[ "$status" -eq 0 ]
[ "${lines[0]}" = "Short" ]
}
@test "No arguments prints usage instructions" {
run short
[ "$status" -eq 0 ]
[ "${lines[0]}" = "Short" ]
}
@test "Get the tools version with -v" {
run short -v
[ "$status" -eq 0 ]
result=$( echo $(short -v) | grep -Eo "Version")
[ "$result" = "Version" ]
}

42
tests/stocks.bats Executable file
View File

@ -0,0 +1,42 @@
#!/bin/env bats
@test "Testing stocks tool" {
echo stocks
}
@test "Check for latest version of bash-snippets on update" {
run stocks update
[ "$status" -eq 0 ]
[ "$output" = "Bash-Snippets is already the latest version" ]
}
@test "The -h option should print usage" {
run stocks -h
[ "$status" -eq 0 ]
[ "${lines[0]}" = "Stocks" ]
}
@test "No arguments prints usage instructions" {
run stocks
[ "$status" -eq 0 ]
[ "${lines[0]}" = "Stocks" ]
}
@test "Get stock info by passing in ticker" {
run stocks AAPL
[ "$status" -eq 0 ]
[ "${lines[0]}" = "AAPL stock info" ]
}
@test "Get stock info by passing in company" {
run stocks Tesla
[ "$status" -eq 0 ]
[ "${lines[0]}" = "TSLA stock info" ]
}
@test "Get the tools version with -v" {
run stocks -v
[ "$status" -eq 0 ]
result=$( echo $(stocks -v) | grep -Eo "Version")
[ "$result" = "Version" ]
}

32
tests/taste.bats Executable file
View File

@ -0,0 +1,32 @@
#!/bin/env bats
@test "Testing taste tool" {
echo taste
export TASTE_API_KEY="275041-BashSnip-KQ51U8H8" >> ~/.bash_profile
}
@test "Check for latest version of bash-snippets on update" {
run taste update
[ "$status" -eq 0 ]
[ "$output" = "Bash-Snippets is already the latest version" ]
}
@test "The -h option should print usage" {
run taste -h
[ "$status" -eq 0 ]
[ "${lines[0]}" = "Taste" ]
}
@test "No arguments prints usage instructions" {
run taste
[ "$status" -eq 0 ]
[ "${lines[0]}" = "Taste" ]
}
@test "Get the tools version with -v" {
run taste -v
[ "$status" -eq 0 ]
result=$( echo $(taste -v) | grep -Eo "Version")
[ "$result" = "Version" ]
}

24
tests/weather.bats Executable file
View File

@ -0,0 +1,24 @@
#!/bin/env bats
@test "Testing weather tool" {
echo weather
}
@test "Check for latest version of bash-snippets on update" {
run weather update
[ "$status" -eq 0 ]
[ "$output" = "Bash-Snippets is already the latest version" ]
}
@test "The -h option should print usage" {
run weather -h
[ "$status" -eq 0 ]
[ "${lines[0]}" = "Weather" ]
}
@test "Get the tools version with -v" {
run weather -v
[ "$status" -eq 0 ]
result=$( echo $(weather -v) | grep -Eo "Version")
[ "$result" = "Version" ]
}

26
tests/ytview.bats Executable file
View File

@ -0,0 +1,26 @@
#!/bin/env bats
@test "Testing ytview tool" {
echo ytview
}
@test "Check for latest version of bash-snippets on update" {
run ytview update
[ "$output" = "Bash-Snippets is already the latest version" ]
}
@test "The -h option should print usage" {
run ytview -h
[ "${lines[0]}" = "Ytview" ]
}
@test "No arguments prints usage instructions" {
run ytview
[ "$status" -eq 0 ]
[ "${lines[0]}" = "Ytview" ]
}
@test "Get the tools version with -v" {
result=$( echo $(ytview -v) | grep -Eo "Version")
[ "$result" = "Version" ]
}

View File

@ -174,7 +174,7 @@ getConfiguredClient || exit 1
getConfiguredPlayer || exit 1
checkInternet || exit 1
while getopts uc:s:h*: option
while getopts vuc:s:h*: option
do
case "${option}" in
s)
@ -197,6 +197,7 @@ do
;;
h) usage && exit 0 ;;
u) update && exit 0 ;;
v) echo "Version $currentVersion" && exit 0 ;;
*) usage && exit 0 ;;
esac
done