mirror of
https://github.com/reactos/reactos.git
synced 2025-02-20 15:35:04 +00:00
[CMD_ROSTEST] Add tests for particular ERRORLEVEL behaviour in some commands.
This commit is contained in:
parent
a5d7a2cd61
commit
0b400bbb98
2 changed files with 131 additions and 0 deletions
|
@ -396,6 +396,108 @@ del tmp.cmd
|
|||
cd .. & rmdir /s/q foobar
|
||||
|
||||
|
||||
::
|
||||
:: ERRORLEVEL tests for special commands.
|
||||
::
|
||||
:: For some commands, the errorlevel is set differently,
|
||||
:: whether or not they are run within a .BAT, a .CMD, or
|
||||
:: directly from the command-line.
|
||||
::
|
||||
:: These commands are:
|
||||
:: APPEND/DPATH, ASSOC, FTYPE, PATH, PROMPT, SET.
|
||||
::
|
||||
:: See https://ss64.com/nt/errorlevel.html for more details.
|
||||
::
|
||||
|
||||
echo ---------- Testing ERRORLEVEL in .BAT and .CMD ----------
|
||||
|
||||
:: Use an auxiliary CMD file
|
||||
mkdir foobar && cd foobar
|
||||
|
||||
echo --- In .BAT file
|
||||
call :outputErrLvlTestToBatch tmp.bat
|
||||
cmd /c tmp.bat
|
||||
del tmp.bat
|
||||
|
||||
echo --- In .CMD file
|
||||
call :outputErrLvlTestToBatch tmp.cmd
|
||||
cmd /c tmp.cmd
|
||||
del tmp.cmd
|
||||
|
||||
:: Cleanup
|
||||
cd .. & rmdir /s/q foobar
|
||||
|
||||
:: Go to the next tests below.
|
||||
goto :continue
|
||||
|
||||
:: ERRORLEVEL test helper function
|
||||
:outputErrLvlTestToBatch (filename)
|
||||
|
||||
echo @echo off> %1
|
||||
echo setlocal enableextensions>> %1
|
||||
|
||||
:: Reset the errorlevel
|
||||
echo call :zeroErrLvl>> %1
|
||||
|
||||
:: dpath
|
||||
:: echo %errorlevel%
|
||||
:: dpath xxx
|
||||
:: echo %errorlevel%
|
||||
:: dpath
|
||||
:: echo %errorlevel%
|
||||
|
||||
echo assoc^>NUL>> %1
|
||||
echo echo %%errorlevel%%>> %1
|
||||
echo assoc .nonexisting^>NUL>> %1
|
||||
echo echo %%errorlevel%%>> %1
|
||||
echo assoc .nonexisting^=^>NUL>> %1
|
||||
echo echo %%errorlevel%%>> %1
|
||||
|
||||
:: ftype
|
||||
:: echo %errorlevel%
|
||||
:: ftype xxx
|
||||
:: echo %errorlevel%
|
||||
:: ftype
|
||||
:: echo %errorlevel%
|
||||
|
||||
echo path^>NUL>> %1
|
||||
echo echo %%errorlevel%%>> %1
|
||||
echo path^;^>NUL>> %1
|
||||
echo echo %%errorlevel%%>> %1
|
||||
|
||||
echo prompt^>NUL>> %1
|
||||
echo echo %%errorlevel%%>> %1
|
||||
echo prompt ^$p^$g^>NUL>> %1
|
||||
echo echo %%errorlevel%%>> %1
|
||||
echo prompt foobar^>NUL>> %1
|
||||
echo echo %%errorlevel%%>> %1
|
||||
|
||||
echo set^>NUL>> %1
|
||||
echo echo %%errorlevel%%>> %1
|
||||
echo set nonexisting^>NUL>> %1
|
||||
echo echo %%errorlevel%%>> %1
|
||||
echo set nonexisting^=^>NUL>> %1
|
||||
echo echo %%errorlevel%%>> %1
|
||||
echo set nonexisting^=trololol^>NUL>> %1
|
||||
echo echo %%errorlevel%%>> %1
|
||||
echo set nonexisting^=^>NUL>> %1
|
||||
echo echo %%errorlevel%%>> %1
|
||||
|
||||
echo goto :eof>> %1
|
||||
|
||||
:: Zero ERRORLEVEL
|
||||
echo :zeroErrLvl>> %1
|
||||
echo exit /B 0 >> %1
|
||||
|
||||
goto :eof
|
||||
|
||||
|
||||
::
|
||||
:: Next suite of tests.
|
||||
::
|
||||
:continue
|
||||
|
||||
|
||||
::
|
||||
:: Finished!
|
||||
::
|
||||
|
|
|
@ -101,4 +101,33 @@ OK
|
|||
OK
|
||||
OK
|
||||
OK
|
||||
---------- Testing ERRORLEVEL in .BAT and .CMD ----------
|
||||
--- In .BAT file
|
||||
0
|
||||
1
|
||||
2
|
||||
2
|
||||
2
|
||||
2
|
||||
2
|
||||
2
|
||||
2
|
||||
1
|
||||
1
|
||||
1
|
||||
1
|
||||
--- In .CMD file
|
||||
0
|
||||
1
|
||||
2
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
1
|
||||
0
|
||||
0
|
||||
0
|
||||
--------- Finished --------------
|
||||
|
|
Loading…
Reference in a new issue