diff options
author | Benoit Lamarche <benoitlamarche@google.com> | 2014-09-24 15:37:54 +0200 |
---|---|---|
committer | Benoit Lamarche <benoitlamarche@google.com> | 2014-10-23 15:58:13 +0200 |
commit | f55223a6f9ffb7152dbe5c01277151a1ed4b9a88 (patch) | |
tree | df96994d21059304ff2b9b169764190e78754ba1 /jack/tests | |
parent | dee2472546a6570f51cea4b0334bbfdcca392498 (diff) | |
download | toolchain_jack-f55223a6f9ffb7152dbe5c01277151a1ed4b9a88.zip toolchain_jack-f55223a6f9ffb7152dbe5c01277151a1ed4b9a88.tar.gz toolchain_jack-f55223a6f9ffb7152dbe5c01277151a1ed4b9a88.tar.bz2 |
Reporting ECJ errors
It fixes a bug where ECJ prints a bad message when a type is missing
Bug: 15249619
Change-Id: If3c48f0e87811408484fb2c1e90557d6546f27a0
Diffstat (limited to 'jack/tests')
3 files changed, 184 insertions, 9 deletions
diff --git a/jack/tests/com/android/jack/errorhandling/CommandLineErrorTest.java b/jack/tests/com/android/jack/errorhandling/CommandLineErrorTest.java index aa000f9..871bd4e 100644 --- a/jack/tests/com/android/jack/errorhandling/CommandLineErrorTest.java +++ b/jack/tests/com/android/jack/errorhandling/CommandLineErrorTest.java @@ -20,14 +20,12 @@ import com.android.jack.IllegalOptionsException; import com.android.jack.Main; import com.android.jack.NothingToDoException; import com.android.jack.Options; -import com.android.jack.category.KnownBugs; import com.android.jack.frontend.FrontendCompilationException; import junit.framework.Assert; import org.junit.BeforeClass; import org.junit.Test; -import org.junit.experimental.categories.Category; import java.io.File; import java.util.ArrayList; @@ -94,7 +92,6 @@ public class CommandLineErrorTest { * Checks that compilation fails correctly when java.lang.Object does not exist on classpath. */ @Test - @Category(KnownBugs.class) public void testCommandLineError003() throws Exception { TestingEnvironment ite = new TestingEnvironment(); @@ -113,10 +110,12 @@ public class CommandLineErrorTest { ite.compile(options); Assert.fail(); } catch (FrontendCompilationException e) { - // Failure is ok, since java.lang.Object does not exists. + // Failure is ok, since java.lang.Object does not exist. } finally { Assert.assertEquals("", ite.endOutRedirection()); - Assert.assertTrue(!ite.endErrRedirection().contains("file")); + String err = ite.endErrRedirection(); + Assert.assertTrue(err.contains("The type java.lang.Object cannot be found in source files, " + + "imported jack libs or the classpath")); } } } diff --git a/jack/tests/com/android/jack/errorhandling/SourceErrorTest.java b/jack/tests/com/android/jack/errorhandling/SourceErrorTest.java index e809437..0ed11c1 100644 --- a/jack/tests/com/android/jack/errorhandling/SourceErrorTest.java +++ b/jack/tests/com/android/jack/errorhandling/SourceErrorTest.java @@ -36,6 +36,7 @@ public class SourceErrorTest { /** * Checks that compilation fails because of invalid "class" keyword. + * parsingErrorId = syntaxCategory + internalCategory + 204 */ @Test public void testInvalidSource001() throws Exception { @@ -45,12 +46,14 @@ public class SourceErrorTest { + "public clas A {}\n"); try { + te.startOutRedirection(); te.startErrRedirection(); te.compile(getOptions(te)); Assert.fail(); } catch (FrontendCompilationException ex) { // Failure is ok since source does not compile. } finally { + Assert.assertEquals("", te.endOutRedirection()); Assert.assertTrue( te.endErrRedirection().contains("Syntax error on token \"clas\", class expected")); } @@ -58,6 +61,7 @@ public class SourceErrorTest { /** * Checks that compilation fails because of invalid "public" keyword. + * parsingErrorId = syntaxCategory + internalCategory + 204 */ @Test public void testInvalidSource002() throws Exception { @@ -67,12 +71,14 @@ public class SourceErrorTest { + "publi class A {}\n"); try { + te.startOutRedirection(); te.startErrRedirection(); te.compile(getOptions(te)); Assert.fail(); } catch (FrontendCompilationException ex) { // Failure is ok since source does not compile. } finally { + Assert.assertEquals("", te.endOutRedirection()); Assert.assertTrue( te.endErrRedirection().contains("Syntax error on token \"publi\", public expected")); } @@ -80,6 +86,7 @@ public class SourceErrorTest { /** * Checks that compilation fails because of a class name that does not match the file name. + * publicClassMustMatchFileNameId = typeRelatedCategory + 325 */ @Test public void testInvalidSource003() throws Exception { @@ -89,12 +96,14 @@ public class SourceErrorTest { + "public class B {}\n"); try { + te.startOutRedirection(); te.startErrRedirection(); te.compile(getOptions(te)); Assert.fail(); } catch (FrontendCompilationException ex) { // Failure is ok since source does not compile. } finally { + Assert.assertEquals("", te.endOutRedirection()); Assert.assertTrue( te.endErrRedirection().contains("The public type B must be defined in its own file")); } @@ -102,6 +111,7 @@ public class SourceErrorTest { /** * Checks that compilation fails because of an import of a class that is not on classpath. + * importNotFoundId = importRelatedCategory + 390 */ @Test public void testInvalidSource004() throws Exception { @@ -112,12 +122,14 @@ public class SourceErrorTest { + "public class A {}\n"); try { + te.startOutRedirection(); te.startErrRedirection(); te.compile(getOptions(te)); Assert.fail(); } catch (FrontendCompilationException ex) { // Failure is ok since source does not compile. } finally { + Assert.assertEquals("", te.endOutRedirection()); Assert.assertTrue( te.endErrRedirection().contains("The import jack.invalidsource.B cannot be resolved")); } @@ -125,6 +137,7 @@ public class SourceErrorTest { /** * Checks that compilation fails because there are too many methods in a single class. + * tooManyMethodsId = internalCategory + 433 */ @Test public void testInvalidSource005() throws Exception { @@ -156,16 +169,174 @@ public class SourceErrorTest { } } + /** + * Checks that compilation fails because of several source errors. + */ + @Test + public void testInvalidSource006() throws Exception { + TestingEnvironment te = new TestingEnvironment(); + + te.addFile(te.getSourceFolder(), "jack.invalidsource", "A.java", "package jack.invalidsource;\n" + + "public class A { private voi m() {} } \n"); + te.addFile(te.getSourceFolder(), "jack.invalidsource", "B.java", "package jack.invalidsource;\n" + + "public class B { private void m(in a) {}; \n private void n(int a) {re}; } \n"); + + try { + te.startOutRedirection(); + te.startErrRedirection(); + te.compile(getOptions(te)); + Assert.fail(); + } catch (FrontendCompilationException ex) { + // Failure is ok since source does not compile. + } finally { + Assert.assertEquals("", te.endOutRedirection()); + String errorString = te.endErrRedirection(); + Assert.assertTrue(errorString.contains("in cannot be resolved to a type")); + Assert.assertTrue(errorString.contains( + "Syntax error, insert \"VariableDeclarators\" to complete LocalVariableDeclaration")); + Assert.assertTrue( + errorString.contains("Syntax error, insert \";\" to complete BlockStatements")); + Assert.assertTrue(errorString.contains("voi cannot be resolved to a type")); + } + } + + /** + * Checks that compilation fails because of a source error, with also some warnings. + */ + @Test + public void testInvalidSource007() throws Exception { + TestingEnvironment te = new TestingEnvironment(); + + te.addFile(te.getSourceFolder(), "jack.invalidsource", "A.java", "package jack.invalidsource;\n" + + "public class A { private void m() {} } \n"); + te.addFile(te.getSourceFolder(), "jack.invalidsource", "B.java", "package jack.invalidsource;\n" + + "public class B { private void m(in a) {}; \n private void n(int a) {}; } \n"); + + try { + te.startOutRedirection(); + te.startErrRedirection(); + te.compile(getOptions(te)); + Assert.fail(); + } catch (FrontendCompilationException ex) { + // Failure is ok since source does not compile. + } finally { + Assert.assertEquals("", te.endOutRedirection()); + Assert.assertTrue(te.endErrRedirection().contains("in cannot be resolved to a type")); + Assert.assertTrue(te.endErrRedirection().contains( + "The method n(int) from the type B is never used locally")); + Assert.assertTrue( + te.endErrRedirection().contains("The method m() from the type A is never used locally")); + } + } + + /** + * Checks that compilation succeeds but prints several warnings. + */ + @Test + public void testInvalidSource008() throws Exception { + TestingEnvironment te = new TestingEnvironment(); + + te.addFile(te.getSourceFolder(), "jack.invalidsource", "A.java", "package jack.invalidsource;\n" + + "public class A { private void m() {} } \n"); + te.addFile(te.getSourceFolder(), "jack.invalidsource", "B.java", "package jack.invalidsource;\n" + + "public class B { private void m(int a) {}; \n private void n(int a) {}; } \n"); + + try { + te.startOutRedirection(); + te.startErrRedirection(); + te.compile(getOptions(te)); + } finally { + Assert.assertEquals("", te.endOutRedirection()); + Assert.assertTrue(te.endErrRedirection().contains( + "The method m(int) from the type B is never used locally")); + Assert.assertTrue(te.endErrRedirection().contains( + "The method n(int) from the type B is never used locally")); + Assert.assertTrue( + te.endErrRedirection().contains("The method m() from the type A is never used locally")); + } + } + + /** + * Checks that compilation fails because of an invalid type. + * undefinedTypeId = typeRelatedCategory + 2 + */ + @Test + public void testInvalidSource009() throws Exception { + TestingEnvironment te = new TestingEnvironment(); + + te.addFile(te.getSourceFolder(), "jack.invalidsource", "A.java", "package jack.invalidsource;\n" + + "public class A { private void m(in a) {}; } \n"); + + try { + te.startOutRedirection(); + te.startErrRedirection(); + te.compile(getOptions(te)); + Assert.fail(); + } catch (FrontendCompilationException ex) { + // Failure is ok since source does not compile. + } finally { + Assert.assertEquals("", te.endOutRedirection()); + Assert.assertTrue( + te.endErrRedirection().contains("in cannot be resolved to a type")); + } + } + + /** + * Checks that compilation fails because of a parsing error. + * parsingErrorInsertToCompleteId = syntaxCategory + internalCategory + 240 + */ + @Test + public void testInvalidSource010() throws Exception { + TestingEnvironment te = new TestingEnvironment(); + + te.addFile(te.getSourceFolder(), "jack.invalidsource", "A.java", "package jack.invalidsource;\n" + + "public class A { private void n(int a) {re;} } \n"); + + try { + te.startOutRedirection(); + te.startErrRedirection(); + te.compile(getOptions(te)); + Assert.fail(); + } catch (FrontendCompilationException ex) { + // Failure is ok since source does not compile. + } finally { + Assert.assertEquals("", te.endOutRedirection()); + Assert.assertTrue(te.endErrRedirection().contains( + "Syntax error, insert \"VariableDeclarators\" to complete LocalVariableDeclaration")); + } + } + + /** + * Checks that compilation succeeds but raises a warning because of an unused private method. + * unusedPrivateMethodId = internalCategory + methodRelatedCategory + 118 + */ + @Test + public void testInvalidSource011() throws Exception { + TestingEnvironment te = new TestingEnvironment(); + + te.addFile(te.getSourceFolder(), "jack.invalidsource", "A.java", "package jack.invalidsource;\n" + + "public class A { private void m() {} } \n"); + + try { + te.startOutRedirection(); + te.startErrRedirection(); + te.compile(getOptions(te)); + } finally { + Assert.assertEquals("", te.endOutRedirection()); + Assert.assertTrue( + te.endErrRedirection().contains("The method m() from the type A is never used locally")); + } + } + @Nonnull private Options getOptions(@Nonnull TestingEnvironment te) { Options options = new Options(); List<String> ecjArgs = new ArrayList<String>(); - ecjArgs.add("-d"); - ecjArgs.add(te.getTestingFolder().getAbsolutePath()); ecjArgs.add(te.getSourceFolder().getAbsolutePath()); options.setEcjArguments(ecjArgs); options.setClasspath(TestTools.getDefaultBootclasspathString() + File.pathSeparator + te.getJackFolder()); + options.setOutputDir(te.getTestingFolder()); return options; } diff --git a/jack/tests/com/android/jack/experimental/incremental/DependenciesTest001.java b/jack/tests/com/android/jack/experimental/incremental/DependenciesTest001.java index e1ef6ea..f93cdb5 100644 --- a/jack/tests/com/android/jack/experimental/incremental/DependenciesTest001.java +++ b/jack/tests/com/android/jack/experimental/incremental/DependenciesTest001.java @@ -527,7 +527,11 @@ public class DependenciesTest001 { Assert.fail(); } catch (FrontendCompilationException e) { // Error is ok - Assert.assertTrue(ite.getStringRepresentingErr().contains("2 problems (2 errors)")); + String err = ite.getStringRepresentingErr(); + Assert.assertTrue( + err.contains("The type B must implement the inherited abstract method I.m(int)")); + Assert.assertTrue( + err.contains("The method m() of type B must override or implement a supertype method")); } ite.addJavaFile("jack.incremental", "B.java", @@ -539,7 +543,8 @@ public class DependenciesTest001 { Assert.fail(); } catch (FrontendCompilationException e) { // Error is ok - Assert.assertTrue(ite.getStringRepresentingErr().contains("1 problem (1 error)")); + Assert.assertTrue(ite.getStringRepresentingErr().contains( + "The method m() of type A must override or implement a supertype method")); } ite.addJavaFile("jack.incremental", "A.java", |