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