comparison test/org/tmatesoft/hg/test/TestStatus.java @ 282:e51dd9a14b6f

Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Sat, 03 Sep 2011 01:21:03 +0200
parents 0dd9da7489dc
children 7a8e1a305a78
comparison
equal deleted inserted replaced
281:81e9a3c9bafe 282:e51dd9a14b6f
20 import static org.junit.Assert.assertEquals; 20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertTrue; 21 import static org.junit.Assert.assertTrue;
22 import static org.tmatesoft.hg.core.HgStatus.Kind.*; 22 import static org.tmatesoft.hg.core.HgStatus.Kind.*;
23 import static org.tmatesoft.hg.repo.HgRepository.TIP; 23 import static org.tmatesoft.hg.repo.HgRepository.TIP;
24 24
25 import java.util.ArrayList;
25 import java.util.Collection; 26 import java.util.Collection;
26 import java.util.Collections; 27 import java.util.Collections;
27 import java.util.HashMap; 28 import java.util.HashMap;
28 import java.util.LinkedList; 29 import java.util.LinkedList;
29 import java.util.List; 30 import java.util.List;
30 import java.util.Map; 31 import java.util.Map;
31 import java.util.TreeMap; 32 import java.util.TreeMap;
32 33
33 import org.junit.Assume; 34 import org.junit.Assume;
35 import org.junit.Ignore;
34 import org.junit.Rule; 36 import org.junit.Rule;
35 import org.junit.Test; 37 import org.junit.Test;
36 import org.tmatesoft.hg.core.HgStatus; 38 import org.tmatesoft.hg.core.HgStatus;
37 import org.tmatesoft.hg.core.HgStatus.Kind; 39 import org.tmatesoft.hg.core.HgStatus.Kind;
38 import org.tmatesoft.hg.core.HgStatusCommand; 40 import org.tmatesoft.hg.core.HgStatusCommand;
62 TestStatus test = new TestStatus(); 64 TestStatus test = new TestStatus();
63 test.testLowLevel(); 65 test.testLowLevel();
64 test.testStatusCommand(); 66 test.testStatusCommand();
65 test.testPerformance(); 67 test.testPerformance();
66 test.errorCollector.verify(); 68 test.errorCollector.verify();
69 //
70 TestStatus t2 = new TestStatus(new HgLookup().detect("/temp/hg/hg4j-merging/hg4j"));
71 t2.testDirstateParentOtherThanTip(238);
72 t2.errorCollector.verify();
73 TestStatus t3 = new TestStatus(new HgLookup().detect("/temp/hg/cpython"));
74 t3.testDirstateParentOtherThanTip(-1);
75 t3.errorCollector.verify();
67 } 76 }
68 77
69 public TestStatus() throws Exception { 78 public TestStatus() throws Exception {
70 this(new HgLookup().detectFromWorkingDir()); 79 this(new HgLookup().detectFromWorkingDir());
71 } 80 }
72 81
73 private TestStatus(HgRepository hgRepo) { 82 private TestStatus(HgRepository hgRepo) {
74 repo = hgRepo; 83 repo = hgRepo;
75 Assume.assumeTrue(!repo.isInvalid()); 84 Assume.assumeTrue(!repo.isInvalid());
76 statusParser = new StatusOutputParser(); 85 statusParser = new StatusOutputParser();
77 eh = new ExecHelper(statusParser, null); 86 eh = new ExecHelper(statusParser, hgRepo.getWorkingDir());
78 } 87 }
79 88
80 @Test 89 @Test
81 public void testLowLevel() throws Exception { 90 public void testLowLevel() throws Exception {
82 final HgWorkingCopyStatusCollector wcc = new HgWorkingCopyStatusCollector(repo); 91 final HgWorkingCopyStatusCollector wcc = new HgWorkingCopyStatusCollector(repo);
102 final String range = String.valueOf(revision) + ":" + String.valueOf(rev2); 111 final String range = String.valueOf(revision) + ":" + String.valueOf(rev2);
103 eh.run("hg", "status", "-A", "--rev", range); 112 eh.run("hg", "status", "-A", "--rev", range);
104 r = new HgStatusCollector(repo).status(revision, rev2); 113 r = new HgStatusCollector(repo).status(revision, rev2);
105 report("Status -A -rev " + range, r, statusParser); 114 report("Status -A -rev " + range, r, statusParser);
106 } 115 }
116
117 /**
118 * hg up --rev <earlier rev>; hg status
119 *
120 * To check if HgWorkingCopyStatusCollector respects actual working copy parent (takes from dirstate)
121 * and if status is calculated correctly
122 */
123 @Test
124 @Ignore("modifies test repository, needs careful configuration")
125 public void testDirstateParentOtherThanTip(int revToUpdate) throws Exception {
126 final HgWorkingCopyStatusCollector wcc = new HgWorkingCopyStatusCollector(repo);
127 statusParser.reset();
128 try {
129 if (revToUpdate != -1) {
130 // there are repositories (like cpython) where WC is not tip-based, and no need to
131 // accomplish that artificially
132 eh.run("hg", "up", "--rev", String.valueOf(revToUpdate));
133 }
134 //
135 eh.run("hg", "status", "-A");
136 HgStatusCollector.Record r = wcc.status(HgRepository.TIP);
137 report("hg status -A", r, statusParser);
138 //
139 statusParser.reset();
140 int revision = 3;
141 eh.run("hg", "status", "-A", "--rev", String.valueOf(revision));
142 r = wcc.status(revision);
143 report("status -A --rev " + revision, r, statusParser);
144 } finally {
145 if (revToUpdate != -1) {
146 // bring the repository to the tip just in case anyone else is using it afterwards
147 eh.run("hg", "up");
148 }
149 }
150 }
151
107 152
108 @Test 153 @Test
109 public void testStatusCommand() throws Exception { 154 public void testStatusCommand() throws Exception {
110 final HgStatusCommand sc = new HgStatusCommand(repo).all(); 155 final HgStatusCommand sc = new HgStatusCommand(repo).all();
111 StatusCollector r; 156 StatusCollector r;
454 } 499 }
455 errorCollector.checkThat(what + "#Non-matching 'copied' keys: ", copiedKeyDiff, equalTo(Collections.<Path>emptyList())); 500 errorCollector.checkThat(what + "#Non-matching 'copied' keys: ", copiedKeyDiff, equalTo(Collections.<Path>emptyList()));
456 errorCollector.checkThat(what + "#COPIED", copyDiff, equalTo(Collections.<Path,String>emptyMap())); 501 errorCollector.checkThat(what + "#COPIED", copyDiff, equalTo(Collections.<Path,String>emptyMap()));
457 } 502 }
458 503
459 private <T> void reportNotEqual(String what, Collection<T> l1, Collection<T> l2) { 504 private <T extends Comparable<? super T>> void reportNotEqual(String what, Collection<T> l1, Collection<T> l2) {
460 List<T> diff = difference(l1, l2); 505 // List<T> diff = difference(l1, l2);
461 errorCollector.checkThat(what, diff, equalTo(Collections.<T>emptyList())); 506 // errorCollector.checkThat(what, diff, equalTo(Collections.<T>emptyList()));
507 ArrayList<T> sl1 = new ArrayList<T>(l1);
508 Collections.sort(sl1);
509 ArrayList<T> sl2 = new ArrayList<T>(l2);
510 Collections.sort(sl2);
511 errorCollector.checkThat(what, sl1, equalTo(sl2));
462 } 512 }
463 513
464 private static <T> List<T> difference(Collection<T> l1, Collection<T> l2) { 514 private static <T> List<T> difference(Collection<T> l1, Collection<T> l2) {
465 LinkedList<T> result = new LinkedList<T>(l2); 515 LinkedList<T> result = new LinkedList<T>(l2);
466 for (T t : l1) { 516 for (T t : l1) {