Change wintest_ok() to not systematically print a '\n'

Francois Gouget fgouget at free.fr
Wed Sep 10 07:24:36 CDT 2003


This is a variation on a patch I sent a long time ago...

The problem is that ok() systematically prints a '\n' which goes against
the convention established by all other functions such as printf, TRACE,
ERR and even the test framework's own trace function. None of these
appends a '\n'.

Because of this, some tests call ok() with a '\n' at the end of the
message which results in two '\n's being printed. But Alexandre did not
want to fix all the tests at once as it would make a big patch (well,
it's just 11567 lines<g.) for a relatively minor issue.

So this patch modifies the 'winetest_ok()' to only append a '\n' if the
format message does not end with one already. This way new tests can be
written with a '\n', and we can fix the old ones progressively (on a
schedule yet to be determined).

I also attached a script that will fix all tests in the Wine tree so
that people can play with this if they want.

Finally, this patch also fixes a couple of tests that define macros
around 'ok' and thus cannot be handled by the script.


Changelog:

 * include/wine/test.h,
   dlls/kernel/tests/locale.c,
   dlls/oleaut32/tests/vartest.c,
   dlls/user/tests/sysparams.c

   Modify winetest_ok to only add a trailing '\n' if there is none.
   Modify macros in the kernel, oleaut32 and user tests to print a '\n'.


Index: include/wine/test.h
===================================================================
RCS file: /home/wine/wine/include/wine/test.h,v
retrieving revision 1.11
diff -u -r1.11 test.h
--- include/wine/test.h	28 Aug 2003 21:43:34 -0000	1.11
+++ include/wine/test.h	10 Sep 2003 10:47:56 -0000
@@ -156,6 +156,7 @@
 int winetest_ok( int condition, const char *msg, ... )
 {
     va_list valist;
+    int len;
     tls_data* data=get_tls_data();

     if (data->todo_level)
@@ -171,7 +172,9 @@
                 vfprintf(stdout, msg, valist);
                 va_end(valist);
             }
-            fputc( '\n', stdout );
+            len=strlen(msg);
+            if (len==0 || msg[len-1]!='\n')
+                fputc( '\n', stdout );
             InterlockedIncrement(&todo_failures);
             return 0;
         }
@@ -190,7 +193,9 @@
                 vfprintf(stdout, msg, valist);
                 va_end(valist);
             }
-            fputc( '\n', stdout );
+            len=strlen(msg);
+            if (len==0 || msg[len-1]!='\n')
+                fputc( '\n', stdout );
             InterlockedIncrement(&failures);
             return 0;
         }
Index: dlls/kernel/tests/locale.c
===================================================================
RCS file: /home/wine/wine/dlls/kernel/tests/locale.c,v
retrieving revision 1.16
diff -u -r1.16 locale.c
--- dlls/kernel/tests/locale.c	5 Sep 2003 23:08:36 -0000	1.16
+++ dlls/kernel/tests/locale.c	10 Sep 2003 11:28:17 -0000
@@ -29,7 +29,7 @@
 #include "winnls.h"

 #define eq(received, expected, label, type) \
-        ok((received) == (expected), "%s: got " type " instead of " type, (label),(received),(expected))
+        ok((received) == (expected), "%s: got " type " instead of " type "\n", (label),(received),(expected))

 #define BUFFER_SIZE		128
 /* Buffer used by callback function */
Index: dlls/oleaut32/tests/vartest.c
===================================================================
RCS file: /home/wine/wine/dlls/oleaut32/tests/vartest.c,v
retrieving revision 1.10
diff -u -r1.10 vartest.c
--- dlls/oleaut32/tests/vartest.c	5 Sep 2003 23:08:33 -0000	1.10
+++ dlls/oleaut32/tests/vartest.c	10 Sep 2003 11:28:23 -0000
@@ -1761,8 +1761,8 @@
 	 */
 	trace( "======== Testing VarUI1FromXXX ========\n");

-#define XOK "should return S_OK"
-#define XOV "should return DISP_E_OVERFLOW"
+#define XOK "should return S_OK\n"
+#define XOV "should return DISP_E_OVERFLOW\n"
 	/* Crashes on Win95: VarUI1FromI2( 0, NULL ) */

 	ok(VarUI1FromStr(NULL, lcid, 0, pByte) == DISP_E_TYPEMISMATCH,"should return DISP_E_TYPEMISMATCH");
Index: dlls/user/tests/sysparams.c
===================================================================
RCS file: /home/wine/wine/dlls/user/tests/sysparams.c,v
retrieving revision 1.16
diff -u -r1.16 sysparams.c
--- dlls/user/tests/sysparams.c	5 Sep 2003 23:08:29 -0000	1.16
+++ dlls/user/tests/sysparams.c	10 Sep 2003 11:28:28 -0000
@@ -42,7 +42,7 @@
 static int strict;

 #define eq(received, expected, label, type) \
-        ok((received) == (expected), "%s: got " type " instead of " type, (label),(received),(expected))
+        ok((received) == (expected), "%s: got " type " instead of " type "\n", (label),(received),(expected))


 #define SPI_SETBEEP_REGKEY           "Control Panel\\Sound"


-- 
Francois Gouget         fgouget at free.fr        http://fgouget.free.fr/
                            $live{free} || die "";
-------------- next part --------------
#!/usr/bin/perl -w
use strict;

my $verbose;

