Mercurial > hg4j
annotate test/org/tmatesoft/hg/test/ExecHelper.java @ 532:688c1ab113bb
Introduce explicit reference to base patch in bundle's group element, use it when cloning to fix defect when few revisions list null,null parents
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Wed, 23 Jan 2013 19:14:15 +0100 |
parents | 7f27122011c3 |
children | 36853bb80a35 |
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 /* |
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
|
2 * Copyright (c) 2011-2012 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; |
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
|
22 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
|
23 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
|
24 |
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
|
25 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
|
26 |
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
|
27 /** |
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 * |
66
52dc3f4cfc76
Primitive test suite in org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
61
diff
changeset
|
29 * @author Artem Tikhomirov |
52dc3f4cfc76
Primitive test suite in org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
61
diff
changeset
|
30 * @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
|
31 */ |
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
|
32 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
|
33 |
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 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
|
35 |
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 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
|
37 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
|
38 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
|
39 } |
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
|
40 |
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 @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
|
42 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
|
43 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
|
44 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
|
45 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
|
46 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
|
47 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
|
48 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
|
49 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
|
50 } |
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
|
51 // 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
|
52 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
|
53 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
|
54 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
|
55 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
|
56 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
|
57 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
|
58 } |
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 } |
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
|
61 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
|
62 } |
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 public void run(String... cmd) throws IOException, InterruptedException { |
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
|
65 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
|
66 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
|
67 } |
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
|
68 |
201
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
111
diff
changeset
|
69 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
|
70 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
|
71 } |
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
|
72 } |