comparison test/org/tmatesoft/hg/test/TestStatus.java @ 68:0e499fed9b3d

StatusCommand with tests. Extra constants to indicate common revision cases
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Sat, 22 Jan 2011 22:11:24 +0100
parents 52dc3f4cfc76
children 6f1b88693d48
comparison
equal deleted inserted replaced
67:64bddc2dcc0e 68:0e499fed9b3d
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@svnkit.com 15 * contact TMate Software at support@svnkit.com
16 */ 16 */
17 package org.tmatesoft.hg.test; 17 package org.tmatesoft.hg.test;
18 18
19 import static com.tmate.hgkit.ll.HgRepository.TIP;
20
19 import java.io.File; 21 import java.io.File;
20 import java.util.Collection; 22 import java.util.Collection;
21 import java.util.LinkedList; 23 import java.util.LinkedList;
22 import java.util.List; 24 import java.util.List;
25
26 import org.tmatesoft.hg.core.StatusCommand;
23 27
24 import com.tmate.hgkit.fs.FileWalker; 28 import com.tmate.hgkit.fs.FileWalker;
25 import com.tmate.hgkit.fs.RepositoryLookup; 29 import com.tmate.hgkit.fs.RepositoryLookup;
26 import com.tmate.hgkit.ll.HgRepository; 30 import com.tmate.hgkit.ll.HgRepository;
27 import com.tmate.hgkit.ll.StatusCollector; 31 import com.tmate.hgkit.ll.StatusCollector;
32 * @author Artem Tikhomirov 36 * @author Artem Tikhomirov
33 * @author TMate Software Ltd. 37 * @author TMate Software Ltd.
34 */ 38 */
35 public class TestStatus { 39 public class TestStatus {
36 40
41 private final HgRepository repo;
37 private StatusOutputParser statusParser; 42 private StatusOutputParser statusParser;
38 private ExecHelper eh; 43 private ExecHelper eh;
39 private final HgRepository repo;
40 44
41 public static void main(String[] args) throws Exception { 45 public static void main(String[] args) throws Exception {
42 HgRepository repo = new RepositoryLookup().detectFromWorkingDir(); 46 HgRepository repo = new RepositoryLookup().detectFromWorkingDir();
43 TestStatus test = new TestStatus(repo); 47 TestStatus test = new TestStatus(repo);
44 test.testLowLevel(); 48 test.testLowLevel();
51 eh = new ExecHelper(statusParser, null); 55 eh = new ExecHelper(statusParser, null);
52 } 56 }
53 57
54 public void testLowLevel() throws Exception { 58 public void testLowLevel() throws Exception {
55 final WorkingCopyStatusCollector wcc = new WorkingCopyStatusCollector(repo, new FileWalker(new File(System.getProperty("user.dir")))); 59 final WorkingCopyStatusCollector wcc = new WorkingCopyStatusCollector(repo, new FileWalker(new File(System.getProperty("user.dir"))));
60 statusParser.reset();
56 eh.run("hg", "status", "-A"); 61 eh.run("hg", "status", "-A");
57 StatusCollector.Record r = wcc.status(HgRepository.TIP); 62 StatusCollector.Record r = wcc.status(HgRepository.TIP);
58 report("hg status -A", r, statusParser); 63 report("hg status -A", r, statusParser);
59 // 64 //
60 statusParser.reset(); 65 statusParser.reset();
69 new StatusCollector(repo).change(revision, r); 74 new StatusCollector(repo).change(revision, r);
70 report("status -A --change " + revision, r, statusParser); 75 report("status -A --change " + revision, r, statusParser);
71 } 76 }
72 77
73 public void testStatusCommand() throws Exception { 78 public void testStatusCommand() throws Exception {
74 throw HgRepository.notImplemented(); 79 final StatusCommand sc = new StatusCommand(repo).all();
80 StatusCollector.Record r;
81 statusParser.reset();
82 eh.run("hg", "status", "-A");
83 sc.execute(r = new StatusCollector.Record());
84 report("hg status -A", r, statusParser);
85 //
86 statusParser.reset();
87 int revision = 3;
88 eh.run("hg", "status", "-A", "--rev", String.valueOf(revision));
89 sc.base(revision).execute(r = new StatusCollector.Record());
90 report("status -A --rev " + revision, r, statusParser);
91 //
92 statusParser.reset();
93 eh.run("hg", "status", "-A", "--change", String.valueOf(revision));
94 sc.base(TIP).revision(revision).execute(r = new StatusCollector.Record());
95 report("status -A --change " + revision, r, statusParser);
96
97 // TODO check not -A, but defaults()/custom set of modifications
75 } 98 }
76 99
77 private static void report(String what, StatusCollector.Record r, StatusOutputParser statusParser) { 100 private static void report(String what, StatusCollector.Record r, StatusOutputParser statusParser) {
78 System.out.println(">>>" + what); 101 System.out.println(">>>" + what);
79 reportNotEqual("MODIFIED", r.getModified(), statusParser.getModified()); 102 reportNotEqual("MODIFIED", r.getModified(), statusParser.getModified());