[PATCH 1/3] [try3] [cmd] Convert the set /a tests to validate better

Ann and Jason Edmeades jason at edmeades.me.uk
Thu Dec 20 17:37:01 CST 2012


Try#3 Learnt to use git better to edit the right file and
      now the tests should pass on all os!
Try#2 Dont hardcode env var names in checking routine
-     Make checking routine a reuseable routine for elsewhere
-     Rename var1/2/3 to foo, bar, baz as per elsewhere

The tests previously set a variable which was not checked until
the subsequent test completed (as env vars are expanded as the
line is read, meaning a sequence of set /a var=x & echo %var%
echos the contents before the set is executed). In addition when
multiple variables are involved in the calculation, only the
first one was being checked, and this is changed to check all
variables involved in the calculation.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.winehq.org/pipermail/wine-patches/attachments/20121220/1dffe993/attachment.html>
-------------- next part --------------
From 6429ca6231f9f2c174191d411ef6a46c0371b684 Mon Sep 17 00:00:00 2001
From: Jason Edmeades <jason at edmeades.me.uk>
Date: Wed, 12 Dec 2012 00:30:45 +0000
Subject: [PATCH 1/3] [try2] [cmd] Convert the set /a tests to validate better

Try#3 Learnt to use git better to edit the right file and
      now the tests should pass on all os!
Try#2 Dont hardcode env var names in checking routine
-     Make checking routine a reuseable routine for elsewhere
-     Rename var1/2/3 to foo, bar, baz as per elsewhere

The tests previously set a variable which was not checked until
the subsequent test completed (as env vars are expanded as the
line is read, meaning a sequence of set /a var=x & echo %var%
echos the contents before the set is executed). In addition when
multiple variables are involved in the calculation, only the
first one was being checked, and this is changed to check all
variables involved in the calculation.
---
 programs/cmd/tests/test_builtins.cmd     |  167 +++++++++++++++++-------------
 programs/cmd/tests/test_builtins.cmd.exp |  147 ++++++++++++++------------
 2 files changed, 176 insertions(+), 138 deletions(-)

diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd
index eb9b888..6cf2ecb 100644
--- a/programs/cmd/tests/test_builtins.cmd
+++ b/programs/cmd/tests/test_builtins.cmd
@@ -1030,85 +1030,108 @@ for /L %%i in (2,2,1) do (
   echo %%i
   echo FAILED
 )
-echo --- for /a
+echo --- set /a
+goto :testseta
+
+Rem Ideally for /f can be used rather than building a command to execute
+rem but that does not work on NT4
+:checkenvvars
+if "%1"=="" goto :eof
+call :executecmd set wine_result=%%%1%%
+if "%wine_result%"=="%2" (
+  echo %1 correctly %2
+) else echo ERROR: %1 incorrectly %wine_result% [%2]
+set %1=
+shift
+shift
+rem shift
+goto :checkenvvars
+:executecmd
+%*
+goto :eof
+
+:testseta
 rem No output when using "set expr" syntax, unless in interactive mode
 rem Need to use "set envvar=expr" to use in a batch script
 echo ------ individual operations
-set WINE_var=0
-set /a WINE_var=1 +2 & echo %WINE_var%
-set /a WINE_var=1 +-2 & echo %WINE_var%
-set /a WINE_var=1 --2 & echo %WINE_var%
-set /a WINE_var=2* 3 & echo %WINE_var%
-set /a WINE_var=-2* -5 & echo %WINE_var%
-set /a WINE_var=12/3 & echo %WINE_var%
-set /a WINE_var=13/3 & echo %WINE_var%
-set /a WINE_var=-13/3 & echo %WINE_var%
+set WINE_foo=0
+set /a WINE_foo=1 +2 & call :checkenvvars WINE_foo 3
+set /a WINE_foo=1 +-2 & call :checkenvvars WINE_foo -1
+set /a WINE_foo=1 --2 & call :checkenvvars WINE_foo 3
+set /a WINE_foo=2* 3 & call :checkenvvars WINE_foo 6
+set /a WINE_foo=-2* -5 & call :checkenvvars WINE_foo 10
+set /a WINE_foo=12/3 & call :checkenvvars WINE_foo 4
+set /a WINE_foo=13/3 & call :checkenvvars WINE_foo 4
+set /a WINE_foo=-13/3 & call :checkenvvars WINE_foo -4
 rem FIXME Divide by zero should return an error, but error messages cannot be tested with current infrastructure
