diff options
author | acolyer <acolyer> | 2003-03-27 15:43:01 +0000 |
---|---|---|
committer | acolyer <acolyer> | 2003-03-27 15:43:01 +0000 |
commit | 989aaf7855fdb2e4f176d6e7b32a3bd0131ee515 (patch) | |
tree | b651d929c728d24382b2f606e106391e8c8e8284 /ajde | |
parent | 56cc4f27afaf591f8cebb2450513cc6eb7d51299 (diff) | |
download | aspectj-989aaf7855fdb2e4f176d6e7b32a3bd0131ee515.tar.gz aspectj-989aaf7855fdb2e4f176d6e7b32a3bd0131ee515.zip |
Extended test case support to allow verification of compiler messages produced
during compilation. Added test case for bug 33474 (full source
location for declare warning messages).
Diffstat (limited to 'ajde')
8 files changed, 141 insertions, 3 deletions
diff --git a/ajde/testdata/examples/declare-warning/all.lst b/ajde/testdata/examples/declare-warning/all.lst new file mode 100644 index 000000000..e169a842c --- /dev/null +++ b/ajde/testdata/examples/declare-warning/all.lst @@ -0,0 +1,2 @@ +apackage/InitCatcher.java
+apackage/SomeClass.java
diff --git a/ajde/testdata/examples/declare-warning/apackage/InitCatcher.java b/ajde/testdata/examples/declare-warning/apackage/InitCatcher.java new file mode 100644 index 000000000..ac34d3c0c --- /dev/null +++ b/ajde/testdata/examples/declare-warning/apackage/InitCatcher.java @@ -0,0 +1,8 @@ +package apackage; + +public aspect InitCatcher { + + declare warning: call(* *.init(..)) : + "Please don't call init methods"; //$NON-NLS-1$ + +}
\ No newline at end of file diff --git a/ajde/testdata/examples/declare-warning/apackage/SomeClass.java b/ajde/testdata/examples/declare-warning/apackage/SomeClass.java new file mode 100644 index 000000000..eff26d5c8 --- /dev/null +++ b/ajde/testdata/examples/declare-warning/apackage/SomeClass.java @@ -0,0 +1,12 @@ +package apackage; + +public class SomeClass { + + public SomeClass() { + init(); // line 6 + } + + public void init() { + } + +}
\ No newline at end of file diff --git a/ajde/testsrc/org/aspectj/ajde/AjdeTestCase.java b/ajde/testsrc/org/aspectj/ajde/AjdeTestCase.java index 8561f04d6..7e21a6939 100644 --- a/ajde/testsrc/org/aspectj/ajde/AjdeTestCase.java +++ b/ajde/testsrc/org/aspectj/ajde/AjdeTestCase.java @@ -21,7 +21,7 @@ public class AjdeTestCase extends TestCase { private static final String TEST_DATA_PATH = "testdata"; //private static final String TEST_DATA_PATH = "C:/Dev/aspectj/modules/ajde/testdata"; - protected NullIdeManager ideManager = new NullIdeManager(); + protected NullIdeManager ideManager = NullIdeManager.getIdeManager(); protected TestBuildListener testerBuildListener = new TestBuildListener(); protected String currTestDataPath; diff --git a/ajde/testsrc/org/aspectj/ajde/AjdeTests.java b/ajde/testsrc/org/aspectj/ajde/AjdeTests.java index 4a0140e90..fcdfd5a8b 100644 --- a/ajde/testsrc/org/aspectj/ajde/AjdeTests.java +++ b/ajde/testsrc/org/aspectj/ajde/AjdeTests.java @@ -26,6 +26,7 @@ public class AjdeTests extends TestCase { suite.addTestSuite(StructureModelRegressionTest.class); suite.addTestSuite(StructureModelTest.class); suite.addTestSuite(VersionTest.class); + suite.addTestSuite(CompilerMessagesTest.class); //$JUnit-END$ return suite; } diff --git a/ajde/testsrc/org/aspectj/ajde/CompilerMessagesTest.java b/ajde/testsrc/org/aspectj/ajde/CompilerMessagesTest.java new file mode 100644 index 000000000..cd518f5dd --- /dev/null +++ b/ajde/testsrc/org/aspectj/ajde/CompilerMessagesTest.java @@ -0,0 +1,67 @@ +/* + * Created on 27-Mar-2003 + * + * To change this generated comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +package org.aspectj.ajde; + +import java.io.IOException; +import java.util.List; + +/** + * @author colyer + * + * To change this generated comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class CompilerMessagesTest extends AjdeTestCase { + + private final String CONFIG_FILE_PATH = "../examples/declare-warning/all.lst"; + + /** + * Constructor for CompilerMessagesTest. + * @param name + */ + public CompilerMessagesTest(String name) { + super(name); + } + + public void testMessages() { + // bug 33474 + // The build has happened, what messages did the compiler give, and do they + // contain the information we expect? + List msgs = NullIdeManager.getIdeManager().getCompilationSourceLineTasks(); + assertEquals("One warning message should be produced",1,msgs.size()); + NullIdeTaskListManager.SourceLineTask task = + (NullIdeTaskListManager.SourceLineTask) msgs.get(0); + assertEquals( 6, task.location.getLine()); + assertEquals( "Please don't call init methods", task.message); + try { + String fullyQualifiedFile = task.location.getSourceFile().getCanonicalPath(); + // this name has a tester specific prefix, followed by the location of the file. + // we can validate the ending. + fullyQualifiedFile = fullyQualifiedFile.replace('\\','/'); // ignore platform differences in slashes + assertTrue( "Fully-qualified source file location returned", + fullyQualifiedFile.endsWith("testdata/examples/declare-warning/apackage/SomeClass.java")); + } catch (IOException ex) { + assertTrue( "Unable to convert source file location: " + task.location.getSourceFile(), false); + } + } + + /* + * @see TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp("examples"); + doSynchronousBuild(CONFIG_FILE_PATH); + } + + /* + * @see AjdeTestCase#tearDown() + */ + protected void tearDown() throws Exception { + super.tearDown(); + } + +} diff --git a/ajde/testsrc/org/aspectj/ajde/NullIdeManager.java b/ajde/testsrc/org/aspectj/ajde/NullIdeManager.java index c3a09e8dc..5e44c5656 100644 --- a/ajde/testsrc/org/aspectj/ajde/NullIdeManager.java +++ b/ajde/testsrc/org/aspectj/ajde/NullIdeManager.java @@ -7,12 +7,17 @@ * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: - * Xerox/PARC initial implementation + * Xerox/PARC initial implementation + * AMC 03.27.2003 changed to allow access to NullIdeManager + * as a singleton - needed for verifying + * compiler warning and error messages. * ******************************************************************/ package org.aspectj.ajde; +import java.util.List; + import javax.swing.JFrame; import org.aspectj.ajde.ui.IdeUIAdapter; @@ -25,11 +30,21 @@ import org.aspectj.ajde.ui.swing.*; */ public class NullIdeManager { + private static NullIdeManager ideManager = null; + private NullIdeTaskListManager taskListManager = null; + + public static NullIdeManager getIdeManager() { + if ( null == ideManager ) { + ideManager = new NullIdeManager(); + } + return ideManager; + } + public void init(String testProjectPath) { try { UserPreferencesAdapter preferencesAdapter = new UserPreferencesStore(); ProjectPropertiesAdapter browserProjectProperties = new NullIdeProperties(testProjectPath); - TaskListManager taskListManager = new NullIdeTaskListManager(); + taskListManager = new NullIdeTaskListManager(); BasicEditor ajdeEditor = new BasicEditor(); IdeUIAdapter uiAdapter = new NullIdeUIAdapter(); JFrame nullFrame = new JFrame(); @@ -53,4 +68,8 @@ public class NullIdeManager { t); } } + + public List getCompilationSourceLineTasks() { + return taskListManager.getSourceLineTasks(); + } } diff --git a/ajde/testsrc/org/aspectj/ajde/NullIdeTaskListManager.java b/ajde/testsrc/org/aspectj/ajde/NullIdeTaskListManager.java index fc840a8d1..d127220eb 100644 --- a/ajde/testsrc/org/aspectj/ajde/NullIdeTaskListManager.java +++ b/ajde/testsrc/org/aspectj/ajde/NullIdeTaskListManager.java @@ -13,6 +13,9 @@ package org.aspectj.ajde; +import java.util.ArrayList; +import java.util.List; + import org.aspectj.bridge.*; /** @@ -21,8 +24,11 @@ import org.aspectj.bridge.*; * @author Mik Kersten */ public class NullIdeTaskListManager implements TaskListManager { + + List sourceLineTasks = new ArrayList(); public void addSourcelineTask(String message, ISourceLocation sourceLocation, IMessage.Kind kind) { + sourceLineTasks.add(new SourceLineTask(message,sourceLocation,kind)); // System.out.println("> added sourceline task: " + message + ", file: " + sourceLocation.getSourceFile().getAbsolutePath() // + ": " + sourceLocation.getLine()); } @@ -32,7 +38,30 @@ public class NullIdeTaskListManager implements TaskListManager { } public void clearTasks() { + sourceLineTasks = new ArrayList(); // System.out.println("> cleared tasks"); } + + /** + * Return the list of source line compiler messages resulting from a compile, so + * that we can test them. + * @return List + */ + public List getSourceLineTasks() { + return sourceLineTasks; + } + + + public static class SourceLineTask { + public String message; + public ISourceLocation location; + public IMessage.Kind kind; + + public SourceLineTask(String m,ISourceLocation l,IMessage.Kind k) { + message = m; + location = l; + kind = k; + } + } } |