Improve test framework

- add assertStdoutLineCount/assertStderrLineCount functions
 - remove spurious "# assert" log output lines
This commit is contained in:
Andrew Bettison 2012-04-12 16:08:18 +09:30
parent 79b3b2a649
commit fab1df61e1
2 changed files with 27 additions and 4 deletions

View File

@ -284,6 +284,14 @@ assertStderrIs() {
_tfw_assert_stdxxx_is stderr "$@" || _tfw_failexit
}
assertStdoutLineCount() {
_tfw_assert_stdxxx_linecount stdout "$@" || _tfw_failexit
}
assertStderrLineCount() {
_tfw_assert_stdxxx_linecount stderr "$@" || _tfw_failexit
}
assertStdoutGrep() {
_tfw_assert_stdxxx_grep stdout "$@" || _tfw_failexit
}
@ -516,7 +524,6 @@ _tfw_eval_awkexpr() {
_tfw_assertExpr() {
local awkexpr=$(_tfw_expr_to_awkexpr "$@")
_tfw_assert _tfw_eval_awkexpr "$awkexpr" || _tfw_failexit
echo "# assert $awkexpr"
}
_tfw_assert_stdxxx_is() {
@ -539,6 +546,22 @@ _tfw_assert_stdxxx_is() {
return 0
}
_tfw_assert_stdxxx_linecount() {
local qual="$1"
shift
_tfw_getopts_assert filecontent --$qual "$@"
shift $((_tfw_getopts_shift - 1))
if [ $# -lt 1 ]; then
_tfw_error "incorrect arguments"
return 254
fi
local lineCount=$(cat $_tfw_tmp/$qual | /usr/bin/wc --lines)
[ -z "$_tfw_message" ] && _tfw_message="$qual line count ($lineCount) $*"
_tfw_assertExpr "$lineCount" "$@" || _tfw_failexit
echo "# assert $_tfw_message"
return 0
}
_tfw_assert_stdxxx_grep() {
local qual="$1"
shift

View File

@ -72,7 +72,7 @@ test_AddThenList() {
execute $dna rhizome list
assertExitStatus --stdout --stderr '==' 0
assertStdoutGrep "^Found 1 rows$"
assertExpr --stdout $(replayStdout | wc --lines) '==' 5
assertStdoutLineCount '==' 6
assertStdoutGrep --matches=1 '^file name = "file1"$'
assertStdoutGrep --matches=0 '^file name = "file2"$'
replayStdout >add1.stdout
@ -82,7 +82,7 @@ test_AddThenList() {
execute $dna rhizome list
assertExitStatus --stdout --stderr '==' 0
assertStdoutGrep "^Found 2 rows$"
assertExpr --stdout $(replayStdout | wc --lines) '==' 9
assertStdoutLineCount '==' 11
assertStdoutGrep --matches=1 '^file name = "file1"$'
assertStdoutGrep --matches=1 '^file name = "file2"$'
}
@ -113,7 +113,7 @@ test_AddDuplicate() {
execute $dna rhizome list
assertExitStatus --stdout --stderr '==' 0
assertStdoutGrep "^Found 2 rows$"
assertExpr --stdout $(replayStdout | wc --lines) '==' 9
assertStdoutLineCount '==' 11
assertStdoutGrep --matches=1 '^file name = "file1"$'
assertStdoutGrep --matches=1 '^file name = "file2"$'
}