forked from GitHub/gf-rgl
Update unittest.py
This commit is contained in:
committed by
Meowyam
parent
d021ebd527
commit
45d47afc36
@@ -9,6 +9,8 @@ python path/to/unittest.py [-h] [-v] [--no-pmcfg] path/to/testfile.gftest (...)
|
|||||||
The script must be located in a sibling directory
|
The script must be located in a sibling directory
|
||||||
to the RGL `src` directory to work properly.
|
to the RGL `src` directory to work properly.
|
||||||
|
|
||||||
|
**Note:** On Windows use WSL (Windows Subsystem for Linux) to run `unittest.py` script, also replace the commented lines for Windows inside the script.
|
||||||
|
|
||||||
## Test format
|
## Test format
|
||||||
|
|
||||||
The test file should look something like this:
|
The test file should look something like this:
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ import argparse
|
|||||||
from subprocess import Popen, PIPE
|
from subprocess import Popen, PIPE
|
||||||
from glob import glob
|
from glob import glob
|
||||||
|
|
||||||
|
GF_PROCESS = 'gf -run'
|
||||||
|
## For WSL on windows replace the GF_PROCESS with following line
|
||||||
|
##GF_PROCESS = 'gf.exe -run'
|
||||||
GRAMMARDIR = '../src'
|
GRAMMARDIR = '../src'
|
||||||
ENCODING = 'utf-8'
|
ENCODING = 'utf-8'
|
||||||
|
|
||||||
@@ -161,7 +164,7 @@ def runtest(testlines, args):
|
|||||||
print()
|
print()
|
||||||
|
|
||||||
# calling GF from a subprocess:
|
# calling GF from a subprocess:
|
||||||
command = 'gf -run'.split()
|
command = GF_PROCESS.split()
|
||||||
gfinput = '\n'.join(gfscript) + '\n'
|
gfinput = '\n'.join(gfscript) + '\n'
|
||||||
gf = Popen(command, stdin=PIPE, stdout=PIPE)
|
gf = Popen(command, stdin=PIPE, stdout=PIPE)
|
||||||
stdout, _stderr = gf.communicate(gfinput.encode(ENCODING))
|
stdout, _stderr = gf.communicate(gfinput.encode(ENCODING))
|
||||||
@@ -182,7 +185,7 @@ def runtest(testlines, args):
|
|||||||
linenr, lang = alltrees.pop(0).split()
|
linenr, lang = alltrees.pop(0).split()
|
||||||
if args.verbose:
|
if args.verbose:
|
||||||
print('---+ line %s (%s), result from GF:' % (linenr, lang))
|
print('---+ line %s (%s), result from GF:' % (linenr, lang))
|
||||||
for tree in alltrees:
|
for tree in alltrees:
|
||||||
print(' |', tree)
|
print(' |', tree)
|
||||||
if len(alltrees) == 0 or gferror("\n".join(alltrees)):
|
if len(alltrees) == 0 or gferror("\n".join(alltrees)):
|
||||||
theerror = "\n".join(alltrees) if alltrees else "No parse trees found"
|
theerror = "\n".join(alltrees) if alltrees else "No parse trees found"
|
||||||
@@ -195,7 +198,7 @@ def runtest(testlines, args):
|
|||||||
if besterrors > 0:
|
if besterrors > 0:
|
||||||
for oldlinenr, oldlang, oldtrees in oldresults:
|
for oldlinenr, oldlang, oldtrees in oldresults:
|
||||||
if besttree not in oldtrees:
|
if besttree not in oldtrees:
|
||||||
error(linenr,
|
error(linenr,
|
||||||
"The result of line %s (%s):\n %s\n"
|
"The result of line %s (%s):\n %s\n"
|
||||||
"is not among the results of line %s (%s):\n %s"
|
"is not among the results of line %s (%s):\n %s"
|
||||||
% (linenr, lang, besttree, oldlinenr, oldlang, "\n ".join(oldtrees)))
|
% (linenr, lang, besttree, oldlinenr, oldlang, "\n ".join(oldtrees)))
|
||||||
|
|||||||
Reference in New Issue
Block a user