[CMD_ROSTEST] Add tests for GOTO :EOF

This commit is contained in:
Hermès Bélusca-Maïto 2020-07-27 00:49:18 +02:00
parent f911bb482d
commit aee1dd2972
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
2 changed files with 64 additions and 0 deletions

View file

@ -50,6 +50,64 @@ goto :EOF
:continue
::
:: Testing :EOF support
::
echo --------- Testing :EOF support ---------
:: Use an auxiliary CMD file to test GOTO :EOF
mkdir foobar && cd foobar
:: GOTO :EOF is available only if commands extensions are enabled
echo @echo off> tmp.cmd
echo setlocal disableextensions>> tmp.cmd
echo goto :eof>> tmp.cmd
call :setError 0
cmd /c tmp.cmd
if %errorlevel% equ 0 (echo Unexpected: GOTO :EOF did not fail^^!) else echo OK
:: GOTO :EOF is done only if the ":EOF" part is followed by whitespace or ends.
:: The following two GOTO's fail because the labels cannot be found.
echo @echo off> tmp.cmd
echo setlocal enableextensions>> tmp.cmd
echo goto :eof,lol>> tmp.cmd
echo echo Batch continues^^!>> tmp.cmd
call :setError 0
cmd /c tmp.cmd
if %errorlevel% equ 0 (echo Unexpected: GOTO :eof,lol did not fail^^!) else echo OK
echo @echo off> tmp.cmd
echo setlocal enableextensions>> tmp.cmd
echo goto :eof:lol>> tmp.cmd
echo echo Batch continues^^!>> tmp.cmd
call :setError 0
cmd /c tmp.cmd
if %errorlevel% equ 0 (echo Unexpected: GOTO :eof:lol did not fail^^!) else echo OK
:: GOTO :EOF expects at least one whitespace character before anything else.
:: Not even '+',':' or other separators are allowed.
echo @echo off> tmp.cmd
echo setlocal enableextensions>> tmp.cmd
echo goto :eof+lol>> tmp.cmd
echo echo Batch continues^^!>> tmp.cmd
call :setError 0
cmd /c tmp.cmd
if %errorlevel% equ 0 (echo Unexpected: GOTO :eof+lol did not fail^^!) else echo OK
:: This GOTO :EOF works.
echo @echo off> tmp.cmd
echo setlocal enableextensions>> tmp.cmd
echo goto :eof@tab@+lol>> tmp.cmd
echo echo You should not see this^^!>> tmp.cmd
call :setError 0
cmd /c tmp.cmd
if %errorlevel% neq 0 (echo Unexpected: GOTO :EOF did fail^^!) else echo OK
:: Cleanup
cd .. & rd /s/q foobar
::
:: Testing GOTO/CALL from and to within parenthesized blocks.
::

View file

@ -2,6 +2,12 @@
Test GOTO ok
--------- Testing CALL within batch ---------
Test CALL ok from :test_call
--------- Testing :EOF support ---------
OK
OK
OK
OK
OK
--------- Testing GOTO within block ---------
Block-test 1: Single-line
Block-test 2: Multi-line