computable-pandoc/scripts/test.sh

70 lines
1.6 KiB
Bash
Raw Normal View History

2023-03-09 15:58:14 -06:00
# Makes tests
2023-02-16 19:04:01 -06:00
# Variables
2023-03-16 09:52:04 -06:00
FILTER=dist/lin.lua
2023-03-15 16:12:48 -06:00
FILES="tests/*.md"
VERBOSE=false
CMD="sh $0"
2023-02-16 19:04:01 -06:00
2023-03-15 16:12:48 -06:00
# Prints help
echo_help () {
echo "Usage:"
echo " $CMD [-vh] [FILES]"
echo "Examples:"
echo " $CMD Tests with 'tests/*.md'"
echo " $CMD -v Verbose tests with 'tests/*.md'"
echo " $CMD tests/fail* Tests with 'tests/fail*'"
echo " $CMD -v tests/fail* Verbose tests with 'tests/fail*'"
echo " $CMD -h Display this help"
exit
}
# Obtains result as "pass" | "fail" | "diff" (AST doesn't match)
get_result () {
2023-03-15 17:33:53 -06:00
result=$([[ $1 -ne 0 ]] && echo "fail" || echo "pass")
2023-03-15 16:12:48 -06:00
if [ -f $2.json ]; then
diff1=$(cat tmp.json | jq)
diff2=$(cat $2.json | jq)
difference=$(diff <( printf '%s\n' "$diff1" ) <( printf '%s\n' "$diff2" ))
result=$([[ $? -eq 0 ]] && echo "pass" || echo "diff")
fi
echo $result
}
# Checks options
while getopts ':vh' opt; do
case "$opt" in
v) VERBOSE=true ; shift ;;
h) echo_help ;;
?) echo "ERROR: only -v or -h is allowed" ; exit 1 ;;
esac
done
# Checks for files
if [ $# -ne 0 ]; then
for file in $*; do
if [ ! -f $file ]; then
echo "ERROR: '$file' is not a file; do '$CMD -h' for more info" ; exit 1
fi
done
FILES=$*
2023-02-16 19:04:01 -06:00
fi
2023-03-11 14:14:24 -06:00
# Makes distribution bundle
sh scripts/make_dist.sh
2023-02-16 19:04:01 -06:00
# Does tests
2023-03-10 21:09:31 -06:00
clear && echo "🐾 Starting tests"
2023-03-15 17:33:53 -06:00
for file in $FILES; do
echo "⚗️ $file:"
expectation=${file:6:4}
ast=$(pandoc -L $FILTER -t json -o tmp.json $file)
result=$(get_result $? $file)
2023-03-15 16:12:48 -06:00
echo " Expect: $expectation"
echo " Result: $result"
if [ "$VERBOSE" = true ]; then
2023-03-15 17:33:53 -06:00
pandoc -L $FILTER -t native $file
2023-03-15 16:12:48 -06:00
fi
rm tmp.json
2023-02-16 19:04:01 -06:00
done