Mercurial > hg4j
comparison test/org/tmatesoft/hg/test/TestHistory.java @ 147:a05145db4d0c
Bring test repos along with us to recreate testbench
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 22 Feb 2011 15:49:26 +0100 |
parents | 4a948ec83980 |
children | 706bcc7cfee4 |
comparison
equal
deleted
inserted
replaced
146:8c9f729f4dfa | 147:a05145db4d0c |
---|---|
16 */ | 16 */ |
17 package org.tmatesoft.hg.test; | 17 package org.tmatesoft.hg.test; |
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 | 22 |
22 import java.util.Collections; | 23 import java.util.Collections; |
23 import java.util.Comparator; | 24 import java.util.Comparator; |
24 import java.util.Iterator; | 25 import java.util.Iterator; |
25 import java.util.LinkedList; | 26 import java.util.LinkedList; |
26 import java.util.List; | 27 import java.util.List; |
27 | 28 |
28 import org.hamcrest.CoreMatchers; | |
29 import org.junit.Rule; | 29 import org.junit.Rule; |
30 import org.junit.Test; | 30 import org.junit.Test; |
31 import org.tmatesoft.hg.core.HgChangeset; | 31 import org.tmatesoft.hg.core.HgChangeset; |
32 import org.tmatesoft.hg.core.HgLogCommand; | 32 import org.tmatesoft.hg.core.HgLogCommand; |
33 import org.tmatesoft.hg.core.HgLogCommand.CollectHandler; | 33 import org.tmatesoft.hg.core.HgLogCommand.CollectHandler; |
47 public class TestHistory { | 47 public class TestHistory { |
48 | 48 |
49 @Rule | 49 @Rule |
50 public ErrorCollectorExt errorCollector = new ErrorCollectorExt(); | 50 public ErrorCollectorExt errorCollector = new ErrorCollectorExt(); |
51 | 51 |
52 private final HgRepository repo; | 52 private HgRepository repo; |
53 private ExecHelper eh; | 53 private final ExecHelper eh; |
54 private LogOutputParser changelogParser; | 54 private LogOutputParser changelogParser; |
55 | 55 |
56 public static void main(String[] args) throws Throwable { | 56 public static void main(String[] args) throws Throwable { |
57 TestHistory th = new TestHistory(); | 57 TestHistory th = new TestHistory(); |
58 th.testCompleteLog(); | 58 th.testCompleteLog(); |
59 th.testFollowHistory(); | 59 th.testFollowHistory(); |
60 th.errorCollector.verify(); | 60 th.errorCollector.verify(); |
61 th.testPerformance(); | 61 // th.testPerformance(); |
62 th.testOriginalTestLogRepo(); | |
63 th.testUsernames(); | |
64 th.testBranches(); | |
65 // | |
66 th.errorCollector.verify(); | |
62 } | 67 } |
63 | 68 |
64 public TestHistory() throws Exception { | 69 public TestHistory() throws Exception { |
65 this(new HgLookup().detectFromWorkingDir()); | 70 this(new HgLookup().detectFromWorkingDir()); |
66 } | 71 } |
67 | 72 |
68 private TestHistory(HgRepository hgRepo) { | 73 private TestHistory(HgRepository hgRepo) { |
69 repo = hgRepo; | 74 repo = hgRepo; |
70 eh = new ExecHelper(changelogParser = new LogOutputParser(true), null); | 75 eh = new ExecHelper(changelogParser = new LogOutputParser(true), null); |
76 | |
71 } | 77 } |
72 | 78 |
73 @Test | 79 @Test |
74 public void testCompleteLog() throws Exception { | 80 public void testCompleteLog() throws Exception { |
75 changelogParser.reset(); | 81 changelogParser.reset(); |
119 private void report(String what, List<HgChangeset> r, boolean reverseConsoleResults) { | 125 private void report(String what, List<HgChangeset> r, boolean reverseConsoleResults) { |
120 final List<Record> consoleResult = changelogParser.getResult(); | 126 final List<Record> consoleResult = changelogParser.getResult(); |
121 if (reverseConsoleResults) { | 127 if (reverseConsoleResults) { |
122 Collections.reverse(consoleResult); | 128 Collections.reverse(consoleResult); |
123 } | 129 } |
124 Iterator<LogOutputParser.Record> consoleResultItr = consoleResult.iterator(); | 130 Iterator<Record> consoleResultItr = consoleResult.iterator(); |
125 for (HgChangeset cs : r) { | 131 for (HgChangeset cs : r) { |
126 LogOutputParser.Record cr = consoleResultItr.next(); | 132 Record cr = consoleResultItr.next(); |
127 int x = cs.getRevision() == cr.changesetIndex ? 0x1 : 0; | 133 int x = cs.getRevision() == cr.changesetIndex ? 0x1 : 0; |
128 x |= cs.getDate().equals(cr.date) ? 0x2 : 0; | 134 x |= cs.getDate().equals(cr.date) ? 0x2 : 0; |
129 x |= cs.getNodeid().toString().equals(cr.changesetNodeid) ? 0x4 : 0; | 135 x |= cs.getNodeid().toString().equals(cr.changesetNodeid) ? 0x4 : 0; |
130 x |= cs.getUser().equals(cr.user) ? 0x8 : 0; | 136 x |= cs.getUser().equals(cr.user) ? 0x8 : 0; |
131 x |= cs.getComment().equals(cr.description) ? 0x10 : 0; | 137 x |= cs.getComment().equals(cr.description) ? 0x10 : 0; |
132 errorCollector.checkThat(String.format(what + ". Error in %d:%d. ", cs.getRevision(), cr.changesetIndex), x, equalTo(0x1f)); | 138 errorCollector.checkThat(String.format(what + ". Error in %d hg4j rev comparing to %d cmdline's.", cs.getRevision(), cr.changesetIndex), x, equalTo(0x1f)); |
133 consoleResultItr.remove(); | 139 consoleResultItr.remove(); |
134 } | 140 } |
135 errorCollector.checkThat(what + ". Insufficient results from Java ", consoleResultItr.hasNext(), equalTo(false)); | 141 errorCollector.checkThat(what + ". Insufficient results from Java ", consoleResultItr.hasNext(), equalTo(false)); |
136 } | 142 } |
137 | 143 |
147 new HgLogCommand(repo).execute(); | 153 new HgLogCommand(repo).execute(); |
148 } | 154 } |
149 final long end = System.currentTimeMillis(); | 155 final long end = System.currentTimeMillis(); |
150 System.out.printf("'hg log --debug', %d runs: Native client total %d (%d per run), Java client %d (%d)\n", runs, start2-start1, (start2-start1)/runs, end-start2, (end-start2)/runs); | 156 System.out.printf("'hg log --debug', %d runs: Native client total %d (%d per run), Java client %d (%d)\n", runs, start2-start1, (start2-start1)/runs, end-start2, (end-start2)/runs); |
151 } | 157 } |
158 | |
159 @Test | |
160 public void testOriginalTestLogRepo() throws Exception { | |
161 repo = Configuration.get().find("log-1"); | |
162 HgLogCommand cmd = new HgLogCommand(repo); | |
163 // funny enough, but hg log -vf a -R c:\temp\hg\test-log\a doesn't work, while --cwd <same> works fine | |
164 // | |
165 changelogParser.reset(); | |
166 eh.run("hg", "log", "--debug", "a", "--cwd", repo.getLocation()); | |
167 report("log a", cmd.file("a", false).execute(), true); | |
168 // | |
169 changelogParser.reset(); | |
170 eh.run("hg", "log", "--debug", "-f", "a", "--cwd", repo.getLocation()); | |
171 List<HgChangeset> r = cmd.file("a", true).execute(); | |
172 report("log -f a", r, true); | |
173 // | |
174 changelogParser.reset(); | |
175 eh.run("hg", "log", "--debug", "-f", "e", "--cwd", repo.getLocation()); | |
176 report("log -f e", cmd.file("e", true).execute(), false /*#1, below*/); | |
177 // | |
178 changelogParser.reset(); | |
179 eh.run("hg", "log", "--debug", "dir/b", "--cwd", repo.getLocation()); | |
180 report("log dir/b", cmd.file("dir/b", false).execute(), true); | |
181 // | |
182 changelogParser.reset(); | |
183 eh.run("hg", "log", "--debug", "-f", "dir/b", "--cwd", repo.getLocation()); | |
184 report("log -f dir/b", cmd.file("dir/b", true).execute(), false /*#1, below*/); | |
185 /* | |
186 * #1: false works because presently commands dispatches history of the queried file, and then history | |
187 * of it's origin. With history comprising of renames only, this effectively gives reversed (newest to oldest) | |
188 * order of revisions. | |
189 */ | |
190 } | |
191 | |
192 @Test | |
193 public void testUsernames() throws Exception { | |
194 repo = Configuration.get().find("log-users"); | |
195 final String user1 = "User One <user1@example.org>"; | |
196 // | |
197 changelogParser.reset(); | |
198 eh.run("hg", "log", "--debug", "-u", user1, "--cwd", repo.getLocation()); | |
199 report("log -u " + user1, new HgLogCommand(repo).user(user1).execute(), true); | |
200 // | |
201 changelogParser.reset(); | |
202 eh.run("hg", "log", "--debug", "-u", "user1", "-u", "user2", "--cwd", repo.getLocation()); | |
203 report("log -u user1 -u user2", new HgLogCommand(repo).user("user1").user("user2").execute(), true); | |
204 // | |
205 changelogParser.reset(); | |
206 eh.run("hg", "log", "--debug", "-u", "user3", "--cwd", repo.getLocation()); | |
207 report("log -u user3", new HgLogCommand(repo).user("user3").execute(), true); | |
208 } | |
209 | |
210 @Test | |
211 public void testBranches() throws Exception { | |
212 repo = Configuration.get().find("log-branches"); | |
213 changelogParser.reset(); | |
214 eh.run("hg", "log", "--debug", "-b", "default", "--cwd", repo.getLocation()); | |
215 report("log -b default" , new HgLogCommand(repo).branch("default").execute(), true); | |
216 // | |
217 changelogParser.reset(); | |
218 eh.run("hg", "log", "--debug", "-b", "test", "--cwd", repo.getLocation()); | |
219 report("log -b test" , new HgLogCommand(repo).branch("test").execute(), true); | |
220 // | |
221 assertTrue("log -b dummy shall yeild empty result", new HgLogCommand(repo).branch("dummy").execute().isEmpty()); | |
222 // | |
223 changelogParser.reset(); | |
224 eh.run("hg", "log", "--debug", "-b", "default", "-b", "test", "--cwd", repo.getLocation()); | |
225 report("log -b default -b test" , new HgLogCommand(repo).branch("default").branch("test").execute(), true); | |
226 } | |
152 } | 227 } |