mirror of
https://github.com/natelandau/shell-scripting-templates.git
synced 2025-11-10 22:13:48 -05:00
bash settings in tests
This commit is contained in:
@@ -34,9 +34,17 @@ setup() {
|
|||||||
VERBOSE=false
|
VERBOSE=false
|
||||||
FORCE=false
|
FORCE=false
|
||||||
DRYRUN=false
|
DRYRUN=false
|
||||||
|
|
||||||
|
set -o errtrace
|
||||||
|
set -o nounset
|
||||||
|
set -o pipefail
|
||||||
}
|
}
|
||||||
|
|
||||||
teardown() {
|
teardown() {
|
||||||
|
set +o nounset
|
||||||
|
set +o errtrace
|
||||||
|
set +o pipefail
|
||||||
|
|
||||||
popd >&2
|
popd >&2
|
||||||
temp_del "${TESTDIR}"
|
temp_del "${TESTDIR}"
|
||||||
}
|
}
|
||||||
@@ -131,6 +139,7 @@ teardown() {
|
|||||||
run info "testing info"
|
run info "testing info"
|
||||||
run debug "testing debug"
|
run debug "testing debug"
|
||||||
run fatal "testing fatal"
|
run fatal "testing fatal"
|
||||||
|
set +o nounset
|
||||||
|
|
||||||
assert_file_exist "${LOGFILE}"
|
assert_file_exist "${LOGFILE}"
|
||||||
run cat "${LOGFILE}"
|
run cat "${LOGFILE}"
|
||||||
@@ -150,6 +159,7 @@ teardown() {
|
|||||||
run notice "testing notice"
|
run notice "testing notice"
|
||||||
run info "testing info"
|
run info "testing info"
|
||||||
run debug "testing debug"
|
run debug "testing debug"
|
||||||
|
set +o nounset
|
||||||
|
|
||||||
assert_file_exist "${LOGFILE}"
|
assert_file_exist "${LOGFILE}"
|
||||||
run cat "${LOGFILE}"
|
run cat "${LOGFILE}"
|
||||||
@@ -169,7 +179,7 @@ teardown() {
|
|||||||
run notice "testing notice"
|
run notice "testing notice"
|
||||||
run info "testing info"
|
run info "testing info"
|
||||||
run debug "testing debug"
|
run debug "testing debug"
|
||||||
|
set +o nounset
|
||||||
assert_file_exist "${LOGFILE}"
|
assert_file_exist "${LOGFILE}"
|
||||||
run cat "${LOGFILE}"
|
run cat "${LOGFILE}"
|
||||||
assert_line --index 0 --regexp "[0-9]+:[0-9]+:[0-9]+ \[ error\] \[.*\] testing error"
|
assert_line --index 0 --regexp "[0-9]+:[0-9]+:[0-9]+ \[ error\] \[.*\] testing error"
|
||||||
@@ -188,7 +198,7 @@ teardown() {
|
|||||||
run notice "testing notice"
|
run notice "testing notice"
|
||||||
run info "testing info"
|
run info "testing info"
|
||||||
run debug "testing debug"
|
run debug "testing debug"
|
||||||
|
set +o nounset
|
||||||
assert_file_exist "${LOGFILE}"
|
assert_file_exist "${LOGFILE}"
|
||||||
run cat "${LOGFILE}"
|
run cat "${LOGFILE}"
|
||||||
assert_line --index 0 --regexp "[0-9]+:[0-9]+:[0-9]+ \[ error\] \[.*\] testing error"
|
assert_line --index 0 --regexp "[0-9]+:[0-9]+:[0-9]+ \[ error\] \[.*\] testing error"
|
||||||
@@ -207,7 +217,7 @@ teardown() {
|
|||||||
run notice "testing notice"
|
run notice "testing notice"
|
||||||
run info "testing info"
|
run info "testing info"
|
||||||
run debug "testing debug"
|
run debug "testing debug"
|
||||||
|
set +o nounset
|
||||||
assert_file_exist "${LOGFILE}"
|
assert_file_exist "${LOGFILE}"
|
||||||
run cat "${LOGFILE}"
|
run cat "${LOGFILE}"
|
||||||
assert_line --index 0 --regexp "[0-9]+:[0-9]+:[0-9]+ \[ error\] \[.*\] testing error"
|
assert_line --index 0 --regexp "[0-9]+:[0-9]+:[0-9]+ \[ error\] \[.*\] testing error"
|
||||||
|
|||||||
@@ -33,13 +33,34 @@ setup() {
|
|||||||
B=(1 2 3 4 5 6)
|
B=(1 2 3 4 5 6)
|
||||||
DUPES=(1 2 3 1 2 3)
|
DUPES=(1 2 3 1 2 3)
|
||||||
|
|
||||||
|
TESTDIR="$(temp_make)"
|
||||||
|
curPath="${PWD}"
|
||||||
|
|
||||||
|
BATSLIB_FILE_PATH_REM="#${TEST_TEMP_DIR}"
|
||||||
|
BATSLIB_FILE_PATH_ADD='<temp>'
|
||||||
|
|
||||||
|
pushd "${TESTDIR}" &>/dev/null
|
||||||
|
|
||||||
######## DEFAULT FLAGS ########
|
######## DEFAULT FLAGS ########
|
||||||
LOGFILE="${TESTDIR}/logs/log.txt"
|
LOGFILE="${TESTDIR}/logs/log.txt"
|
||||||
QUIET=false
|
QUIET=false
|
||||||
LOGLEVEL=ERROR
|
LOGLEVEL=OFF
|
||||||
VERBOSE=false
|
VERBOSE=false
|
||||||
FORCE=false
|
FORCE=false
|
||||||
DRYRUN=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 ########
|
######## RUN TESTS ########
|
||||||
@@ -81,6 +102,7 @@ setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "_setdiff_: Print elements not common to arrays" {
|
@test "_setdiff_: Print elements not common to arrays" {
|
||||||
|
set +o nounset
|
||||||
run _setdiff_ "${A[*]}" "${B[*]}"
|
run _setdiff_ "${A[*]}" "${B[*]}"
|
||||||
assert_output "one two three"
|
assert_output "one two three"
|
||||||
|
|
||||||
@@ -89,6 +111,7 @@ setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "_removeDupes_: remove duplicates" {
|
@test "_removeDupes_: remove duplicates" {
|
||||||
|
set +o nounset
|
||||||
run _removeDupes_ "${DUPES[@]}"
|
run _removeDupes_ "${DUPES[@]}"
|
||||||
assert_line --index 0 "3"
|
assert_line --index 0 "3"
|
||||||
assert_line --index 1 "2"
|
assert_line --index 1 "2"
|
||||||
|
|||||||
@@ -43,9 +43,16 @@ setup() {
|
|||||||
VERBOSE=false
|
VERBOSE=false
|
||||||
FORCE=false
|
FORCE=false
|
||||||
DRYRUN=false
|
DRYRUN=false
|
||||||
|
set -o errtrace
|
||||||
|
set -o nounset
|
||||||
|
set -o pipefail
|
||||||
}
|
}
|
||||||
|
|
||||||
teardown() {
|
teardown() {
|
||||||
|
set +o nounset
|
||||||
|
set +o errtrace
|
||||||
|
set +o pipefail
|
||||||
|
|
||||||
popd >&2
|
popd >&2
|
||||||
temp_del "${TESTDIR}"
|
temp_del "${TESTDIR}"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,10 +53,15 @@ setup() {
|
|||||||
FORCE=false
|
FORCE=false
|
||||||
DRYRUN=false
|
DRYRUN=false
|
||||||
PASS=123
|
PASS=123
|
||||||
|
set -o errtrace
|
||||||
|
set -o nounset
|
||||||
|
set -o pipefail
|
||||||
}
|
}
|
||||||
|
|
||||||
teardown() {
|
teardown() {
|
||||||
|
set +o nounset
|
||||||
|
set +o errtrace
|
||||||
|
set +o pipefail
|
||||||
popd &>/dev/null
|
popd &>/dev/null
|
||||||
temp_del "${TESTDIR}"
|
temp_del "${TESTDIR}"
|
||||||
}
|
}
|
||||||
@@ -191,9 +196,11 @@ _testParseFilename_() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "_parseFilename_: file with one extension" {
|
@test "_parseFilename_: file with one extension" {
|
||||||
|
|
||||||
touch "testfile.txt"
|
touch "testfile.txt"
|
||||||
VERBOSE=true
|
VERBOSE=true
|
||||||
run _parseFilename_ "testfile.txt"
|
run _parseFilename_ "testfile.txt"
|
||||||
|
set +o nounset
|
||||||
|
|
||||||
assert_success
|
assert_success
|
||||||
assert_line --index 0 --regexp "\[ debug\].*{PARSE_FULL}: /.*testfile\.txt$"
|
assert_line --index 0 --regexp "\[ debug\].*{PARSE_FULL}: /.*testfile\.txt$"
|
||||||
@@ -204,10 +211,11 @@ _testParseFilename_() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "_parseFilename_: file with dots in name" {
|
@test "_parseFilename_: file with dots in name" {
|
||||||
|
|
||||||
touch "testfile.for.testing.txt"
|
touch "testfile.for.testing.txt"
|
||||||
VERBOSE=true
|
VERBOSE=true
|
||||||
run _parseFilename_ "testfile.for.testing.txt"
|
run _parseFilename_ "testfile.for.testing.txt"
|
||||||
|
set +o nounset
|
||||||
assert_success
|
assert_success
|
||||||
assert_line --index 0 --regexp "\[ debug\].*{PARSE_FULL}: /.*testfile\.for\.testing\.txt$"
|
assert_line --index 0 --regexp "\[ debug\].*{PARSE_FULL}: /.*testfile\.for\.testing\.txt$"
|
||||||
assert_line --index 1 --regexp "\[ debug\].*${PARSE_BASE}: 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" {
|
@test "_parseFilename_: file with no extension" {
|
||||||
|
|
||||||
touch "testfile"
|
touch "testfile"
|
||||||
VERBOSE=true
|
VERBOSE=true
|
||||||
run _parseFilename_ "testfile"
|
run _parseFilename_ "testfile"
|
||||||
|
set +o nounset
|
||||||
assert_success
|
assert_success
|
||||||
assert_line --index 0 --regexp "\[ debug\].*{PARSE_FULL}: /.*testfile$"
|
assert_line --index 0 --regexp "\[ debug\].*{PARSE_FULL}: /.*testfile$"
|
||||||
assert_line --index 1 --regexp "\[ debug\].*${PARSE_BASE}: testfile$"
|
assert_line --index 1 --regexp "\[ debug\].*${PARSE_BASE}: testfile$"
|
||||||
@@ -230,9 +239,11 @@ _testParseFilename_() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "_parseFilename_: file with tar.gz" {
|
@test "_parseFilename_: file with tar.gz" {
|
||||||
|
|
||||||
touch "testfile.tar.gz"
|
touch "testfile.tar.gz"
|
||||||
VERBOSE=true
|
VERBOSE=true
|
||||||
run _parseFilename_ "testfile.tar.gz"
|
run _parseFilename_ "testfile.tar.gz"
|
||||||
|
set +o nounset
|
||||||
|
|
||||||
assert_success
|
assert_success
|
||||||
assert_line --index 0 --regexp "\[ debug\].*{PARSE_FULL}: /.*testfile\.tar\.gz$"
|
assert_line --index 0 --regexp "\[ debug\].*{PARSE_FULL}: /.*testfile\.tar\.gz$"
|
||||||
@@ -246,7 +257,7 @@ _testParseFilename_() {
|
|||||||
touch "testfile.tar.gzip.bzip"
|
touch "testfile.tar.gzip.bzip"
|
||||||
VERBOSE=true
|
VERBOSE=true
|
||||||
run _parseFilename_ -n3 "testfile.tar.gzip.bzip"
|
run _parseFilename_ -n3 "testfile.tar.gzip.bzip"
|
||||||
|
set +o nounset
|
||||||
assert_success
|
assert_success
|
||||||
assert_line --index 0 --regexp "\[ debug\].*{PARSE_FULL}: /.*testfile\.tar\.gzip\.bzip$"
|
assert_line --index 0 --regexp "\[ debug\].*{PARSE_FULL}: /.*testfile\.tar\.gzip\.bzip$"
|
||||||
assert_line --index 1 --regexp "\[ debug\].*${PARSE_BASE}: testfile\.tar\.gzip\.bzip$"
|
assert_line --index 1 --regexp "\[ debug\].*${PARSE_BASE}: testfile\.tar\.gzip\.bzip$"
|
||||||
|
|||||||
@@ -53,9 +53,16 @@ setup() {
|
|||||||
FORCE=false
|
FORCE=false
|
||||||
DRYRUN=false
|
DRYRUN=false
|
||||||
|
|
||||||
|
set -o errtrace
|
||||||
|
set -o nounset
|
||||||
|
set -o pipefail
|
||||||
}
|
}
|
||||||
|
|
||||||
teardown() {
|
teardown() {
|
||||||
|
set +o nounset
|
||||||
|
set +o errtrace
|
||||||
|
set +o pipefail
|
||||||
|
|
||||||
popd &>/dev/null
|
popd &>/dev/null
|
||||||
temp_del "${TESTDIR}"
|
temp_del "${TESTDIR}"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,9 +53,16 @@ setup() {
|
|||||||
FORCE=false
|
FORCE=false
|
||||||
DRYRUN=false
|
DRYRUN=false
|
||||||
|
|
||||||
|
set -o errtrace
|
||||||
|
set -o nounset
|
||||||
|
set -o pipefail
|
||||||
}
|
}
|
||||||
|
|
||||||
teardown() {
|
teardown() {
|
||||||
|
set +o nounset
|
||||||
|
set +o errtrace
|
||||||
|
set +o pipefail
|
||||||
|
|
||||||
popd &>/dev/null
|
popd &>/dev/null
|
||||||
temp_del "${TESTDIR}"
|
temp_del "${TESTDIR}"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user