comparison test/org/tmatesoft/hg/test/TestHistory.java @ 202:706bcc7cfee4

Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 26 Apr 2011 02:50:06 +0200
parents a05145db4d0c
children 4252faa556cd
comparison
equal deleted inserted replaced
201:a736f42ed75b 202:706bcc7cfee4
18 18
19 import static org.hamcrest.CoreMatchers.equalTo; 19 import static org.hamcrest.CoreMatchers.equalTo;
20 import static org.hamcrest.CoreMatchers.is; 20 import static org.hamcrest.CoreMatchers.is;
21 import static org.junit.Assert.assertTrue; 21 import static org.junit.Assert.assertTrue;
22 22
23 import java.util.ArrayList;
23 import java.util.Collections; 24 import java.util.Collections;
24 import java.util.Comparator; 25 import java.util.Comparator;
25 import java.util.Iterator; 26 import java.util.Iterator;
26 import java.util.LinkedList; 27 import java.util.LinkedList;
27 import java.util.List; 28 import java.util.List;
120 } catch (IllegalArgumentException ex) { 121 } catch (IllegalArgumentException ex) {
121 System.out.println("Can't test file history with follow because need to query specific file with history"); 122 System.out.println("Can't test file history with follow because need to query specific file with history");
122 } 123 }
123 } 124 }
124 125
125 private void report(String what, List<HgChangeset> r, boolean reverseConsoleResults) { 126 private void report(String what, List<HgChangeset> r, boolean reverseConsoleResult) {
126 final List<Record> consoleResult = changelogParser.getResult(); 127 final List<Record> consoleResult = changelogParser.getResult();
127 if (reverseConsoleResults) { 128 report(what, r, consoleResult, reverseConsoleResult, errorCollector);
129 }
130
131 static void report(String what, List<HgChangeset> hg4jResult, List<Record> consoleResult, boolean reverseConsoleResult, ErrorCollectorExt errorCollector) {
132 consoleResult = new ArrayList<Record>(consoleResult); // need a copy in case callee would use result again
133 if (reverseConsoleResult) {
128 Collections.reverse(consoleResult); 134 Collections.reverse(consoleResult);
129 } 135 }
136 errorCollector.checkThat(what + ". Number of changeset reported didn't match", consoleResult.size(), equalTo(hg4jResult.size()));
130 Iterator<Record> consoleResultItr = consoleResult.iterator(); 137 Iterator<Record> consoleResultItr = consoleResult.iterator();
131 for (HgChangeset cs : r) { 138 for (HgChangeset cs : hg4jResult) {
139 if (!consoleResultItr.hasNext()) {
140 errorCollector.addError(new AssertionError("Ran out of console results while there are still hg4j results"));
141 break;
142 }
132 Record cr = consoleResultItr.next(); 143 Record cr = consoleResultItr.next();
133 int x = cs.getRevision() == cr.changesetIndex ? 0x1 : 0; 144 int x = cs.getRevision() == cr.changesetIndex ? 0x1 : 0;
134 x |= cs.getDate().equals(cr.date) ? 0x2 : 0; 145 x |= cs.getDate().equals(cr.date) ? 0x2 : 0;
135 x |= cs.getNodeid().toString().equals(cr.changesetNodeid) ? 0x4 : 0; 146 x |= cs.getNodeid().toString().equals(cr.changesetNodeid) ? 0x4 : 0;
136 x |= cs.getUser().equals(cr.user) ? 0x8 : 0; 147 x |= cs.getUser().equals(cr.user) ? 0x8 : 0;
137 x |= cs.getComment().equals(cr.description) ? 0x10 : 0; 148 // need to do trim() on comment because command-line template does, and there are
138 errorCollector.checkThat(String.format(what + ". Error in %d hg4j rev comparing to %d cmdline's.", cs.getRevision(), cr.changesetIndex), x, equalTo(0x1f)); 149 // repositories that have couple of newlines in the end of the comment (e.g. hello sample repo from the book)
150 x |= cs.getComment().trim().equals(cr.description) ? 0x10 : 0;
151 errorCollector.checkThat(String.format(what + ". Mismatch (0x%x) in %d hg4j rev comparing to %d cmdline's.", x, cs.getRevision(), cr.changesetIndex), x, equalTo(0x1f));
139 consoleResultItr.remove(); 152 consoleResultItr.remove();
140 } 153 }
141 errorCollector.checkThat(what + ". Insufficient results from Java ", consoleResultItr.hasNext(), equalTo(false)); 154 errorCollector.checkThat(what + ". Unprocessed results in console left (insufficient from hg4j)", consoleResultItr.hasNext(), equalTo(false));
142 } 155 }
143 156
144 public void testPerformance() throws Exception { 157 public void testPerformance() throws Exception {
145 final int runs = 10; 158 final int runs = 10;
146 final long start1 = System.currentTimeMillis(); 159 final long start1 = System.currentTimeMillis();