-set /a WINE_var=5 %% 5 & echo %WINE_var%
-set /a WINE_var=5 %% 3 & echo %WINE_var%
-set /a WINE_var=5 %% -3 & echo %WINE_var%
-set /a WINE_var=-5 %% -3 & echo %WINE_var%
-set /a WINE_var=1 ^<^< 0 & echo %WINE_var%
-set /a WINE_var=1 ^<^< 2 & echo %WINE_var%
-set /a WINE_var=1 ^<^< -2 & echo %WINE_var%
-set /a WINE_var=-1 ^<^< -2 & echo %WINE_var%
-set /a WINE_var=-1 ^<^< 2 & echo %WINE_var%
-set /a WINE_var=9 ^>^> 0 & echo %WINE_var%
-set /a WINE_var=9 ^>^> 2 & echo %WINE_var%
-set /a WINE_var=9 ^>^> -2 & echo %WINE_var%
-set /a WINE_var=-9 ^>^> -2 & echo %WINE_var%
-set /a WINE_var=-9 ^>^> 2 & echo %WINE_var%
-set /a WINE_var=5 ^& 0 & echo %WINE_var%
-set /a WINE_var=5 ^& 1 & echo %WINE_var%
-set /a WINE_var=5 ^& 3 & echo %WINE_var%
-set /a WINE_var=5 ^& 4 & echo %WINE_var%
-set /a WINE_var=5 ^& 1 & echo %WINE_var%
-set /a WINE_var=5 ^| 0 & echo %WINE_var%
-set /a WINE_var=5 ^| 1 & echo %WINE_var%
-set /a WINE_var=5 ^| 3 & echo %WINE_var%
-set /a WINE_var=5 ^| 4 & echo %WINE_var%
-set /a WINE_var=5 ^| 1 & echo %WINE_var%
-set /a WINE_var=5 ^^ 0 & echo %WINE_var%
-set /a WINE_var=5 ^^ 1 & echo %WINE_var%
-set /a WINE_var=5 ^^ 3 & echo %WINE_var%
-set /a WINE_var=5 ^^ 4 & echo %WINE_var%
-set /a WINE_var=5 ^^ 1 & echo %WINE_var%
+set /a WINE_foo=5 %% 5 & call :checkenvvars WINE_foo 0
+set /a WINE_foo=5 %% 3 & call :checkenvvars WINE_foo 2
+set /a WINE_foo=5 %% -3 & call :checkenvvars WINE_foo 2
+set /a WINE_foo=-5 %% -3 & call :checkenvvars WINE_foo -2
+set /a WINE_foo=1 ^<^< 0 & call :checkenvvars WINE_foo 1
+set /a WINE_foo=1 ^<^< 2 & call :checkenvvars WINE_foo 4
+set /a WINE_foo=1 ^<^< -2 & call :checkenvvars WINE_foo 0
+set /a WINE_foo=-1 ^<^< -2 & call :checkenvvars WINE_foo 0
+set /a WINE_foo=-1 ^<^< 2 & call :checkenvvars WINE_foo -4
+set /a WINE_foo=9 ^>^> 0 & call :checkenvvars WINE_foo 9
+set /a WINE_foo=9 ^>^> 2 & call :checkenvvars WINE_foo 2
+set /a WINE_foo=9 ^>^> -2 & call :checkenvvars WINE_foo 0
+set /a WINE_foo=-9 ^>^> -2 & call :checkenvvars WINE_foo -1
+set /a WINE_foo=-9 ^>^> 2 & call :checkenvvars WINE_foo -3
+set /a WINE_foo=5 ^& 0 & call :checkenvvars WINE_foo 0
+set /a WINE_foo=5 ^& 1 & call :checkenvvars WINE_foo 1
+set /a WINE_foo=5 ^& 3 & call :checkenvvars WINE_foo 1
+set /a WINE_foo=5 ^& 4 & call :checkenvvars WINE_foo 4
+set /a WINE_foo=5 ^& 1 & call :checkenvvars WINE_foo 1
+set /a WINE_foo=5 ^| 0 & call :checkenvvars WINE_foo 5
+set /a WINE_foo=5 ^| 1 & call :checkenvvars WINE_foo 5
+set /a WINE_foo=5 ^| 3 & call :checkenvvars WINE_foo 7
+set /a WINE_foo=5 ^| 4 & call :checkenvvars WINE_foo 5
+set /a WINE_foo=5 ^| 1 & call :checkenvvars WINE_foo 5
+set /a WINE_foo=5 ^^ 0 & call :checkenvvars WINE_foo 5
+set /a WINE_foo=5 ^^ 1 & call :checkenvvars WINE_foo 4
+set /a WINE_foo=5 ^^ 3 & call :checkenvvars WINE_foo 6
+set /a WINE_foo=5 ^^ 4 & call :checkenvvars WINE_foo 1
+set /a WINE_foo=5 ^^ 1 & call :checkenvvars WINE_foo 4
 echo ------ precedence and grouping
