Release 1.6-rc2.
[wine/testsucceed.git] / programs / cmd / tests / test_cmdline.cmd
blob32a1ef2e48f0adc4dd8d0820397c9cea81e923a0
1 @echo off
2 mkdir foobar
3 cd foobar
4 echo file1 > file1
6 rem Basic test of command line. Note a section prefix per command
7 rem to resync, as wine does not output anything in these cases yet.
8 echo --- Test 1
9 cmd.exe /c echo Line1
10 cmd.exe /c echo "Line2"
11 echo --- Test 2
12 cmd.exe /c echo Test quotes "&" work
13 echo --- Test 3
14 cmd.exe /c echo "&"
15 echo --- Test 4
16 cmd.exe /c echo "<"
17 echo --- Test 5
18 cmd.exe /c echo ">"
19 echo --- Test 6
20 cmd.exe /c echo "\"
21 echo --- Test 7
22 cmd.exe /c echo "|"
23 echo --- Test 8
24 cmd.exe /c echo "`"
25 echo --- Test 9
26 cmd.exe /c echo """
27 echo --- Test 10
28 echo on > file3
29 @type file3
30 @echo off
31 echo --- Test 11
32 cmd.exe /c echo on >file3
33 @type file3
34 @echo off
35 echo --- Test 12
36 cmd.exe /c "echo passed1"
37 echo --- Test 13
38 cmd.exe /c " echo passed2 "
39 echo --- Test 14
40 cmd.exe /c "dir /ad ..\fooba* /b"
41 echo --- Test 15
42 cmd.exe /cecho No whitespace
43 echo --- Test 16
44 cmd.exe /c
45 echo --- Test 17
46 cmd.exe /c@space@
47 echo --- Test 18
48 rem Ensure no interactive prompting when cmd.exe /c or /k
49 echo file2 > file2
50 cmd.exe /c copy file1 file2 >nul
51 echo No prompts or I would not get here1
52 rem - Try cmd.exe /k as well
53 cmd.exe /k "copy file1 file2 >nul && exit"
54 echo No prompts or I would not get here2
56 rem Nonexistent variable expansion is as per command line, i.e. left as-is
57 cmd.exe /c echo %%hello1%%
58 cmd.exe /c echo %%hello2
59 cmd.exe /c echo %%hello3^:h=t%%
60 cmd.exe /c echo %%hello4%%%%
62 rem Cannot issue a call from cmd.exe /c
63 cmd.exe /c call :hello5
65 rem %1-9 has no meaning
66 cmd.exe /c echo one = %%1
68 rem for loop vars need expanding
69 cmd.exe /c for /L %%i in (1,1,5) do @echo %%i
71 rem goto's are ineffective
72 cmd.exe /c goto :fred
73 cmd.exe /c goto eof
75 rem - %var% is expanded at read time, not execute time
76 set var=11
77 cmd.exe /c "set var=22 && setlocal && set var=33 && endlocal && echo var contents: %%var%%"
79 rem - endlocal ineffective on cmd.exe /c lines
80 cmd.exe /c "set var=22 && setlocal && set var=33 && endlocal && set var"
81 set var=99
83 rem - Environment is inherited ok
84 cmd.exe /c ECHO %%VAR%%
86 rem - Exit works
87 cmd.exe /c exit
89 cd ..
90 rd foobar /s /q
92 rem - Temporary batch files
93 echo @echo 0 > "say.bat"
94 echo @echo 1 > "say one.bat"
95 echo @echo 2 > "saytwo.bat"
96 echo @echo 3 > "say (3).bat"
97 echo @echo 4 > "say .bat"
98 echo @echo 5 > "bazbaz(5).bat"
100 echo ------ Testing invocation of batch files ----------
101 call say one
102 call "say one"
103 call "say"" one"
104 call "say one
105 call :setError 0
106 call say" one"
107 if errorlevel 2 echo error %ErrorLevel%
108 call say "one"
109 call :setError 0
110 call s"ay one
111 if errorlevel 2 echo error %ErrorLevel%
112 call :setError 0
113 call s"aytwo
114 if errorlevel 2 echo error %ErrorLevel%
115 call say (3)
116 call "say (3)"
117 call :setError 0
118 call say" (3)"
119 if errorlevel 2 echo error %ErrorLevel%
120 call :setError 0
121 call say" "(3) prints 4?!
122 if errorlevel 2 echo error %ErrorLevel%
124 echo ------ Testing invocation with CMD /C -------------
125 cmd /c say one
126 cmd /c "say one"
127 call :setError 0
128 cmd /c "say"" one"
129 if errorlevel 2 echo error %ErrorLevel%
130 cmd /c "say one
131 call :setError 0
132 cmd /c say" one"
133 if errorlevel 2 echo error %ErrorLevel%
134 cmd /c say "one"
135 call :setError 0
136 cmd /c s"ay one
137 if errorlevel 2 echo error %ErrorLevel%
138 call :setError 0
139 cmd /c s"aytwo
140 if errorlevel 2 echo error %ErrorLevel%
141 cmd /c say (3)
142 call :setError 0
143 cmd /c say" (3)"
144 if errorlevel 2 echo error %ErrorLevel%
145 call :setError 0
146 cmd /c say" "(3) prints 4?!
147 if errorlevel 2 echo error %ErrorLevel%
148 call :setError 0
149 rem Deliberately invoking a fully qualified batch name containing a bracket
150 rem should fail, as a bracket is a command delimiter.
151 cmd /c "bazbaz(5).bat"
152 if errorlevel 1 echo Passed
154 echo ---------- Testing CMD /C quoting -----------------
155 cmd /c @echo "hi"
156 call :setError 0
157 cmd /c say" "one
158 if errorlevel 2 echo error %ErrorLevel%
159 cmd /c @echo "\"\\"\\\"\\\\" "\"\\"\\\"\\\\"
160 rem ---- all 5 conditions met, quotes preserved
161 cmd /c "say one"
162 rem cond 1 - /s
163 cmd /s/c "say one"
164 cmd /s/c ""say one""
165 rem cond 2 - not 2 quotes
166 cmd /c "say one
167 call :setError 0
168 cmd /c "say"" one"
169 if errorlevel 2 echo error %ErrorLevel%
170 rem cond 3 - special char - first test fails on Vista, W2K8!
171 cmd /c "say (3)"
172 cmd /c ""say (3)""
173 rem cond 4 - no spaces (quotes make no difference here)
174 cmd /c saytwo
175 cmd /c "saytwo"
176 cmd /c "saytwo
177 rem cond 5 - string between quotes must be name of executable
178 cmd /c "say five"
179 echo @echo 5 >"say five.bat"
180 cmd /c "say five"
182 echo ------- Testing CMD /C qualifier treatment ------------
183 rem no need for space after /c
184 cmd /csay one
185 cmd /c"say one"
186 rem ignore quote before qualifier
187 rem FIXME the next command in wine starts a sub-CMD
188 echo THIS FAILS: cmd "/c"say one
189 rem ignore anything before /c
190 rem FIXME the next command in wine starts a sub-CMD
191 echo THIS FAILS: cmd ignoreme/c say one
193 echo --------- Testing special characters --------------
194 echo @echo amp > "say&.bat"
195 call say&
196 echo @echo ( > "say(.bat"
197 call say(
198 echo @echo ) > "say).bat"
199 call say)
200 echo @echo [ > "say[.bat"
201 call say[
202 echo @echo ] > "say].bat"
203 call say]
204 echo @echo { > "say{.bat"
205 call say{
206 echo @echo } > "say}.bat"
207 call say}
208 echo @echo = > "say=.bat"
209 call say=
210 echo @echo sem > "say;.bat"
211 call say;
212 setlocal DisableDelayedExpansion
213 echo @echo ! > "say!.bat"
214 call say!
215 endlocal
216 setlocal EnableDelayedExpansion
217 call say!
218 endlocal
219 echo @echo %%%% > "say%%.bat"
220 call say%%
221 echo @echo ' > "say'.bat"
222 call say'
223 echo @echo + > "say+.bat"
224 call say+
225 echo @echo com > "say,.bat"
226 call say,
227 echo @echo ` > "say`.bat"
228 call say'
229 echo @echo ~ > "say~.bat"
230 call say~
232 echo --------- Testing parameter passing --------------
233 echo @echo 1:%%1,2:%%2 > tell.bat
234 call tell 1
235 call tell (1)
236 call tell 1(2)
237 call :setError 0
238 call tell(1)
239 if errorlevel 2 echo error %ErrorLevel%
240 call :setError 0
241 call tell((1))
242 if errorlevel 2 echo error %ErrorLevel%
243 call :setError 0
244 call tell(1)(2)
245 if errorlevel 2 echo error %ErrorLevel%
246 call :setError 0
247 call tell(1);,;(2)
248 if errorlevel 2 echo error %ErrorLevel%
249 call :setError 0
250 call tell;1 2
251 if errorlevel 2 echo error %ErrorLevel%
252 call :setError 0
253 call tell; 1, ;2
254 if errorlevel 2 echo error %ErrorLevel%
255 call :setError 0
256 call tell;1;;2
257 if errorlevel 2 echo error %ErrorLevel%
258 call tell "p "1 p" "2
259 call tell p"1 p";2
261 echo --------- Testing delimiters and parameter passing --------------
262 echo @echo 0:%%0,1:%%1,2:%%2,All:'%%*'> tell.bat
263 call;tell 1 2
264 call tell 1 2
265 ==call==tell==1==2
266 call tell(1234)
267 call tell(12(34)
268 call tell(12;34)
269 echo --------- Finished --------------
270 del tell.bat say*.* bazbaz*.bat
271 exit
272 :setError
273 exit /B %1