Mercurial > hg4j
comparison test/org/tmatesoft/hg/test/TestStatus.java @ 109:dd4d2d0e42cd
Handler for StatusCommand to get notifications in the form of HgStatus object
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Sat, 29 Jan 2011 04:17:13 +0100 |
parents | 0b2dcca7de9f |
children | 2e395db595e2 |
comparison
equal
deleted
inserted
replaced
108:0c9804857000 | 109:dd4d2d0e42cd |
---|---|
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; | 19 import static org.hamcrest.CoreMatchers.equalTo; |
20 import static org.tmatesoft.hg.core.StatusCommand.HgStatus.Kind.*; | |
20 import static org.tmatesoft.hg.repo.HgRepository.TIP; | 21 import static org.tmatesoft.hg.repo.HgRepository.TIP; |
21 | 22 |
22 import java.util.Collection; | 23 import java.util.Collection; |
23 import java.util.Collections; | 24 import java.util.Collections; |
24 import java.util.HashMap; | 25 import java.util.HashMap; |
25 import java.util.LinkedList; | 26 import java.util.LinkedList; |
26 import java.util.List; | 27 import java.util.List; |
28 import java.util.Map; | |
29 import java.util.TreeMap; | |
27 | 30 |
28 import org.junit.Assume; | 31 import org.junit.Assume; |
29 import org.junit.Rule; | 32 import org.junit.Rule; |
30 import org.junit.Test; | 33 import org.junit.Test; |
31 import org.tmatesoft.hg.core.Path; | 34 import org.tmatesoft.hg.core.Path; |
32 import org.tmatesoft.hg.core.StatusCommand; | 35 import org.tmatesoft.hg.core.StatusCommand; |
36 import org.tmatesoft.hg.core.StatusCommand.HgStatus; | |
37 import org.tmatesoft.hg.core.StatusCommand.HgStatus.Kind; | |
33 import org.tmatesoft.hg.repo.HgLookup; | 38 import org.tmatesoft.hg.repo.HgLookup; |
34 import org.tmatesoft.hg.repo.HgRepository; | 39 import org.tmatesoft.hg.repo.HgRepository; |
35 import org.tmatesoft.hg.repo.HgStatusCollector; | 40 import org.tmatesoft.hg.repo.HgStatusCollector; |
36 import org.tmatesoft.hg.repo.HgWorkingCopyStatusCollector; | 41 import org.tmatesoft.hg.repo.HgWorkingCopyStatusCollector; |
37 | 42 |
98 } | 103 } |
99 | 104 |
100 @Test | 105 @Test |
101 public void testStatusCommand() throws Exception { | 106 public void testStatusCommand() throws Exception { |
102 final StatusCommand sc = new StatusCommand(repo).all(); | 107 final StatusCommand sc = new StatusCommand(repo).all(); |
103 HgStatusCollector.Record r; | 108 StatusCollector r; |
104 statusParser.reset(); | 109 statusParser.reset(); |
105 eh.run("hg", "status", "-A"); | 110 eh.run("hg", "status", "-A"); |
106 sc.execute(r = new HgStatusCollector.Record()); | 111 sc.execute(r = new StatusCollector()); |
107 report("hg status -A", r, statusParser); | 112 report("hg status -A", r); |
108 // | 113 // |
109 statusParser.reset(); | 114 statusParser.reset(); |
110 int revision = 3; | 115 int revision = 3; |
111 eh.run("hg", "status", "-A", "--rev", String.valueOf(revision)); | 116 eh.run("hg", "status", "-A", "--rev", String.valueOf(revision)); |
112 sc.base(revision).execute(r = new HgStatusCollector.Record()); | 117 sc.base(revision).execute(r = new StatusCollector()); |
113 report("status -A --rev " + revision, r, statusParser); | 118 report("status -A --rev " + revision, r); |
114 // | 119 // |
115 statusParser.reset(); | 120 statusParser.reset(); |
116 eh.run("hg", "status", "-A", "--change", String.valueOf(revision)); | 121 eh.run("hg", "status", "-A", "--change", String.valueOf(revision)); |
117 sc.base(TIP).revision(revision).execute(r = new HgStatusCollector.Record()); | 122 sc.base(TIP).revision(revision).execute(r = new StatusCollector()); |
118 report("status -A --change " + revision, r, statusParser); | 123 report("status -A --change " + revision, r); |
119 | 124 |
120 // TODO check not -A, but defaults()/custom set of modifications | 125 // TODO check not -A, but defaults()/custom set of modifications |
126 } | |
127 | |
128 private static class StatusCollector implements StatusCommand.Handler { | |
129 private final Map<StatusCommand.HgStatus.Kind, List<Path>> map = new TreeMap<StatusCommand.HgStatus.Kind, List<Path>>(); | |
130 | |
131 public void handleStatus(HgStatus s) { | |
132 List<Path> l = map.get(s.getKind()); | |
133 if (l == null) { | |
134 l = new LinkedList<Path>(); | |
135 map.put(s.getKind(), l); | |
136 } | |
137 l.add(s.getPath()); | |
138 } | |
139 | |
140 public List<Path> get(Kind k) { | |
141 List<Path> rv = map.get(k); | |
142 if (rv == null) { | |
143 return Collections.emptyList(); | |
144 } | |
145 return rv; | |
146 } | |
121 } | 147 } |
122 | 148 |
123 public void testRemovedAgainstNonTip() { | 149 public void testRemovedAgainstNonTip() { |
124 /* | 150 /* |
125 status --rev N when a file added past revision N was removed ((both physically and in dirstate), but not yet committed | 151 status --rev N when a file added past revision N was removed ((both physically and in dirstate), but not yet committed |
141 statusParser.reset(); | 167 statusParser.reset(); |
142 eh.run("hg", "status", "-A", "--rev", "3:80"); | 168 eh.run("hg", "status", "-A", "--rev", "3:80"); |
143 } | 169 } |
144 final long start2 = System.currentTimeMillis(); | 170 final long start2 = System.currentTimeMillis(); |
145 for (int i = 0; i < runs; i++) { | 171 for (int i = 0; i < runs; i++) { |
146 HgStatusCollector.Record r = new HgStatusCollector.Record(); | 172 StatusCollector r = new StatusCollector(); |
147 new StatusCommand(repo).all().base(3).revision(80).execute(r); | 173 new StatusCommand(repo).all().base(3).revision(80).execute(r); |
148 } | 174 } |
149 final long end = System.currentTimeMillis(); | 175 final long end = System.currentTimeMillis(); |
150 System.out.printf("'hg status -A --rev 3:80', %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); | 176 System.out.printf("'hg status -A --rev 3:80', %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 } | 177 } |
152 | 178 |
153 | 179 private void report(String what, StatusCollector r) { |
180 reportNotEqual(what + "#MODIFIED", r.get(Modified), statusParser.getModified()); | |
181 reportNotEqual(what + "#ADDED", r.get(Added), statusParser.getAdded()); | |
182 reportNotEqual(what + "#REMOVED", r.get(Removed), statusParser.getRemoved()); | |
183 reportNotEqual(what + "#CLEAN", r.get(Clean), statusParser.getClean()); | |
184 reportNotEqual(what + "#IGNORED", r.get(Ignored), statusParser.getIgnored()); | |
185 reportNotEqual(what + "#MISSING", r.get(Missing), statusParser.getMissing()); | |
186 reportNotEqual(what + "#UNKNOWN", r.get(Unknown), statusParser.getUnknown()); | |
187 // FIXME test copies | |
188 } | |
189 | |
154 private void report(String what, HgStatusCollector.Record r, StatusOutputParser statusParser) { | 190 private void report(String what, HgStatusCollector.Record r, StatusOutputParser statusParser) { |
155 reportNotEqual(what + "#MODIFIED", r.getModified(), statusParser.getModified()); | 191 reportNotEqual(what + "#MODIFIED", r.getModified(), statusParser.getModified()); |
156 reportNotEqual(what + "#ADDED", r.getAdded(), statusParser.getAdded()); | 192 reportNotEqual(what + "#ADDED", r.getAdded(), statusParser.getAdded()); |
157 reportNotEqual(what + "#REMOVED", r.getRemoved(), statusParser.getRemoved()); | 193 reportNotEqual(what + "#REMOVED", r.getRemoved(), statusParser.getRemoved()); |
158 reportNotEqual(what + "#CLEAN", r.getClean(), statusParser.getClean()); | 194 reportNotEqual(what + "#CLEAN", r.getClean(), statusParser.getClean()); |