Mercurial > hg4j
comparison test/org/tmatesoft/hg/test/TestHistory.java @ 214:4252faa556cd
Use custom timezone identifier to avoid applying daylight savings from the zone guessed
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Mon, 16 May 2011 21:10:36 +0200 |
parents | 706bcc7cfee4 |
children | 4c3b9f679412 |
comparison
equal
deleted
inserted
replaced
211:644ee58c9f16 | 214:4252faa556cd |
---|---|
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.io.File; | |
23 import java.util.ArrayList; | 24 import java.util.ArrayList; |
24 import java.util.Collections; | 25 import java.util.Collections; |
25 import java.util.Comparator; | 26 import java.util.Comparator; |
26 import java.util.Iterator; | 27 import java.util.Iterator; |
27 import java.util.LinkedList; | 28 import java.util.LinkedList; |
67 th.errorCollector.verify(); | 68 th.errorCollector.verify(); |
68 } | 69 } |
69 | 70 |
70 public TestHistory() throws Exception { | 71 public TestHistory() throws Exception { |
71 this(new HgLookup().detectFromWorkingDir()); | 72 this(new HgLookup().detectFromWorkingDir()); |
73 // this(new HgLookup().detect("\\temp\\hg\\hello")); | |
72 } | 74 } |
73 | 75 |
74 private TestHistory(HgRepository hgRepo) { | 76 private TestHistory(HgRepository hgRepo) { |
75 repo = hgRepo; | 77 repo = hgRepo; |
76 eh = new ExecHelper(changelogParser = new LogOutputParser(true), null); | 78 eh = new ExecHelper(changelogParser = new LogOutputParser(true), new File(repo.getLocation())); |
77 | 79 |
78 } | 80 } |
79 | 81 |
80 @Test | 82 @Test |
81 public void testCompleteLog() throws Exception { | 83 public void testCompleteLog() throws Exception { |
86 } | 88 } |
87 | 89 |
88 @Test | 90 @Test |
89 public void testFollowHistory() throws Exception { | 91 public void testFollowHistory() throws Exception { |
90 final Path f = Path.create("cmdline/org/tmatesoft/hg/console/Remote.java"); | 92 final Path f = Path.create("cmdline/org/tmatesoft/hg/console/Remote.java"); |
91 try { | 93 assertTrue(repo.getFileNode(f).exists()); |
92 if (repo.getFileNode(f).exists()) { // FIXME getFileNode shall not fail with IAE | 94 changelogParser.reset(); |
93 changelogParser.reset(); | 95 eh.run("hg", "log", "--debug", "--follow", f.toString()); |
94 eh.run("hg", "log", "--debug", "--follow", f.toString()); | 96 |
95 | 97 class H extends CollectHandler implements FileHistoryHandler { |
96 class H extends CollectHandler implements FileHistoryHandler { | 98 boolean copyReported = false; |
97 boolean copyReported = false; | 99 boolean fromMatched = false; |
98 boolean fromMatched = false; | 100 public void copy(FileRevision from, FileRevision to) { |
99 public void copy(FileRevision from, FileRevision to) { | 101 copyReported = true; |
100 copyReported = true; | 102 fromMatched = "src/com/tmate/hgkit/console/Remote.java".equals(from.getPath().toString()); |
101 fromMatched = "src/com/tmate/hgkit/console/Remote.java".equals(from.getPath().toString()); | |
102 } | |
103 }; | |
104 H h = new H(); | |
105 new HgLogCommand(repo).file(f, true).execute(h); | |
106 String what = "hg log - FOLLOW FILE HISTORY"; | |
107 errorCollector.checkThat(what + "#copyReported ", h.copyReported, is(true)); | |
108 errorCollector.checkThat(what + "#copyFromMatched", h.fromMatched, is(true)); | |
109 // | |
110 // cmdline always gives in changesets in order from newest (bigger rev number) to oldest. | |
111 // LogCommand does other way round, from oldest to newest, follewed by revisions of copy source, if any | |
112 // (apparently older than oldest of the copy target). Hence need to sort Java results according to rev numbers | |
113 final LinkedList<HgChangeset> sorted = new LinkedList<HgChangeset>(h.getChanges()); | |
114 Collections.sort(sorted, new Comparator<HgChangeset>() { | |
115 public int compare(HgChangeset cs1, HgChangeset cs2) { | |
116 return cs1.getRevision() < cs2.getRevision() ? 1 : -1; | |
117 } | |
118 }); | |
119 report(what, sorted, false); | |
120 } | 103 } |
121 } catch (IllegalArgumentException ex) { | 104 }; |
122 System.out.println("Can't test file history with follow because need to query specific file with history"); | 105 H h = new H(); |
123 } | 106 new HgLogCommand(repo).file(f, true).execute(h); |
107 String what = "hg log - FOLLOW FILE HISTORY"; | |
108 errorCollector.checkThat(what + "#copyReported ", h.copyReported, is(true)); | |
109 errorCollector.checkThat(what + "#copyFromMatched", h.fromMatched, is(true)); | |
110 // | |
111 // cmdline always gives in changesets in order from newest (bigger rev number) to oldest. | |
112 // LogCommand does other way round, from oldest to newest, follewed by revisions of copy source, if any | |
113 // (apparently older than oldest of the copy target). Hence need to sort Java results according to rev numbers | |
114 final LinkedList<HgChangeset> sorted = new LinkedList<HgChangeset>(h.getChanges()); | |
115 Collections.sort(sorted, new Comparator<HgChangeset>() { | |
116 public int compare(HgChangeset cs1, HgChangeset cs2) { | |
117 return cs1.getRevision() < cs2.getRevision() ? 1 : -1; | |
118 } | |
119 }); | |
120 report(what, sorted, false); | |
124 } | 121 } |
125 | 122 |
126 private void report(String what, List<HgChangeset> r, boolean reverseConsoleResult) { | 123 private void report(String what, List<HgChangeset> r, boolean reverseConsoleResult) { |
127 final List<Record> consoleResult = changelogParser.getResult(); | 124 final List<Record> consoleResult = changelogParser.getResult(); |
128 report(what, r, consoleResult, reverseConsoleResult, errorCollector); | 125 report(what, r, consoleResult, reverseConsoleResult, errorCollector); |
140 errorCollector.addError(new AssertionError("Ran out of console results while there are still hg4j results")); | 137 errorCollector.addError(new AssertionError("Ran out of console results while there are still hg4j results")); |
141 break; | 138 break; |
142 } | 139 } |
143 Record cr = consoleResultItr.next(); | 140 Record cr = consoleResultItr.next(); |
144 int x = cs.getRevision() == cr.changesetIndex ? 0x1 : 0; | 141 int x = cs.getRevision() == cr.changesetIndex ? 0x1 : 0; |
145 x |= cs.getDate().equals(cr.date) ? 0x2 : 0; | 142 x |= cs.getDate().toString().equals(cr.date) ? 0x2 : 0; |
146 x |= cs.getNodeid().toString().equals(cr.changesetNodeid) ? 0x4 : 0; | 143 x |= cs.getNodeid().toString().equals(cr.changesetNodeid) ? 0x4 : 0; |
147 x |= cs.getUser().equals(cr.user) ? 0x8 : 0; | 144 x |= cs.getUser().equals(cr.user) ? 0x8 : 0; |
148 // need to do trim() on comment because command-line template does, and there are | 145 // need to do trim() on comment because command-line template does, and there are |
149 // repositories that have couple of newlines in the end of the comment (e.g. hello sample repo from the book) | 146 // 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; | 147 x |= cs.getComment().trim().equals(cr.description) ? 0x10 : 0; |