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.9KB

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