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