diff --git a/test/alerts.bats b/test/alerts.bats index 61ae399..c809fba 100755 --- a/test/alerts.bats +++ b/test/alerts.bats @@ -34,9 +34,17 @@ setup() { VERBOSE=false FORCE=false DRYRUN=false + + set -o errtrace + set -o nounset + set -o pipefail } teardown() { + set +o nounset + set +o errtrace + set +o pipefail + popd >&2 temp_del "${TESTDIR}" } @@ -131,6 +139,7 @@ teardown() { run info "testing info" run debug "testing debug" run fatal "testing fatal" + set +o nounset assert_file_exist "${LOGFILE}" run cat "${LOGFILE}" @@ -150,6 +159,7 @@ teardown() { run notice "testing notice" run info "testing info" run debug "testing debug" + set +o nounset assert_file_exist "${LOGFILE}" run cat "${LOGFILE}" @@ -169,7 +179,7 @@ teardown() { run notice "testing notice" run info "testing info" run debug "testing debug" - + set +o nounset assert_file_exist "${LOGFILE}" run cat "${LOGFILE}" assert_line --index 0 --regexp "[0-9]+:[0-9]+:[0-9]+ \[ error\] \[.*\] testing error" @@ -188,7 +198,7 @@ teardown() { run notice "testing notice" run info "testing info" run debug "testing debug" - + set +o nounset assert_file_exist "${LOGFILE}" run cat "${LOGFILE}" assert_line --index 0 --regexp "[0-9]+:[0-9]+:[0-9]+ \[ error\] \[.*\] testing error" @@ -207,7 +217,7 @@ teardown() { run notice "testing notice" run info "testing info" run debug "testing debug" - + set +o nounset assert_file_exist "${LOGFILE}" run cat "${LOGFILE}" assert_line --index 0 --regexp "[0-9]+:[0-9]+:[0-9]+ \[ error\] \[.*\] testing error" diff --git a/test/arrays.bats b/test/arrays.bats index ab1a632..2b980e8 100755 --- a/test/arrays.bats +++ b/test/arrays.bats @@ -33,13 +33,34 @@ setup() { B=(1 2 3 4 5 6) DUPES=(1 2 3 1 2 3) + TESTDIR="$(temp_make)" + curPath="${PWD}" + + BATSLIB_FILE_PATH_REM="#${TEST_TEMP_DIR}" + BATSLIB_FILE_PATH_ADD='' + + pushd "${TESTDIR}" &>/dev/null + ######## DEFAULT FLAGS ######## LOGFILE="${TESTDIR}/logs/log.txt" QUIET=false - LOGLEVEL=ERROR + LOGLEVEL=OFF VERBOSE=false FORCE=false DRYRUN=false + + set -o errtrace + set -o nounset + set -o pipefail +} + +teardown() { + set +o nounset + set +o errtrace + set +o pipefail + + popd &>/dev/null + temp_del "${TESTDIR}" } ######## RUN TESTS ######## @@ -81,6 +102,7 @@ setup() { } @test "_setdiff_: Print elements not common to arrays" { + set +o nounset run _setdiff_ "${A[*]}" "${B[*]}" assert_output "one two three" @@ -89,6 +111,7 @@ setup() { } @test "_removeDupes_: remove duplicates" { + set +o nounset run _removeDupes_ "${DUPES[@]}" assert_line --index 0 "3" assert_line --index 1 "2" diff --git a/test/baseHelpers.bats b/test/baseHelpers.bats index b212e9b..71bcae4 100755 --- a/test/baseHelpers.bats +++ b/test/baseHelpers.bats @@ -43,9 +43,16 @@ setup() { VERBOSE=false FORCE=false DRYRUN=false + set -o errtrace + set -o nounset + set -o pipefail } teardown() { + set +o nounset + set +o errtrace + set +o pipefail + popd >&2 temp_del "${TESTDIR}" } diff --git a/test/files.bats b/test/files.bats index baadb20..219346f 100755 --- a/test/files.bats +++ b/test/files.bats @@ -53,10 +53,15 @@ setup() { FORCE=false DRYRUN=false PASS=123 - + set -o errtrace + set -o nounset + set -o pipefail } teardown() { + set +o nounset + set +o errtrace + set +o pipefail popd &>/dev/null temp_del "${TESTDIR}" } @@ -191,9 +196,11 @@ _testParseFilename_() { } @test "_parseFilename_: file with one extension" { + touch "testfile.txt" VERBOSE=true run _parseFilename_ "testfile.txt" + set +o nounset assert_success assert_line --index 0 --regexp "\[ debug\].*{PARSE_FULL}: /.*testfile\.txt$" @@ -204,10 +211,11 @@ _testParseFilename_() { } @test "_parseFilename_: file with dots in name" { + touch "testfile.for.testing.txt" VERBOSE=true run _parseFilename_ "testfile.for.testing.txt" - + set +o nounset assert_success assert_line --index 0 --regexp "\[ debug\].*{PARSE_FULL}: /.*testfile\.for\.testing\.txt$" assert_line --index 1 --regexp "\[ debug\].*${PARSE_BASE}: testfile\.for\.testing\.txt$" @@ -217,10 +225,11 @@ _testParseFilename_() { } @test "_parseFilename_: file with no extension" { + touch "testfile" VERBOSE=true run _parseFilename_ "testfile" - + set +o nounset assert_success assert_line --index 0 --regexp "\[ debug\].*{PARSE_FULL}: /.*testfile$" assert_line --index 1 --regexp "\[ debug\].*${PARSE_BASE}: testfile$" @@ -230,9 +239,11 @@ _testParseFilename_() { } @test "_parseFilename_: file with tar.gz" { + touch "testfile.tar.gz" VERBOSE=true run _parseFilename_ "testfile.tar.gz" + set +o nounset assert_success assert_line --index 0 --regexp "\[ debug\].*{PARSE_FULL}: /.*testfile\.tar\.gz$" @@ -246,7 +257,7 @@ _testParseFilename_() { touch "testfile.tar.gzip.bzip" VERBOSE=true run _parseFilename_ -n3 "testfile.tar.gzip.bzip" - + set +o nounset assert_success assert_line --index 0 --regexp "\[ debug\].*{PARSE_FULL}: /.*testfile\.tar\.gzip\.bzip$" assert_line --index 1 --regexp "\[ debug\].*${PARSE_BASE}: testfile\.tar\.gzip\.bzip$" diff --git a/test/numbers.bats b/test/numbers.bats index e8d7beb..7900b66 100755 --- a/test/numbers.bats +++ b/test/numbers.bats @@ -53,9 +53,16 @@ setup() { FORCE=false DRYRUN=false + set -o errtrace + set -o nounset + set -o pipefail } teardown() { + set +o nounset + set +o errtrace + set +o pipefail + popd &>/dev/null temp_del "${TESTDIR}" } diff --git a/test/textProcessing.bats b/test/textProcessing.bats index 88da4b3..dbcd3d9 100755 --- a/test/textProcessing.bats +++ b/test/textProcessing.bats @@ -53,9 +53,16 @@ setup() { FORCE=false DRYRUN=false + set -o errtrace + set -o nounset + set -o pipefail } teardown() { + set +o nounset + set +o errtrace + set +o pipefail + popd &>/dev/null temp_del "${TESTDIR}" }