got bild to gen java tests (others commented out) and run those tests. rm'd .stg map in Index.stg.

This commit is contained in:
parrt 2015-06-02 11:40:19 -07:00
parent 07aea10ca7
commit fafc7722c8
4 changed files with 66 additions and 61 deletions

25
bild.py
View File

@ -65,6 +65,19 @@ TARGETS = OrderedDict([
("JavaScript",uniformpath(JAVASCRIPT_TARGET))
])
# Base templates specific to targets needed by tests in TestFolders
RUNTIME_TEST_TEMPLATES = {
"Java" : uniformpath(JAVA_TARGET)+"/tool/test/org/antlr/v4/test/runtime/java/Java.test.stg",
# "CSharp" : uniformpath(CSHARP_TARGET)+"/tool/test/org/antlr/v4/test/rt/csharp/CSharp.test.stg",
# "Python2" : uniformpath(PYTHON2_TARGET)+"/tool/test/org/antlr/v4/test/rt/py2/Python2.test.stg",
# "Python3" : uniformpath(PYTHON3_TARGET)+"/tool/test/org/antlr/v4/test/rt/py3/Python3.test.stg",
# "NodeJS" : uniformpath(JAVASCRIPT_TARGET)+"/tool/test/org/antlr/v4/test/rt/js/node/NodeJS.test.stg",
# "Safari" : uniformpath(JAVASCRIPT_TARGET)+"/tool/test/org/antlr/v4/test/rt/js/safari/Safari.test.stg",
# "Firefox" : uniformpath(JAVASCRIPT_TARGET)+"/tool/test/org/antlr/v4/test/rt/js/firefox/Firefox.test.stg",
# "Chrome" : uniformpath(JAVASCRIPT_TARGET)+"/tool/test/org/antlr/v4/test/rt/js/chrome/Chrome.test.stg",
# "Explorer" : uniformpath(JAVASCRIPT_TARGET)+"/tool/test/org/antlr/v4/test/rt/js/explorer/Explorer.test.stg"
}
def parsers():
antlr3("tool/src/org/antlr/v4/parse", "gen3", version="3.5.2", package="org.antlr.v4.parse")
@ -247,7 +260,10 @@ def regen_tests():
+ os.pathsep + hamcrest_jar
args = ["-nowarn", "-Xlint", "-Xlint:-serial", "-g"]
javac("tool/test", "out/test", version="1.6", cp=cp, args=args) # all targets can use org.antlr.v4.test.*
java(classname="org.antlr.v4.test.rt.gen.Generator", cp="out/test:dist/antlr4-"+VERSION+"-complete.jar")
for targetTemplate in RUNTIME_TEST_TEMPLATES:
java(classname="org.antlr.v4.testgen.TestGenerator", cp="out/test:dist/antlr4-"+VERSION+"-complete.jar",
progargs=['-o', 'gen/test', '-templates', RUNTIME_TEST_TEMPLATES[targetTemplate]])
javac("gen/test", "out/test", version="1.6", cp=cp, args=args) # compile generated runtime tests
print_and_log("test generation complete")
@ -279,8 +295,7 @@ def test_javascript():
def test_target(t):
require(regen_tests)
cp = uniformpath("dist/antlr4-" + VERSION + "-complete.jar") \
+ os.pathsep + uniformpath("out/test")
cp = uniformpath("out/test") + os.pathsep + uniformpath("dist/antlr4-" + VERSION + "-complete.jar")
juprops = ["-D%s=%s" % (p, test_properties[p]) for p in test_properties]
args = ["-nowarn", "-Xlint", "-Xlint:-serial", "-g"]
print_and_log("Testing %s ..." % t)
@ -293,7 +308,7 @@ def test_target(t):
def test(t, cp, juprops, args):
junit_jar, hamcrest_jar = load_junitjars()
srcdir = uniformpath(TARGETS[t] + "/tool/test")
srcdir = uniformpath('gen')
dstdir = uniformpath( "out/test/" + t)
# Prefix CLASSPATH with individual target tests
thiscp = dstdir + os.pathsep + cp
@ -309,7 +324,7 @@ def test(t, cp, juprops, args):
javac(base, "out/test/" + t, version="1.6", cp=thisjarwithjunit, args=args, skip=skip)
skip = []
elif t=='JavaScript':
# don't test browsers automatically, this is overkilling and unreliable
# don't test browsers automatically, this is overkill and unreliable
browsers = ["safari","chrome","firefox","explorer"]
skip = [ uniformpath(srcdir + "/org/antlr/v4/test/rt/js/" + b) for b in browsers ]
javac(srcdir, trgdir="out/test/" + t, version="1.6", cp=thisjarwithjunit, args=args, skip=skip)

