Correctly counting test failures

This commit is contained in:
Tom Alexander 2020-04-12 14:44:53 -04:00
parent db575d145e
commit aa7155d467
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -1,34 +1,37 @@
#!/usr/bin/env bash
#
# Runs the full suite of tests against LinkedIn DustJS and duster to compare the result
set -uo pipefail
set -euo pipefail
IFS=$'\n\t'
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
failed_count=0
find "$DIR/test_cases" -maxdepth 1 -mindepth 1 -type d | sort | while read test_group; do
failed_count_in_group=0
while read -r test_group; do
test_group_name=$(basename "$test_group")
find "$test_group" -maxdepth 1 -mindepth 1 -type f -name '*.json' | sort | while read test_case; do
failed_count_in_testcase=0
while read -r test_case; do
test_case_file_name=$(basename "$test_case")
test_case_name=${test_case_file_name%.*}
set +e
(
if cmp --quiet <(xargs -a <(find "$test_group" -maxdepth 1 -mindepth 1 -type f -name 'main.dust'; find "$test_group" -maxdepth 1 -mindepth 1 -type f -name '*.dust' ! -name 'main.dust') node dustjs_shim.js < "$test_case") <(xargs -a <(find "$test_group" -maxdepth 1 -mindepth 1 -type f -name 'main.dust'; find "$test_group" -maxdepth 1 -mindepth 1 -type f -name '*.dust' ! -name 'main.dust') ../target/debug/duster-cli < "$test_case"); then
if cmp --quiet <(xargs -a <(find "$test_group" -maxdepth 1 -mindepth 1 -type f -name 'main.dust'; find "$test_group" -maxdepth 1 -mindepth 1 -type f -name '*.dust' ! -name 'main.dust') node "$DIR/dustjs_shim.js" < "$test_case") <(xargs -a <(find "$test_group" -maxdepth 1 -mindepth 1 -type f -name 'main.dust'; find "$test_group" -maxdepth 1 -mindepth 1 -type f -name '*.dust' ! -name 'main.dust') "$DIR/../target/debug/duster-cli" < "$test_case"); then
echo "$test_group_name::$test_case_name PASSED"
else
echo "$test_group_name::$test_case_name FAILED"
diff <(xargs -a <(find "$test_group" -maxdepth 1 -mindepth 1 -type f -name 'main.dust'; find "$test_group" -maxdepth 1 -mindepth 1 -type f -name '*.dust' ! -name 'main.dust') node dustjs_shim.js < "$test_case") <(xargs -a <(find "$test_group" -maxdepth 1 -mindepth 1 -type f -name 'main.dust'; find "$test_group" -maxdepth 1 -mindepth 1 -type f -name '*.dust' ! -name 'main.dust') ../target/debug/duster-cli < "$test_case")
diff <(xargs -a <(find "$test_group" -maxdepth 1 -mindepth 1 -type f -name 'main.dust'; find "$test_group" -maxdepth 1 -mindepth 1 -type f -name '*.dust' ! -name 'main.dust') node "$DIR/dustjs_shim.js" < "$test_case") <(xargs -a <(find "$test_group" -maxdepth 1 -mindepth 1 -type f -name 'main.dust'; find "$test_group" -maxdepth 1 -mindepth 1 -type f -name '*.dust' ! -name 'main.dust') "$DIR/../target/debug/duster-cli" < "$test_case")
exit 1
fi
)
if [ $? -ne 0 ]; then
failed_count_in_testcase=$((failed_count_in_testcase + 1))
failed_count=$((failed_count + 1))
fi
echo "testcase failed $failed_count_in_testcase"
done
echo "group failed: $failed_count_in_group"
done
set -e
done <<<"$(find "$test_group" -maxdepth 1 -mindepth 1 -type f -name '*.json' | sort)"
done <<<"$(find "$DIR/test_cases" -maxdepth 1 -mindepth 1 -type d | sort)"
echo "total failed $failed_count"
if [ $failed_count -ne 0 ]; then
echo "$failed_count failed tests"
exit 1
else
echo "All tests passed"
fi