comparison test/org/tmatesoft/hg/test/TestHistory.java @ 103:0b2dcca7de9f

ErrorCollector in tests to grab multiple errors
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 28 Jan 2011 04:57:46 +0100
parents a3a2e5deb320
children 645829962785
comparison
equal deleted inserted replaced
102:a3a2e5deb320 103:0b2dcca7de9f
14 * the terms of a license other than GNU General Public License 14 * the terms of a license other than GNU General Public License
15 * contact TMate Software at support@hg4j.com 15 * contact TMate Software at support@hg4j.com
16 */ 16 */
17 package org.tmatesoft.hg.test; 17 package org.tmatesoft.hg.test;
18 18
19 import static org.hamcrest.CoreMatchers.equalTo;
20 import static org.hamcrest.CoreMatchers.is;
21
19 import java.util.Collections; 22 import java.util.Collections;
23 import java.util.Comparator;
20 import java.util.Iterator; 24 import java.util.Iterator;
25 import java.util.LinkedList;
21 import java.util.List; 26 import java.util.List;
22 27
28 import org.hamcrest.CoreMatchers;
29 import org.junit.Rule;
23 import org.junit.Test; 30 import org.junit.Test;
24 import org.tmatesoft.hg.core.Cset; 31 import org.tmatesoft.hg.core.Cset;
25 import org.tmatesoft.hg.core.LogCommand; 32 import org.tmatesoft.hg.core.LogCommand;
26 import org.tmatesoft.hg.core.LogCommand.CollectHandler; 33 import org.tmatesoft.hg.core.LogCommand.CollectHandler;
27 import org.tmatesoft.hg.core.LogCommand.FileHistoryHandler; 34 import org.tmatesoft.hg.core.LogCommand.FileHistoryHandler;
37 * @author Artem Tikhomirov 44 * @author Artem Tikhomirov
38 * @author TMate Software Ltd. 45 * @author TMate Software Ltd.
39 */ 46 */
40 public class TestHistory { 47 public class TestHistory {
41 48
49 @Rule
50 public ErrorCollectorExt errorCollector = new ErrorCollectorExt();
51
42 private final HgRepository repo; 52 private final HgRepository repo;
43 private ExecHelper eh; 53 private ExecHelper eh;
44 private LogOutputParser changelogParser; 54 private LogOutputParser changelogParser;
45 55
46 public static void main(String[] args) throws Exception { 56 public static void main(String[] args) throws Throwable {
47 TestHistory th = new TestHistory(); 57 TestHistory th = new TestHistory();
48 th.testCompleteLog(); 58 th.testCompleteLog();
49 th.testFollowHistory(); 59 th.testFollowHistory();
60 th.errorCollector.verify();
50 th.testPerformance(); 61 th.testPerformance();
51 } 62 }
52 63
53 public TestHistory() throws Exception { 64 public TestHistory() throws Exception {
54 this(new HgLookup().detectFromWorkingDir()); 65 this(new HgLookup().detectFromWorkingDir());
83 fromMatched = "src/com/tmate/hgkit/console/Remote.java".equals(from.getPath().toString()); 94 fromMatched = "src/com/tmate/hgkit/console/Remote.java".equals(from.getPath().toString());
84 } 95 }
85 }; 96 };
86 H h = new H(); 97 H h = new H();
87 new LogCommand(repo).file(f, true).execute(h); 98 new LogCommand(repo).file(f, true).execute(h);
88 System.out.print("hg log - FOLLOW FILE HISTORY"); 99 String what = "hg log - FOLLOW FILE HISTORY";
89 System.out.println("\tcopyReported:" + h.copyReported + ", and was " + (h.fromMatched ? "CORRECT" : "WRONG")); 100 errorCollector.checkThat(what + "#copyReported ", h.copyReported, is(true));
90 report("hg log - FOLLOW FILE HISTORY", h.getChanges(), false); 101 errorCollector.checkThat(what + "#copyFromMatched", h.fromMatched, is(true));
102 //
103 // cmdline always gives in changesets in order from newest (bigger rev number) to oldest.
104 // LogCommand does other way round, from oldest to newest, follewed by revisions of copy source, if any
105 // (apparently older than oldest of the copy target). Hence need to sort Java results according to rev numbers
106 final LinkedList<Cset> sorted = new LinkedList<Cset>(h.getChanges());
107 Collections.sort(sorted, new Comparator<Cset>() {
108 public int compare(Cset cs1, Cset cs2) {
109 return cs1.getRevision() < cs2.getRevision() ? 1 : -1;
110 }
111 });
112 report(what, sorted, false);
91 } 113 }
92 } catch (IllegalArgumentException ex) { 114 } catch (IllegalArgumentException ex) {
93 System.out.println("Can't test file history with follow because need to query specific file with history"); 115 System.out.println("Can't test file history with follow because need to query specific file with history");
94 } 116 }
95 } 117 }
98 final List<Record> consoleResult = changelogParser.getResult(); 120 final List<Record> consoleResult = changelogParser.getResult();
99 if (reverseConsoleResults) { 121 if (reverseConsoleResults) {
100 Collections.reverse(consoleResult); 122 Collections.reverse(consoleResult);
101 } 123 }
102 Iterator<LogOutputParser.Record> consoleResultItr = consoleResult.iterator(); 124 Iterator<LogOutputParser.Record> consoleResultItr = consoleResult.iterator();
103 boolean hasErrors = false;
104 for (Cset cs : r) { 125 for (Cset cs : r) {
105 LogOutputParser.Record cr = consoleResultItr.next(); 126 LogOutputParser.Record cr = consoleResultItr.next();
106 int x = cs.getRevision() == cr.changesetIndex ? 0x1 : 0; 127 int x = cs.getRevision() == cr.changesetIndex ? 0x1 : 0;
107 x |= cs.getDate().equals(cr.date) ? 0x2 : 0; 128 x |= cs.getDate().equals(cr.date) ? 0x2 : 0;
108 x |= cs.getNodeid().toString().equals(cr.changesetNodeid) ? 0x4 : 0; 129 x |= cs.getNodeid().toString().equals(cr.changesetNodeid) ? 0x4 : 0;
109 x |= cs.getUser().equals(cr.user) ? 0x8 : 0; 130 x |= cs.getUser().equals(cr.user) ? 0x8 : 0;
110 x |= cs.getComment().equals(cr.description) ? 0x10 : 0; 131 x |= cs.getComment().equals(cr.description) ? 0x10 : 0;
111 if (x != 0x1f) { 132 errorCollector.checkThat(String.format(what + ". Error in %d:%d. ", cs.getRevision(), cr.changesetIndex), x, equalTo(0x1f));
112 System.err.printf("Error in %d (%d):0%o\n", cs.getRevision(), cr.changesetIndex, x);
113 hasErrors = true;
114 }
115 consoleResultItr.remove(); 133 consoleResultItr.remove();
116 } 134 }
117 if (consoleResultItr.hasNext()) { 135 errorCollector.checkThat(what + ". Insufficient results from Java ", consoleResultItr.hasNext(), equalTo(false));
118 System.out.println("Insufficient results from Java");
119 hasErrors = true;
120 }
121 System.out.println(what + (hasErrors ? " FAIL" : " OK"));
122 } 136 }
123 137
124 public void testPerformance() throws Exception { 138 public void testPerformance() throws Exception {
125 final int runs = 10; 139 final int runs = 10;
126 final long start1 = System.currentTimeMillis(); 140 final long start1 = System.currentTimeMillis();