1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
#!/bin/sh
. $(dirname $0)/functions
. ${_dbc_root}/internal/common
test_dbc_logline(){
local output
# test echoing one line to user and logfile
output=$(dbc_logline foo 2>&1 >/dev/null)
assertTrue "dbc_logline foo returned error" $?
assertEquals foo. "$output"
assertFilesEqual $_dbc_logfile ./data/dbc_logline.simple.txt
# test that a second line is logged appropriately
dbc_logline bar >/dev/null 2>&1
assertFilesEqual $_dbc_logfile ./data/dbc_logline.twolines.txt
# test that multiple arguments are logged appropriately
cat /dev/null > $_dbc_logfile
output=$(dbc_logline foo bar 2>&1 >/dev/null)
assertTrue "dbc_logline foo bar returned error" $?
assertEquals "foo bar." "$output"
assertFilesEqual $_dbc_logfile ./data/dbc_logline.twowords.txt
# assure that quoting and escaping are handled properly
output=$(dbc_logline "\"foobar's\ttab\"" 2>&1 >/dev/null)
assertTrue "dbc_logline (with escaping) returned error" $?
assertEquals "\"foobar's tab\"." "$output"
}
test_dbc_logpart(){
# make sure it properly logs partial lines
dbc_logpart foo >/dev/null 2>&1
assertTrue "dbc_logpart foo returned error" $?
assertFilesEqual $_dbc_logfile ./data/dbc_logpart.noeol.txt
# ...and that it completes them with the next logline.
dbc_logline bar >/dev/null 2>&1
assertFilesEqual $_dbc_logfile ./data/dbc_logline.twowords.txt
}
test_dbc_debug(){
local olddebug
if [ "${dbc_debug:-}" ]; then olddebug=$dbc_debug; else olddebug=""; fi
# make sure it doesn't do anything by default
dbc_debug=""
_dbc_debug foo bar >/dev/null 2>&1
assertTrue "_dbc_debug foo bar returned error" $?
assertFilesEqual $_dbc_logfile /dev/null
# ...and that it completes them with the next logline.
dbc_debug=1
_dbc_debug foo bar >/dev/null 2>&1
assertTrue "_dbc_debug foo bar returned error" $?
assertFilesEqual $_dbc_logfile ./data/dbc_logline.twowords.txt
dbc_debug=$olddebug
}
test_dbc_mktemp(){
local t
# try making a temp file w/out arguments
t=$(dbc_mktemp)
assertTrue "dbc_mktemp (no args) failed" $?
assertTrue "dbc_mktemp (no args) file $t nonexistant" '[ -f "$t" ]'
assertTrue "dbc_mktemp (no args) file $t nonempty" '[ ! -s "$t" ]'
rm -f "$t"
# try making a temp file with arguments
t=$(dbc_mktemp foo.XXXXXX)
assertTrue "dbc_mktemp (no args) failed" $?
assertTrue "dbc_mktemp (no args) file $t nonexistant" '[ -f "$t" ]'
assertTrue "dbc_mktemp (no args) file $t nonempty" '[ ! -s "$t" ]'
rm -f "$t"
}
. /usr/share/shunit2/shunit2
|