2020-04-12 18:37:54 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
|
|
|
# Runs the full suite of tests against LinkedIn DustJS and duster to compare the result
|
2020-04-12 18:44:53 +00:00
|
|
|
set -euo pipefail
|
2020-04-12 18:37:54 +00:00
|
|
|
IFS=$'\n\t'
|
|
|
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
|
|
|
|
failed_count=0
|
2020-04-12 19:24:38 +00:00
|
|
|
show_diff=0
|
|
|
|
|
|
|
|
while (( "$#" )); do
|
|
|
|
if [ "$1" = "--help" ]; then
|
|
|
|
cat<<EOF
|
|
|
|
Runs the full compliance test suite.
|
|
|
|
|
|
|
|
Options:
|
|
|
|
--show-diff Shows the difference between the two dust implementations
|
|
|
|
EOF
|
|
|
|
exit 0
|
|
|
|
elif [ "$1" = "--show-diff" ]; then
|
|
|
|
show_diff=1
|
|
|
|
else
|
|
|
|
(>&2 echo "Unrecognized option: $1")
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
shift
|
|
|
|
done
|
2020-04-12 18:37:54 +00:00
|
|
|
|
2020-04-12 18:44:53 +00:00
|
|
|
while read -r test_group; do
|
2020-04-12 18:37:54 +00:00
|
|
|
test_group_name=$(basename "$test_group")
|
2020-04-12 18:44:53 +00:00
|
|
|
while read -r test_case; do
|
2020-04-12 18:37:54 +00:00
|
|
|
test_case_file_name=$(basename "$test_case")
|
|
|
|
test_case_name=${test_case_file_name%.*}
|
2020-04-12 18:44:53 +00:00
|
|
|
set +e
|
2020-04-12 18:37:54 +00:00
|
|
|
(
|
2020-05-09 19:59:33 +00:00
|
|
|
if cmp -s <(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' | sort) 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' | sort) "$DIR/../target/debug/duster-cli" < "$test_case"); then
|
2020-04-12 18:37:54 +00:00
|
|
|
echo "$test_group_name::$test_case_name PASSED"
|
|
|
|
else
|
|
|
|
echo "$test_group_name::$test_case_name FAILED"
|
2020-04-12 19:24:38 +00:00
|
|
|
if [ $show_diff -eq 1 ]; then
|
2020-05-16 19:22:48 +00:00
|
|
|
diff --label "dustjs-linkedin" --label "duster" <(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' | sort) node "$DIR/dustjs_shim.js" < "$test_case" 2>/dev/null ) <(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' | sort) "$DIR/../target/debug/duster-cli" < "$test_case" 2>/dev/null )
|
2020-04-12 19:24:38 +00:00
|
|
|
fi
|
2020-04-12 18:37:54 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
)
|
|
|
|
if [ $? -ne 0 ]; then
|
2020-04-12 18:44:53 +00:00
|
|
|
failed_count=$((failed_count + 1))
|
2020-04-12 18:37:54 +00:00
|
|
|
fi
|
2020-04-12 18:44:53 +00:00
|
|
|
set -e
|
|
|
|
done <<<"$(find "$test_group" -maxdepth 1 -mindepth 1 -type f -name '*.json' | sort)"
|
2020-05-16 20:46:39 +00:00
|
|
|
done <<<"$(find "$DIR/test_cases" -maxdepth 1 -mindepth 1 -type d ! -name '_*' | sort)"
|
|
|
|
|
|
|
|
ignored_count=$(find "$DIR/test_cases" -maxdepth 1 -mindepth 1 -type d -name '_*' | wc -l)
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo "$ignored_count ignored tests"
|
2020-04-12 18:37:54 +00:00
|
|
|
|
2020-04-12 18:44:53 +00:00
|
|
|
if [ $failed_count -ne 0 ]; then
|
|
|
|
echo "$failed_count failed tests"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo "All tests passed"
|
|
|
|
fi
|