[PATCH 1/5] cmd/tests: add more tests for command line parsing

Martin Wilck mwilck at arcor.de
Mon Aug 29 17:34:30 CDT 2011


This patch adds some tests for command line parsing and treatment
of quotes and special characters in the command line and in program
names and parameters. The .exp file was created using Win XP.
Follow-up patches will fix the marked TODOs.
---
 programs/cmd/tests/rsrc.rc              |    6 +
 programs/cmd/tests/test_parsing.cmd     |  158 +++++++++++++++++++++++++++++++
 programs/cmd/tests/test_parsing.cmd.exp |   77 +++++++++++++++
 3 files changed, 241 insertions(+), 0 deletions(-)
 create mode 100644 programs/cmd/tests/test_parsing.cmd
 create mode 100644 programs/cmd/tests/test_parsing.cmd.exp

diff --git a/programs/cmd/tests/rsrc.rc b/programs/cmd/tests/rsrc.rc
index bcb738d..fca0783 100644
--- a/programs/cmd/tests/rsrc.rc
+++ b/programs/cmd/tests/rsrc.rc
@@ -21,3 +21,9 @@ test_builtins.cmd TESTCMD "test_builtins.cmd"
 
 /* @makedep: test_builtins.cmd.exp */
 test_builtins.cmd.exp TESTOUT "test_builtins.cmd.exp"
+
+/* @makedep: test_parsing.cmd */
+test_parsing.cmd TESTCMD "test_parsing.cmd"
+
+/* @makedep: test_parsing.cmd.exp */
+test_parsing.cmd.exp TESTOUT "test_parsing.cmd.exp"
diff --git a/programs/cmd/tests/test_parsing.cmd b/programs/cmd/tests/test_parsing.cmd
new file mode 100644
index 0000000..4db6b94
--- /dev/null
+++ b/programs/cmd/tests/test_parsing.cmd
@@ -0,0 +1,158 @@
+ at echo off
+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 1 echo error %ErrorLevel%
+call say "one"
+call :setError 0
+call s"ay one
+if errorlevel 1 echo error %ErrorLevel%
+call :setError 0
+call s"aytwo
+if errorlevel 1 echo error %ErrorLevel%
+call say (3)
+call "say (3)"
+call :setError 0
+call say" (3)"
+if errorlevel 1 echo error %ErrorLevel%
+call :setError 0
+call say" "(3) prints 4?!
+if errorlevel 1 echo error %ErrorLevel%
+echo ------ Testing invocation with CMD /C -------------
+cmd /c say one
+cmd /c "say one"
+cmd /c "say"" one"
+cmd /c "say one
+call :setError 0
+cmd /c say" one"
+if errorlevel 1 echo error %ErrorLevel%
+cmd /c say "one"
+call :setError 0
+cmd /c s"ay one
+if errorlevel 1 echo error %ErrorLevel%
+call :setError 0
+cmd /c s"aytwo
+if errorlevel 1 echo error %ErrorLevel%
+cmd /c say (3)
+cmd /c "say (3)"
+call :setError 0
+cmd /c say" (3)"
+if errorlevel 1 echo error %ErrorLevel%
+call :setError 0
+cmd /c say" "(3) prints 4?!
+if errorlevel 1 echo error %ErrorLevel%
+echo ---------- Testing CMD /C quoting -----------------
+cmd /c @echo "hi"
+call :setError 0
+cmd /c say" "one
+if errorlevel 1 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 1 echo error %ErrorLevel%
+rem cond 3 - special char
+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 weirdness ---------------
+rem no need for space after /c
+cmd /csay one
+cmd /c"say one"
+rem ignore quote before qualifier
+cmd "/c"say one
+rem ignore anything before /c
+rem this needs a trick because if it doesn't work a sub-cmd will be spawned
+echo @exit /B 0 >_good_.bat
+echo @exit /B 1 >_bad_.bat
+call :setError 0
+cmd /c_good_ <_bad_.bat >_tst_.out
+if errorlevel 1 (echo bad) else echo good
+call :setError 0
+cmd ignoreme/c_good_ <_bad_.bat >_tst_.out
+if errorlevel 1 (echo bad) else echo good
+del _good_.bat _bad_.bat _tst_.out
+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 ; > "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 --------- 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 1 echo error %ErrorLevel%
+call :setError 0
+call tell((1))
+if errorlevel 1 echo error %ErrorLevel%
+call :setError 0
+call tell(1)(2)
+if errorlevel 1 echo error %ErrorLevel%
+call :setError 0
+call tell(1);,;(2)
+if errorlevel 1 echo error %ErrorLevel%
+call :setError 0
+call tell;1 2
+if errorlevel 1 echo error %ErrorLevel%
+call :setError 0
+call tell; 1, ;2
+if errorlevel 1 echo error %ErrorLevel%
+call :setError 0
+call tell;1;;2
+if errorlevel 1 echo error %ErrorLevel%
+call tell "p "1 p" "2
+call tell p"1 p";2
+del tell.bat say*.*
+:setError
+exit /B %1
diff --git a/programs/cmd/tests/test_parsing.cmd.exp b/programs/cmd/tests/test_parsing.cmd.exp
new file mode 100644
index 0000000..4d07801
--- /dev/null
+++ b/programs/cmd/tests/test_parsing.cmd.exp
@@ -0,0 +1,77 @@
+------ 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@
+1 at space@
+ at todo_wine@0 at space@
+ at todo_wine@0 at space@
+1 at space@
+0 at space@
+1 at space@
+2 at space@
+0 at space@
+0 at space@
+ at todo_wine@3 at space@
+ at todo_wine@4 at space@
+---------- Testing CMD /C quoting -----------------
+ at todo_wine@"hi"
+1 at space@
+ at todo_wine@"\"\\"\\\"\\\\"@space@"\"\\"\\\"\\\\"
+1 at space@
+0 at space@
+ at todo_wine@1 at space@
+ at todo_wine@0 at space@
+ at todo_wine@0 at space@
+0 at space@
+ at todo_wine@3 at space@
+2 at space@
+2 at space@
+2 at space@
+0 at space@
+5 at space@
+---------- Testing CMD /C weirdness ---------------
+0 at space@
+1 at space@
+0 at space@
+good
+ at todo_wine@good
+--------- 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@
+'@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@
+ at todo_wine@1:"p at space@"1,2:p"@space@"2 at space@
+ at todo_wine@1:p"1 at space@p",2:2 at space@
-- 
1.7.3.4



More information about the wine-patches mailing list