-set /a WINE_var=4 + 2*3 & echo %WINE_var%
-set /a WINE_var=(4+2)*3 & echo %WINE_var%
-set /a WINE_var=4 * 3/5 & echo %WINE_var%
-set /a WINE_var=(4 * 3)/5 & echo %WINE_var%
-set /a WINE_var=4 * 5 %% 4 & echo %WINE_var%
-set /a WINE_var=4 * (5 %% 4) & echo %WINE_var%
-set /a WINE_var=3 %% (5 + 8 %% 3 ^^ 2) & echo %WINE_var%
-set /a WINE_var=3 %% (5 + 8 %% 3 ^^ -2) & echo %WINE_var%
+set /a WINE_foo=4 + 2*3 & call :checkenvvars WINE_foo 10
+set /a WINE_foo=(4+2)*3 & call :checkenvvars WINE_foo 18
+set /a WINE_foo=4 * 3/5 & call :checkenvvars WINE_foo 2
+set /a WINE_foo=(4 * 3)/5 & call :checkenvvars WINE_foo 2
+set /a WINE_foo=4 * 5 %% 4 & call :checkenvvars WINE_foo 0
+set /a WINE_foo=4 * (5 %% 4) & call :checkenvvars WINE_foo 4
+set /a WINE_foo=3 %% (5 + 8 %% 3 ^^ 2) & call :checkenvvars WINE_foo 3
+set /a WINE_foo=3 %% (5 + 8 %% 3 ^^ -2) & call :checkenvvars WINE_foo 3
 echo ------ octal and hexadecimal
-set /a WINE_var=0xf + 3 & echo %WINE_var%
-set /a WINE_var=0xF + 3 & echo %WINE_var%
-set /a WINE_var=015 + 2 & echo %WINE_var%
-set /a WINE_var=3, 8+3,0 & echo %WINE_var%
+set /a WINE_foo=0xf + 3 & call :checkenvvars WINE_foo 18
+set /a WINE_foo=0xF + 3 & call :checkenvvars WINE_foo 18
+set /a WINE_foo=015 + 2 & call :checkenvvars WINE_foo 15
+set /a WINE_foo=3, 8+3,0 & call :checkenvvars WINE_foo 3
 echo ------ variables
