chore: Switch to this repository from predecessor
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Glen Whitney 2021-01-30 15:37:53 -08:00
parent 9ecfa63f58
commit 7b00b01856
23 changed files with 733 additions and 32 deletions

36
bin/extract_tests.xsh Normal file
View file

@ -0,0 +1,36 @@
#!/usr/bin/env xonsh
import re
#### Set Parameters
# Should be a list of Path objects:
TEST_LIST = pg`tests/*.spt`
# Should be the top-level directory for all extracted tests:
# (there will be one subdirectory per item in TEST_LIST)
DESTINATION = 'tests/extracted'
# Extension for extracted files:
EXT = 'fos'
# Extension for expectations:
EXP = 'expect'
for path in TEST_LIST:
destdir = pf"{DESTINATION}/{path.stem}"
mkdir -p @(destdir)
contents = path.read_text()
tests = re.split(r'test\s*(.+?)\s*\[\[.*?\n', contents)[1:]
testit = iter(tests)
for name, details in zip(testit, testit):
em = re.search(r'\n\s*\]\]', details)
if not em: continue
example = details[:em.start()+1]
expath = destdir / f"{name}.{EXT}"
expath.write_text(example)
echo Wrote @(expath)
xm = re.search(r'/\*\*\s+writes.*?\n([\s\S]*?)\*\*/', details[em.end():])
if xm:
xpath = destdir / f"{name}.{EXP}"
xpath.write_text(xm[1])
echo " ...and" @(xpath)

71
bin/fosgen Executable file
View file

@ -0,0 +1,71 @@
#!/bin/bash
##### Convenience:
erro() { printf "%s\n" "$*" >&2; }
##### Set defaults:
SUPPRESS_ERR=YES
LANGUAGE=Python
##### Extract command line options:
while [[ $1 = -* ]]
do
case $1 in
-h|--help)
echo
echo "Usage:"
echo " fosgen [-d] [-l LANGUAGE] FILE"
echo
echo "Writes to standard output the code generated from the fostr"
echo "program in FILE, targeting the specified LANGUAGE (which"
echo "defaults to Python)."
echo
echo "The -d option writes diagnostic output to standard error."
exit
;;
-d)
SUPPRESS_ERR=''
;;
-l)
shift
LANGUAGE="$1"
;;
esac
shift
done
##### Get positional arguments:
PROGRAM=$1
##### Corral resources:
BINDIR=$(dirname $BASH_SOURCE)
SUNJAR="$BINDIR/../lib/sunshine.jar"
PROJDIR="$BINDIR/.."
if [[ ! -f $SUNJAR ]]; then
erro "Please download the Spoofax Sunshine jar to the lib directory."
erro "Recommended command:"
erro " curl -o lib/sunshine.jar -L 'http://artifacts.metaborg.org/service/local/artifact/maven/redirect?r=snapshots&g=org.metaborg&a=org.metaborg.sunshine2&v=LATEST'"
exit 1
fi
if [[ ! $MVN_REPO ]]; then
MVN_REPO="$HOME/.m2/repository"
fi
if [[ ! -d $MVN_REPO ]]; then
MVN_REPO="/root/.m2/repository"
fi
if [[ ! -d $MVN_REPO ]]; then
erro "Cannot find your Maven repository. Please set environment variable"
erro "MVN_REPO to its full path and re-run."
exit 1
fi
##### Perform the code generation:
if [[ $SUPPRESS_ERR ]]
then
exec 2>/dev/null
fi
java -jar $SUNJAR transform -p $PROJDIR -l $PROJDIR -l $MVN_REPO -n $LANGUAGE -i $PROGRAM
exit $?

19
bin/generate_test_code Executable file
View file

@ -0,0 +1,19 @@
#!/bin/bash
failed=0
for dir in tests/extracted/*; do
for file in $dir/*.fos; do
for language in Python Javascript Haskell; do
echo bin/fosgen -l ${language%.*} $file ...
bin/fosgen -l $language $file
if [[ $? -ne 0 ]]; then
echo ' ... Failed.'
((failed++))
fi
done
done
done
echo "Code generation completed with $failed failures."
exit $failed

33
bin/run_tests Executable file
View file

@ -0,0 +1,33 @@
#!/bin/bash
command=$1
ext=$2
total=0
failed=0
diffed=0
for dir in tests/extracted/*; do
for file in $dir/*.$ext; do
((total++))
$command $file > $file.out
if [[ $? -ne 0 ]]; then
echo ERROR: $command $file failed.
((failed++))
else
if [[ -f ${file%.*}.expect ]]; then
echo ---- diff ${file%.*}.expect $file.out ----
diff ${file%.*}.expect $file.out
if [[ $? -ne 0 ]]; then
((diffed++))
fi
echo -------------------------------
fi
fi
done
done
echo "Ran $total tests: $failed failures, $diffed runs differed."
if [[ $failed -gt 0 ]] || [[ $diffed -gt 0 ]]; then
exit 1
fi
exit 0