From aa7155d467320656546cbe13a7184656c3253d5a Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 12 Apr 2020 14:44:53 -0400 Subject: [PATCH] Correctly counting test failures --- js/run_compliance_suite.bash | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/js/run_compliance_suite.bash b/js/run_compliance_suite.bash index bcce9ae..aaa94d6 100755 --- a/js/run_compliance_suite.bash +++ b/js/run_compliance_suite.bash @@ -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