You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BasicCommandTestCase.java 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /* *******************************************************************
  2. * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.ajdt.internal.compiler.batch;
  13. import java.io.File;
  14. import java.util.ArrayList;
  15. //import java.util.Arrays;
  16. import java.util.List;
  17. import org.aspectj.ajdt.ajc.*;
  18. import org.aspectj.ajdt.ajc.AjdtCommand;
  19. import org.aspectj.bridge.ICommand;
  20. //import org.aspectj.bridge.IMessage;
  21. import org.aspectj.bridge.MessageHandler;
  22. /**
  23. * @author hugunin
  24. *
  25. * To change this generated comment edit the template variable "typecomment":
  26. * Window>Preferences>Java>Templates.
  27. * To enable and disable the creation of type comments go to
  28. * Window>Preferences>Java>Code Generation.
  29. */
  30. public class BasicCommandTestCase extends CommandTestCase {
  31. /**
  32. * Constructor for CommandTestCase.
  33. * @param name
  34. */
  35. public BasicCommandTestCase(String name) {
  36. super(name);
  37. }
  38. public void testA() {
  39. checkCompile("src1/A.java", NO_ERRORS);
  40. }
  41. public void testA1() {
  42. checkCompile("src1/A1.java", NO_ERRORS);
  43. }
  44. public void testBadA() {
  45. checkCompile("src1/BadA.java", new int[] {7, 8});
  46. }
  47. public void testHello() {
  48. checkCompile("src1/Hello.java", NO_ERRORS);
  49. }
  50. public void testBadHello() {
  51. checkCompile("src1/BadHello.java", new int[] {5});
  52. }
  53. public void testMissingHello() {
  54. checkCompile("src1/MissingHello.java", TOP_ERROR);
  55. }
  56. public void testBadBinding() {
  57. checkCompile("src1/BadBinding.java", new int[] {2, 4, 8, 10, 13, 16, 19});
  58. }
  59. public void testThisAndModifiers() {
  60. checkCompile("src1/ThisAndModifiers.java", NO_ERRORS);
  61. }
  62. public void testDeclares() {
  63. checkCompile("src1/Declares.java", new int[] {2});
  64. }
  65. public void testDeclareWarning() {
  66. checkCompile("src1/DeclareWarning.java", NO_ERRORS);
  67. }
  68. public void testP1() {
  69. checkCompile("src1/p1/Foo.java", NO_ERRORS);
  70. }
  71. public void testUnimplementedSyntax() {
  72. checkCompile("src1/UnimplementedSyntax.java",
  73. new int[] {5, 15, 16, 22, 25});
  74. }
  75. public void testXlintWarn() {
  76. checkCompile("src1/Xlint.java", NO_ERRORS);
  77. }
  78. public void testXlintError() {
  79. List args = new ArrayList();
  80. args.add("-d");
  81. args.add(getSandboxName());
  82. args.add("-classpath");
  83. args.add(getRuntimeClasspath() + File.pathSeparator + "../lib/junit/junit.jar;../testing-client/bin");
  84. args.add("-Xlint:error");
  85. args.add(AjdtAjcTests.TESTDATA_PATH + "/src1/Xlint.java");
  86. runCompiler(args, new int[] {2});
  87. }
  88. public void testMissingJarError() {
  89. List args = new ArrayList();
  90. args.add("-d");
  91. args.add(getSandboxName());
  92. args.add("-classpath");
  93. args.add(getRuntimeClasspath() + File.pathSeparator + "../lib/junit/junit.jar;../testing-client/bin;not_found_anywhere.jar");
  94. args.add(AjdtAjcTests.TESTDATA_PATH + "/src1/ThisAndModifiers.java");
  95. ICommand command = new AjdtCommand();
  96. MessageHandler myHandler = new MessageHandler();
  97. //myHandler.setInterceptor(org.aspectj.tools.ajc.Main.MessagePrinter.TERSE);
  98. /*boolean result = */command.runCommand((String[])args.toArray(new String[args.size()]), myHandler);
  99. //System.err.println("messages: " + Arrays.asList(myHandler.getMessages(IMessage.INFO, true)));
  100. // DON'T yet have a way of testing that we actually got a particular info message
  101. assertEquals("only info for missing jar", 0, myHandler.getErrors().length);
  102. }
  103. public void testMissingRuntimeError() {
  104. List args = new ArrayList();
  105. args.add("-d");
  106. args.add(getSandboxName());
  107. args.add("-classpath");
  108. args.add("../lib/junit/junit.jar;../testing-client/bin");
  109. args.add(AjdtAjcTests.TESTDATA_PATH + "/src1/ThisAndModifiers.java");
  110. ICommand command = new AjdtCommand();
  111. MessageHandler myHandler = new MessageHandler();
  112. myHandler.setInterceptor(org.aspectj.tools.ajc.Main.MessagePrinter.TERSE);
  113. /*boolean result = */command.runCommand((String[])args.toArray(new String[args.size()]), myHandler);
  114. assertEquals("error for org.aspectj.lang.JoinPoint not found", 1, myHandler.getErrors().length);
  115. }
  116. public void testImplicitOutputDir() {
  117. List args = new ArrayList();
  118. args.add("-classpath");
  119. args.add(getRuntimeClasspath() + File.pathSeparator +
  120. "../lib/junit/junit.jar;../testing-client/bin");
  121. File f1 = new File(AjdtAjcTests.TESTDATA_PATH + "/src1/p1/Foo.class");
  122. File f2 = new File(AjdtAjcTests.TESTDATA_PATH + "/src1/WrongPackage.class");
  123. File f3 = new File(AjdtAjcTests.TESTDATA_PATH + "/src1/WrongPackage$1.class");
  124. if (f1.exists()) f1.delete();
  125. if (f2.exists()) f2.delete();
  126. if (f3.exists()) f3.delete();
  127. args.add(AjdtAjcTests.TESTDATA_PATH + "/src1/p1/Foo.java");
  128. args.add(AjdtAjcTests.TESTDATA_PATH + "/src1/WrongPackage.java");
  129. runCompiler(args, NO_ERRORS);
  130. assertTrue(f1.getPath(), f1.exists());
  131. assertTrue(f2.getPath(), f2.exists());
  132. assertTrue(f3.getPath(), f3.exists());
  133. if (f1.exists()) f1.delete();
  134. if (f2.exists()) f2.delete();
  135. if (f3.exists()) f3.delete();
  136. }
  137. public void testSizeChanges() {
  138. File f1 = new File(getSandboxName(),"SizeIssues.class");
  139. List args = new ArrayList();
  140. args.add("-d");
  141. args.add(getSandboxName());
  142. args.add("-classpath");
  143. args.add(getRuntimeClasspath() + File.pathSeparator +
  144. "../lib/junit/junit.jar;../testing-client/bin");
  145. args.add(AjdtAjcTests.TESTDATA_PATH + "/src1/SizeIssuesAspect.java");
  146. args.add(AjdtAjcTests.TESTDATA_PATH + "/src1/SizeIssues.java");
  147. runCompiler(args, NO_ERRORS);
  148. long size = f1.length();
  149. for (int i=0; i < 1; i++) {
  150. f1.delete();
  151. runCompiler(args, NO_ERRORS);
  152. assertEquals(size, f1.length());
  153. }
  154. }
  155. }