annotate test/com/tmate/hgkit/TestStatus.java @ 64:19e9e220bf68

Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 21 Jan 2011 05:56:43 +0100
parents 25819103de17
children
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 {
62
25819103de17 Few more tests for status
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
24 HgRepository repo = new RepositoryLookup().detectFromWorkingDir();
25819103de17 Few more tests for status
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
25 final WorkingCopyStatusCollector wcc = new WorkingCopyStatusCollector(repo, new FileWalker(new File(System.getProperty("user.dir"))));
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
26 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
27 ExecHelper eh = new ExecHelper(statusParser, null);
62
25819103de17 Few more tests for status
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
28 //
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
29 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
30 StatusCollector.Record r = wcc.status(HgRepository.TIP);
62
25819103de17 Few more tests for status
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
31 report("hg status -A", r, statusParser);
25819103de17 Few more tests for status
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
32 //
25819103de17 Few more tests for status
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
33 statusParser.reset();
25819103de17 Few more tests for status
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
34 int revision = 3;
25819103de17 Few more tests for status
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
35 eh.run("hg", "status", "-A", "--rev", String.valueOf(revision));
25819103de17 Few more tests for status
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
36 r = wcc.status(revision);
25819103de17 Few more tests for status
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
37 report("status -A --rev " + revision, r, statusParser);
25819103de17 Few more tests for status
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
38 //
25819103de17 Few more tests for status
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
39 statusParser.reset();
25819103de17 Few more tests for status
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
40 eh.run("hg", "status", "-A", "--change", String.valueOf(revision));
25819103de17 Few more tests for status
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
41 r = new StatusCollector.Record();
25819103de17 Few more tests for status
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
42 new StatusCollector(repo).change(revision, r);
25819103de17 Few more tests for status
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
43 report("status -A --change " + revision, r, statusParser);
25819103de17 Few more tests for status
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
44 }
25819103de17 Few more tests for status
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
45
25819103de17 Few more tests for status
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
46 private static void report(String what, StatusCollector.Record r, StatusOutputParser statusParser) {
25819103de17 Few more tests for status
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
47 System.out.println(">>>" + what);
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
48 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
49 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
50 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
51 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
52 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
53 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
54 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
55 // TODO compare equals
62
25819103de17 Few more tests for status
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
56 System.out.println("<<<\n");
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
57 }
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
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 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
60 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
61 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
62 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
63 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
64 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
65 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
66 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
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 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
69 } 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
70 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
71 }
fac8e7fcc8b0 Simple test framework - capable of parsing Hg cmdline output to compare with Java result
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
72 }
fac8e7fcc8b0 Simple test framework - capable of parsing Hg cmdline output to compare with Java result
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73
fac8e7fcc8b0 Simple test framework - capable of parsing Hg cmdline output to compare with Java result
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
74 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
75 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
76 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
77 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
78 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
79 } 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
80 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
81 }
fac8e7fcc8b0 Simple test framework - capable of parsing Hg cmdline output to compare with Java result
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
82 }
fac8e7fcc8b0 Simple test framework - capable of parsing Hg cmdline output to compare with Java result
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
83 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
84 }
fac8e7fcc8b0 Simple test framework - capable of parsing Hg cmdline output to compare with Java result
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
85 }