Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

BugTests.java 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /********************************************************************
  2. * Copyright (c) 2006 Contributors. All rights reserved.
  3. * This program and the accompanying materials are made available
  4. * under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution and is available at
  6. * http://eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors: IBM Corporation - initial API and implementation
  9. * Helen Hawkins - initial version
  10. *******************************************************************/
  11. package org.aspectj.tools.ajdoc;
  12. import java.io.File;
  13. import java.util.ArrayList;
  14. import java.util.List;
  15. public class BugTests extends AjdocTestCase {
  16. public void testPr160302() throws Exception {
  17. initialiseProject("pr160302");
  18. File[] files = {new File(getAbsoluteProjectDir() + "/C.java")};
  19. runAjdoc(files);
  20. assertFalse("expected clean build of project but found that build aborted",Main.hasAborted());
  21. File html = new File(getAbsolutePathOutdir() + File.separator + "C.html");
  22. if (!html.exists()) {
  23. fail("couldn't find " + getAbsolutePathOutdir() + File.separator + "C.html - were there javadoc/compilation errors?");
  24. }
  25. assertFalse("expected all decorating tags to be removed but found that they" +
  26. " weren't",AjdocOutputChecker.containsString(html, Config.DECL_ID_STRING));
  27. }
  28. /**
  29. * Passing the "-Xlint:error" option through to the compiler should
  30. * cause the ajc build to fail because the advice did not match
  31. */
  32. public void testPr148906_1() {
  33. initialiseProject("pr148906");
  34. File[] files = {new File(getAbsoluteProjectDir() + "/AdviceDidNotMatch.aj")};
  35. String[] ajOptions = {new String("-Xlint:error")};
  36. runAjdoc(files,"1.5",ajOptions);
  37. assertTrue("expected ajc to fail but it did not", Main.hasAborted());
  38. assertEquals("expected ajc to fail with an adviceDidNotMatch error but it" +
  39. " failed instead with " + Main.getErrors()[0].getMessage(),
  40. "advice defined in AdviceDidNotMatch has not been applied [Xlint:adviceDidNotMatch]",
  41. Main.getErrors()[0].getMessage());
  42. }
  43. /**
  44. * Passing the "-Xlintfile" option through to the compiler should
  45. * cause the ajc build to fail because the advice did not match
  46. */
  47. public void testPr148906_2() {
  48. initialiseProject("pr148906");
  49. File[] files = {new File(getAbsoluteProjectDir() + "/AdviceDidNotMatch.aj")};
  50. String[] ajOptions = {new String("-Xlintfile"), new String(getAbsoluteProjectDir() + File.separator + "Xlint.properties")};
  51. runAjdoc(files,"1.5",ajOptions);
  52. assertTrue("expected ajc to fail but it did not", Main.hasAborted());
  53. assertEquals("expected ajc to fail with an adviceDidNotMatch error but it" +
  54. " failed instead with " + Main.getErrors()[0].getMessage(),
  55. "advice defined in AdviceDidNotMatch has not been applied [Xlint:adviceDidNotMatch]",
  56. Main.getErrors()[0].getMessage());
  57. }
  58. /**
  59. * Passing the -aspectpath option though to the compiler should
  60. * result in relationships being displayed
  61. */
  62. public void testPr148906_3() throws Exception {
  63. initialiseProject("pr148906");
  64. File[] files = {new File(getAbsoluteProjectDir() + "/C.java")};
  65. String[] ajOptions = {new String("-aspectpath"), new String(getAbsoluteProjectDir() + File.separator + "simple.jar")};
  66. runAjdoc(files,"1.6",ajOptions);
  67. assertFalse("expected clean build of project but found that build aborted",Main.hasAborted());
  68. File html = new File(getAbsolutePathOutdir() + File.separator + "C.html");
  69. if (!html.exists()) {
  70. fail("couldn't find " + getAbsolutePathOutdir() + File.separator + "C.html - were there javadoc/compilation errors?");
  71. }
  72. assertTrue("expected to find 'Advised by' in the html output but did " +
  73. " not",AjdocOutputChecker.containsString(html,
  74. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY.getName()));
  75. }
  76. /**
  77. * Passing an option starting with "-" that doesn't require a second entry
  78. * should mean everything is correctly given to the compiler. For example:
  79. * '-outxml -aspectpath <file>" should mean both '-outxml' and the aspectpath
  80. * options are given correctly.
  81. */
  82. public void testPr148906_4() throws Exception {
  83. initialiseProject("pr148906");
  84. File[] files = {new File(getAbsoluteProjectDir() + "/C.java")};
  85. String[] ajOptions = {new String("-outxml"),new String("-aspectpath"), new String(getAbsoluteProjectDir() + File.separator + "simple.jar")};
  86. runAjdoc(files,"1.6",ajOptions);
  87. assertFalse("expected clean build of project but found that build aborted",Main.hasAborted());
  88. File html = new File(getAbsolutePathOutdir() + File.separator + "C.html");
  89. if (!html.exists()) {
  90. fail("couldn't find " + getAbsolutePathOutdir() + File.separator + "C.html - were there javadoc/compilation errors?");
  91. }
  92. assertTrue("expected to find 'Advised by' in the html output but did " +
  93. " not",AjdocOutputChecker.containsString(html,
  94. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY.getName()));
  95. File aopFile = new File(getAbsolutePathOutdir() + File.separator
  96. + "META-INF" + File.separator + "aop-ajc.xml");
  97. assertTrue("couldn't find " + getAbsolutePathOutdir() + File.separator
  98. + "META-INF" + File.separator + "aop-ajc.xml" ,
  99. aopFile.exists());
  100. }
  101. /**
  102. * Passing bogus option to ajc
  103. */
  104. public void testPr148906_5() throws Exception {
  105. initialiseProject("pr148906");
  106. File[] files = {new File(getAbsoluteProjectDir() + "/C.java")};
  107. String[] ajOptions = {new String("-bogus")};
  108. runAjdoc(files,"1.5",ajOptions);
  109. assertTrue("expected build of project to abort",Main.hasAborted());
  110. }
  111. /**
  112. * Not passing any files to ajdoc should result in both the ajdoc
  113. * and ajc usage messages
  114. */
  115. public void testPr148906_6() throws Exception {
  116. initialiseProject("pr148906");
  117. List options = new ArrayList();
  118. options.add("-verbose");
  119. runAjdoc(options);
  120. assertTrue("expected the ajdoc usage message to be reported",Main.hasShownAjdocUsageMessage());
  121. assertTrue("expected build of project to abort",Main.hasAborted());
  122. }
  123. /**
  124. * javadoc comments should still appear even if preceded by
  125. * 'normal' comments
  126. */
  127. public void testPr164356() throws Exception {
  128. initialiseProject("pr164356");
  129. File[] files = {new File(getAbsoluteProjectDir() + "/C.java")};
  130. runAjdoc(files);
  131. File htmlFile = new File(getAbsolutePathOutdir() + "/C.html");
  132. if (!htmlFile.exists()) {
  133. fail("couldn't find " + htmlFile.getAbsolutePath() +
  134. " (ajc aborted: " + Main.hasAborted() + ")");
  135. }
  136. String foo = "description of foo";
  137. String bar = "description of bar";
  138. String goo = "description of goo";
  139. String bas = "description of bas";
  140. assertTrue("expected method description 'description of foo' to appear" +
  141. " in ajdoc output but it did not",
  142. AjdocOutputChecker.containsString(htmlFile, foo));
  143. assertTrue("expected method description 'description of bar' to " +
  144. "appear in ajdoc output but it did not",
  145. AjdocOutputChecker.containsString(htmlFile, bar));
  146. assertFalse("didn't expect method description 'description of goo' to " +
  147. "appear in ajdoc output but it did not",
  148. AjdocOutputChecker.containsString(htmlFile, goo));
  149. assertTrue("expected method description 'description of bas' to appear" +
  150. " in ajdoc output but it did not",
  151. AjdocOutputChecker.containsString(htmlFile, bas));
  152. }
  153. /**
  154. * Comments for a constructor should be included in the ajdoc output
  155. */
  156. public void testPr164340() throws Exception {
  157. initialiseProject("pr164340");
  158. File[] files = {new File(getAbsoluteProjectDir() + "/C.java")};
  159. runAjdoc(files);
  160. File htmlFile = new File(getAbsolutePathOutdir() + "/C.html");
  161. if (!htmlFile.exists()) {
  162. fail("couldn't find " + htmlFile.getAbsolutePath() +
  163. " (ajc aborted: " + Main.hasAborted() + ")");
  164. }
  165. String methodDesc = "This is method foo";
  166. String constDesc = "This is a constructor";
  167. assertTrue("expected method description 'This is method foo' to appear" +
  168. " in ajdoc output but it did not",
  169. AjdocOutputChecker.containsString(htmlFile, methodDesc));
  170. assertTrue("expected constructor description 'This is a constructor' to " +
  171. "appear in ajdoc output but it did not",
  172. AjdocOutputChecker.containsString(htmlFile, constDesc));
  173. }
  174. }