2021-01-30 23:37:53 +00:00
|
|
|
#!/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)
|
2021-03-01 18:39:18 +00:00
|
|
|
chmod ugo+rwx @(destdir)
|
2021-01-30 23:37:53 +00:00
|
|
|
contents = path.read_text()
|
|
|
|
tests = re.split(r'test\s*(.+?)\s*\[\[.*?\n', contents)[1:]
|
|
|
|
testit = iter(tests)
|
|
|
|
for name, details in zip(testit, testit):
|
2021-02-10 20:47:34 +00:00
|
|
|
pfm = re.search(r'\n\s*\]\][\s\S]*?parse\s*fails', details)
|
|
|
|
if pfm: continue # skip examples that don't parse
|
|
|
|
ntfm = re.search(r'\n\s*\]\].*?don.t.test', details)
|
|
|
|
if ntfm: continue # explicit skip
|
2021-02-18 04:17:05 +00:00
|
|
|
em = re.search(r'\n\]\]', details)
|
2021-01-30 23:37:53 +00:00
|
|
|
if not em: continue
|
2021-02-18 04:17:05 +00:00
|
|
|
example = details[:em.start()+1].replace('[[','').replace(']]','')
|
2021-01-30 23:37:53 +00:00
|
|
|
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)
|