cmd: Add simple test for %errorlevel%.

This commit is contained in:
Dan Kegel 2011-05-25 21:42:37 -07:00 committed by Alexandre Julliard
parent 6115951502
commit 67873bdc9f
2 changed files with 34 additions and 0 deletions

View File

@ -94,6 +94,24 @@ del /a:r *.test
if not exist r.test echo r.test not found after delete, good
if exist r.test echo r.test found after delete, bad
echo -----------Testing Errorlevel-----------
rem nt 4.0 doesn't really support a way of setting errorlevel, so this is weak
rem See http://www.robvanderwoude.com/exit.php
call :setError 1
echo %ErrorLevel%
if errorlevel 2 echo errorlevel too high, bad
if errorlevel 1 echo errorlevel just right, good
call :setError 0
echo abc%ErrorLevel%def
if errorlevel 1 echo errorlevel nonzero, bad
if not errorlevel 1 echo errorlevel zero, good
rem Now verify that setting a real variable hides its magic variable
set errorlevel=7
echo %ErrorLevel% should be 7
if errorlevel 7 echo setting var worked too well, bad
call :setError 3
echo %ErrorLevel% should still be 7
echo -----------Testing GOTO-----------
if a==a goto dest1
:dest1
@ -107,3 +125,11 @@ echo goto with a leading tab worked
if d==d goto dest4
:dest4@space@
echo goto with a following space worked
echo -----------Done, jumping to EOF-----------
goto :eof
rem Subroutine to set errorlevel and return
rem in windows nt 4.0, this always sets errorlevel 1, since /b isn't supported
:setError
exit /B %1
rem This line runs under cmd in windows NT 4, but not in more modern versions.

View File

@ -82,8 +82,16 @@ if /I seems to work
not-r.test not found after delete, good
r.test found before delete, good
r.test not found after delete, good
-----------Testing Errorlevel-----------
1
errorlevel just right, good
abc0def@or_broken@abc1def
errorlevel zero, good@or_broken@errorlevel nonzero, bad
7 should be 7
7 should still be 7
-----------Testing GOTO-----------
goto with no leading space worked
goto with a leading space worked
goto with a leading tab worked
goto with a following space worked
-----------Done, jumping to EOF-----------