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.

HarnessSelectionTest.java 14KB

21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
19 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. /* *******************************************************************
  2. * Copyright (c) 1999-2001 Xerox Corporation,
  3. * 2002 Palo Alto Research Center, Incorporated (PARC).
  4. * All rights reserved.
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Common Public License v1.0
  7. * which accompanies this distribution and is available at
  8. * http://www.eclipse.org/legal/cpl-v10.html
  9. *
  10. * Contributors:
  11. * Xerox/PARC initial implementation
  12. * ******************************************************************/
  13. package org.aspectj.testing.drivers;
  14. import org.aspectj.bridge.IMessage;
  15. import org.aspectj.bridge.MessageHandler;
  16. import org.aspectj.bridge.MessageUtil;
  17. import org.aspectj.testing.harness.bridge.AbstractRunSpec;
  18. import org.aspectj.testing.harness.bridge.AjcTest;
  19. import org.aspectj.testing.run.IRunStatus;
  20. import org.aspectj.testing.run.RunValidator;
  21. import org.aspectj.testing.util.BridgeUtil;
  22. import org.aspectj.testing.util.RunUtils;
  23. import org.aspectj.testing.xml.AjcSpecXmlReader;
  24. import org.aspectj.util.LangUtil;
  25. import java.io.File;
  26. import java.io.IOException;
  27. import java.util.ArrayList;
  28. import java.util.Hashtable;
  29. import java.util.List;
  30. import junit.framework.TestCase;
  31. /**
  32. * The harness supports custom-coded queries based on
  33. * -ajctest{kind}={query} parameters
  34. * (until we move to an XML database with real queries).
  35. */
  36. public class HarnessSelectionTest extends TestCase {
  37. private static final String TESTDATA = "../testing-drivers/testdata";
  38. private static final String INC_HARNESS_DIR
  39. = TESTDATA + "/incremental/harness";
  40. private static final String SELECT
  41. = INC_HARNESS_DIR + "/selectionTest.xml";
  42. /** @see testIncrementalSuite() */
  43. private static final String INCREMENTAL
  44. = INC_HARNESS_DIR + "/suite.xml";
  45. private static final String TITLE_LIST_ONE
  46. = INC_HARNESS_DIR + "/titleListOne.txt";
  47. private static final String TITLE_LIST_PLURAL
  48. = INC_HARNESS_DIR + "/titleListPlural.txt";
  49. private static Hashtable SPECS = new Hashtable();
  50. private static AjcTest.Suite.Spec getSpec(String suiteFile) {
  51. AjcTest.Suite.Spec result = (AjcTest.Suite.Spec) SPECS.get(suiteFile);
  52. if (null == result) {
  53. try {
  54. result = AjcSpecXmlReader.getReader().readAjcSuite(new File(suiteFile));
  55. SPECS.put(suiteFile, result);
  56. } catch (IOException e) {
  57. e.printStackTrace(System.err);
  58. }
  59. }
  60. try {
  61. return (AjcTest.Suite.Spec) result.clone();
  62. } catch (CloneNotSupportedException e) {
  63. e.printStackTrace(System.err);
  64. assertTrue("clone failed: " + e, false);
  65. return null; // keep compiler happy
  66. }
  67. }
  68. private boolean verbose;
  69. public HarnessSelectionTest(String name) {
  70. super(name);
  71. }
  72. public void testFilesAvailable() {
  73. String[] files = new String[] {
  74. SELECT, INCREMENTAL, TITLE_LIST_ONE, TITLE_LIST_PLURAL
  75. };
  76. for (int i = 0; i < files.length; i++) {
  77. assertTrue(files[i], new File(files[i]).canRead());
  78. }
  79. }
  80. public void testIncrementalSuite() {
  81. System.err.println("skipping testIncrementalSuite - too long");
  82. if (true) return;
  83. if (!eclipseAvailable()) {
  84. System.err.println("skipping test - eclipse classes not available");
  85. return;
  86. }
  87. String[] options = new String[]
  88. { "!verbose", "!eclipse",
  89. };
  90. Exp exp = new Exp(6, 6, 0, 6, 0, 0, 0);
  91. checkSelection(INCREMENTAL, options, "INFIX IGNORED", exp);
  92. }
  93. public void testKeywordSelectionBoth() {
  94. if (!eclipseAvailable()) {
  95. System.err.println("skipping test - eclipse classes not available");
  96. return;
  97. }
  98. String[] options = new String[]
  99. { "-ajctestRequireKeywords=requireKeyword",
  100. "-ajctestSkipKeywords=skipKeyword,skipUnenforcedAjcLimit",
  101. "!verbose",
  102. "-eclipse",
  103. };
  104. Exp exp = new Exp(17, 1, 16, 1, 0, 0, 1);
  105. checkSelection(SELECT, options, "keyword skipKeyword was found", exp);
  106. }
  107. public void testKeywordSelectionRequire() {
  108. if (!eclipseAvailable()) {
  109. System.err.println("skipping test - eclipse classes not available");
  110. return;
  111. }
  112. String[] options = new String[]
  113. { "-ajctestRequireKeywords=skipKeyword",
  114. "!verbose",
  115. "-eclipse",
  116. };
  117. Exp exp = new Exp(17, 1, 16, 1, 0, 0, 16);
  118. checkSelection(SELECT, options, "keyword skipKeyword was not found", exp);
  119. }
  120. public void testKeywordSelectionSkip() {
  121. if (!eclipseAvailable()) {
  122. System.err.println("skipping test - eclipse classes not available");
  123. return;
  124. }
  125. String[] options = new String[]
  126. { "-ajctestSkipKeywords=requireKeyword",
  127. "!verbose",
  128. "-eclipse",
  129. };
  130. Exp exp = new Exp(17, 0, 17, 0, 0, 0, 17);
  131. checkSelection(SELECT, options, "keyword requireKeyword was found", exp);
  132. }
  133. public void testNoOptions() {
  134. if (!ajcAvailable()) {
  135. System.err.println("skipping test - ajc classes not available");
  136. return;
  137. }
  138. String[] options = new String[]
  139. { "!ajc"
  140. };
  141. Exp exp = new Exp(17, 3, 14, 3, 0, 0, 4);
  142. checkSelection(SELECT, options, "normally-valid", exp);
  143. }
  144. public void testEclipseOptionsSkip() {
  145. String[] options = new String[]
  146. { "-eclipse",
  147. "-ajctestRequireKeywords=eclipseOptionSkip"
  148. };
  149. Exp exp = new Exp(17, 0, 17, 0, 0, 0, 6);
  150. checkSelection(SELECT, options, "old ajc 1.0 option", exp);
  151. }
  152. public void testAjcEclipseConflict() {
  153. if (!ajcAvailable()) {
  154. System.err.println("skipping test - ajc classes not available");
  155. return;
  156. }
  157. String[] options = new String[]
  158. { "!ajc"
  159. };
  160. Exp exp = new Exp(17, 3, 14, 3, 0, 0, 6);
  161. checkSelection(SELECT, options, "conflict between !eclipse and !ajc", exp);
  162. }
  163. public void testEclipseConflict() {
  164. String[] options = new String[]
  165. { "^eclipse",
  166. "-ajctestSkipKeywords=skipUnenforcedAjcLimit"
  167. };
  168. Exp exp = new Exp(17, 3, 14, 3, 0, 0, 6);
  169. checkSelection(SELECT, options, "force conflict between eclipse", exp);
  170. }
  171. public void testSinglePR() {
  172. String[] options = new String[]
  173. { "-eclipse", "-ajctestPR=100"
  174. };
  175. Exp exp = new Exp(17, 1, 16, 1, 0, 0, 16);
  176. checkSelection(SELECT, options, "bugId required", exp);
  177. }
  178. public void testTwoPR() {
  179. String[] options = new String[]
  180. { "-eclipse", "-ajctestPR=100,101"
  181. };
  182. Exp exp = new Exp(17, 2, 15, 2, 0, 0, 15);
  183. checkSelection(SELECT, options, "bugId required", exp);
  184. }
  185. public void testTitleContainsSubstringSelection() {
  186. String[] options = new String[]
  187. { "-ajctestTitleContains=run and ",
  188. "-eclipse"
  189. };
  190. Exp exp = new Exp(17, 1, 16, 1, 0, 0, 16);
  191. checkSelection(SELECT, options, "run and", exp);
  192. }
  193. public void testTitleContainsSubstringSelectionPlural() {
  194. String[] options = new String[]
  195. { "-ajctestTitleContains= run and , if skipKeyword ",
  196. "-eclipse"
  197. };
  198. Exp exp = new Exp(17, 2, 15, 2, 0, 0, 15);
  199. checkSelection(SELECT, options, "title", exp);
  200. }
  201. public void testTitleContainsExactSelection() {
  202. String[] options = new String[]
  203. { "-ajctestTitleContains=run and pass",
  204. "-eclipse"
  205. };
  206. Exp exp = new Exp(17, 1, 16, 1, 0, 0, 16);
  207. checkSelection(SELECT, options, "run and pass", exp);
  208. }
  209. public void testTitleContainsExactSelectionPlural() {
  210. String[] options = new String[]
  211. { "-ajctestTitleContains= run and pass , omit if skipKeyword ",
  212. "-eclipse"
  213. };
  214. Exp exp = new Exp(17, 2, 15, 2, 0, 0, 15);
  215. checkSelection(SELECT, options, "title", exp);
  216. }
  217. public void testTitleListSelection() {
  218. String[] options = new String[]
  219. { "-ajctestTitleList=run and pass",
  220. "-eclipse"
  221. };
  222. Exp exp = new Exp(17, 1, 16, 1, 0, 0, 16);
  223. checkSelection(SELECT, options, "run and pass", exp);
  224. }
  225. public void testTitleListSelectionPlural() {
  226. String[] options = new String[]
  227. { "-ajctestTitleList= run and pass , omit if skipKeyword ",
  228. "-eclipse"
  229. };
  230. Exp exp = new Exp(17, 2, 15, 2, 0, 0, 15);
  231. checkSelection(SELECT, options, "title", exp);
  232. }
  233. public void testTitleListFileSelection() {
  234. String[] options = new String[]
  235. { "-ajctestTitleList=" + TITLE_LIST_ONE,
  236. "-eclipse"
  237. };
  238. Exp exp = new Exp(17, 1, 16, 1, 0, 0, 16);
  239. checkSelection(SELECT, options, TITLE_LIST_ONE, exp);
  240. }
  241. public void testTitleListFileSelectionPlural() {
  242. String[] options = new String[]
  243. { "-ajctestTitleList=" + TITLE_LIST_PLURAL,
  244. "-eclipse"
  245. };
  246. Exp exp = new Exp(17, 2, 15, 2, 0, 0, 15);
  247. checkSelection(SELECT, options, TITLE_LIST_PLURAL, exp);
  248. // Now check the "fail only" path
  249. options = new String[]
  250. { "-ajctestTitleFailList=" + TITLE_LIST_PLURAL,
  251. "-eclipse"
  252. };
  253. // 1 messages skipped when run under 1.4 for other reasons,
  254. // so count "skip" instead of TITLE_LIST_PLURAL
  255. exp = new Exp(17, 2, 15, 2, 0, 0, 15);
  256. checkSelection(SELECT, options, "skip", exp);
  257. }
  258. /**
  259. * Run the static test suite with the given options.
  260. * @param setupHolder the IMessageHolder for any setup messages
  261. * @return null if setup failed or Harness.RunResult if suite completed.
  262. */
  263. private Harness.RunResult runSuite(String suiteFile, String[] options, MessageHandler setupHolder) {
  264. AbstractRunSpec.RT runtime = new AbstractRunSpec.RT();
  265. runtime.setOptions(options);
  266. AjcTest.Suite.Spec spec = getSpec(suiteFile);
  267. assertNotNull(spec);
  268. ArrayList kids = spec.getChildren();
  269. assertNotNull(kids);
  270. if ((suiteFile == SELECT) && (17 != kids.size())) {
  271. assertTrue("expected 17 kids, got " + kids.size(), false);
  272. }
  273. if (!spec.adoptParentValues(runtime, setupHolder)) {
  274. return null;
  275. } else {
  276. class TestHarness extends Harness {
  277. public RunResult run(AjcTest.Suite.Spec spec) {
  278. return super.run(spec);
  279. }
  280. }
  281. TestHarness h = new TestHarness();
  282. return h.run(spec);
  283. }
  284. }
  285. class Exp {
  286. public final int tests;
  287. public final int testsRun;
  288. public final int skipped;
  289. public final int passed;
  290. public final int failed;
  291. public final int incomplete;
  292. public final int infix;
  293. Exp(int tests, int testsRun, int skipped, int passed, int failed, int incomplete, int infix) {
  294. this.tests = tests;
  295. this.testsRun = testsRun;
  296. this.skipped = skipped;
  297. this.passed = passed;
  298. this.failed = failed;
  299. this.incomplete = incomplete;
  300. this.infix = infix;
  301. }
  302. }
  303. public void checkSelection(String suiteFile, String[] options, String infoInfix, Exp exp) {
  304. MessageHandler holder = new MessageHandler();
  305. Harness.RunResult result = runSuite(suiteFile, options, holder);
  306. if (verbose) {
  307. MessageUtil.print(System.out, holder, " setup - ");
  308. }
  309. assertNotNull("Harness.RunResult", result);
  310. // XXX sync hack snooping of message text with skip messages, harness
  311. final List skipList = MessageUtil.getMessages(holder, IMessage.INFO, false, "skip");
  312. final int numSkipped = skipList.size();
  313. IRunStatus status = result.status;
  314. assertNotNull(status);
  315. if (verbose) {
  316. RunUtils.print(System.out, "result - ", status);
  317. System.out.println(BridgeUtil.childString(status, numSkipped, result.numIncomplete));
  318. }
  319. assertEquals("skips", exp.skipped, numSkipped);
  320. IRunStatus[] children = status.getChildren();
  321. assertNotNull(children);
  322. assertTrue(children.length + "!= expRun=" + exp.testsRun,
  323. exp.testsRun == children.length);
  324. int actPass = 0;
  325. for (int i = 0; i < children.length; i++) {
  326. if (RunValidator.NORMAL.runPassed(children[i])) {
  327. actPass++;
  328. }
  329. }
  330. if (exp.passed != actPass) {
  331. assertTrue("exp.passed=" + exp.passed + " != actPass=" + actPass, false);
  332. }
  333. if (!LangUtil.isEmpty(infoInfix)) {
  334. int actInfix = MessageUtil.getMessages(holder, IMessage.INFO, false, infoInfix).size();
  335. if (actInfix != exp.infix) {
  336. String s = "for infix \"" + infoInfix
  337. + "\" actInfix=" + actInfix + " != expInfix=" + exp.infix;
  338. assertTrue(s, false);
  339. }
  340. }
  341. }
  342. private boolean ajcAvailable() { // XXX util
  343. try {
  344. return (null != Class.forName("org.aspectj.compiler.base.JavaCompiler"));
  345. } catch (ClassNotFoundException e) {
  346. return false;
  347. }
  348. }
  349. private boolean eclipseAvailable() { // XXX util
  350. try {
  351. return (null != Class.forName("org.aspectj.ajdt.ajc.AjdtCommand"));
  352. } catch (ClassNotFoundException e) {
  353. return false;
  354. }
  355. }
  356. }