View File

@ -13,16 +13,3 @@ TestFolders ::= [
"SemPredEvalParser": [],
"Sets": []
]
/** Base templates specific to targets needed by tests in TestFolders */
Targets ::= [
"Java" : "./tool/test/org/antlr/v4/test/runtime/java/Java.test.stg",
"CSharp" : "../antlr4-csharp/tool/test/org/antlr/v4/test/rt/csharp/CSharp.test.stg",
"Python2" : "../antlr4-python2/tool/test/org/antlr/v4/test/rt/py2/Python2.test.stg",
"Python3" : "../antlr4-python3/tool/test/org/antlr/v4/test/rt/py3/Python3.test.stg",
"NodeJS" : "../antlr4-javascript/tool/test/org/antlr/v4/test/rt/js/node/NodeJS.test.stg",
"Safari" : "../antlr4-javascript/tool/test/org/antlr/v4/test/rt/js/safari/Safari.test.stg",
"Firefox" : "../antlr4-javascript/tool/test/org/antlr/v4/test/rt/js/firefox/Firefox.test.stg",
"Chrome" : "../antlr4-javascript/tool/test/org/antlr/v4/test/rt/js/chrome/Chrome.test.stg",
"Explorer" : "../antlr4-javascript/tool/test/org/antlr/v4/test/rt/js/explorer/Explorer.test.stg"
]

View File

