Add a script to run a single test to make development easier since I often want to focus on one test at a time.

This commit is contained in:
Tom Alexander 2020-05-17 16:32:16 -04:00
parent 74c83ef374
commit a33b46661e
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 89 additions and 21 deletions

View File

@ -27,27 +27,17 @@ EOF
done
while read -r test_group; do
test_group_name=$(basename "$test_group")
while read -r test_case; do
test_case_file_name=$(basename "$test_case")
test_case_name=${test_case_file_name%.*}
set +e
(
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
echo "$test_group_name::$test_case_name PASSED"
else
echo "$test_group_name::$test_case_name FAILED"
if [ $show_diff -eq 1 ]; then
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 )
fi
exit 1
fi
)
if [ $? -ne 0 ]; then
failed_count=$((failed_count + 1))
fi
set -e
done <<<"$(find "$test_group" -maxdepth 1 -mindepth 1 -type f -name '*.json' | sort)"
set +e
if [ $show_diff -eq 1 ]; then
"$DIR/run_single_test.bash" --show-diff "$test_group"
else
"$DIR/run_single_test.bash" --show-diff "$test_group"
fi
result=$?
if [ $result -ne 0 ]; then
failed_count=$((failed_count + result))
fi
set -e
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)

78
js/run_single_test.bash Executable file
View File

@ -0,0 +1,78 @@
#!/usr/bin/env bash
#
# Runs a single test against LinkedIn DustJS and duster to compare the result
set -euo pipefail
IFS=$'\n\t'
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
test_group=""
test_mode=""
function show_help {
cat<<EOF
Runs a single test from the compliance test suite.
Usage: run_single_test.bash [options] <path_to_test_folder>
Options:
--show-diff Shows the difference between the two dust implementations
--dustjs Print the output of dustjs instead of comparing
--duster Print the output of duster instead of comparing
EOF
}
while (( "$#" )); do
if [ "$1" = "--help" ]; then
show_help
exit 0
elif [ "$1" = "--show-diff" ]; then
show_diff=1
elif [ "$1" = "--dustjs" ]; then
test_mode="dustjs"
elif [ "$1" = "--duster" ]; then
test_mode="duster"
elif [ ! "$1" = -* ]; then
test_group="$1"
else
(>&2 echo "Unrecognized option: $1")
exit 1
fi
shift
done
# Assert a test group was specified
if [ "$test_group" = "" ]; then
show_help
exit 1
fi
failed_count=0
test_group_name=$(basename "$test_group")
while read -r test_case; do
test_case_file_name=$(basename "$test_case")
test_case_name=${test_case_file_name%.*}
set +e
if [ "$test_mode" = "dustjs" ]; then
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"
elif [ "$test_mode" = "duster" ]; then
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"
else
(
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
echo "$test_group_name::$test_case_name PASSED"
else
echo "$test_group_name::$test_case_name FAILED"
if [ $show_diff -eq 1 ]; then
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 )
fi
exit 1
fi
)
if [ $? -ne 0 ]; then
failed_count=$((failed_count + 1))
fi
fi
set -e
done <<<"$(find "$test_group" -maxdepth 1 -mindepth 1 -type f -name '*.json' | sort)"
exit "$failed_count"