Mercurial > hg4j
annotate test/org/tmatesoft/hg/test/TestHistory.java @ 99:4d7bb95d553b
StatusCommand().add should list copies
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 27 Jan 2011 23:08:51 +0100 |
parents | bcd31a4c638a |
children | b71b3f7d24d4 |
rev | line source |
---|---|
70
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2011 TMate Software Ltd |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
3 * |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
7 * |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
11 * GNU General Public License for more details. |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
12 * |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
13 * For information on how to redistribute this software under |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
15 * contact TMate Software at support@svnkit.com |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
17 package org.tmatesoft.hg.test; |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
19 import java.util.Collections; |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
20 import java.util.Iterator; |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
21 import java.util.List; |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
22 |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
23 import org.tmatesoft.hg.core.Cset; |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
24 import org.tmatesoft.hg.core.LogCommand; |
82
7255c971dd66
Promitive test for follow file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
25 import org.tmatesoft.hg.core.LogCommand.CollectHandler; |
7255c971dd66
Promitive test for follow file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
26 import org.tmatesoft.hg.core.LogCommand.FileHistoryHandler; |
7255c971dd66
Promitive test for follow file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
27 import org.tmatesoft.hg.core.LogCommand.FileRevision; |
7255c971dd66
Promitive test for follow file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
28 import org.tmatesoft.hg.core.Path; |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
70
diff
changeset
|
29 import org.tmatesoft.hg.repo.HgRepository; |
95
bcd31a4c638a
Lookup to HgLookup
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
82
diff
changeset
|
30 import org.tmatesoft.hg.repo.HgLookup; |
70
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 import org.tmatesoft.hg.test.LogOutputParser.Record; |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 /** |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 * |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
36 * @author Artem Tikhomirov |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 * @author TMate Software Ltd. |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 */ |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
39 public class TestHistory { |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
40 |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 private final HgRepository repo; |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 private ExecHelper eh; |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 private LogOutputParser changelogParser; |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
45 public static void main(String[] args) throws Exception { |
95
bcd31a4c638a
Lookup to HgLookup
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
82
diff
changeset
|
46 TestHistory th = new TestHistory(new HgLookup().detectFromWorkingDir()); |
70
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
47 th.testCompleteLog(); |
82
7255c971dd66
Promitive test for follow file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
48 th.testFollowHistory(); |
70
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
49 } |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
50 |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
51 public TestHistory(HgRepository hgRepo) { |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
52 repo = hgRepo; |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
53 eh = new ExecHelper(changelogParser = new LogOutputParser(true), null); |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
54 } |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
55 |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 public void testCompleteLog() throws Exception { |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
57 changelogParser.reset(); |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
58 eh.run("hg", "log", "--debug"); |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
59 List<Cset> r = new LogCommand(repo).execute(); |
82
7255c971dd66
Promitive test for follow file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
60 report("hg log - COMPLETE REPO HISTORY", r, true); |
7255c971dd66
Promitive test for follow file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
61 } |
7255c971dd66
Promitive test for follow file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
62 |
7255c971dd66
Promitive test for follow file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
63 public void testFollowHistory() throws Exception { |
7255c971dd66
Promitive test for follow file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
64 final Path f = Path.create("cmdline/org/tmatesoft/hg/console/Remote.java"); |
7255c971dd66
Promitive test for follow file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
65 try { |
7255c971dd66
Promitive test for follow file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
66 if (repo.getFileNode(f).exists()) { // FIXME getFileNode shall not fail with IAE |
7255c971dd66
Promitive test for follow file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
67 changelogParser.reset(); |
7255c971dd66
Promitive test for follow file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
68 eh.run("hg", "log", "--debug", "--follow", f.toString()); |
7255c971dd66
Promitive test for follow file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
69 |
7255c971dd66
Promitive test for follow file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
70 class H extends CollectHandler implements FileHistoryHandler { |
7255c971dd66
Promitive test for follow file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
71 boolean copyReported = false; |
7255c971dd66
Promitive test for follow file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
72 boolean fromMatched = false; |
7255c971dd66
Promitive test for follow file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
73 public void copy(FileRevision from, FileRevision to) { |
7255c971dd66
Promitive test for follow file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
74 copyReported = true; |
7255c971dd66
Promitive test for follow file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
75 fromMatched = "src/com/tmate/hgkit/console/Remote.java".equals(from.getPath().toString()); |
7255c971dd66
Promitive test for follow file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
76 } |
7255c971dd66
Promitive test for follow file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
77 }; |
7255c971dd66
Promitive test for follow file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
78 H h = new H(); |
7255c971dd66
Promitive test for follow file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
79 new LogCommand(repo).file(f, true).execute(h); |
7255c971dd66
Promitive test for follow file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
80 System.out.print("hg log - FOLLOW FILE HISTORY"); |
7255c971dd66
Promitive test for follow file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
81 System.out.println("\tcopyReported:" + h.copyReported + ", and was " + (h.fromMatched ? "CORRECT" : "WRONG")); |
7255c971dd66
Promitive test for follow file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
82 report("hg log - FOLLOW FILE HISTORY", h.getChanges(), false); |
7255c971dd66
Promitive test for follow file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
83 } |
7255c971dd66
Promitive test for follow file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
84 } catch (IllegalArgumentException ex) { |
7255c971dd66
Promitive test for follow file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
85 System.out.println("Can't test file history with follow because need to query specific file with history"); |
7255c971dd66
Promitive test for follow file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
86 } |
70
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
87 } |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
88 |
82
7255c971dd66
Promitive test for follow file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
89 private void report(String what, List<Cset> r, boolean reverseConsoleResults) { |
70
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
90 final List<Record> consoleResult = changelogParser.getResult(); |
82
7255c971dd66
Promitive test for follow file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
91 if (reverseConsoleResults) { |
7255c971dd66
Promitive test for follow file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
92 Collections.reverse(consoleResult); |
7255c971dd66
Promitive test for follow file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
93 } |
70
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
94 Iterator<LogOutputParser.Record> consoleResultItr = consoleResult.iterator(); |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
95 boolean hasErrors = false; |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
96 for (Cset cs : r) { |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
97 LogOutputParser.Record cr = consoleResultItr.next(); |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
98 int x = cs.getRevision() == cr.changesetIndex ? 0x1 : 0; |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
99 x |= cs.getDate().equals(cr.date) ? 0x2 : 0; |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
100 x |= cs.getNodeid().toString().equals(cr.changesetNodeid) ? 0x4 : 0; |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
101 x |= cs.getUser().equals(cr.user) ? 0x8 : 0; |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
102 x |= cs.getComment().equals(cr.description) ? 0x10 : 0; |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
103 if (x != 0x1f) { |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
104 System.err.printf("Error in %d (%d):0%o\n", cs.getRevision(), cr.changesetIndex, x); |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
105 hasErrors = true; |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
106 } |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
107 consoleResultItr.remove(); |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
108 } |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
109 if (consoleResultItr.hasNext()) { |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
110 System.out.println("Insufficient results from Java"); |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
111 hasErrors = true; |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
112 } |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
113 System.out.println(what + (hasErrors ? " FAIL" : " OK")); |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
114 } |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
115 } |