1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.exec.issues;
19
20 import static org.junit.jupiter.api.Assertions.assertEquals;
21 import static org.junit.jupiter.api.Assertions.assertFalse;
22
23 import java.io.ByteArrayOutputStream;
24 import java.io.File;
25 import java.util.HashMap;
26 import java.util.Map;
27
28 import org.apache.commons.exec.CommandLine;
29 import org.apache.commons.exec.DefaultExecutor;
30 import org.apache.commons.exec.Executor;
31 import org.apache.commons.exec.OS;
32 import org.apache.commons.exec.PumpStreamHandler;
33 import org.apache.commons.exec.TestUtil;
34 import org.junit.jupiter.api.AfterEach;
35 import org.junit.jupiter.api.BeforeEach;
36 import org.junit.jupiter.api.Disabled;
37 import org.junit.jupiter.api.Test;
38
39
40
41
42 public class Exec36Test {
43
44 private final Executor exec = DefaultExecutor.builder().get();
45 private final File testDir = new File("src/test/scripts");
46 private final File printArgsScript = TestUtil.resolveScriptForOS(testDir + "/printargs");
47
48 private ByteArrayOutputStream baos;
49
50
51
52
53 @Test
54 @Disabled
55 public void _testExec36_4() throws Exception {
56
57 CommandLine cmdl;
58
59 final String line = "./script/jrake " + "cruise:publish_installers " + "INSTALLER_VERSION=unstable_2_1 "
60 + "INSTALLER_PATH=\"/var/lib/cruise-agent/installers\" " + "INSTALLER_DOWNLOAD_SERVER='something'" + "WITHOUT_HELP_DOC=true";
61
62 cmdl = CommandLine.parse(line);
63 final String[] args = cmdl.toStrings();
64 assertEquals("./script/jrake", args[0]);
65 assertEquals("cruise:publish_installers", args[1]);
66 assertEquals("INSTALLER_VERSION=unstable_2_1", args[2]);
67 assertEquals("INSTALLER_PATH=\"/var/lib/cruise-agent/installers\"", args[3]);
68 assertEquals("INSTALLER_DOWNLOAD_SERVER='something'", args[4]);
69 assertEquals("WITHOUT_HELP_DOC=true", args[5]);
70 }
71
72
73
74
75 @Test
76 @Disabled
77 public void _testExec36_5() {
78
79 CommandLine cmdl;
80
81 final String line = "dotnetfx.exe" + " /q:a "
82 + "/c:\"install.exe /l \"\"c:\\Documents and Settings\\myusername\\Local Settings\\Temp\\netfx.log\"\" /q\"";
83
84 cmdl = CommandLine.parse(line);
85 final String[] args = cmdl.toStrings();
86 assertEquals("dotnetfx.exe", args[0]);
87 assertEquals("/q:a", args[1]);
88 assertEquals("/c:\"install.exe /l \"\"c:\\Documents and Settings\\myusername\\Local Settings\\Temp\\netfx.log\"\" /q\"", args[2]);
89 }
90
91
92
93
94
95
96 @Test
97 @Disabled
98 public void _testExec36_6() {
99
100 final String commandline = "C:\\CVS_DB\\WeightsEngine /f WeightsEngine.mak CFG=\"WeightsEngine - Win32Release\"";
101
102 final CommandLine cmdl = CommandLine.parse(commandline);
103 final String[] args = cmdl.getArguments();
104 assertEquals("/f", args[0]);
105 assertEquals("WeightsEngine.mak", args[1]);
106 assertEquals("CFG=\"WeightsEngine - Win32Release\"", args[2]);
107 }
108
109 @BeforeEach
110 public void setUp() throws Exception {
111
112 this.baos = new ByteArrayOutputStream();
113 this.exec.setStreamHandler(new PumpStreamHandler(baos, baos));
114 }
115
116 @AfterEach
117 public void tearDown() throws Exception {
118 this.baos.close();
119 }
120
121
122
123
124
125
126
127 @Test
128 public void testExec36_1() throws Exception {
129
130 if (OS.isFamilyUnix()) {
131
132 CommandLine cmdl;
133
134
135
136
137
138
139 final String expected = "./script/jrake\n" + "cruise:publish_installers\n" + "INSTALLER_VERSION=unstable_2_1\n"
140 + "INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\"\n" + "INSTALLER_DOWNLOAD_SERVER='something'\n" + "WITHOUT_HELP_DOC=true";
141
142 cmdl = new CommandLine(printArgsScript);
143 cmdl.addArgument("./script/jrake", false);
144 cmdl.addArgument("cruise:publish_installers", false);
145 cmdl.addArgument("INSTALLER_VERSION=unstable_2_1", false);
146 cmdl.addArgument("INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\"", false);
147 cmdl.addArgument("INSTALLER_DOWNLOAD_SERVER='something'", false);
148 cmdl.addArgument("WITHOUT_HELP_DOC=true", false);
149
150 final int exitValue = exec.execute(cmdl);
151 final String result = baos.toString().trim();
152 assertFalse(exec.isFailure(exitValue));
153 assertEquals(expected, result);
154 } else {
155 System.err.println("The test 'testExec36_1' does not support the following OS : " + System.getProperty("os.name"));
156 }
157 }
158
159
160
161
162
163
164
165
166 @Test
167 public void testExec36_2() throws Exception {
168
169 String expected;
170
171
172
173
174 if (OS.isFamilyWindows()) {
175 expected = "dotnetfx.exe\n" + "/q:a\n" + "/c:\"install.exe /l \"\"\\Documents and Settings\\myusername\\Local Settings\\Temp\\netfx.log\"\" /q\"";
176 } else if (OS.isFamilyUnix()) {
177 expected = "dotnetfx.exe\n" + "/q:a\n" + "/c:\"install.exe /l \"\"/Documents and Settings/myusername/Local Settings/Temp/netfx.log\"\" /q\"";
178 } else {
179 System.err.println("The test 'testExec36_3' does not support the following OS : " + System.getProperty("os.name"));
180 return;
181 }
182
183 CommandLine cmdl;
184 final File file = new File("/Documents and Settings/myusername/Local Settings/Temp/netfx.log");
185 final Map<String, File> map = new HashMap<>();
186 map.put("FILE", file);
187
188 cmdl = new CommandLine(printArgsScript);
189 cmdl.setSubstitutionMap(map);
190 cmdl.addArgument("dotnetfx.exe", false);
191 cmdl.addArgument("/q:a", false);
192 cmdl.addArgument("/c:\"install.exe /l \"\"${FILE}\"\" /q\"", false);
193
194 final int exitValue = exec.execute(cmdl);
195 final String result = baos.toString().trim();
196 assertFalse(exec.isFailure(exitValue));
197
198 if (OS.isFamilyUnix()) {
199
200 assertEquals(expected, result);
201 }
202 }
203 }