annotate test/org/tmatesoft/hg/test/TestManifest.java @ 76:658fa6b3a371

Fixed a defect when a file added and removed past some revision was reported as R for status against that rev
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 24 Jan 2011 04:38:09 +0100
parents 6f1b88693d48
children bcd31a4c638a
rev   line source
67
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2011 TMate Software Ltd
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 * the terms of a license other than GNU General Public License
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
15 * contact TMate Software at support@svnkit.com
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 package org.tmatesoft.hg.test;
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 67
diff changeset
19 import static org.tmatesoft.hg.repo.HgRepository.TIP;
67
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21 import java.util.LinkedHashMap;
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22 import java.util.LinkedList;
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23 import java.util.Map;
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 import org.tmatesoft.hg.core.LogCommand.FileRevision;
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 67
diff changeset
26 import org.tmatesoft.hg.core.Nodeid;
67
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 import org.tmatesoft.hg.core.Path;
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28 import org.tmatesoft.hg.core.RepositoryTreeWalker;
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 67
diff changeset
29 import org.tmatesoft.hg.repo.HgRepository;
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 67
diff changeset
30 import org.tmatesoft.hg.repo.Lookup;
67
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 /**
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 *
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35 * @author Artem Tikhomirov
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36 * @author TMate Software Ltd.
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
37 */
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 public class TestManifest {
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40 private final HgRepository repo;
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41 private ManifestOutputParser manifestParser;
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 private ExecHelper eh;
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 final LinkedList<FileRevision> revisions = new LinkedList<FileRevision>();
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 private RepositoryTreeWalker.Handler handler = new RepositoryTreeWalker.Handler() {
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 public void file(FileRevision fileRevision) {
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47 revisions.add(fileRevision);
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48 }
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50 public void end(Nodeid manifestRevision) {}
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
51 public void dir(Path p) {}
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52 public void begin(Nodeid manifestRevision) {}
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53 };
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 public static void main(String[] args) throws Exception {
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 67
diff changeset
56 HgRepository repo = new Lookup().detectFromWorkingDir();
67
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57 TestManifest tm = new TestManifest(repo);
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58 tm.testTip();
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
59 tm.testFirstRevision();
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60 tm.testRevisionInTheMiddle();
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61 }
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
62
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
63 public TestManifest(HgRepository hgRepo) {
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 repo = hgRepo;
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65 eh = new ExecHelper(manifestParser = new ManifestOutputParser(), null);
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 }
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
68 public void testTip() throws Exception {
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
69 testRevision(TIP);
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
70 }
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
71
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
72 public void testFirstRevision() throws Exception {
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73 testRevision(0);
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
74 }
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
75
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
76 public void testRevisionInTheMiddle() throws Exception {
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
77 int rev = repo.getManifest().getRevisionCount() / 2;
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
78 if (rev == 0) {
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
79 throw new IllegalStateException("Need manifest with few revisions");
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
80 }
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
81 testRevision(rev);
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
82 }
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
83
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
84 private void testRevision(int rev) throws Exception {
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
85 manifestParser.reset();
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
86 eh.run("hg", "manifest", "--debug", "--rev", String.valueOf(rev));
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
87 revisions.clear();
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
88 new RepositoryTreeWalker(repo).revision(rev).walk(handler);
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
89 report("manifest " + (rev == TIP ? "TIP:" : "--rev " + rev));
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
90 }
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
91
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
92 private void report(String what) throws Exception {
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
93 final Map<Path, Nodeid> cmdLineResult = new LinkedHashMap<Path, Nodeid>(manifestParser.getResult());
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
94 boolean error = false;
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
95 for (FileRevision fr : revisions) {
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
96 Nodeid nid = cmdLineResult.remove(fr.getPath());
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
97 if (nid == null) {
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
98 System.out.println("Extra " + fr.getPath() + " in Java result");
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
99 error = true;
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
100 } else {
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
101 if (!nid.equals(fr.getRevision())) {
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
102 System.out.println("Non-matching nodeid:" + nid);
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
103 error = true;
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
104 }
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
105 }
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
106 }
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
107 if (!cmdLineResult.isEmpty()) {
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
108 System.out.println("Non-matched entries from command line:");
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
109 error = true;
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
110 for (Path p : cmdLineResult.keySet()) {
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
111 System.out.println(p);
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
112 }
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
113 }
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
114 System.out.println(what + (error ? " ERROR" : " OK"));
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
115 }
64bddc2dcc0e Tests for manifest cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
116 }