From 3803134fce8bdc4074107f2573f5db749a56367d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Delanoy?= Date: Thu, 11 Oct 2012 03:08:02 +0200 Subject: [PATCH] cmd/tests: Add tests for command line parsing. Adapted from original patch by Martin Wilck . --- programs/cmd/tests/test_cmdline.cmd | 167 ++++++++++++++++++++++++ programs/cmd/tests/test_cmdline.cmd.exp | 77 +++++++++++ 2 files changed, 244 insertions(+) diff --git a/programs/cmd/tests/test_cmdline.cmd b/programs/cmd/tests/test_cmdline.cmd index ad035ab91ec..7e08b292c25 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 36645da2914..7e9ac3286e5 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@var contents: 11 var=33@space@ 99 +------ Testing invocation of batch files ---------- +0@space@ +1@space@ +@todo_wine@1@space@ +1@space@ +@todo_wine@1@space@ +0@space@ +@todo_wine@1@space@ +@todo_wine@2@space@ +0@space@ +3@space@ +@todo_wine@3@space@ +@todo_wine@4@space@ +------ Testing invocation with CMD /C ------------- +0@space@ +@todo_wine@1@space@ +@todo_wine@0@space@ +0@space@ +@todo_wine@1@space@ +0@space@ +@todo_wine@1@space@ +@todo_wine@2@space@ +0@space@ +@todo_wine@3@space@ +@todo_wine@4@space@ +---------- Testing CMD /C quoting ----------------- +"hi" +@todo_wine@1@space@ +"\"\\"\\\"\\\\"@space@"\"\\"\\\"\\\\" +@todo_wine@1@space@ +0@space@ +1@space@ +0@space@ +@todo_wine@0@space@ +0@space@@or_broken@3@space@ +3@space@ +2@space@ +2@space@ +2@space@ +0@space@ +@todo_wine@5@space@ +------- Testing CMD /C qualifier treatment ------------ +0@space@ +@todo_wine@1@space@ +THIS FAILS: cmd "/c"say one +THIS FAILS: cmd ignoreme/c say one +--------- Testing special characters -------------- +0@space@ +@todo_wine@0@space@ +)@space@ +[@space@ +]@space@ +{@space@ +}@space@ +0@space@ +@todo_wine@0@space@ +!@space@ +@todo_wine@0@space@@or_broken@!@space@ +@todo_wine@0@space@ +'@space@ ++@space@ +0@space@ +'@space@ +~@space@ +--------- Testing parameter passing -------------- +1:1,2:@space@ +1:(1),2:@space@ +1:1(2),2:@space@ +@todo_wine@1:(1),2:@space@ +@todo_wine@1:((1)),2:@space@ +@todo_wine@1:(1)(2),2:@space@ +@todo_wine@1:(1),2:(2)@space@ +@todo_wine@1:1,2:2@space@ +@todo_wine@1:1,2:2@space@ +@todo_wine@1:1,2:2@space@ +1:"p@space@"1,2:p"@space@"2@space@ +1:p"1@space@p",2:2@space@