Skip to content

Commit

Permalink
Updates to tests (#185)
Browse files Browse the repository at this point in the history
* ✅ 💚 fix shebang in tests

It was `#!/bin/env` now `#!/usr/bin/env`.  The [travis config](.travis.yml)
masked this by calling `bats` on the  `./tests` directory.

* ✅ fix: revert `cheats.bats`

It was incorrectly overwritten with content of `stocks.bat`.

* ✅ add bats boilerplate test file

- [x] 🍱 add `skeleton.bats` boilerplate test file
- [x] 🔨 refactor cheat.bats from new bats boilerplate
- [x] ✏️ fix typo in `skeleton`

* 💬 bump version tag in bak2dvd to match repo

- [x] 🔨 refactor `bak2dvd.bats` from new bats boilerplate

* 👽 update weather test due to external change

wttr returns "Paramus" and not "Paramus, United States of America" as
it did previously.

* 💚 🍎 fix taste test

- [x] 🔨 refactor `taste.bats` from new bats boilerplate

* ✅ 💚 🍎 🐧 fix bats output checks

- [x] ✅ 💚 update skeleton.bats
- [x] 🍎 fix regex comparisons in bash 3.2
- [x] ✅ refactor bak2dvd, cheat, taste, short, weather
- [x] ✅ 💚 add url tests to short.bats

* Update weather.bats to cover no input params
  • Loading branch information
virgilwashere authored and alexanderepstein committed May 6, 2019
1 parent a3ba107 commit 4c899d8
Show file tree
Hide file tree
Showing 22 changed files with 422 additions and 138 deletions.
5 changes: 3 additions & 2 deletions bak2dvd/bak2dvd
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
# Author: Charles Oblender https://github.com/oblende
currentVersion="1.1.6"
currentVersion="1.22.1"
configuredClient=""

tarwrite() {
Expand Down Expand Up @@ -551,7 +551,8 @@ while test $# -gt 0; do
-v) echo "Version $currentVersion"
exit 0
;;
-u) getConfiguredClient || exit 1
-u|update)
getConfiguredClient || exit 1
checkInternet || exit 1
update
exit 0
Expand Down
2 changes: 1 addition & 1 deletion skeleton
Expand Up @@ -35,7 +35,7 @@ update()
{
# Author: Alexander Epstein https://github.com/alexanderepstein
# Update utility version 1.2.0
# To test the tool enter in the defualt values that are in the examples for each variable
# To test the tool enter in the default values that are in the examples for each variable
repositoryName="Bash-Snippets" #Name of repostiory to be updated ex. Sandman-Lite
githubUserName="alexanderepstein" #username that hosts the repostiory ex. alexanderepstein
nameOfInstallFile="install.sh" # change this if the installer file has a different name be sure to include file extension if there is one
Expand Down
79 changes: 79 additions & 0 deletions skeleton.bats
@@ -0,0 +1,79 @@
#!/usr/bin/env bats

export TOOL_NAME='skeleton'

setup() {
# $REPO_DIR/tests/skeleton.bats
REPO_DIR="$( cd "$( dirname "${BATS_TEST_DIRNAME}")" >/dev/null 2>&1 && pwd)"
TOOL_DIR="$( cd "${REPO_DIR}/${TOOL_NAME}" >/dev/null 2>&1 && pwd)"
}

@test "Testing ${TOOL_NAME} tool" {
echo "${TOOL_NAME}"
}

@test "Confirm the \$REPO_DIR variable is evaluated" {
cd "${REPO_DIR}" && pwd
[[ "$status" -eq 0 ]]
}

@test "Change into the tool directory for ${TOOL_NAME}" {
cd "${TOOL_DIR}" && pwd
[[ "$status" -eq 0 ]]
}

@test "Check for latest version of bash-snippets on update" {
if [[ "$(uname)" == "Linux" ]]; then
run "${TOOL_DIR}/${TOOL_NAME}" update
[[ "$status" -eq 0 ]]
[ "$output" == "Bash-Snippets is already the latest version" ]
fi
}

@test "The -h option should print usage" {
run "${TOOL_DIR}/${TOOL_NAME}" -h
[[ "$status" -eq 0 ]]
# if bash is less than 7 yrs old
if ((${BASH_VERSINFO[0]} >= 4)); then
[[ "${lines[0]}" = "${TOOL_NAME^}" ]]
else
# or im probably a stoneage mac
[[ "$(echo "${output}" | grep -i "${TOOL_NAME}")" ]]
fi
}

@test "No arguments prints usage instructions" {
run "${TOOL_DIR}/${TOOL_NAME}"
[[ "$status" -eq 0 ]]
# if bash is less than 7 yrs old
if ((${BASH_VERSINFO[0]} >= 4)); then
[[ "${lines[0]}" = "${TOOL_NAME^}" ]]
else
# or im probably a stoneage mac
[[ "$(echo "${output}" | grep -i "${TOOL_NAME}")" ]]
fi
}

@test "Get the tools version with -v" {
run "${TOOL_DIR}/${TOOL_NAME}" -v
[[ "$status" -eq 0 ]]
expected='Version'
[[ "${output}" =~ "${expected}" ]]
}


# Tool specific tests
@test "Do that cool thing" {
run "${TOOL_DIR}/${TOOL_NAME}" cool
[[ "$status" -eq 0 ]]
expected='This is awesome'
[[ "${output}" =~ "${expected}" ]]
}

@test "Testing coolness factor" {
run "${TOOL_DIR}/${TOOL_NAME}" cool --even-cooler
[[ "$status" -eq 0 ]]
expected='subzero'
[[ "printf '%s\n' ${lines[1]}" =~ "${expected}" ]]
}

76 changes: 59 additions & 17 deletions tests/bak2dvd.bats
@@ -1,30 +1,72 @@
#!/bin/env bats
#!/usr/bin/env bats
#
export TOOL_NAME='bak2dvd'

@test "Testing bak2dvd tool" {
echo bak2dvd
setup() {
# $REPO_DIR/tests/bak2dvd.bats
REPO_DIR="$( cd "$( dirname "${BATS_TEST_DIRNAME}")" >/dev/null 2>&1 && pwd)"
TOOL_DIR="$( cd "${REPO_DIR}/${TOOL_NAME}" >/dev/null 2>&1 && pwd)"
}

@test "Testing ${TOOL_NAME} tool" {
echo "${TOOL_NAME}"
}

@test "Confirm the \$REPO_DIR variable is evaluated" {
cd "${REPO_DIR}" && pwd

[[ "$status" -eq 0 ]]
}

# can cd into script dir
@test "Confirm a valid directory for ${TOOL_NAME}" {
cd "${TOOL_DIR}" && pwd

[[ "$status" -eq 0 ]]
}

@test "Check for latest version of bash-snippets on update" {
if [[ "$(uname)" == "Linux" ]];then
run bak2dvd update
[ "$status" -eq 0 ]
[ "$output" = "Bash-Snippets is already the latest version" ]
fi
if [[ "$(uname)" == "Linux" ]]; then
run "${TOOL_DIR}/${TOOL_NAME}" update

[[ "$status" -eq 0 ]]
[ "$output" == "Bash-Snippets is already the latest version" ]
fi
}

@test "The -h option should print usage" {
if [[ "$(uname)" == "Linux" ]];then
run bak2dvd -h
[ "$status" -eq 0 ]
[ "${lines[0]}" = "Bak2dvd" ]
run "${TOOL_DIR}/${TOOL_NAME}" -h

[[ "$status" -eq 0 ]]
# if bash is less than 7 yrs old
if ((${BASH_VERSINFO[0]} >= 4)); then
[[ "${lines[0]}" = "${TOOL_NAME^}" ]]
else
# or im probably a stoneage mac
[[ "$(echo "${output}" | grep -i "${TOOL_NAME}")" ]]
fi
}


@test "No arguments prints usage instructions" {
run "${TOOL_DIR}/${TOOL_NAME}"

[[ "$status" -eq 0 ]]
# if bash is less than 7 yrs old
if ((${BASH_VERSINFO[0]} >= 4)); then
[[ "${lines[0]}" = "${TOOL_NAME^}" ]]
else
# or im probably a stoneage mac
[[ "$(echo "${output}" | grep -i "${TOOL_NAME}")" ]]
fi
}

@test "Get the tools version with -v" {
run bak2dvd -v
[ "$status" -eq 0 ]
result=$( echo $(bak2dvd -v) | grep -Eo "Version")
[ "$result" = "Version" ]
run "${TOOL_DIR}/${TOOL_NAME}" -v

[[ "$status" -eq 0 ]]
expected='Version'
[[ "${output}" =~ "${expected}" ]]
}

# Tool specific tests

90 changes: 64 additions & 26 deletions tests/cheat.bats
@@ -1,43 +1,81 @@
#!/bin/env bats
#!/usr/bin/env bats

@test "Testing stocks tool" {
echo stocks
export TOOL_NAME='cheat'

setup() {
# $REPO_DIR/tests/tool.bats
REPO_DIR="$( cd "$( dirname "${BATS_TEST_DIRNAME}")" >/dev/null 2>&1 && pwd)"
TOOL_DIR="$( cd "${REPO_DIR}/${TOOL_NAME}" >/dev/null 2>&1 && pwd)"
}

@test "Testing ${TOOL_NAME} tool" {
echo "${TOOL_NAME}"
}

@test "Confirm the \$REPO_DIR variable is evaluated" {
cd "${REPO_DIR}" && pwd

[[ "$status" -eq 0 ]]
}

# can cd into script dir
@test "Confirm a valid directory for ${TOOL_NAME}" {
cd "${TOOL_DIR}" && pwd

[[ "$status" -eq 0 ]]
}

@test "Check for latest version of bash-snippets on update" {
if [[ "$(uname)" == "Linux" ]];then
run stocks update
[ "$status" -eq 0 ]
[ "$output" = "Bash-Snippets is already the latest version" ]
fi
if [[ "$(uname)" == "Linux" ]]; then
run "${TOOL_DIR}/${TOOL_NAME}" update

[[ "$status" -eq 0 ]]
[ "$output" == "Bash-Snippets is already the latest version" ]
fi
}

@test "The -h option should print usage" {
run stocks -h
[ "$status" -eq 0 ]
[ "${lines[0]}" = "Stocks" ]
run "${TOOL_DIR}/${TOOL_NAME}" -h

[[ "$status" -eq 0 ]]
# if bash is less than 7 yrs old
if ((${BASH_VERSINFO[0]} >= 4)); then
[[ "${lines[0]}" = "${TOOL_NAME^}" ]]
else
# or im probably a stoneage mac
[[ "$(echo "${output}" | grep -i "${TOOL_NAME}")" ]]
fi
}

@test "No arguments prints usage instructions" {
run stocks
[ "$status" -eq 0 ]
[ "${lines[0]}" = "Stocks" ]
run "${TOOL_DIR}/${TOOL_NAME}"

[[ "$status" -eq 0 ]]
# if bash is less than 7 yrs old
if ((${BASH_VERSINFO[0]} >= 4)); then
[[ "${lines[0]}" = "${TOOL_NAME^}" ]]
else
# or im probably a stoneage mac
[[ "$(echo "${output}" | grep -i "${TOOL_NAME}")" ]]
fi
}

@test "Get stock info by passing in ticker" {
result=$( echo $(stocks AAPL) | grep -Eo "AAPL stock info" )
[ "$result" = "AAPL stock info" ]

@test "Get the tools version with -v" {
run "${TOOL_DIR}/${TOOL_NAME}" -v

[[ "$status" -eq 0 ]]
expected='Version'
[[ "${output}" =~ "${expected}" ]]
}

@test "Get stock info by passing in company" {
result=$( echo $(stocks Apple) | grep -Eo "AAPL stock info" )
[ "$result" = "AAPL stock info" ]
@test "Grabbing information on a programming language (rust)" {
run "${TOOL_DIR}/${TOOL_NAME}" rust
[[ "$status" -eq 0 ]]
[[ "${lines[0]}" =~ 'Rust is a systems' ]]
}

@test "Get the tools version with -v" {
run stocks -v
[ "$status" -eq 0 ]
result=$( echo $(stocks -v) | grep -Eo "Version")
[ "$result" = "Version" ]
@test "Testing unkown topic due to misspelling" {
run "${TOOL_DIR}/${TOOL_NAME}" suuuper thiingsa
[[ "$status" -eq 0 ]]
[[ "printf '%s\n' ${lines[1]}" =~ 'Unknown' ]]
}
2 changes: 1 addition & 1 deletion tests/cloudup.bats
@@ -1,4 +1,4 @@
#!/bin/env bats
#!/usr/bin/env bats

@test "Testing cloudup tool" {
echo cloudup
Expand Down
2 changes: 1 addition & 1 deletion tests/crypt.bats
@@ -1,4 +1,4 @@
#!/bin/env bats
#!/usr/bin/env bats

@test "Testing crypt tool" {
echo crypt
Expand Down
2 changes: 1 addition & 1 deletion tests/cryptocurrency.bats
@@ -1,4 +1,4 @@
#!/bin/env bats
#!/usr/bin/env bats

@test "Testing cryptocurrency tool" {
echo cryptocurrency
Expand Down
2 changes: 1 addition & 1 deletion tests/currency.bats
@@ -1,4 +1,4 @@
#!/bin/env bats
#!/usr/bin/env bats

@test "Testing currency tool" {
echo currency
Expand Down
2 changes: 1 addition & 1 deletion tests/geo.bats
@@ -1,4 +1,4 @@
#!/bin/env bats
#!/usr/bin/env bats

@test "Testing geo tool" {
echo geo
Expand Down
2 changes: 1 addition & 1 deletion tests/meme.bats
@@ -1,4 +1,4 @@
#!/bin/env bats
#!/usr/bin/env bats

@test "Testing meme tool" {
echo meme
Expand Down
2 changes: 1 addition & 1 deletion tests/movies.bats
@@ -1,4 +1,4 @@
#!/bin/env bats
#!/usr/bin/env bats

@test "Testing movies tool" {
echo movies
Expand Down
2 changes: 1 addition & 1 deletion tests/newton.bats
@@ -1,4 +1,4 @@
#!/bin/env bats
#!/usr/bin/env bats

@test "Testing newton tool" {
echo newton
Expand Down
2 changes: 1 addition & 1 deletion tests/qrify.bats
@@ -1,4 +1,4 @@
#!/bin/env bats
#!/usr/bin/env bats

@test "Testing qrify tool" {
echo qrify
Expand Down

0 comments on commit 4c899d8

Please sign in to comment.