=?UTF-8?Q?Fr=C3=A9d=C3=A9ric=20Delanoy=20?=: cmd/tests: Add tests for command line parsing.

Alexandre Julliard julliard at winehq.org
Thu Oct 11 15:25:16 CDT 2012


Module: wine
Branch: master
Commit: 3803134fce8bdc4074107f2573f5db749a56367d
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=3803134fce8bdc4074107f2573f5db749a56367d

Author: Frédéric Delanoy <frederic.delanoy at gmail.com>
Date:   Thu Oct 11 03:08:02 2012 +0200

cmd/tests: Add tests for command line parsing.

Adapted from original patch by Martin Wilck <mwilck at arcor.de>.

---

 programs/cmd/tests/test_cmdline.cmd     |  167 +++++++++++++++++++++++++++++++
 programs/cmd/tests/test_cmdline.cmd.exp |   77 ++++++++++++++
 2 files changed, 244 insertions(+), 0 deletions(-)

diff --git a/programs/cmd/tests/test_cmdline.cmd b/programs/cmd/tests/test_cmdline.cmd
index ad035ab..7e08b29 100644
--- a/programs/cmd/tests/test_cmdline.cmd
+++ b/programs/cmd/tests/test_cmdline.cmd
@@ -88,3 +88,170 @@ cmd.exe /c exit
 
 cd ..
 rd foobar /s /q
+
+rem - Temporary batch files
+echo @echo 0 > "say.bat"
+echo @echo 1 > "say one.bat"
+echo @echo 2 > "saytwo.bat"
+echo @echo 3 > "say (3).bat"
+echo @echo 4 > "say .bat"
+
+echo ------ Testing invocation of batch files ----------
+call say one
+call "say one"
+call "say"" one"
+call "say one
+call :setError 0
+call say" one"
+if errorlevel 2 echo error %ErrorLevel%
+call say "one"
+call :setError 0
+call s"ay one
+if errorlevel 2 echo error %ErrorLevel%
+call :setError 0
+call s"aytwo
+if errorlevel 2 echo error %ErrorLevel%
+call say (3)
+call "say (3)"
+call :setError 0
+call say" (3)"
+if errorlevel 2 echo error %ErrorLevel%
+call :setError 0
+call say" "(3) prints 4?!
+if errorlevel 2 echo error %ErrorLevel%
+
+echo ------ Testing invocation with CMD /C -------------
+cmd /c say one
+cmd /c "say one"
+call :setError 0
+cmd /c "say"" one"
+if errorlevel 2 echo error %ErrorLevel%
+cmd /c "say one
+call :setError 0
+cmd /c say" one"
+if errorlevel 2 echo error %ErrorLevel%
+cmd /c say "one"
+call :setError 0
+cmd /c s"ay one
+if errorlevel 2 echo error %ErrorLevel%
+call :setError 0
+cmd /c s"aytwo
+if errorlevel 2 echo error %ErrorLevel%
+cmd /c say (3)
+call :setError 0
+cmd /c say" (3)"
+if errorlevel 2 echo error %ErrorLevel%
+call :setError 0
+cmd /c say" "(3) prints 4?!
+if errorlevel 2 echo error %ErrorLevel%
+
+echo ---------- Testing CMD /C quoting -----------------
+cmd /c @echo "hi"
+call :setError 0
+cmd /c say" "one
+if errorlevel 2 echo error %ErrorLevel%
+cmd /c @echo "\"\\"\\\"\\\\" "\"\\"\\\"\\\\"
+rem ---- all 5 conditions met, quotes preserved
+cmd /c "say one"
+rem cond 1 - /s
+cmd /s/c "say one"
+cmd /s/c ""say one""
+rem cond 2 - not 2 quotes
+cmd /c "say one
+call :setError 0
+cmd /c "say"" one"
+if errorlevel 2 echo error %ErrorLevel%
+rem cond 3 - special char - first test fails on Vista, W2K8!
+cmd /c "say (3)"
+cmd /c ""say (3)""
+rem cond 4 - no spaces (quotes make no difference here)
+cmd /c saytwo
+cmd /c "saytwo"
+cmd /c "saytwo
+rem cond 5 - string between quotes must be name of executable
+cmd /c "say five"
+echo @echo 5 >"say five.bat"
+cmd /c "say five"
+
+echo ------- Testing CMD /C qualifier treatment ------------
+rem no need for space after /c
+cmd /csay one
+cmd /c"say one"
+rem ignore quote before qualifier
+rem FIXME the next command in wine starts a sub-CMD
+echo THIS FAILS: cmd "/c"say one
+rem ignore anything before /c
+rem FIXME the next command in wine starts a sub-CMD
+echo THIS FAILS: cmd ignoreme/c say one
+
+echo --------- Testing special characters --------------
+echo @echo amp > "say&.bat"
+call say&
+echo @echo ( > "say(.bat"
+call say(
+echo @echo ) > "say).bat"
+call say)
+echo @echo [ > "say[.bat"
+call say[
+echo @echo ] > "say].bat"
+call say]
+echo @echo { > "say{.bat"
+call say{
+echo @echo } > "say}.bat"
+call say}
+echo @echo = > "say=.bat"
+call say=
+echo @echo sem > "say;.bat"
+call say;
+setlocal DisableDelayedExpansion
+echo @echo ! > "say!.bat"
+call say!
+endlocal
+setlocal EnableDelayedExpansion
+call say!
+endlocal
+echo @echo %%%% > "say%%.bat"
+call say%%
+echo @echo ' > "say'.bat"
+call say'
+echo @echo + > "say+.bat"
+call say+
+echo @echo com > "say,.bat"
+call say,
+echo @echo ` > "say`.bat"
+call say'
+echo @echo ~ > "say~.bat"
+call say~
+
+echo --------- Testing parameter passing  --------------
+echo @echo 1:%%1,2:%%2 > tell.bat
+call tell 1
+call tell (1)
+call tell 1(2)
+call :setError 0
+call tell(1)
+if errorlevel 2 echo error %ErrorLevel%
+call :setError 0
+call tell((1))
+if errorlevel 2 echo error %ErrorLevel%
+call :setError 0
+call tell(1)(2)
+if errorlevel 2 echo error %ErrorLevel%
+call :setError 0
+call tell(1);,;(2)
+if errorlevel 2 echo error %ErrorLevel%
+call :setError 0
+call tell;1 2
+if errorlevel 2 echo error %ErrorLevel%
+call :setError 0
+call tell; 1, ;2
+if errorlevel 2 echo error %ErrorLevel%
+call :setError 0
+call tell;1;;2
+if errorlevel 2 echo error %ErrorLevel%
+call tell "p "1 p" "2
+call tell p"1 p";2
+del tell.bat say*.*
+exit
+:setError
+exit /B %1
diff --git a/programs/cmd/tests/test_cmdline.cmd.exp b/programs/cmd/tests/test_cmdline.cmd.exp
index 36645da..7e9ac32 100644
--- a/programs/cmd/tests/test_cmdline.cmd.exp
+++ b/programs/cmd/tests/test_cmdline.cmd.exp
@@ -45,3 +45,80 @@ one = %1
 @todo_wine at var contents: 11
 var=33 at space@
 99