@ -57,30 +57,31 @@ public class TestGenerator {
protected final boolean visualize;
public static final String mainTestIndex = "org/antlr4/runtime/test/templates/Index.stg";
/** Execute from antlr4 root dir:
* *
* $ java TestGenerator -o output-root-dir -target (Java|Python2|Python3|Javascript|CSharp) -viz
* $ java TestGenerator -o output-root-dir # gen all targets
* $ java TestGenerator -o output-root-dir -templates -viz
*
* Examples:
* Example:
*
* $ java TestGenerator -o /tmp # gen all targets in /tmp
* $ java TestGenerator -o /Users/parrt/antlr/code/antlr4/tool/test -target Java
*
* Gives:
*
* Generating target Java
* Generate file /tmp/org/antlr4/runtime/test/templates/SemPredEvalParser/TestSemPredEvalParser.java
* Generate file /tmp/org/antlr4/runtime/test/templates/LexerErrors/TestLexerErrors.java
* Generate file /tmp/org/antlr4/runtime/test/templates/CompositeParsers/TestCompositeParsers.java
* ...
* $ java org.antlr.v4.testgen.TestGenerator -o /tmp -templates ../antlr4-python2/tool/test/org/antlr/v4/test/rt/py2/Python2.test.stg
Generating target Python2
Generating file /tmp/org/antlr4/runtime/test/python2/TestSemPredEvalParser.java
Generating file /tmp/org/antlr4/runtime/test/python2/TestLexerErrors.java
Generating file /tmp/org/antlr4/runtime/test/python2/TestCompositeParsers.java
Generating file /tmp/org/antlr4/runtime/test/python2/TestListeners.java
Generating file /tmp/org/antlr4/runtime/test/python2/TestLeftRecursion.java
Generating file /tmp/org/antlr4/runtime/test/python2/TestParserErrors.java
Generating file /tmp/org/antlr4/runtime/test/python2/TestCompositeLexers.java
Generating file /tmp/org/antlr4/runtime/test/python2/TestSets.java
Generating file /tmp/org/antlr4/runtime/test/python2/TestParserExec.java
Generating file /tmp/org/antlr4/runtime/test/python2/TestLexerExec.java
Generating file /tmp/org/antlr4/runtime/test/python2/TestFullContextParsing.java
Generating file /tmp/org/antlr4/runtime/test/python2/TestSemPredEvalLexer.java
Generating file /tmp/org/antlr4/runtime/test/python2/TestParseTrees.java
*/
public static void main(String[] args) {
String outDir = null;
String targetSpecificTemplateFile;
String target = null;
String targetSpecificTemplateFile = null;
boolean viz = false;
int i = 0;
@ -90,9 +91,9 @@ public class TestGenerator {
i++;
outDir = args[i];
}
else if (arg.startsWith("-target")) {
else if (arg.startsWith("-templates")) {
i++;
target = args[i];
targetSpecificTemplateFile = args[i];
}
else if (arg.startsWith("-viz")) {
viz = true;
@ -100,27 +101,15 @@ public class TestGenerator {
i++;
}
if ( outDir==null ) {
System.err.println("You must give an output root dir");
if ( outDir==null || targetSpecificTemplateFile==null ) {
System.err.println("You must give an output root dir and templates file");
System.exit(1);
}
STGroup index = new STGroupFile(antlrRoot+"/runtime-testsuite/resources/"+mainTestIndex);
index.load();
Map<String, Object> folders = index.rawGetDictionary("Targets"); // get map target to .stg file
if ( target!=null ) {
targetSpecificTemplateFile = (String)folders.get(target);
genTarget(target, outDir, targetSpecificTemplateFile, viz);
}
else { // do all targets
for (String t : folders.keySet()) {
targetSpecificTemplateFile = (String)folders.get(t);
genTarget(t, outDir, targetSpecificTemplateFile, viz);
}
}
genTarget(outDir, targetSpecificTemplateFile, viz);
}
public static void genTarget(final String targetName, String outDir, String targetSpecificTemplateFile, boolean viz) {
public static void genTarget(final String outDir, String targetSpecificTemplateFile, boolean viz) {
TestGenerator gen = new TestGenerator("UTF-8",
new File(targetSpecificTemplateFile),
new File(outDir),
@ -132,11 +121,17 @@ public class TestGenerator {
}
@Override
public File getOutputDir(String templateFolder) {
String targetName = getTargetNameFromTemplatesFileName();
// compute package
int packageStart = templateFolder.indexOf("org/antlr4/runtime/test/templates");
return new File(new File(outputDirectory,targetName), templateFolder.substring(packageStart));
int templatesStart = templateFolder.indexOf("/templates");
String packageDir = templateFolder.substring(packageStart,templatesStart);
File root = outputDirectory;
File f = new File(root, packageDir);
return new File(f, targetName.toLowerCase());
}
};
gen.info("Generating target " + targetName);
gen.info("Generating target " + gen.getTargetNameFromTemplatesFileName());
gen.execute();
}
@ -181,7 +176,7 @@ public class TestGenerator {
private void generateTestFile(STGroup index, STGroup targetGroup, String testFile, String templateFolder, Collection<String> testTemplates) {
File targetFolder = getOutputDir(templateFolder);
File targetFile = new File(targetFolder, "Test" + testFile + ".java");
info("Generate file "+targetFile.getAbsolutePath());
info("Generating file "+targetFile.getAbsolutePath());
List<ST> templates = new ArrayList<ST>();
for (String template : testTemplates) {
STGroup testGroup = new STGroupFile(templateFolder + "/" + template + STGroup.GROUP_FILE_EXTENSION);
@ -256,6 +251,14 @@ public class TestGenerator {
}
}
public String getTargetNameFromTemplatesFileName() {
// runtimeTemplates is like ../antlr4-python2/tool/test/org/antlr/v4/test/rt/py2/Python2.test.stg
// extra target name
int targetEnd = runtimeTemplates.getPath().indexOf(".test.stg");
String targetAtEnd = runtimeTemplates.getPath().substring(0, targetEnd);
return targetAtEnd.substring(targetAtEnd.lastIndexOf('/') + 1);
}
public File getOutputDir(String templateFolder) {
return new File(outputDirectory, templateFolder.substring(0, templateFolder.indexOf("/templates")));
}

View File

@ -1,5 +1,5 @@
TestFile(file) ::= <<
package org.antlr4.runtime.test;
package org.antlr4.runtime.test.java;
import org.antlr.v4.test.rt.java.BaseTest;
import org.junit.Test;
@ -326,7 +326,7 @@ walker.walk(new LeafListener(), <s>);
TokenGetterListener(X) ::= <<
public static class LeafListener extends TBaseListener {
public void exitA(TParser.AContext ctx) {
if (ctx.getChildCount()==2)
if (ctx.getChildCount()==2)
System.out.printf("%s %s %s",ctx.INT(0).getSymbol().getText(),
ctx.INT(1).getSymbol().getText(),ctx.INT());
else
@ -341,7 +341,7 @@ public static class LeafListener extends TBaseListener {
if (ctx.getChildCount()==2) {
System.out.printf("%s %s %s",ctx.b(0).start.getText(),
ctx.b(1).start.getText(),ctx.b().get(0).start.getText());
} else
} else
System.out.println(ctx.b(0).start.getText());
}
}
@ -354,7 +354,7 @@ public static class LeafListener extends TBaseListener {
if (ctx.getChildCount()==3) {
System.out.printf("%s %s %s\n",ctx.e(0).start.getText(),
ctx.e(1).start.getText(), ctx.e().get(0).start.getText());
} else
} else
System.out.println(ctx.INT().getSymbol().getText());
}
}
@ -380,7 +380,7 @@ void foo() {
>>
Declare_foo() ::= <<public void foo() {System.out.println("foo");}>>
Invoke_foo() ::= "this.foo();"
Declare_pred() ::= <<boolean pred(boolean v) {