-set /a WINE_var=WINE_foo=3, WINE_foo+1 & echo %WINE_var%
-if defined WINE_foo (echo %WINE_foo%) else (
-    echo WINE_foo not defined
-)
-set /a WINE_var=WINE_foo=3, WINE_foo+=1 & echo %WINE_var%
-set /a WINE_var=WINE_foo=3, WINE_bar=1, WINE_bar+=WINE_foo, WINE_bar & echo %WINE_var%
-set /a WINE_var=WINE_foo*= WINE_foo & echo %WINE_var%
-set /a WINE_var=WINE_whateverNonExistingVar & echo %WINE_var%
-set /a WINE_var=WINE_whateverNonExistingVar + WINE_bar & echo %WINE_var%
-set /a WINE_var=WINE_foo -= WINE_foo + 7 & echo %WINE_var%
-set /a WINE_var=WINE_foo /= 3 + 2 & echo %WINE_var%
-set /a WINE_var=WINE_foo=5, WINE_foo %%=2 & echo %WINE_var%
-set /a WINE_var=WINE_foo ^<^<= 2 & echo %WINE_var%
-set /a WINE_var=WINE_foo ^>^>= 2 & echo %WINE_var%
-set /a WINE_var=WINE_foo ^&= 2 & echo %WINE_var%
-set /a WINE_var=WINE_foo=5, WINE_foo ^|= 2 & echo %WINE_var%
-set /a WINE_var=WINE_foo=5, WINE_foo ^^= 2 & echo %WINE_var%
-set /a WINE_var=WINE_foo=19, WINE_foo %%= 4 + (WINE_bar %%= 7) & echo.
-set WINE_foo=
-set WINE_bar=
-set WINE_var=
+set /a WINE_foo=WINE_bar=3, WINE_bar+1 & call :checkenvvars WINE_foo 3 WINE_bar 3
+set /a WINE_foo=WINE_bar=3, WINE_bar+=1 & call :checkenvvars WINE_foo 3 WINE_bar 4
+set /a WINE_foo=WINE_bar=3, WINE_baz=1, WINE_baz+=WINE_bar, WINE_baz & call :checkenvvars WINE_foo 3 WINE_bar 3 WINE_baz 4
+set WINE_bar=3
+set /a WINE_foo=WINE_bar*= WINE_bar & call :checkenvvars WINE_foo 9 WINE_bar 9
+set /a WINE_foo=WINE_whateverNonExistingVar & call :checkenvvars WINE_foo 0
+set WINE_bar=4
+set /a WINE_foo=WINE_whateverNonExistingVar + WINE_bar & call :checkenvvars WINE_foo 4 WINE_bar 4
+set WINE_bar=4
+set /a WINE_foo=WINE_bar -= WINE_bar + 7 & call :checkenvvars WINE_foo -7 WINE_bar -7
+set WINE_bar=-7
+set /a WINE_foo=WINE_bar /= 3 + 2 & call :checkenvvars WINE_foo -1 WINE_bar -1
+set /a WINE_foo=WINE_bar=5, WINE_bar %%=2 & call :checkenvvars WINE_foo 5 WINE_bar 1
+set WINE_bar=1
+set /a WINE_foo=WINE_bar ^<^<= 2 & call :checkenvvars WINE_foo 4 WINE_bar 4
+set WINE_bar=4
+set /a WINE_foo=WINE_bar ^>^>= 2 & call :checkenvvars WINE_foo 1 WINE_bar 1
+set WINE_bar=1
+set /a WINE_foo=WINE_bar ^&= 2 & call :checkenvvars WINE_foo 0 WINE_bar 0
+set /a WINE_foo=WINE_bar=5, WINE_bar ^|= 2 & call :checkenvvars WINE_foo 5 WINE_bar 7
+set /a WINE_foo=WINE_bar=5, WINE_bar ^^= 2 & call :checkenvvars WINE_foo 5 WINE_bar 7
+set WINE_baz=4
+set /a WINE_foo=WINE_bar=19, WINE_bar %%= 4 + (WINE_baz %%= 7) & call :checkenvvars WINE_foo 19 WINE_bar 3 WINE_baz 4
+
 echo --- for /F
 mkdir foobar & cd foobar
 echo ------ string argument
diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp
index e7300b4..fd59c31 100644
--- a/programs/cmd/tests/test_builtins.cmd.exp
+++ b/programs/cmd/tests/test_builtins.cmd.exp
@@ -715,76 +715,91 @@ ErrorLevel 0
 -1
 1
 3
---- for /a
+--- set /a
 ------ individual operations
