Finally test.sh again ready

This commit is contained in:
perro tuerto 2023-03-15 15:12:48 -07:00
parent e7db4df984
commit 30100855cf
4 changed files with 64 additions and 22 deletions

View File

@ -28,7 +28,7 @@ For example, if `DOC` is `source.md` and the output `FORMAT` is HTML, do:
Learn how to do LiNP [here].
## Test
## Develop
Clone this repo:
@ -38,17 +38,15 @@ Enter the repo:
cd literate-pandoc
Inside, do:
Inside, do the tests:
sh scripts/test.sh FORMAT1 FORMAT2
sh scripts/test.sh
For example, if `FORMAT1` is Markdwon and `FORMAT2` is HTML, do:
For other kind of tests, do:
sh tests/test.sh markdown html
sh scripts/test.sh -h
For distribution tests, do:
sh scripts/test.sh FORMAT1 FORMAT2
Contribute!
## Acknowledgments

2
dist/linp.lua vendored
View File

@ -6352,7 +6352,7 @@ return {
if is_chosen(block) then
raw = sanitize(block.content)
doc = lit.parse(raw)
print(doc)
-- print(doc)
end
end,
}

View File

@ -2,13 +2,52 @@
# Variables
FILTER=dist/linp.lua
FILES="tests/*.md"
VERBOSE=false
CMD="sh $0"
# Checks args
if [ -z "$@" ]; then
echo "ERROR: At least one argument is needed. For example:"
echo " sh $0 native"
echo " sh $0 native markdown"
exit 1
# 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 () {
result=$([[ $1 -eq 0 ]] && echo "pass" || echo "fail")
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=$*
fi
# Makes distribution bundle
@ -16,10 +55,15 @@ sh scripts/make_dist.sh
# Does tests
clear && echo "🐾 Starting tests"
for arg in "$@"; do
echo && echo "⚗️ Test in '$arg' format:"
mds=$'\n\n'`(pandoc -t markdown tests/*.md)`
rst=$'\n\n'`(pandoc -t markdown tests/*.rst)`
org=$'\n\n'`(pandoc -t markdown tests/*.org)`
echo "$mds" "$rst" "$org" | pandoc -L $FILTER -t $arg
for testfile in $FILES; do
echo "⚗️ $testfile:"
expectation=${testfile:6:4}
ast=$(pandoc -L $FILTER -t json -o tmp.json $testfile)
result=$(get_result $? $testfile)
echo " Expect: $expectation"
echo " Result: $result"
if [ "$VERBOSE" = true ]; then
pandoc -L $FILTER -t native $testfile
fi
rm tmp.json
done

View File

@ -26,7 +26,7 @@ return {
if is_chosen(block) then
raw = sanitize(block.content)
doc = lit.parse(raw)
print(doc)
-- print(doc)
end
end,
}