[1/5] cmd/tests: Treat lines that start with '---' as resynchronization points.

Francois Gouget fgouget at free.fr
Mon Nov 28 05:13:10 CST 2011


This lets us better deal with missing and extra lines in the test output.
Also, all standard test section headers act as resynchronization points so this also limits the flurry or error messages one gets in case of missing or extra lines.
---

Case in point. In the 'IF' tests we were missing one line and had one 
extra. So we matched it this way:

Output                  | Actual                  | Match
foo2                    | foo2                    | @todo_wine at foo1
foo3                    | foo3                    | @todo_wine at foo2
Failed to open 'bar'    | Failed to open 'bar'    | @todo_wine at foo3
file does not exist, ok | file does not exist, ok | file does not exist, ok

This totally fails to capture the fact that foo2 and foo3 are output 
just as expected. Also fixing cmd so that the 'Failed to open' error 
goes to stderr as expected results in the output missing one line which 
not only breaks this one test and all those that follows, but was also 
impossible to handle with the existing code.

As is this patch limits the damage caused by extra or missing line to 
the section they are in since section headers start with '---'. But more 
importantly it makes it possible to correctly handle such situations 
(but leaves that to patch [4/5]).


 programs/cmd/tests/batch.c               |   32 +++++++++++++++++++++++------
 programs/cmd/tests/test_builtins.cmd     |    2 +-
 programs/cmd/tests/test_builtins.cmd.exp |    2 +-
 3 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/programs/cmd/tests/batch.c b/programs/cmd/tests/batch.c
index bfc5959..93c5f57 100644
--- a/programs/cmd/tests/batch.c
+++ b/programs/cmd/tests/batch.c
@@ -276,7 +276,8 @@ static void test_output(const char *out_data, DWORD out_size, const char *exp_da
     const char *out_ptr = out_data, *exp_ptr = exp_data, *out_nl, *exp_nl, *err;
     DWORD line = 0;
     static const char todo_wine_cmd[] = {'@','t','o','d','o','_','w','i','n','e','@'};
-    BOOL is_todo_wine;
+    static const char resync_cmd[] = {'-','-','-'};
+    BOOL is_todo_wine, is_out_resync, is_exp_resync;
 
     while(out_ptr < out_data+out_size && exp_ptr < exp_data+exp_size) {
         line++;
@@ -290,6 +291,10 @@ static void test_output(const char *out_data, DWORD out_size, const char *exp_da
             exp_ptr += sizeof(todo_wine_cmd);
             winetest_start_todo("wine");
         }
+        is_exp_resync=(exp_ptr+sizeof(resync_cmd) <= exp_nl &&
+                       !memcmp(exp_ptr, resync_cmd, sizeof(resync_cmd)));
+        is_out_resync=(out_ptr+sizeof(resync_cmd) <= out_nl &&
+                       !memcmp(out_ptr, resync_cmd, sizeof(resync_cmd)));
 
         trace("comparing '%.*s'\n", (int)(out_nl-out_ptr), out_ptr);
         trace("with      '%.*s'%s\n", (int)(exp_nl-exp_ptr), exp_ptr, is_todo_wine ? " todo" : "");
@@ -301,18 +306,31 @@ static void test_output(const char *out_data, DWORD out_size, const char *exp_da
         else if(err == exp_nl)
             ok(0, "excess characters on line %d (got '%.*s', wanted '%.*s')\n",
                line, (int)(out_nl-out_ptr), out_ptr, (int)(exp_nl-exp_ptr), exp_ptr);
+        else if (!err && is_todo_wine && is_out_resync && is_exp_resync)
+            /* Consider that the todo_wine was to deal with extra lines,
+             * not for the resync line itself
+             */
+            err = NULL;
         else
             ok(!err, "unexpected char 0x%x position %d in line %d (got '%.*s', wanted '%.*s')\n",
                (err ? *err : 0), (err ? (int)(err-out_ptr) : -1), line, (int)(out_nl-out_ptr), out_ptr, (int)(exp_nl-exp_ptr), exp_ptr);
 
         if(is_todo_wine) winetest_end_todo("wine");
 
-        exp_ptr = exp_nl+1;
-        out_ptr = out_nl+1;
-        if(out_nl+1 < out_data+out_size && out_nl[0] == '\r' && out_nl[1] == '\n')
-            out_ptr++;
-        if(exp_nl+1 < exp_data+exp_size && exp_nl[0] == '\r' && exp_nl[1] == '\n')
-            exp_ptr++;
+        if (is_exp_resync && err && is_todo_wine)
+            exp_ptr -= sizeof(todo_wine_cmd);
+        else if (!is_exp_resync || (is_exp_resync && !err))
+        {
+            exp_ptr = exp_nl+1;
+            if(exp_nl+1 < exp_data+exp_size && exp_nl[0] == '\r' && exp_nl[1] == '\n')
+                exp_ptr++;
+        }
+        if (!is_out_resync || (is_out_resync && !err))
+        {
+            out_ptr = out_nl+1;
+            if(out_nl+1 < out_data+out_size && out_nl[0] == '\r' && out_nl[1] == '\n')
+                out_ptr++;
+        }
     }
 
     ok(exp_ptr >= exp_data+exp_size, "unexpected end of output in line %d, missing %s\n", line, exp_ptr);
diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd
index bcaccb2..1734650 100644
--- a/programs/cmd/tests/test_builtins.cmd
+++ b/programs/cmd/tests/test_builtins.cmd
@@ -164,7 +164,7 @@ type C
 (if 1==0 (echo A > B) else echo C)
 cd .. & rd /s/q foobar
 
-echo ------------ Testing ^^ escape character --------------
+echo ------------ Testing circumflex escape character --------------
 rem Using something like "echo foo^" asks for an additional char after a "More?" prompt on the following line; it's not possible to currently test that non-interactively
 echo ^hell^o, world
 echo hell^o, world
diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp
index e35b710..68355c4 100644
--- a/programs/cmd/tests/test_builtins.cmd.exp
+++ b/programs/cmd/tests/test_builtins.cmd.exp
@@ -178,7 +178,7 @@ foo
 A
 B
 C
- at todo_wine@------------ Testing ^ escape character --------------
+------------ Testing circumflex escape character --------------
 @todo_wine at hello, world
 @todo_wine at hello, world
 @todo_wine at hell^o, world
-- 
1.7.7.1




More information about the wine-patches mailing list