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]. Learn how to do LiNP [here].
## Test ## Develop
Clone this repo: Clone this repo:
@ -38,17 +38,15 @@ Enter the repo:
cd literate-pandoc 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: Contribute!
sh scripts/test.sh FORMAT1 FORMAT2
## Acknowledgments ## Acknowledgments

2
dist/linp.lua vendored
View File

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

View File

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

View File

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