Mercurial > hg4j
comparison test/org/tmatesoft/hg/test/TestStatus.java @ 66:52dc3f4cfc76
Primitive test suite in org.tmatesoft
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 21 Jan 2011 18:20:05 +0100 |
parents | test/com/tmate/hgkit/TestStatus.java@25819103de17 |
children | 0e499fed9b3d |
comparison
equal
deleted
inserted
replaced
65:e21df6259f83 | 66:52dc3f4cfc76 |
---|---|
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 java.io.File; | |
20 import java.util.Collection; | |
21 import java.util.LinkedList; | |
22 import java.util.List; | |
23 | |
24 import com.tmate.hgkit.fs.FileWalker; | |
25 import com.tmate.hgkit.fs.RepositoryLookup; | |
26 import com.tmate.hgkit.ll.HgRepository; | |
27 import com.tmate.hgkit.ll.StatusCollector; | |
28 import com.tmate.hgkit.ll.WorkingCopyStatusCollector; | |
29 | |
30 /** | |
31 * | |
32 * @author Artem Tikhomirov | |
33 * @author TMate Software Ltd. | |
34 */ | |
35 public class TestStatus { | |
36 | |
37 private StatusOutputParser statusParser; | |
38 private ExecHelper eh; | |
39 private final HgRepository repo; | |
40 | |
41 public static void main(String[] args) throws Exception { | |
42 HgRepository repo = new RepositoryLookup().detectFromWorkingDir(); | |
43 TestStatus test = new TestStatus(repo); | |
44 test.testLowLevel(); | |
45 test.testStatusCommand(); | |
46 } | |
47 | |
48 public TestStatus(HgRepository hgRepo) { | |
49 repo = hgRepo; | |
50 statusParser = new StatusOutputParser(); | |
51 eh = new ExecHelper(statusParser, null); | |
52 } | |
53 | |
54 public void testLowLevel() throws Exception { | |
55 final WorkingCopyStatusCollector wcc = new WorkingCopyStatusCollector(repo, new FileWalker(new File(System.getProperty("user.dir")))); | |
56 eh.run("hg", "status", "-A"); | |
57 StatusCollector.Record r = wcc.status(HgRepository.TIP); | |
58 report("hg status -A", r, statusParser); | |
59 // | |
60 statusParser.reset(); | |
61 int revision = 3; | |
62 eh.run("hg", "status", "-A", "--rev", String.valueOf(revision)); | |
63 r = wcc.status(revision); | |
64 report("status -A --rev " + revision, r, statusParser); | |
65 // | |
66 statusParser.reset(); | |
67 eh.run("hg", "status", "-A", "--change", String.valueOf(revision)); | |
68 r = new StatusCollector.Record(); | |
69 new StatusCollector(repo).change(revision, r); | |
70 report("status -A --change " + revision, r, statusParser); | |
71 } | |
72 | |
73 public void testStatusCommand() throws Exception { | |
74 throw HgRepository.notImplemented(); | |
75 } | |
76 | |
77 private static void report(String what, StatusCollector.Record r, StatusOutputParser statusParser) { | |
78 System.out.println(">>>" + what); | |
79 reportNotEqual("MODIFIED", r.getModified(), statusParser.getModified()); | |
80 reportNotEqual("ADDED", r.getAdded(), statusParser.getAdded()); | |
81 reportNotEqual("REMOVED", r.getRemoved(), statusParser.getRemoved()); | |
82 reportNotEqual("CLEAN", r.getClean(), statusParser.getClean()); | |
83 reportNotEqual("IGNORED", r.getIgnored(), statusParser.getIgnored()); | |
84 reportNotEqual("MISSING", r.getMissing(), statusParser.getMissing()); | |
85 reportNotEqual("UNKNOWN", r.getUnknown(), statusParser.getUnknown()); | |
86 // TODO compare equals | |
87 System.out.println("<<<\n"); | |
88 } | |
89 | |
90 private static <T> void reportNotEqual(String what, Collection<T> l1, Collection<T> l2) { | |
91 List<T> diff = difference(l1, l2); | |
92 System.out.print(what); | |
93 if (!diff.isEmpty()) { | |
94 System.out.print(" are NOT the same: "); | |
95 for (T t : diff) { | |
96 System.out.print(t); | |
97 System.out.print(", "); | |
98 } | |
99 System.out.println(); | |
100 } else { | |
101 System.out.println(" are the same"); | |
102 } | |
103 } | |
104 | |
105 private static <T> List<T> difference(Collection<T> l1, Collection<T> l2) { | |
106 LinkedList<T> result = new LinkedList<T>(l2); | |
107 for (T t : l1) { | |
108 if (l2.contains(t)) { | |
109 result.remove(t); | |
110 } else { | |
111 result.add(t); | |
112 } | |
113 } | |
114 return result; | |
115 } | |
116 } |