Module: wine
Branch: master
Commit: 6f0e9e5e4e5db8cfbddad65d9bd10b00e1666dfd
URL: https://gitlab.winehq.org/wine/wine/-/commit/6f0e9e5e4e5db8cfbddad65d9bd10b…
Author: Eric Pouech <epouech(a)codeweavers.com>
Date: Sun May 5 09:08:23 2024 +0200
cmd/tests: Test success/failure of commands.
The || and && operators to chain commands rely on the LHS command
to be successful (or unsucessful) to decide upon launching the RHS
command.
Unfortunately, success/failure is not always when errorlevel is
0 (non zero).
Some exmaples:
- if a redirection fails (eg. appending to a non existing file),
the command (builtin/external) is always unsuccessful (and the
error level is untouched,
- external command (when redirection is ok) is succesful when
program exit code is zero,
- ditto for a call to a label inside the batch file, with
the 'exit /b' parameter,
- it's way more complicated for builtins. Eg 'type' is unsuccessful
on a non existing file, while 'dir' (on the same unexisting file)
succeeds.
So start adding some tests about success / failure of some commands.
Signed-off-by: Eric Pouech <epouech(a)codeweavers.com>
---
programs/cmd/tests/test_builtins.cmd | 9 +++++++++
programs/cmd/tests/test_builtins.cmd.exp | 9 +++++++++
2 files changed, 18 insertions(+)
diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd
index 77207318223..8fa724c2682 100644
--- a/programs/cmd/tests/test_builtins.cmd
+++ b/programs/cmd/tests/test_builtins.cmd
@@ -450,6 +450,15 @@ if 1==0 (echo o1) else echo o2&&echo o3
if 1==0 (echo p1) else echo p2||echo p3
echo ---
if 1==0 (echo q1) else echo q2&echo q3
+echo ------------- Testing internal commands return codes
+call :setError 0 &&echo SUCCESS||echo FAILURE %errorlevel%
+call :setError 33 &&echo SUCCESS||echo FAILURE %errorlevel%
+call :setError 666
+echo foo &&echo SUCCESS||echo FAILURE %errorlevel%
+echo foo >> h:\i\dont\exist\at\all.txt &&echo SUCCESS||echo FAILURE %errorlevel%
+type NUL &&echo SUCCESS||echo FAILURE %errorlevel%
+type h:\i\dont\exist\at\all.txt &&echo SUCCESS||echo FAILURE %errorlevel%
+echo ---
echo ------------ Testing 'set' ------------
call :setError 0
rem Remove any WINE_FOO* WINE_BA* environment variables from shell before proceeding
diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp
index 026befada11..76665765b26 100644
--- a/programs/cmd/tests/test_builtins.cmd.exp
+++ b/programs/cmd/tests/test_builtins.cmd.exp
@@ -449,6 +449,15 @@ p2
@todo_wine@---
q2
q3
+------------- Testing internal commands return codes
+SUCCESS
+FAILURE 0
+@todo_wine@foo@space@
+@todo_wine@SUCCESS
+@todo_wine@FAILURE 666
+SUCCESS
+@todo_wine@FAILURE 0
+@todo_wine@---
------------ Testing 'set' ------------
1
0