my @file;
my $l;
my @chars;
my $len;
my $c;

sub skip_bracket();
sub skip_parent();
sub skip_string();

sub setup_line($)
{
    return 0 if ($l >= @file);

    $c=$_[0];
    $len=length($file[$l]);
    @chars=split //,$file[$l];
    print "$l,$c: $file[$l]" if ($verbose);
    return 1;
}

sub skip_bracket()
{
    while (1) {
        while ($c<$len) {
            print "skip_bracket: $c -> '$chars[$c]'\n" if ($verbose);
            if ($chars[$c] eq "]") {
                print "skip_bracket returns 1\n" if ($verbose);
                return 1;
            } elsif ($chars[$c] eq "\"") {
                $c++;
                skip_string();
            } elsif ($chars[$c] eq "(") {
                $c++;
                skip_parent();
            } elsif ($chars[$c] eq "[") {
                $c++;
                skip_bracket();
            }
            $c++;
        }
        $l++;
        return 0 if (!setup_line(0));
    }
    return 0;
}

sub skip_parent()
{
    while (1) {
        while ($c<$len) {
            print "skip_parent: $c -> '$chars[$c]'\n" if ($verbose);
            if ($chars[$c] eq ")") {
                print "skip_parent returns 1\n" if ($verbose);
                return 1;
            } elsif ($chars[$c] eq "\"") {
                $c++;
                skip_string();
            } elsif ($chars[$c] eq "(") {
                $c++;
                skip_parent();
            } elsif ($chars[$c] eq "[") {
                $c++;
                skip_bracket();
            }
            $c++;
        }
        $l++;
        return 0 if (!setup_line(0));
    }
    return 0;
}

sub skip_string()
{
    my $backslash;
    while (1) {
        while ($c<$len) {
            print "skip_string: $c -> '$chars[$c]'\n" if ($verbose);
            if ($chars[$c] eq "\"") {
                if (!$backslash) {
                    print "skip_string returns 1\n" if ($verbose);
                    return 1;
                }
                $backslash=undef;
            } elsif ($chars[$c] eq "\\") {
                $backslash=($backslash?undef:1);
            } else {
                $backslash=undef;
            }
            $c++;
        }
        $l++;
        return 0 if (!setup_line(0));
    }
    return 0;
}

sub skip_arg1()
{
    while (1) {
        while ($c<$len) {
            print "skip_arg1: $c -> '$chars[$c]'\n" if ($verbose);
            if ($chars[$c] eq ",") {
                print "skip_arg1 returns 1\n" if ($verbose);
                return 1;
            } elsif ($chars[$c] eq "\"") {
                $c++;
                skip_string();
            } elsif ($chars[$c] eq "(") {
                $c++;
                skip_parent();
            } elsif ($chars[$c] eq "[") {
                $c++;
                skip_bracket();
            }
            $c++;
        }
        $l++;
        return 0 if (!setup_line(0));
    }
    return 0;
}

sub get_quote()
{
    while (1) {
        while ($c<$len) {
            print "get_quote: $c -> '$chars[$c]'\n" if ($verbose);
            if ($chars[$c] eq "\"") {
                print "get_quote returns 1\n" if ($verbose);
                return 1;
            } elsif ($chars[$c] !~ /(\s|\n)/) {
                return 0;
            }
            $c++;
        }
        $l++;
        return 0 if (!setup_line(0));
    }
    return 0;
}

sub fix_ok($)
{
    # Setup
    setup_line($_[0]);

    # Locate the format string
    return undef if (!skip_arg1());
    $c++;
    return undef if (!get_quote());
    $c++;
    return undef if (!skip_string());

    # Check and modify
    if ($c>=2 and ($chars[$c-2] ne "\\" or $chars[$c-1] ne "n")) {
        return substr($file[$l],0,$c) . "\\n" . substr($file[$l],$c);
    }
    return undef;
}

sub fix_file
{
    my $c_file = $_[0];

    open(FILE_HANDLE, "<$c_file") or die("Error opening file $c_file\n");
    @file = <FILE_HANDLE>;
    close(FILE_HANDLE);

    #add a new line to the end of any ok calls we find
    my $modified;
    $l=0;
    while ($l<@file) {
        if ($file[$l] =~ /^(.*\bok\s*\()/) {
            my $res=fix_ok(length($1));
            if (defined $res and $res ne $file[$l]) {
                print "\n$file[$l]$res" if ($verbose);
                $file[$l]=$res;
                $modified=1;
            }
        }
        $l++;
    }

    if ($modified) {
        open(FILE_HANDLE, ">$c_file");
        print FILE_HANDLE @file;
        close(FILE_HANDLE);
    }
}

sub do_current_dir
{
    my $i = 0;

    #get the current directory's listing
    opendir(DIR_HANDLE, ".") or die("Error opening .\n");
    my @dir_listing = grep { !/^\.\.?/ } readdir(DIR_HANDLE);
    closedir(DIR_HANDLE);

    #for each file in the directory
    while($dir_listing[$i])
    {
        #if a directory is found then do that one too
        if(-d $dir_listing[$i])
        {
            chdir $dir_listing[$i];
            do_current_dir();
            chdir "..";
        }

        #if it's a c file then fix the calls to ok
        if ($dir_listing[$i] =~ /\.c$/)
        {
            fix_file($dir_listing[$i]);
        }

        $i++;
    }
}

do_current_dir();


More information about the wine-patches mailing list