+------ Testing invocation of batch files ----------
+0 at space@
+1 at space@
+ at todo_wine@1 at space@
+1 at space@
+ at todo_wine@1 at space@
+0 at space@
+ at todo_wine@1 at space@
+ at todo_wine@2 at space@
+0 at space@
+3 at space@
+ at todo_wine@3 at space@
+ at todo_wine@4 at space@
+------ Testing invocation with CMD /C -------------
+0 at space@
+ at todo_wine@1 at space@
+ at todo_wine@0 at space@
+0 at space@
+ at todo_wine@1 at space@
+0 at space@
+ at todo_wine@1 at space@
+ at todo_wine@2 at space@
+0 at space@
+ at todo_wine@3 at space@
+ at todo_wine@4 at space@
+---------- Testing CMD /C quoting -----------------
+"hi"
+ at todo_wine@1 at space@
+"\"\\"\\\"\\\\"@space@"\"\\"\\\"\\\\"
+ at todo_wine@1 at space@
+0 at space@
+1 at space@
+0 at space@
+ at todo_wine@0 at space@
+0 at space@@or_broken at 3@space@
+3 at space@
+2 at space@
+2 at space@
+2 at space@
+0 at space@
+ at todo_wine@5 at space@
+------- Testing CMD /C qualifier treatment ------------
+0 at space@
+ at todo_wine@1 at space@
+THIS FAILS: cmd "/c"say one
+THIS FAILS: cmd ignoreme/c say one
+--------- Testing special characters --------------
+0 at space@
+ at todo_wine@0 at space@
+)@space@
+[@space@
+]@space@
+{@space@
+}@space@
+0 at space@
+ at todo_wine@0 at space@
+!@space@
+ at todo_wine@0 at space@@or_broken@!@space@
+ at todo_wine@0 at space@
+'@space@
++ at space@
+0 at space@
+'@space@
+~@space@
+--------- Testing parameter passing  --------------
+1:1,2:@space@
+1:(1),2:@space@
+1:1(2),2:@space@
+ at todo_wine@1:(1),2:@space@
+ at todo_wine@1:((1)),2:@space@
+ at todo_wine@1:(1)(2),2:@space@
+ at todo_wine@1:(1),2:(2)@space@
+ at todo_wine@1:1,2:2 at space@
+ at todo_wine@1:1,2:2 at space@
+ at todo_wine@1:1,2:2 at space@
+1:"p at space@"1,2:p"@space@"2 at space@
+1:p"1 at space@p",2:2 at space@




More information about the wine-cvs mailing list