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