From 486e13c28b216b7917a2d75789b34956c4c105fe Mon Sep 17 00:00:00 2001 From: jdf Date: Thu, 18 Mar 2010 02:30:23 +0000 Subject: [PATCH] Test-sicles --- app/test/resources/bug763.pde | 8 +++++ app/test/resources/bug820.pde | 2 ++ .../test/processing/parsing/ParserTests.java | 36 +++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 app/test/resources/bug763.pde create mode 100644 app/test/resources/bug820.pde diff --git a/app/test/resources/bug763.pde b/app/test/resources/bug763.pde new file mode 100644 index 000000000..fca102749 --- /dev/null +++ b/app/test/resources/bug763.pde @@ -0,0 +1,8 @@ +void setup() +{ +} + +void draw() +{ + println("i am a bug...); +} \ No newline at end of file diff --git a/app/test/resources/bug820.pde b/app/test/resources/bug820.pde new file mode 100644 index 000000000..4dce2709b --- /dev/null +++ b/app/test/resources/bug820.pde @@ -0,0 +1,2 @@ +float x1 = 0; +float x1 = 2; diff --git a/app/test/src/test/processing/parsing/ParserTests.java b/app/test/src/test/processing/parsing/ParserTests.java index 96d1b8213..9090a9361 100644 --- a/app/test/src/test/processing/parsing/ParserTests.java +++ b/app/test/src/test/processing/parsing/ParserTests.java @@ -7,6 +7,8 @@ import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.StringWriter; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.junit.BeforeClass; import org.junit.Test; import processing.app.Base; @@ -102,6 +104,30 @@ public class ParserTests { } } + static void expectCompilerException(final String id, + final String expectedMessage, + final int expectedLine) { + try { + final String program = preprocess(id, res(id + ".pde")); + final ProcessResult compilerResult = COMPILER.compile(id, program); + if (compilerResult.succeeded()) { + fail("Expected to fail with \"" + expectedMessage + "\" on line " + + expectedLine); + } + final String e = compilerResult.getStderr().split("\n")[0]; + System.err.println(e); + final Matcher m = Pattern.compile(":(\\d+):\\s+(.+)$").matcher(e); + m.find(); + assertEquals(expectedMessage, m.group(2)); + assertEquals(String.valueOf(expectedLine), m.group(1)); + } catch (Exception e) { + if (!e.equals(e.getCause()) && e.getCause() != null) + fail(e.getCause().toString()); + else + fail(e.toString()); + } + } + static void expectGood(final String id) { try { final String program = preprocess(id, res(id + ".pde")); @@ -188,6 +214,16 @@ public class ParserTests { expectGood("bug631"); } + @Test + public void bug763() { + expectRunnerException("bug763", "Unterminated string constant", 6); + } + + @Test + public void bug820() { + expectCompilerException("bug820", "x1 is already defined in setup()", 21); + } + @Test public void bug1511() { expectGood("bug1511");