diff options
author | aclement <aclement> | 2006-10-23 12:49:11 +0000 |
---|---|---|
committer | aclement <aclement> | 2006-10-23 12:49:11 +0000 |
commit | 70dda814951a9cf2f79e958b2bd93f66f390b6da (patch) | |
tree | a440fce9ef278cc2bf3b32272622d62b9d371dce /ajdoc/testsrc/org | |
parent | 757004ca6702a97369aac2ba62532f13ac5ced36 (diff) | |
download | aspectj-70dda814951a9cf2f79e958b2bd93f66f390b6da.tar.gz aspectj-70dda814951a9cf2f79e958b2bd93f66f390b6da.zip |
tests and fixes for 148906: Support -Xlintfile for ajdoc
Diffstat (limited to 'ajdoc/testsrc/org')
-rw-r--r-- | ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocTestCase.java | 46 | ||||
-rw-r--r-- | ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocTests.java | 3 | ||||
-rw-r--r-- | ajdoc/testsrc/org/aspectj/tools/ajdoc/BugTests.java | 133 |
3 files changed, 181 insertions, 1 deletions
diff --git a/ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocTestCase.java b/ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocTestCase.java index 27979b925..8c7c05d9c 100644 --- a/ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocTestCase.java +++ b/ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocTestCase.java @@ -12,6 +12,8 @@ package org.aspectj.tools.ajdoc; import java.io.File; import java.io.IOException; +import java.util.Iterator; +import java.util.List; import junit.framework.AssertionFailedError; import junit.framework.TestCase; @@ -156,6 +158,36 @@ public class AjdocTestCase extends TestCase{ } /** + * Run the ajdoc command with the default visibility + * and source level, the given input files and the given + * aspectj options + */ + public void runAjdoc(File[] inputFiles, String sourceLevel, String[] ajOptions) { + if (inputFiles.length == 0) { + fail("need to pass some files into ajdoc"); + } + if (!sourceLevel.equals("1.3") + && !sourceLevel.equals("1.4") + && !sourceLevel.equals("1.5")) { + fail("need to pass ajdoc '1.3', '1.4', or '1.5' as the source level"); + } + String[] args = new String[6 + inputFiles.length + ajOptions.length]; + args[0] = "-source"; + args[1] = sourceLevel; + args[2] = "-classpath"; + args[3] = AjdocTests.ASPECTJRT_PATH.getPath(); + args[4] = "-d"; + args[5] = getAbsolutePathOutdir(); + for (int i = 0; i < ajOptions.length; i++) { + args[6 + i] = ajOptions[i]; + } + for (int i = 0; i < inputFiles.length; i++) { + args[6 + i +ajOptions.length] = inputFiles[i].getAbsolutePath(); + } + org.aspectj.tools.ajdoc.Main.main(args); + } + + /** * Run the ajdoc command with the given visibility argument, * the given source level argument and the given input files. */ @@ -263,4 +295,18 @@ public class AjdocTestCase extends TestCase{ args[7] = "@" + getAbsoluteProjectDir() + File.separatorChar + lstFile; org.aspectj.tools.ajdoc.Main.main(args); } + + /** + * Run the ajdoc command with the given options + */ + public void runAjdoc(List options) { + String[] args = new String[options.size()]; + int i = 0; + for (Iterator iter = options.iterator(); iter.hasNext();) { + String element = (String) iter.next(); + args[i] = element; + i++; + } + org.aspectj.tools.ajdoc.Main.main(args); + } } diff --git a/ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocTests.java b/ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocTests.java index f9d50e56f..6debbe13b 100644 --- a/ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocTests.java +++ b/ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocTests.java @@ -44,7 +44,8 @@ public class AjdocTests extends TestCase { suite.addTestSuite(FullyQualifiedArgumentTest.class); suite.addTestSuite(EnumTest.class); suite.addTestSuite(PointcutVisibilityTest.class); - suite.addTestSuite(ExecutionTestCase.class);// !!! must be last because it exists + suite.addTestSuite(ExecutionTestCase.class); + suite.addTestSuite(BugTests.class); //$JUnit-END$ return suite; } diff --git a/ajdoc/testsrc/org/aspectj/tools/ajdoc/BugTests.java b/ajdoc/testsrc/org/aspectj/tools/ajdoc/BugTests.java new file mode 100644 index 000000000..eeb8f141a --- /dev/null +++ b/ajdoc/testsrc/org/aspectj/tools/ajdoc/BugTests.java @@ -0,0 +1,133 @@ +/******************************************************************** + * Copyright (c) 2006 Contributors. All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation + * Helen Hawkins - initial version + *******************************************************************/ +package org.aspectj.tools.ajdoc; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +public class BugTests extends AjdocTestCase { + + public void testPr160302() throws Exception { + initialiseProject("pr160302"); + File[] files = {new File(getAbsoluteProjectDir() + "/C.java")}; + runAjdoc(files); + assertFalse("expected clean build of project but found that build aborted",Main.hasAborted()); + File html = new File(getAbsolutePathOutdir() + File.separator + "C.html"); + if (html == null || !html.exists()) { + fail("couldn't find " + getAbsolutePathOutdir() + File.separator + "C.html - were there javadoc/compilation errors?"); + } + assertFalse("expected all decorating tags to be removed but found that they" + + " weren't",AjdocOutputChecker.containsString(html, Config.DECL_ID_STRING)); + } + + /** + * Passing the "-Xlint:error" option through to the compiler should + * cause the ajc build to fail because the advice did not match + */ + public void testPr148906_1() { + initialiseProject("pr148906"); + File[] files = {new File(getAbsoluteProjectDir() + "/AdviceDidNotMatch.aj")}; + String[] ajOptions = {new String("-Xlint:error")}; + runAjdoc(files,"1.5",ajOptions); + assertTrue("expected ajc to fail but it did not", Main.hasAborted()); + assertEquals("expected ajc to fail with an adviceDidNotMatch error but it" + + " failed instead with " + Main.getErrors()[0].getMessage(), + "advice defined in AdviceDidNotMatch has not been applied [Xlint:adviceDidNotMatch]", + Main.getErrors()[0].getMessage()); + } + + /** + * Passing the "-Xlintfile" option through to the compiler should + * cause the ajc build to fail because the advice did not match + */ + public void testPr148906_2() { + initialiseProject("pr148906"); + File[] files = {new File(getAbsoluteProjectDir() + "/AdviceDidNotMatch.aj")}; + String[] ajOptions = {new String("-Xlintfile"), new String(getAbsoluteProjectDir() + File.separator + "Xlint.properties")}; + runAjdoc(files,"1.5",ajOptions); + assertTrue("expected ajc to fail but it did not", Main.hasAborted()); + assertEquals("expected ajc to fail with an adviceDidNotMatch error but it" + + " failed instead with " + Main.getErrors()[0].getMessage(), + "advice defined in AdviceDidNotMatch has not been applied [Xlint:adviceDidNotMatch]", + Main.getErrors()[0].getMessage()); + } + + /** + * Passing the -aspectpath option though to the compiler should + * result in relationships being displayed + */ + public void testPr148906_3() throws Exception { + initialiseProject("pr148906"); + File[] files = {new File(getAbsoluteProjectDir() + "/C.java")}; + String[] ajOptions = {new String("-aspectpath"), new String(getAbsoluteProjectDir() + File.separator + "simple.jar")}; + runAjdoc(files,"1.5",ajOptions); + assertFalse("expected clean build of project but found that build aborted",Main.hasAborted()); + File html = new File(getAbsolutePathOutdir() + File.separator + "C.html"); + if (html == null || !html.exists()) { + fail("couldn't find " + getAbsolutePathOutdir() + File.separator + "C.html - were there javadoc/compilation errors?"); + } + assertTrue("expected to find 'Advised by' in the html output but did " + + " not",AjdocOutputChecker.containsString(html, + HtmlDecorator.HtmlRelationshipKind.ADVISED_BY.getName())); + } + + /** + * Passing an option starting with "-" that doesn't require a second entry + * should mean everything is correctly given to the compiler. For example: + * '-outxml -aspectpath <file>" should mean both '-outxml' and the aspectpath + * options are given correctly. + */ + public void testPr148906_4() throws Exception { + initialiseProject("pr148906"); + File[] files = {new File(getAbsoluteProjectDir() + "/C.java")}; + String[] ajOptions = {new String("-outxml"),new String("-aspectpath"), new String(getAbsoluteProjectDir() + File.separator + "simple.jar")}; + runAjdoc(files,"1.5",ajOptions); + assertFalse("expected clean build of project but found that build aborted",Main.hasAborted()); + File html = new File(getAbsolutePathOutdir() + File.separator + "C.html"); + if (html == null || !html.exists()) { + fail("couldn't find " + getAbsolutePathOutdir() + File.separator + "C.html - were there javadoc/compilation errors?"); + } + assertTrue("expected to find 'Advised by' in the html output but did " + + " not",AjdocOutputChecker.containsString(html, + HtmlDecorator.HtmlRelationshipKind.ADVISED_BY.getName())); + File aopFile = new File(getAbsolutePathOutdir() + File.separator + + "META-INF" + File.separator + "aop-ajc.xml"); + assertTrue("couldn't find " + getAbsolutePathOutdir() + File.separator + + "META-INF" + File.separator + "aop-ajc.xml" , + aopFile != null && aopFile.exists()); + } + + /** + * Passing bogus option to ajc + */ + public void testPr148906_5() throws Exception { + initialiseProject("pr148906"); + File[] files = {new File(getAbsoluteProjectDir() + "/C.java")}; + String[] ajOptions = {new String("-bogus")}; + runAjdoc(files,"1.5",ajOptions); + assertTrue("expected build of project to abort",Main.hasAborted()); + } + + /** + * Not passing any files to ajdoc should result in both the ajdoc + * and ajc usage messages + */ + public void testPr148906_6() throws Exception { + initialiseProject("pr148906"); + List options = new ArrayList(); + options.add("-verbose"); + runAjdoc(options); + assertTrue("expected the ajdoc usage message to be reported",Main.hasShownAjdocUsageMessage()); + assertTrue("expected build of project to abort",Main.hasAborted()); + } + +} |