annotate test/org/tmatesoft/hg/test/ExecHelper.java @ 709:497e697636fc

Report merged lines as changed block if possible, not as a sequence of added/deleted blocks. To facilitate access to merge parent lines AddBlock got mergeLineAt() method that reports index of the line in the second parent (if any), while insertedAt() has been changed to report index in the first parent always
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 21 Aug 2013 16:23:27 +0200
parents 36853bb80a35
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 /*
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 413
diff changeset
2 * Copyright (c) 2011-2013 TMate Software Ltd
66
52dc3f4cfc76 Primitive test suite in org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
3 *
52dc3f4cfc76 Primitive test suite in org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
4 * This program is free software; you can redistribute it and/or modify
52dc3f4cfc76 Primitive test suite in org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
5 * it under the terms of the GNU General Public License as published by
52dc3f4cfc76 Primitive test suite in org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
6 * the Free Software Foundation; version 2 of the License.
52dc3f4cfc76 Primitive test suite in org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
7 *
52dc3f4cfc76 Primitive test suite in org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
8 * This program is distributed in the hope that it will be useful,
52dc3f4cfc76 Primitive test suite in org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
52dc3f4cfc76 Primitive test suite in org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
52dc3f4cfc76 Primitive test suite in org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
11 * GNU General Public License for more details.
52dc3f4cfc76 Primitive test suite in org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
12 *
52dc3f4cfc76 Primitive test suite in org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
13 * For information on how to redistribute this software under
52dc3f4cfc76 Primitive test suite in org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
14 * the terms of a license other than GNU General Public License
102
a3a2e5deb320 Updated contact address to support@hg4j.com
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 66
diff changeset
15 * contact TMate Software at support@hg4j.com
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
16 */
66
52dc3f4cfc76 Primitive test suite in org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
17 package org.tmatesoft.hg.test;
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
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 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
20 import java.io.IOException;
110
0170f95ca915 On Windows, if hg.exe is wrapped into batch file, need to use cmd.exe to let it run
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
21 import java.util.ArrayList;
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 413
diff changeset
22 import java.util.Arrays;
413
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
23 import java.util.List;
110
0170f95ca915 On Windows, if hg.exe is wrapped into batch file, need to use cmd.exe to let it run
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
24 import java.util.StringTokenizer;
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
25
413
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
26 import org.tmatesoft.hg.internal.ProcessExecHelper;
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
27
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
28 /**
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 413
diff changeset
29 * Utility to run a command line application and to parse its output
66
52dc3f4cfc76 Primitive test suite in org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
30 * @author Artem Tikhomirov
52dc3f4cfc76 Primitive test suite in org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
31 * @author TMate Software Ltd.
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
32 */
413
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
33 public class ExecHelper extends ProcessExecHelper {
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
34
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 private final OutputParser parser;
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
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 public ExecHelper(OutputParser outParser, File workingDir) {
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 parser = outParser;
413
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
39 super.cwd(workingDir);
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
40 }
413
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
41
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
42 @Override
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
43 protected List<String> prepareCommand(List<String> cmd) {
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
44 String commandName = cmd.get(0);
110
0170f95ca915 On Windows, if hg.exe is wrapped into batch file, need to use cmd.exe to let it run
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
45 if (System.getProperty("os.name").startsWith("Windows")) {
0170f95ca915 On Windows, if hg.exe is wrapped into batch file, need to use cmd.exe to let it run
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
46 StringTokenizer st = new StringTokenizer(System.getenv("PATH"), ";");
0170f95ca915 On Windows, if hg.exe is wrapped into batch file, need to use cmd.exe to let it run
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
47 while (st.hasMoreTokens()) {
0170f95ca915 On Windows, if hg.exe is wrapped into batch file, need to use cmd.exe to let it run
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
48 File pe = new File(st.nextToken());
413
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
49 if (new File(pe, commandName + ".exe").exists()) {
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
50 return cmd;
110
0170f95ca915 On Windows, if hg.exe is wrapped into batch file, need to use cmd.exe to let it run
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
51 }
388
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 203
diff changeset
52 // PATHEXT controls precedence of .exe, .bat and .cmd files, usually .exe wins
413
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
53 if (new File(pe, commandName + ".bat").exists() || new File(pe, commandName + ".cmd").exists()) {
110
0170f95ca915 On Windows, if hg.exe is wrapped into batch file, need to use cmd.exe to let it run
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
54 ArrayList<String> command = new ArrayList<String>();
0170f95ca915 On Windows, if hg.exe is wrapped into batch file, need to use cmd.exe to let it run
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
55 command.add("cmd.exe");
0170f95ca915 On Windows, if hg.exe is wrapped into batch file, need to use cmd.exe to let it run
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
56 command.add("/C");
413
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
57 command.addAll(cmd);
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
58 return command;
110
0170f95ca915 On Windows, if hg.exe is wrapped into batch file, need to use cmd.exe to let it run
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
59 }
0170f95ca915 On Windows, if hg.exe is wrapped into batch file, need to use cmd.exe to let it run
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
60 }
0170f95ca915 On Windows, if hg.exe is wrapped into batch file, need to use cmd.exe to let it run
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
61 }
413
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
62 return super.prepareCommand(cmd);
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
63 }
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
64
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 413
diff changeset
65 public void run(List<String> cmd) throws IOException, InterruptedException {
413
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
66 CharSequence res = super.exec(cmd);
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
67 parser.parse(res);
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 }
413
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
69
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 413
diff changeset
70 public void run(String... cmd) throws IOException, InterruptedException {
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 413
diff changeset
71 run(Arrays.asList(cmd));
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 413
diff changeset
72 }
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 413
diff changeset
73
201
a736f42ed75b Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 111
diff changeset
74 public int getExitValue() {
413
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
75 return super.exitValue();
203
66fd2c73c56f Basic test for HgOutgoingCommand. Handle cases with no outgoing changes in RepositoryComparator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 201
diff changeset
76 }
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
77 }