-0
- at todo_wine@3
- at todo_wine@-1
- at todo_wine@3
- at todo_wine@6
- at todo_wine@10
- at todo_wine@4
- at todo_wine@4
- at todo_wine@-4
-0
- at todo_wine@2
- at todo_wine@2
- at todo_wine@-2
- at todo_wine@1
- at todo_wine@4
-0 at or_broken@1073741824
-0 at or_broken@-1073741824
- at todo_wine@-4
- at todo_wine@9
- at todo_wine@2
-0
- at todo_wine@-1
- at todo_wine@-3
-0
- at todo_wine@1
- at todo_wine@1
- at todo_wine@4
- at todo_wine@1
- at todo_wine@5
- at todo_wine@5
- at todo_wine@7
- at todo_wine@5
- at todo_wine@5
- at todo_wine@5
- at todo_wine@4
- at todo_wine@6
- at todo_wine@1
+ at todo_wine@WINE_foo correctly 3
+ at todo_wine@WINE_foo correctly -1
+ at todo_wine@WINE_foo correctly 3
+ at todo_wine@WINE_foo correctly 6
+ at todo_wine@WINE_foo correctly 10
+ at todo_wine@WINE_foo correctly 4
+ at todo_wine@WINE_foo correctly 4
+ at todo_wine@WINE_foo correctly -4
+ at todo_wine@WINE_foo correctly 0
+ at todo_wine@WINE_foo correctly 2
+ at todo_wine@WINE_foo correctly 2
+ at todo_wine@WINE_foo correctly -2
+ at todo_wine@WINE_foo correctly 1
+ at todo_wine@WINE_foo correctly 4
+ at todo_wine@WINE_foo correctly 0 at or_broken@ERROR: WINE_foo incorrectly 1073741824 [0]
+ at todo_wine@WINE_foo correctly 0 at or_broken@ERROR: WINE_foo incorrectly -1073741824 [0]
+ at todo_wine@WINE_foo correctly -4
+ at todo_wine@WINE_foo correctly 9
+ at todo_wine@WINE_foo correctly 2
+ at todo_wine@WINE_foo correctly 0
+ at todo_wine@WINE_foo correctly -1
+ at todo_wine@WINE_foo correctly -3
+ at todo_wine@WINE_foo correctly 0
+ at todo_wine@WINE_foo correctly 1
+ at todo_wine@WINE_foo correctly 1
+ at todo_wine@WINE_foo correctly 4
+ at todo_wine@WINE_foo correctly 1
+ at todo_wine@WINE_foo correctly 5
+ at todo_wine@WINE_foo correctly 5
+ at todo_wine@WINE_foo correctly 7
+ at todo_wine@WINE_foo correctly 5
+ at todo_wine@WINE_foo correctly 5
+ at todo_wine@WINE_foo correctly 5
+ at todo_wine@WINE_foo correctly 4
+ at todo_wine@WINE_foo correctly 6
+ at todo_wine@WINE_foo correctly 1
+ at todo_wine@WINE_foo correctly 4
 ------ precedence and grouping
- at todo_wine@4
- at todo_wine@10
- at todo_wine@18 at or_broken@10
- at todo_wine@2 at or_broken@0
- at todo_wine@2 at or_broken@0
-0 at or_broken@4
- at todo_wine@4
- at todo_wine@3 at or_broken@4
+ at todo_wine@WINE_foo correctly 10
+ at todo_wine@WINE_foo correctly 18 at or_broken@ERROR: WINE_foo incorrectly  [18]
+ at todo_wine@WINE_foo correctly 2 at or_broken@ERROR: WINE_foo incorrectly 0 [2]
+ at todo_wine@WINE_foo correctly 2 at or_broken@ERROR: WINE_foo incorrectly  [2]
+ at todo_wine@WINE_foo correctly 0 at or_broken@ERROR: WINE_foo incorrectly 4 [0]
+ at todo_wine@WINE_foo correctly 4 at or_broken@ERROR: WINE_foo incorrectly  [4]
+ at todo_wine@WINE_foo correctly 3 at or_broken@ERROR: WINE_foo incorrectly  [3]
+ at todo_wine@WINE_foo correctly 3 at or_broken@ERROR: WINE_foo incorrectly  [3]
 ------ octal and hexadecimal
- at todo_wine@3 at or_broken@4
- at todo_wine@18
- at todo_wine@18
- at todo_wine@15
+ at todo_wine@WINE_foo correctly 18
+ at todo_wine@WINE_foo correctly 18
+ at todo_wine@WINE_foo correctly 15
+ at todo_wine@WINE_foo correctly 3
 ------ variables
