]> source.dussan.org Git - aspectj.git/commitdiff
Extended test case support to allow verification of compiler messages produced
authoracolyer <acolyer>
Thu, 27 Mar 2003 15:43:01 +0000 (15:43 +0000)
committeracolyer <acolyer>
Thu, 27 Mar 2003 15:43:01 +0000 (15:43 +0000)
during compilation. Added test case for bug 33474 (full source
location for declare warning messages).

ajde/testdata/examples/declare-warning/all.lst [new file with mode: 0644]
ajde/testdata/examples/declare-warning/apackage/InitCatcher.java [new file with mode: 0644]
ajde/testdata/examples/declare-warning/apackage/SomeClass.java [new file with mode: 0644]
ajde/testsrc/org/aspectj/ajde/AjdeTestCase.java
ajde/testsrc/org/aspectj/ajde/AjdeTests.java
ajde/testsrc/org/aspectj/ajde/CompilerMessagesTest.java [new file with mode: 0644]
ajde/testsrc/org/aspectj/ajde/NullIdeManager.java
ajde/testsrc/org/aspectj/ajde/NullIdeTaskListManager.java

diff --git a/ajde/testdata/examples/declare-warning/all.lst b/ajde/testdata/examples/declare-warning/all.lst
new file mode 100644 (file)
index 0000000..e169a84
--- /dev/null
@@ -0,0 +1,2 @@
+apackage/InitCatcher.java\r
+apackage/SomeClass.java\r
diff --git a/ajde/testdata/examples/declare-warning/apackage/InitCatcher.java b/ajde/testdata/examples/declare-warning/apackage/InitCatcher.java
new file mode 100644 (file)
index 0000000..ac34d3c
--- /dev/null
@@ -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 (file)
index 0000000..eff26d5
--- /dev/null
@@ -0,0 +1,12 @@
+package apackage;
+
+public class SomeClass {
+       
+       public SomeClass() {
+               init();  // line 6      
+       }
+       
+       public void init() {
+       }
+       
+}
\ No newline at end of file
index 8561f04d68fbb3103f2c98a39f21ccfb7ad74da4..7e21a6939d47335f13ed31dabc8a442473da27e6 100644 (file)
@@ -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;
 
index 4a0140e9020afef1eec0c430330b1a10926d122c..fcdfd5a8b3a3549cc036aba952fb4010653d2889 100644 (file)
@@ -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 (file)
index 0000000..cd518f5
--- /dev/null
@@ -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();
+       }
+
+}
index c3a09e8dcb7d76db55ded44957390107ad49883d..5e44c56569181d6c70915a64a1b0d20ae32dd5e7 100644 (file)
@@ -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();
+       }
 }
index fc840a8d131bb15cd60de6433586ccabfa2c6223..d127220eb07ff5d8079a84ccaa2ba8b6987110e2 100644 (file)
@@ -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;
+               }
+       }
 }