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.

TestDiffsTest.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 Eclipse Public License v1.0
  7. * which accompanies this distribution and is available at
  8. * http://www.eclipse.org/legal/epl-v10.html
  9. *
  10. * Contributors:
  11. * Xerox/PARC initial implementation
  12. * ******************************************************************/
  13. package org.aspectj.testing.util;
  14. import java.io.File;
  15. import java.io.FileWriter;
  16. import java.io.IOException;
  17. import java.io.PrintWriter;
  18. import java.util.ArrayList;
  19. import java.util.ListIterator;
  20. import org.aspectj.util.FileUtil;
  21. import junit.framework.TestCase;
  22. /**
  23. *
  24. */
  25. public class TestDiffsTest extends TestCase {
  26. /**
  27. * Expected results in test below.
  28. */
  29. private static void genTestInput(File expected, File actual) throws IOException {
  30. FileWriter writer = null;
  31. try {
  32. writer = new FileWriter(expected);
  33. PrintWriter pw = new PrintWriter(writer);
  34. pw.println("PASS passed in both");
  35. pw.println("## random text to ignore: " + System.currentTimeMillis());
  36. pw.println("FAIL failed in both");
  37. pw.println("PASS failed in actual (broken)");
  38. pw.println("FAIL passed in actual (fixed)");
  39. pw.println("PASS not in actual (missing-pass)");
  40. pw.println("FAIL not in actual (missing-fail)");
  41. pw.flush();
  42. writer.close();
  43. writer = new FileWriter(actual);
  44. pw = new PrintWriter(writer);
  45. pw.println("PASS passed in actual (fixed)");
  46. pw.println("## random text to ignore: " + System.currentTimeMillis());
  47. pw.println("PASS not in expected (added-pass)");
  48. pw.println("FAIL failed in both");
  49. pw.println("PASS passed in both");
  50. pw.println("FAIL failed in actual (broken)");
  51. pw.println("FAIL not in expected (added-fail)");
  52. pw.flush();
  53. writer.close();
  54. writer = null;
  55. } finally {
  56. if (null != writer) {
  57. try { writer.close(); }
  58. catch (IOException e) { } // ignore
  59. }
  60. }
  61. }
  62. ArrayList tempFiles;
  63. /**
  64. * Constructor for FileUtilTest.
  65. * @param arg0
  66. */
  67. public TestDiffsTest(String arg0) {
  68. super(arg0);
  69. tempFiles = new ArrayList();
  70. }
  71. public void tearDown() {
  72. for (ListIterator iter = tempFiles.listIterator(); iter.hasNext();) {
  73. File dir = (File) iter.next();
  74. FileUtil.deleteContents(dir);
  75. dir.delete();
  76. iter.remove();
  77. }
  78. }
  79. public void testCompareResults() {
  80. File tempDir = org.aspectj.util.FileUtil.getTempDir("testCompareResults");
  81. File expected = new File(tempDir, "expected.txt");
  82. File actual = new File(tempDir, "actual.txt");
  83. tempFiles.add(expected);
  84. tempFiles.add(actual);
  85. try {
  86. genTestInput(expected, actual);
  87. } catch (IOException e) {
  88. assertTrue(e.getMessage(), false);
  89. }
  90. TestDiffs result = TestDiffs.compareResults(expected, actual);
  91. assertEquals(2, result.missing.size());
  92. assertEquals(2, result.added.size());
  93. assertEquals(1, result.fixed.size());
  94. assertEquals(1, result.broken.size());
  95. assertEquals(3, result.actualFailed.size());
  96. assertEquals(3, result.actualPassed.size());
  97. assertEquals(6, result.actual.size());
  98. assertEquals(3, result.expectedFailed.size());
  99. assertEquals(3, result.expectedPassed.size());
  100. assertEquals(6, result.expected.size());
  101. assertEquals(1, result.stillFailing.size());
  102. assertEquals(1, result.stillPassing.size());
  103. }
  104. }