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"
186rem ignore quote before qualifier
187rem FIXME the next command in wine starts a sub-CMD
188echo THIS FAILS: cmd "/c"say one
189rem ignore anything before /c
190rem FIXME the next command in wine starts a sub-CMD
191echo THIS FAILS: cmd ignoreme/c say one
192
193echo --------- Testing special characters --------------
194echo @echo amp > "say&.bat"
195call say&
196echo @echo ( > "say(.bat"
197call say(
198echo @echo ) > "say).bat"
199call say)
200echo @echo [ > "say[.bat"
201call say[
202echo @echo ] > "say].bat"
203call say]
204echo @echo { > "say{.bat"
205call say{
206echo @echo } > "say}.bat"
207call say}
208echo @echo = > "say=.bat"
209call say=
210echo @echo sem > "say;.bat"
211call say;
212setlocal DisableDelayedExpansion
213echo @echo ! > "say!.bat"
214call say!
215endlocal
216setlocal EnableDelayedExpansion
217call say!
218endlocal
219echo @echo %%%% > "say%%.bat"
220call say%%
221echo @echo ' > "say'.bat"
222call say'
223echo @echo + > "say+.bat"
224call say+
225echo @echo com > "say,.bat"
226call say,
227echo @echo ` > "say`.bat"
228call say'
229echo @echo ~ > "say~.bat"
230call say~
231
232echo --------- Testing parameter passing  --------------
233echo @echo 1:%%1,2:%%2 > tell.bat
234call tell 1
235call tell (1)
236call tell 1(2)
237call :setError 0
238call tell(1)
239if errorlevel 2 echo error %ErrorLevel%
240call :setError 0
241call tell((1))
242if errorlevel 2 echo error %ErrorLevel%
243call :setError 0
244call tell(1)(2)
245if errorlevel 2 echo error %ErrorLevel%
246call :setError 0
247call tell(1);,;(2)
248if errorlevel 2 echo error %ErrorLevel%
249call :setError 0
250call tell;1 2
251if errorlevel 2 echo error %ErrorLevel%
252call :setError 0
253call tell; 1, ;2
254if errorlevel 2 echo error %ErrorLevel%
255call :setError 0
256call tell;1;;2
257if errorlevel 2 echo error %ErrorLevel%
258call tell "p "1 p" "2
259call tell p"1 p";2
260
261echo --------- Testing delimiters and parameter passing  --------------
262echo @echo 0:%%0,1:%%1,2:%%2,All:'%%*'> tell.bat
263call;tell 1 2
264call   tell 1 2
265==call==tell==1==2
266call tell(1234)
267call tell(12(34)
268call tell(12;34)
269echo --------- Finished  --------------
270del tell.bat say*.* bazbaz*.bat
271exit
272:setError
273exit /B %1
274