mirror of
https://github.com/natelandau/shell-scripting-templates.git
synced 2025-11-10 14:13:45 -05:00
bash settings in tests
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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='<temp>'
|
||||
|
||||
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"
|
||||
|
||||
@@ -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}"
|
||||
}
|
||||
|
||||
@@ -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$"
|
||||
|
||||
@@ -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}"
|
||||
}
|
||||
|
||||
@@ -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}"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user