I noticed that the oleaut32/safearray test uses statements such as:
ok(a->cDims == i,"a->cDims not initialised?\n");
But it is not necessary to add a '\n' to ok statements. All it does is insert an extra '\n' after each test error.
I could send a patch to fix this (small) issue, but I think this behavior of 'ok' is wrong. It 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'. 'ok' is the exception there and safearray is not the first test (nor the last) to get caught by this.
So if noone objects I'll send a patch that stops 'ok' from appending this '\n', and adds a '\n' to all calls to ok. Actually, I would be pretty happy if someone could come up with a perl script doing the latter...
Comments?
"Francois Gouget" fgouget@free.fr wrote:
So if noone objects I'll send a patch that stops 'ok' from appending this '\n', and adds a '\n' to all calls to ok. Actually, I would be pretty happy if someone could come up with a perl script doing the latter...
Comments?
Your explanations look very reasonable to me. Of course if somebody will come up with a script to automate the task it would be better.
Francois Gouget wrote:
So if noone objects I'll send a patch that stops 'ok' from appending this '\n', and adds a '\n' to all calls to ok. Actually, I would be pretty happy if someone could come up with a perl script doing the latter...
I came up with a perl script that does what you want. It may not be perfect though so use it with caution.
Enjoy, Glen Kaukola
#!/usr/bin/perl sub fix_oks { my $c_file = $_[0];
open(FILE_HANDLE, "<$c_file") or die("Error opening file $c_file\n"); my @contents = <FILE_HANDLE>; close(FILE_HANDLE);
#add a new line to the end of any ok calls we find s/(.*)(\bok(.*)([^"])(^"*)(")(.*)/$1$2$3$4\n$5$6/g for @contents;
open(FILE_HANDLE, ">$c_file"); print(FILE_HANDLE @contents); close(FILE_HANDLE); }
sub do_current_dir { my $i = 0;
#get the current directory's listing opendir(DIR_HANDLE, ".") or die("Error opening $directory\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_oks($dir_listing[$i]); }
$i++; } }
do_current_dir();
On Mon, 30 Dec 2002, Glen wrote:
Francois Gouget wrote:
So if noone objects I'll send a patch that stops 'ok' from appending this '\n', and adds a '\n' to all calls to ok. Actually, I would be pretty happy if someone could come up with a perl script doing the latter...
I came up with a perl script that does what you want. It may not be perfect though so use it with caution.
Thanks for the script. It has some problems though: * it modifies all files. This makes later cvs diff veeeery slow as it has to check each and every file for differences * it did not seem to match the 'ok' calls I have here
So I modified it and came up with the following which seems to be working ok.
#!/usr/bin/perl sub fix_oks { my $c_file = $_[0];
open(FILE_HANDLE, "<$c_file") or die("Error opening file $c_file\n"); my @contents = <FILE_HANDLE>; close(FILE_HANDLE);
#add a new line to the end of any ok calls we find my $modified; my $line2; foreach (@contents) { if (/\bok\s*((.*));\s*$/) { my @components=split /,/,$1; foreach my $item (@components) { if ($item !~ /^\s*".*\n"\s*$/) { $item=~s/^(\s*".*)("\s*)$/$1\n$2/; } } my $args=join(",",@components); my $line=$_; $line=~s/(\bok\s*()(.*)();\s*)$/$1$args$3/; if ($line ne $_) { $_=$line; $modified=1; } } elsif (/\bok\s*(.*,\s*$/) { $line2=1; } else { if ($line2) { if (!/".*\n"/) { my $line=$_; s/("([^"]|\")*)(")/$1\n$3/; $modified=1 if ($line ne $_); } } $line2=undef; } }
if ($modified) { open(FILE_HANDLE, ">$c_file"); print(FILE_HANDLE @contents); close(FILE_HANDLE); } }
sub do_current_dir { my $i = 0;
#get the current directory's listing opendir(DIR_HANDLE, ".") or die("Error opening $directory\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_oks($dir_listing[$i]); }
$i++; } }
do_current_dir();