Mercurial > hg4j
annotate test/org/tmatesoft/hg/test/TestPhases.java @ 557:b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Sun, 24 Feb 2013 00:11:40 +0100 |
parents | ba36f66c32b4 |
children | fedc54356091 |
rev | line source |
---|---|
474
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2012 TMate Software Ltd |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
3 * |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
7 * |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
11 * GNU General Public License for more details. |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
12 * |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
13 * For information on how to redistribute this software under |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
17 package org.tmatesoft.hg.test; |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
19 import static org.junit.Assert.*; |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
20 |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
21 import java.util.regex.Matcher; |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
22 import java.util.regex.Pattern; |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
23 |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
24 import org.junit.Rule; |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
25 import org.junit.Test; |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
26 import org.tmatesoft.hg.internal.PhasesHelper; |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
27 import org.tmatesoft.hg.repo.HgChangelog; |
493
ba36f66c32b4
Refactor to keep knowledge about repository control files and their location in respect to .hg/ in a single place (facilitate future adoption of shared repositories)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
477
diff
changeset
|
28 import org.tmatesoft.hg.repo.HgInternals; |
474
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
29 import org.tmatesoft.hg.repo.HgLookup; |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
30 import org.tmatesoft.hg.repo.HgParentChildMap; |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 import org.tmatesoft.hg.repo.HgPhase; |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 import org.tmatesoft.hg.repo.HgRepository; |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 /** |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 * {hg4j.tests.repos}/test-phases/ |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
36 * @author Artem Tikhomirov |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 * @author TMate Software Ltd. |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 */ |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
39 public class TestPhases { |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
40 |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 @Rule |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 public ErrorCollectorExt errorCollector = new ErrorCollectorExt(); |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 @Test |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
45 public void testHelperNoParentChildMap() throws Exception { |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
46 HgRepository repo = Configuration.get().find("test-phases"); |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
47 HgPhase[] expected = readPhases(repo); |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
48 final long start = System.nanoTime(); |
493
ba36f66c32b4
Refactor to keep knowledge about repository control files and their location in respect to .hg/ in a single place (facilitate future adoption of shared repositories)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
477
diff
changeset
|
49 PhasesHelper ph = new PhasesHelper(HgInternals.getImplementationRepo(repo), null); |
474
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
50 initAndCheck(ph, expected); |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
51 final long end = System.nanoTime(); |
477
9c9d09111aee
Tests for file flags(exec, link, regular)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
474
diff
changeset
|
52 // μ == \u03bc |
9c9d09111aee
Tests for file flags(exec, link, regular)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
474
diff
changeset
|
53 System.out.printf("Without ParentWalker (simulates log command for single file): %,d μs\n", (end - start)/1000); |
474
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
54 } |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
55 |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 @Test |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
57 public void testHelperWithParentChildMap() throws Exception { |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
58 HgRepository repo = Configuration.get().find("test-phases"); |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
59 HgPhase[] expected = readPhases(repo); |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
60 final long start1 = System.nanoTime(); |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
61 HgParentChildMap<HgChangelog> pw = new HgParentChildMap<HgChangelog>(repo.getChangelog()); |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
62 pw.init(); |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
63 final long start2 = System.nanoTime(); |
493
ba36f66c32b4
Refactor to keep knowledge about repository control files and their location in respect to .hg/ in a single place (facilitate future adoption of shared repositories)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
477
diff
changeset
|
64 PhasesHelper ph = new PhasesHelper(HgInternals.getImplementationRepo(repo), pw); |
474
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
65 initAndCheck(ph, expected); |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
66 final long end = System.nanoTime(); |
477
9c9d09111aee
Tests for file flags(exec, link, regular)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
474
diff
changeset
|
67 System.out.printf("With ParentWalker(simulates log command for whole repo): %,d μs (pw init: %,d ns)\n", (end - start1)/1000, start2 - start1); |
474
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
68 } |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
69 |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
70 private HgPhase[] initAndCheck(PhasesHelper ph, HgPhase[] expected) { |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
71 HgChangelog clog = ph.getRepo().getChangelog(); |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
72 HgPhase[] result = new HgPhase[clog.getRevisionCount()]; |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
73 for (int i = 0, l = clog.getLastRevision(); i <= l; i++) { |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
74 result[i] = ph.getPhase(i, null); |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
75 } |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
76 assertEquals(expected.length, result.length); |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
77 for (int i = 0; i < result.length; i++) { |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
78 errorCollector.assertTrue(result[i] == expected[i]); |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
79 } |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
80 return result; |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
81 } |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
82 |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
83 private static HgPhase[] readPhases(HgRepository repo) throws Exception { |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
84 HgPhase[] result = new HgPhase[repo.getChangelog().getRevisionCount()]; |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
85 OutputParser.Stub output = new OutputParser.Stub(); |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
86 ExecHelper eh = new ExecHelper(output, repo.getWorkingDir()); |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
87 eh.run("hg", "phase", "-r", "0:-1"); |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
88 Matcher m = Pattern.compile("(\\d+): (\\w+)$", Pattern.MULTILINE).matcher(output.result()); |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
89 int i = 0; |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
90 while (m.find()) { |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
91 int x = Integer.parseInt(m.group(1)); |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
92 assert x == i; |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
93 HgPhase v = HgPhase.parse(m.group(2)); |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
94 result[x] = v; |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
95 i++; |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
96 } |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
97 return result; |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
98 } |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
99 |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
100 public static void main(String[] args) throws Exception { |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
101 HgRepository repo = new HgLookup().detect(System.getProperty("user.home") + "/hg/test-phases/"); |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
102 HgPhase[] v = readPhases(repo); |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
103 printPhases(v); |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
104 } |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
105 |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
106 private static void printPhases(HgPhase[] phase) { |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
107 for (int i = 0; i < phase.length; i++) { |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
108 System.out.printf("rev:%3d, phase:%s\n", i, phase[i]); |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
109 } |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
110 } |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
111 |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
112 } |