Mercurial > jhg
annotate test/com/tmate/hgkit/TestStatus.java @ 61:fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> | 
|---|---|
| date | Tue, 18 Jan 2011 18:32:49 +0100 | 
| parents | |
| children | 25819103de17 | 
| rev | line source | 
|---|---|
| 
61
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
1 /* | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
2 * Copyright (c) 2011 Artem Tikhomirov | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
3 */ | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
4 package com.tmate.hgkit; | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
5 | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
6 import java.io.File; | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
7 import java.util.Collection; | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
8 import java.util.LinkedList; | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
9 import java.util.List; | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
10 | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
11 import com.tmate.hgkit.fs.FileWalker; | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
12 import com.tmate.hgkit.fs.RepositoryLookup; | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
13 import com.tmate.hgkit.ll.HgRepository; | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
14 import com.tmate.hgkit.ll.StatusCollector; | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
15 import com.tmate.hgkit.ll.WorkingCopyStatusCollector; | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
16 | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
17 /** | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
18 * | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
19 * @author artem | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
20 */ | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
21 public class TestStatus { | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
22 | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
23 public static void main(String[] args) throws Exception { | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
24 final StatusOutputParser statusParser = new StatusOutputParser(); | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
25 ExecHelper eh = new ExecHelper(statusParser, null); | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
26 eh.run("hg", "status", "-A"); | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
27 // run java equivalent | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
28 HgRepository repo = new RepositoryLookup().detectFromWorkingDir(); | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
29 final WorkingCopyStatusCollector wcc = new WorkingCopyStatusCollector(repo, new FileWalker(new File(System.getProperty("user.dir")))); | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
30 StatusCollector.Record r = wcc.status(HgRepository.TIP); | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
31 // compare result | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
32 reportNotEqual("MODIFIED", r.getModified(), statusParser.getModified()); | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
33 reportNotEqual("ADDED", r.getAdded(), statusParser.getAdded()); | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
34 reportNotEqual("REMOVED", r.getRemoved(), statusParser.getRemoved()); | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
35 reportNotEqual("CLEAN", r.getClean(), statusParser.getClean()); | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
36 reportNotEqual("IGNORED", r.getIgnored(), statusParser.getIgnored()); | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
37 reportNotEqual("MISSING", r.getMissing(), statusParser.getMissing()); | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
38 reportNotEqual("UNKNOWN", r.getUnknown(), statusParser.getUnknown()); | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
39 // TODO compare equals | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
40 } | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
41 | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
42 private static <T> void reportNotEqual(String what, Collection<T> l1, Collection<T> l2) { | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
43 List<T> diff = difference(l1, l2); | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
44 System.out.print(what); | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
45 if (!diff.isEmpty()) { | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
46 System.out.print(" are NOT the same: "); | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
47 for (T t : diff) { | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
48 System.out.print(t); | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
49 System.out.print(", "); | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
50 } | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
51 System.out.println(); | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
52 } else { | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
53 System.out.println(" are the same"); | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
54 } | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
55 } | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
56 | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
57 private static <T> List<T> difference(Collection<T> l1, Collection<T> l2) { | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
58 LinkedList<T> result = new LinkedList<T>(l2); | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
59 for (T t : l1) { | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
60 if (l2.contains(t)) { | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
61 result.remove(t); | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
62 } else { | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
63 result.add(t); | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
64 } | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
65 } | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
66 return result; | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
67 } | 
| 
 
fac8e7fcc8b0
Simple test framework - capable of parsing Hg cmdline output to compare with Java result
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
68 } | 
