diff options
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/org/anarres/cpp/ErrorTestCase.java | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/tests/org/anarres/cpp/ErrorTestCase.java b/src/tests/org/anarres/cpp/ErrorTestCase.java index d5d44a3..d7d01e8 100644 --- a/src/tests/org/anarres/cpp/ErrorTestCase.java +++ b/src/tests/org/anarres/cpp/ErrorTestCase.java @@ -8,13 +8,15 @@ import static org.anarres.cpp.Token.*; public class ErrorTestCase extends BaseTestCase { - private void testError(Source source) + private void testError(Preprocessor p) throws LexerException, IOException { for (;;) { - Token tok = source.token(); + Token tok = p.token(); if (tok.getType() == EOF) break; + else if (tok.getType() == ERROR) + throw new LexerException("Error token: " + tok); } } @@ -22,12 +24,15 @@ public class ErrorTestCase extends BaseTestCase { private void testError(String input) throws Exception { StringLexerSource sl; PreprocessorListener pl; + Preprocessor p; /* Without a PreprocessorListener, throws an exception. */ sl = new StringLexerSource(input, true); + p = new Preprocessor(); + p.addInput(sl); try { - testError(sl); - fail("Lexing succeeded"); + testError(p); + fail("Lexing succeeded unexpectedly on " + input); } catch (LexerException e) { /* ignored */ @@ -35,10 +40,13 @@ public class ErrorTestCase extends BaseTestCase { /* With a PreprocessorListener, records the error. */ sl = new StringLexerSource(input, true); + p = new Preprocessor(); + p.addInput(sl); pl = new PreprocessorListener(); - sl.setListener(pl); - testError(sl); - assertTrue(pl.getErrors() > 0); + p.setListener(pl); + assertNotNull("CPP has listener", p.getListener()); + testError(p); + assertTrue("Listener has errors", pl.getErrors() > 0); } public void testErrors() throws Exception { |