test-queries: can debug a testcase

`tests/test-queries regex` filters the test cases.

If the resulting set has only one test case, run it under gdb.
This commit is contained in:
Colin Dellow 2018-03-10 11:54:36 -05:00
parent 210f322a1c
commit b7c134efc0
2 changed files with 32 additions and 11 deletions

3
.gitignore vendored
View File

@ -42,3 +42,6 @@
/testcase-out.txt /testcase-out.txt
/testcase-stdout.txt /testcase-stdout.txt
/testcase-stderr.txt /testcase-stderr.txt
/testcase-expected.txt
/testcase-cmds.txt
/testcases.txt

View File

@ -24,18 +24,36 @@ main() {
root=$(readlink -f "$root") root=$(readlink -f "$root")
cd "$root" cd "$root"
queries=$(find tests/queries -type f -name '*.sql' | sort) find_cmd=(find tests/queries -type f -name '*.sql')
while read -r file; do debug=0
echo "Testing: $file" if [ -n "${1:-""}" ]; then
query=$(head -n1 "$file" | tail -n1) find_cmd+=(-regex ".*$1.*")
results=$(tail -n+2 "$file") debug=1
if ! "$root"/sqlite/sqlite3 -init <(run_query "$file" "$query") < /dev/null > testcase-stdout.txt 2> testcase-stderr.txt; then fi
echo "...FAILED; check testcase-{out,err}.txt" >&2
exit 1
fi
diff testcase-out.txt <(echo "$results") "${find_cmd[@]}" | sort > testcases.txt
done < <(echo "$queries")
if [ ! -s testcases.txt ]; then
echo "no matching testcases found"
exit 1
fi
if [ "$(cat testcases.txt | wc -l)" == "1" ]; then
gdb -ex run --args "$root"/sqlite/sqlite3 -init testcase-cmds.txt
else
while read -r file; do
echo "Testing: $file"
query=$(head -n1 "$file" | tail -n1)
tail -n+2 "$file" > testcase-expected.txt
run_query "$file" "$query" > testcase-cmds.txt
if ! "$root"/sqlite/sqlite3 -init testcase-cmds.txt < /dev/null > testcase-stdout.txt 2> testcase-stderr.txt; then
echo "...FAILED; check testcase-{out,err}.txt" >&2
exit 1
fi
diff testcase-out.txt testcase-expected.txt
done < testcases.txt
fi
} }
main "$@" main "$@"