diff --git a/bak2dvd/bak2dvd b/bak2dvd/bak2dvd index 2b85f6ab..a85780ad 100755 --- a/bak2dvd/bak2dvd +++ b/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() { @@ -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 diff --git a/skeleton b/skeleton index e833abab..bc51173a 100755 --- a/skeleton +++ b/skeleton @@ -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 diff --git a/skeleton.bats b/skeleton.bats new file mode 100644 index 00000000..c13234cc --- /dev/null +++ b/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}" ]] +} + diff --git a/tests/bak2dvd.bats b/tests/bak2dvd.bats index 776b1190..0f6614d2 100755 --- a/tests/bak2dvd.bats +++ b/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 + diff --git a/tests/cheat.bats b/tests/cheat.bats index b96c9b41..dfc9db9f 100755 --- a/tests/cheat.bats +++ b/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' ]] } diff --git a/tests/cloudup.bats b/tests/cloudup.bats index 947d737f..11dd0a9e 100755 --- a/tests/cloudup.bats +++ b/tests/cloudup.bats @@ -1,4 +1,4 @@ -#!/bin/env bats +#!/usr/bin/env bats @test "Testing cloudup tool" { echo cloudup diff --git a/tests/crypt.bats b/tests/crypt.bats index 3d5cf803..ccad67eb 100755 --- a/tests/crypt.bats +++ b/tests/crypt.bats @@ -1,4 +1,4 @@ -#!/bin/env bats +#!/usr/bin/env bats @test "Testing crypt tool" { echo crypt diff --git a/tests/cryptocurrency.bats b/tests/cryptocurrency.bats index f2693a07..3e4a8a5f 100755 --- a/tests/cryptocurrency.bats +++ b/tests/cryptocurrency.bats @@ -1,4 +1,4 @@ -#!/bin/env bats +#!/usr/bin/env bats @test "Testing cryptocurrency tool" { echo cryptocurrency diff --git a/tests/currency.bats b/tests/currency.bats index 80570db1..32281372 100755 --- a/tests/currency.bats +++ b/tests/currency.bats @@ -1,4 +1,4 @@ -#!/bin/env bats +#!/usr/bin/env bats @test "Testing currency tool" { echo currency diff --git a/tests/geo.bats b/tests/geo.bats index a80e6703..7eaed9d3 100755 --- a/tests/geo.bats +++ b/tests/geo.bats @@ -1,4 +1,4 @@ -#!/bin/env bats +#!/usr/bin/env bats @test "Testing geo tool" { echo geo diff --git a/tests/meme.bats b/tests/meme.bats index ff1910ce..5146c132 100755 --- a/tests/meme.bats +++ b/tests/meme.bats @@ -1,4 +1,4 @@ -#!/bin/env bats +#!/usr/bin/env bats @test "Testing meme tool" { echo meme diff --git a/tests/movies.bats b/tests/movies.bats index e8e62c92..3c5f583d 100755 --- a/tests/movies.bats +++ b/tests/movies.bats @@ -1,4 +1,4 @@ -#!/bin/env bats +#!/usr/bin/env bats @test "Testing movies tool" { echo movies diff --git a/tests/newton.bats b/tests/newton.bats index 2eb3c570..9f6a01b6 100755 --- a/tests/newton.bats +++ b/tests/newton.bats @@ -1,4 +1,4 @@ -#!/bin/env bats +#!/usr/bin/env bats @test "Testing newton tool" { echo newton diff --git a/tests/qrify.bats b/tests/qrify.bats index f55d2ec8..9e08f924 100755 --- a/tests/qrify.bats +++ b/tests/qrify.bats @@ -1,4 +1,4 @@ -#!/bin/env bats +#!/usr/bin/env bats @test "Testing qrify tool" { echo qrify diff --git a/tests/short.bats b/tests/short.bats index 8f7ddf3a..40a1986a 100755 --- a/tests/short.bats +++ b/tests/short.bats @@ -1,32 +1,90 @@ -#!/bin/env bats +#!/usr/bin/env bats -@test "Testing short tool" { - echo short +export TOOL_NAME='short' + +setup() { + # $REPO_DIR/tests/short.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 short 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 short -h - [ "$status" -eq 0 ] - [ "${lines[0]}" = "Short" ] + 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 short - [ "$status" -eq 0 ] - [ "${lines[0]}" = "Short" ] + 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 short -v - [ "$status" -eq 0 ] - result=$( echo $(short -v) | grep -Eo "Version") - [ "$result" = "Version" ] + run "${TOOL_DIR}/${TOOL_NAME}" -v + + [[ "$status" -eq 0 ]] + expected='Version' + [[ "${output}" =~ "${expected}" ]] } + +# Tool specific tests + +@test "Shorten github repo URL" { + longurl='https://github.com/alexanderepstein/Bash-Snippets' + run "${TOOL_DIR}/${TOOL_NAME}" -s "${longurl}" + + [[ "$status" -eq 0 ]] + expected='http://tinyurl.com/uowfbb5' + [[ "${lines[2]}" =~ "${expected}" ]] +} + +@test "Expand tinyurl URL" { + shorturl='http://tinyurl.com/uowfbb5' + run "${TOOL_DIR}/${TOOL_NAME}" -e "${shorturl}" + + [[ "$status" -eq 0 ]] + expected='https://github.com/alexanderepstein/Bash-Snippets' + [[ "${lines[2]}" =~ "${expected}" ]] +} + diff --git a/tests/siteciphers.bats b/tests/siteciphers.bats index e7c01342..c1b960ea 100755 --- a/tests/siteciphers.bats +++ b/tests/siteciphers.bats @@ -1,4 +1,4 @@ -#!/bin/env bats +#!/usr/bin/env bats @test "Testing siteciphers tool" { echo siteciphers diff --git a/tests/stocks.bats b/tests/stocks.bats index b96c9b41..2460242f 100755 --- a/tests/stocks.bats +++ b/tests/stocks.bats @@ -1,4 +1,4 @@ -#!/bin/env bats +#!/usr/bin/env bats @test "Testing stocks tool" { echo stocks diff --git a/tests/taste.bats b/tests/taste.bats index 7d70e52d..1a71350e 100755 --- a/tests/taste.bats +++ b/tests/taste.bats @@ -1,63 +1,86 @@ -#!/bin/env bats +#!/usr/bin/env bats -@test "Testing taste tool" { - echo taste - export TASTE_API_KEY="290044-Taste-QIQUQKOZ" +export TOOL_NAME='taste' +export TASTE_API_KEY="290044-Taste-QIQUQKOZ" +setup() { + # $REPO_DIR/tests/taste.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 "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" { - if [[ "$(uname)" == "Darwin" ]]; then - run taste -h - [ "$status" -eq 0 ] - [ "${lines[0]}" = "Taste" ] - fi + 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}" ]] } @test "Testing short recommendations" { - if [[ "$(uname)" == "Darwin" ]]; then - run taste 50 Cent - [ "$status" -eq 0 ] + run "${TOOL_DIR}/${TOOL_NAME}" 50 Cent + + # order of ouput lines changed + [[ "$status" -eq 0 ]] [ "${lines[0]}" = "===================================" ] [ "${lines[1]}" = "G-Unit: music" ] - [ "${lines[2]}" = "Lloyd Banks: music" ] - [ "${lines[3]}" = "The Game: music" ] + [ "${lines[2]}" = "The Game: music" ] + [ "${lines[3]}" = "Lloyd Banks: music" ] [ "${lines[4]}" = "===================================" ] - fi } @test "Testing long recommendations" { - if [[ "$(uname)" == "Darwin" ]]; then - run taste -i Sublime - [ "$status" -eq 0 ] - response=$(echo $(taste -i Sublime) | grep -Eo "Soundsystem is the fifth studio album by 311, released on October 12, 1999. Soundsystem, which was certified Gold by the RIAA,") - [ "$response" = "Soundsystem is the fifth studio album by 311, released on October 12, 1999. Soundsystem, which was certified Gold by the RIAA," ] -fi + run "${TOOL_DIR}/${TOOL_NAME}" -i Sublime + + [[ "$status" -eq 0 ]] + expected='Soundsystem is the fifth studio album by 311, released on October 12, 1999. Soundsystem, which was certified Gold by the RIAA,' + [[ "${output}" =~ "${expected}" ]] } @test "Testing search on item" { - if [[ "$(uname)" == "Darwin" ]]; then - run taste -s Kendrick Lamar - [ "$status" -eq 0 ] - response=$(echo $(taste -s Kendrick Lamar) | grep -Eo "Kendrick Lamar Duckworth") - [ "$response" = "Kendrick Lamar Duckworth" ] -fi -} + run "${TOOL_DIR}/${TOOL_NAME}" -s Kendrick Lamar -@test "No arguments prints usage instructions" { - if [[ "$(uname)" == "Darwin" ]]; then - run taste - [ "$status" -eq 0 ] - [ "${lines[0]}" = "Taste" ] -fi + [[ "$status" -eq 0 ]] + expected='Kendrick Lamar Duckworth' + [[ "${output}" =~ "${expected}" ]] } -@test "Get the tools version with -v" { - if [[ "$(uname)" == "Darwin" ]]; then - run taste -v - [ "$status" -eq 0 ] - result=$( echo $(taste -v) | grep -Eo "Version") - [ "$result" = "Version" ] -fi -} diff --git a/tests/todo.bats b/tests/todo.bats index aa678e15..698ddb8f 100755 --- a/tests/todo.bats +++ b/tests/todo.bats @@ -1,4 +1,4 @@ -#!/bin/env bats +#!/usr/bin/env bats @test "Testing todo tool" { echo todo diff --git a/tests/transfer.bats b/tests/transfer.bats index 844ea2ce..83d55d88 100755 --- a/tests/transfer.bats +++ b/tests/transfer.bats @@ -1,4 +1,4 @@ -#!/bin/env bats +#!/usr/bin/env bats @test "Testing transfer tool" { echo transfer diff --git a/tests/weather.bats b/tests/weather.bats index bb64da29..1460fc87 100755 --- a/tests/weather.bats +++ b/tests/weather.bats @@ -1,32 +1,75 @@ -#!/bin/env bats +#!/usr/bin/env bats -@test "Testing weather tool" { - echo weather +export TOOL_NAME='weather' + +setup() { + # $REPO_DIR/tests/weather.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 weather 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 weather -h - [ "$status" -eq 0 ] - [ "${lines[0]}" = "Weather" ] + 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 "Testing weather with specified location" { - run weather Paramus - [ "$status" -eq 0 ] - [ "${lines[0]}" = "Weather report: Paramus, United States of America" ] +@test "No arguments shows weather at current location" { + run "${TOOL_DIR}/${TOOL_NAME}" + + [[ "$status" -eq 0 ]] + expected='Weather report: Lat' + [[ "${lines[0]}" =~ "${expected}" ]] } @test "Get the tools version with -v" { - run weather -v + run "${TOOL_DIR}/${TOOL_NAME}" -v + + [[ "$status" -eq 0 ]] + expected='Version' + [[ "${output}" =~ "${expected}" ]] +} + +# Tool specific tests +@test "Testing weather with specified location" { + run "${TOOL_DIR}/${TOOL_NAME}" Paramus + [ "$status" -eq 0 ] - result=$( echo $(weather -v) | grep -Eo "Version") - [ "$result" = "Version" ] + # API changed + #[ "${lines[0]}" = "Weather report: Paramus, United States of America" ] + [ "${lines[0]}" = "Weather report: Paramus" ] } + diff --git a/tests/ytview.bats b/tests/ytview.bats index e29dd4d3..ebcc9ed0 100755 --- a/tests/ytview.bats +++ b/tests/ytview.bats @@ -1,4 +1,4 @@ -#!/bin/env bats +#!/usr/bin/env bats @test "Testing ytview tool" { echo ytview