Mercurial > hg4j
comparison test/org/tmatesoft/hg/test/TestManifest.java @ 103:0b2dcca7de9f
ErrorCollector in tests to grab multiple errors
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 28 Jan 2011 04:57:46 +0100 |
parents | a3a2e5deb320 |
children | 5c43e937e15b |
comparison
equal
deleted
inserted
replaced
102:a3a2e5deb320 | 103:0b2dcca7de9f |
---|---|
14 * the terms of a license other than GNU General Public License | 14 * the terms of a license other than GNU General Public License |
15 * contact TMate Software at support@hg4j.com | 15 * contact TMate Software at support@hg4j.com |
16 */ | 16 */ |
17 package org.tmatesoft.hg.test; | 17 package org.tmatesoft.hg.test; |
18 | 18 |
19 import static org.hamcrest.CoreMatchers.equalTo; | |
20 import static org.hamcrest.CoreMatchers.notNullValue; | |
19 import static org.tmatesoft.hg.repo.HgRepository.TIP; | 21 import static org.tmatesoft.hg.repo.HgRepository.TIP; |
20 | 22 |
23 import java.util.Collections; | |
21 import java.util.LinkedHashMap; | 24 import java.util.LinkedHashMap; |
22 import java.util.LinkedList; | 25 import java.util.LinkedList; |
23 import java.util.Map; | 26 import java.util.Map; |
24 | 27 |
25 import org.junit.Assume; | 28 import org.junit.Assume; |
29 import org.junit.Rule; | |
26 import org.junit.Test; | 30 import org.junit.Test; |
27 import org.tmatesoft.hg.core.LogCommand.FileRevision; | 31 import org.tmatesoft.hg.core.LogCommand.FileRevision; |
28 import org.tmatesoft.hg.core.Nodeid; | 32 import org.tmatesoft.hg.core.Nodeid; |
29 import org.tmatesoft.hg.core.Path; | 33 import org.tmatesoft.hg.core.Path; |
30 import org.tmatesoft.hg.core.RepositoryTreeWalker; | 34 import org.tmatesoft.hg.core.RepositoryTreeWalker; |
35 import org.tmatesoft.hg.repo.HgLookup; | |
31 import org.tmatesoft.hg.repo.HgRepository; | 36 import org.tmatesoft.hg.repo.HgRepository; |
32 import org.tmatesoft.hg.repo.HgLookup; | |
33 | 37 |
34 | 38 |
35 /** | 39 /** |
36 * | 40 * |
37 * @author Artem Tikhomirov | 41 * @author Artem Tikhomirov |
38 * @author TMate Software Ltd. | 42 * @author TMate Software Ltd. |
39 */ | 43 */ |
40 public class TestManifest { | 44 public class TestManifest { |
45 | |
46 @Rule | |
47 public ErrorCollectorExt errorCollector = new ErrorCollectorExt(); | |
41 | 48 |
42 private final HgRepository repo; | 49 private final HgRepository repo; |
43 private ManifestOutputParser manifestParser; | 50 private ManifestOutputParser manifestParser; |
44 private ExecHelper eh; | 51 private ExecHelper eh; |
45 final LinkedList<FileRevision> revisions = new LinkedList<FileRevision>(); | 52 final LinkedList<FileRevision> revisions = new LinkedList<FileRevision>(); |
52 public void end(Nodeid manifestRevision) {} | 59 public void end(Nodeid manifestRevision) {} |
53 public void dir(Path p) {} | 60 public void dir(Path p) {} |
54 public void begin(Nodeid manifestRevision) {} | 61 public void begin(Nodeid manifestRevision) {} |
55 }; | 62 }; |
56 | 63 |
57 public static void main(String[] args) throws Exception { | 64 public static void main(String[] args) throws Throwable { |
58 TestManifest tm = new TestManifest(); | 65 TestManifest tm = new TestManifest(); |
59 tm.testTip(); | 66 tm.testTip(); |
60 tm.testFirstRevision(); | 67 tm.testFirstRevision(); |
61 tm.testRevisionInTheMiddle(); | 68 tm.testRevisionInTheMiddle(); |
69 tm.errorCollector.verify(); | |
62 } | 70 } |
63 | 71 |
64 public TestManifest() throws Exception { | 72 public TestManifest() throws Exception { |
65 this(new HgLookup().detectFromWorkingDir()); | 73 this(new HgLookup().detectFromWorkingDir()); |
66 } | 74 } |
98 report("manifest " + (rev == TIP ? "TIP:" : "--rev " + rev)); | 106 report("manifest " + (rev == TIP ? "TIP:" : "--rev " + rev)); |
99 } | 107 } |
100 | 108 |
101 private void report(String what) throws Exception { | 109 private void report(String what) throws Exception { |
102 final Map<Path, Nodeid> cmdLineResult = new LinkedHashMap<Path, Nodeid>(manifestParser.getResult()); | 110 final Map<Path, Nodeid> cmdLineResult = new LinkedHashMap<Path, Nodeid>(manifestParser.getResult()); |
103 boolean error = false; | |
104 for (FileRevision fr : revisions) { | 111 for (FileRevision fr : revisions) { |
105 Nodeid nid = cmdLineResult.remove(fr.getPath()); | 112 Nodeid nid = cmdLineResult.remove(fr.getPath()); |
106 if (nid == null) { | 113 errorCollector.checkThat("Extra " + fr.getPath() + " in Java result", nid, notNullValue()); |
107 System.out.println("Extra " + fr.getPath() + " in Java result"); | 114 if (nid != null) { |
108 error = true; | 115 errorCollector.checkThat("Non-matching nodeid:" + nid, nid, equalTo(fr.getRevision())); |
109 } else { | |
110 if (!nid.equals(fr.getRevision())) { | |
111 System.out.println("Non-matching nodeid:" + nid); | |
112 error = true; | |
113 } | |
114 } | 116 } |
115 } | 117 } |
116 if (!cmdLineResult.isEmpty()) { | 118 errorCollector.checkThat("Non-matched entries from command line:", cmdLineResult, equalTo(Collections.<Path,Nodeid>emptyMap())); |
117 System.out.println("Non-matched entries from command line:"); | |
118 error = true; | |
119 for (Path p : cmdLineResult.keySet()) { | |
120 System.out.println(p); | |
121 } | |
122 } | |
123 System.out.println(what + (error ? " ERROR" : " OK")); | |
124 } | 119 } |
125 } | 120 } |