- at todo_wine@3
- at todo_wine@3 at or_broken@WINE_foo not defined
- at todo_wine@3 at or_broken@0
- at todo_wine@3 at or_broken@0
- at todo_wine@3 at or_broken@0
- at todo_wine@9 at or_broken@0
-0
- at todo_wine@4 at or_broken@0
- at todo_wine@-7 at or_broken@0
- at todo_wine@-1 at or_broken@0
- at todo_wine@5 at or_broken@0
- at todo_wine@4 at or_broken@0
- at todo_wine@1 at or_broken@0
-0
- at todo_wine@5 at or_broken@0
-
+ at todo_wine@WINE_foo correctly 3 at or_broken@ERROR: WINE_foo incorrectly 0 [3]
+ at todo_wine@WINE_bar correctly 3 at or_broken@ERROR: WINE_bar incorrectly  [3]
+ at todo_wine@WINE_foo correctly 3 at or_broken@ERROR: WINE_foo incorrectly 0 [3]
+ at todo_wine@WINE_bar correctly 4 at or_broken@ERROR: WINE_bar incorrectly  [4]
+ at todo_wine@WINE_foo correctly 3 at or_broken@ERROR: WINE_foo incorrectly 0 [3]
+ at todo_wine@WINE_bar correctly 3 at or_broken@ERROR: WINE_bar incorrectly  [3]
+ at todo_wine@WINE_baz correctly 4 at or_broken@ERROR: WINE_baz incorrectly  [4]
+ at todo_wine@WINE_foo correctly 9 at or_broken@ERROR: WINE_foo incorrectly 3 [9]
+ at todo_wine@WINE_bar correctly 9 at or_broken@ERROR: WINE_bar incorrectly 3 [9]
+ at todo_wine@WINE_foo correctly 0
+ at todo_wine@WINE_foo correctly 4
+WINE_bar correctly 4
+ at todo_wine@WINE_foo correctly -7 at or_broken@ERROR: WINE_foo incorrectly 4 [-7]
+ at todo_wine@WINE_bar correctly -7 at or_broken@ERROR: WINE_bar incorrectly 4 [-7]
+ at todo_wine@WINE_foo correctly -1 at or_broken@ERROR: WINE_foo incorrectly -7 [-1]
+ at todo_wine@WINE_bar correctly -1 at or_broken@ERROR: WINE_bar incorrectly -7 [-1]
+ at todo_wine@WINE_foo correctly 5 at or_broken@ERROR: WINE_foo incorrectly 0 [5]
+ at todo_wine@WINE_bar correctly 1 at or_broken@ERROR: WINE_bar incorrectly  [1]
+ at todo_wine@WINE_foo correctly 4 at or_broken@ERROR: WINE_foo incorrectly 1 [4]
+ at todo_wine@WINE_bar correctly 4 at or_broken@ERROR: WINE_bar incorrectly 1 [4]
+ at todo_wine@WINE_foo correctly 1 at or_broken@ERROR: WINE_foo incorrectly 4 [1]
+ at todo_wine@WINE_bar correctly 1 at or_broken@ERROR: WINE_bar incorrectly 4 [1]
+ at todo_wine@WINE_foo correctly 0 at or_broken@ERROR: WINE_foo incorrectly 1 [0]
+ at todo_wine@WINE_bar correctly 0 at or_broken@ERROR: WINE_bar incorrectly 1 [0]
+ at todo_wine@WINE_foo correctly 5 at or_broken@ERROR: WINE_foo incorrectly 0 [5]
+ at todo_wine@WINE_bar correctly 7 at or_broken@ERROR: WINE_bar incorrectly  [7]
+ at todo_wine@WINE_foo correctly 5 at or_broken@ERROR: WINE_foo incorrectly 0 [5]
+ at todo_wine@WINE_bar correctly 7 at or_broken@ERROR: WINE_bar incorrectly  [7]
+ at todo_wine@WINE_foo correctly 19 at or_broken@ERROR: WINE_foo incorrectly 0 [19]
+ at todo_wine@WINE_bar correctly 3 at or_broken@ERROR: WINE_bar incorrectly  [3]
+WINE_baz correctly 4
 --- for /F
 ------ string argument
 a
-- 
1.7.9.5


More information about the wine-patches mailing list