Mercurial > hg4j
comparison test/org/tmatesoft/hg/test/TestManifest.java @ 67:64bddc2dcc0e
Tests for manifest cmd
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 21 Jan 2011 19:21:43 +0100 |
parents | |
children | 6f1b88693d48 |
comparison
equal
deleted
inserted
replaced
66:52dc3f4cfc76 | 67:64bddc2dcc0e |
---|---|
1 /* | |
2 * Copyright (c) 2011 TMate Software Ltd | |
3 * | |
4 * This program is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; version 2 of the License. | |
7 * | |
8 * This program is distributed in the hope that it will be useful, | |
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 * GNU General Public License for more details. | |
12 * | |
13 * For information on how to redistribute this software under | |
14 * the terms of a license other than GNU General Public License | |
15 * contact TMate Software at support@svnkit.com | |
16 */ | |
17 package org.tmatesoft.hg.test; | |
18 | |
19 import static com.tmate.hgkit.ll.HgRepository.TIP; | |
20 | |
21 import java.util.LinkedHashMap; | |
22 import java.util.LinkedList; | |
23 import java.util.Map; | |
24 | |
25 import org.tmatesoft.hg.core.LogCommand.FileRevision; | |
26 import org.tmatesoft.hg.core.Path; | |
27 import org.tmatesoft.hg.core.RepositoryTreeWalker; | |
28 | |
29 import com.tmate.hgkit.fs.RepositoryLookup; | |
30 import com.tmate.hgkit.ll.HgRepository; | |
31 import com.tmate.hgkit.ll.Nodeid; | |
32 | |
33 /** | |
34 * | |
35 * @author Artem Tikhomirov | |
36 * @author TMate Software Ltd. | |
37 */ | |
38 public class TestManifest { | |
39 | |
40 private final HgRepository repo; | |
41 private ManifestOutputParser manifestParser; | |
42 private ExecHelper eh; | |
43 final LinkedList<FileRevision> revisions = new LinkedList<FileRevision>(); | |
44 private RepositoryTreeWalker.Handler handler = new RepositoryTreeWalker.Handler() { | |
45 | |
46 public void file(FileRevision fileRevision) { | |
47 revisions.add(fileRevision); | |
48 } | |
49 | |
50 public void end(Nodeid manifestRevision) {} | |
51 public void dir(Path p) {} | |
52 public void begin(Nodeid manifestRevision) {} | |
53 }; | |
54 | |
55 public static void main(String[] args) throws Exception { | |
56 HgRepository repo = new RepositoryLookup().detectFromWorkingDir(); | |
57 TestManifest tm = new TestManifest(repo); | |
58 tm.testTip(); | |
59 tm.testFirstRevision(); | |
60 tm.testRevisionInTheMiddle(); | |
61 } | |
62 | |
63 public TestManifest(HgRepository hgRepo) { | |
64 repo = hgRepo; | |
65 eh = new ExecHelper(manifestParser = new ManifestOutputParser(), null); | |
66 } | |
67 | |
68 public void testTip() throws Exception { | |
69 testRevision(TIP); | |
70 } | |
71 | |
72 public void testFirstRevision() throws Exception { | |
73 testRevision(0); | |
74 } | |
75 | |
76 public void testRevisionInTheMiddle() throws Exception { | |
77 int rev = repo.getManifest().getRevisionCount() / 2; | |
78 if (rev == 0) { | |
79 throw new IllegalStateException("Need manifest with few revisions"); | |
80 } | |
81 testRevision(rev); | |
82 } | |
83 | |
84 private void testRevision(int rev) throws Exception { | |
85 manifestParser.reset(); | |
86 eh.run("hg", "manifest", "--debug", "--rev", String.valueOf(rev)); | |
87 revisions.clear(); | |
88 new RepositoryTreeWalker(repo).revision(rev).walk(handler); | |
89 report("manifest " + (rev == TIP ? "TIP:" : "--rev " + rev)); | |
90 } | |
91 | |
92 private void report(String what) throws Exception { | |
93 final Map<Path, Nodeid> cmdLineResult = new LinkedHashMap<Path, Nodeid>(manifestParser.getResult()); | |
94 boolean error = false; | |
95 for (FileRevision fr : revisions) { | |
96 Nodeid nid = cmdLineResult.remove(fr.getPath()); | |
97 if (nid == null) { | |
98 System.out.println("Extra " + fr.getPath() + " in Java result"); | |
99 error = true; | |
100 } else { | |
101 if (!nid.equals(fr.getRevision())) { | |
102 System.out.println("Non-matching nodeid:" + nid); | |
103 error = true; | |
104 } | |
105 } | |
106 } | |
107 if (!cmdLineResult.isEmpty()) { | |
108 System.out.println("Non-matched entries from command line:"); | |
109 error = true; | |
110 for (Path p : cmdLineResult.keySet()) { | |
111 System.out.println(p); | |
112 } | |
113 } | |
114 System.out.println(what + (error ? " ERROR" : " OK")); | |
115 } | |
116 } |