X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2Fmisc%2FRegressionTests.java;h=dfe30b63f4f8f85d5893b48d7477fe452f3a06e9;hp=33e17acc82cdadbf1e175d957babd87e5e120c9b;hb=bbb16d2522ed587238fd7a69e346d5e5e8f2551a;hpb=67d5def8fede01f412905fb5ff968b79894166fb diff --git a/src/edu/berkeley/sbp/misc/RegressionTests.java b/src/edu/berkeley/sbp/misc/RegressionTests.java index 33e17ac..dfe30b6 100644 --- a/src/edu/berkeley/sbp/misc/RegressionTests.java +++ b/src/edu/berkeley/sbp/misc/RegressionTests.java @@ -13,7 +13,15 @@ public class RegressionTests { public static boolean yes = false; public static boolean graph = false; - public static File[] includes = new File[] { new File("tests") }; + public static GrammarAST.ImportResolver resolver = new GrammarAST.ImportResolver() { + public InputStream getImportStream(String importname) { + try { + return new FileInputStream("tests/"+importname); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + }; public static void main() throws Exception { main(new String[] { null, "tests/testcase.g", "tests/regression.tc" }); @@ -35,17 +43,31 @@ public class RegressionTests { s = s2; } + CharParser cp; + Tree res; + InputStream metaGrammarStream = s[0] == null ? RegressionTests.class.getClassLoader().getResourceAsStream("edu/berkeley/sbp/meta/meta.g") : new FileInputStream(s[0]); - Tree res = new CharParser(GrammarAST.getMetaGrammar()).parse(metaGrammarStream).expand1(); - Union meta = GrammarAST.buildFromAST(res, "s", includes); + res = new CharParser(GrammarAST.getMetaGrammar()).parse(metaGrammarStream).expand1(); + Union meta = GrammarAST.buildFromAST(res, "s", resolver); + cp = new CharParser(meta); + + System.err.println("serializing grammar to grammar.ser..."); + ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("grammar.ser")); + oos.writeObject(cp); + oos.close(); + + System.err.println("deserializing grammar from grammar.ser..."); + ObjectInputStream ois = new ObjectInputStream(new FileInputStream("grammar.ser")); + cp = (CharParser)ois.readObject(); + ois.close(); System.err.println("parsing " + s[1]); res = new CharParser(meta).parse(new FileInputStream(s[1])).expand1(); - Union testcasegrammar = GrammarAST.buildFromAST(res, "s", includes); + Union testcasegrammar = GrammarAST.buildFromAST(res, "s", resolver); if (testcasegrammar==null) return; CharParser parser = new CharParser(testcasegrammar); @@ -70,13 +92,14 @@ public class RegressionTests { Tree tt = r2.expand1(); for(int i=0; i> results = res==null ? new HashSet>() : res.expand();