Update ooo320-m1
[ooovba.git] / sc / source / ui / vba / testvba / testResult.pl
blob171be2597ddb1ccf0d7e2bcc9f5642bc5c67a5ef
1 #!/usr/bin/perl -w
2 use File::Temp qw/ tempfile tempdir /;
3 use File::Basename;
4 use File::stat;
5 use File::Copy;
7 my $binDir = dirname($0);
8 my $timestampclean= "perl $binDir/timestampsClean.pl";
9 #sub gen_diff($)
11 sub testLog
13 # 2 No Log to compare against
14 # 1 Log passed
15 # 0 Log failed
16 my $result = 0;
17 my $testfile = shift;
18 my $dirtocheck = shift;
19 my $filename = basename($testfile);
20 $filename = "$logdir/$filename";
21 print "processing $testfile $filename\n";
22 if ( -f $filename ) {
23 my $tmpFile;
24 $dir = tempdir( CLEANUP => 1 );
25 ($fh, $tmpFile) = tempfile( DIR => $dir );
26 close($fh);
28 my $status = system("diff -U 0 -p $testfile $filename | $timestampclean > $tmpFile");
29 my $info = stat($tmpFile) or die "no $tmpFile: $!";
30 if ( ($status >>=8) == 0 && ( $info->size == 0) ) {
31 #print "diff worked size is 0\n";
32 $result = 1;
34 elsif ( ($status >>=8) == 0 && ( $info->size > 0) )
36 #print "diff worked size > 0\n";
37 $result = 0;
39 else
41 #print "diff failed size > 0\n";
42 $result = 0;
45 else
47 #print "not file > 0\n";
48 $result = 2;
50 #print "diff result = $result\n";
51 return $result;
54 if ( ! ( $logdir = shift @ARGV ) ) {
55 print STDERR "No logdir specified!\n";
56 usage();
57 exit 1;
60 if ( ! ( $testlogdir = shift @ARGV ) ) {
61 print STDERR "No testdocuments dir to compare against specified!\n";
62 usage();
63 exit 1;
66 if ( !(-d $logdir ) ) {
67 print STDERR "No output directory $logdir exists, please create it!!!!\n";
68 exit 1;
70 if ( !(-d $testlogdir ) ) {
71 print STDERR "the directory containing the logfiles to compare against \"$logdir\" does not exist\n";
72 usage();
73 exit 1;
75 print "logdir $logdir\n";
76 print "testlogdir $testlogdir\n";
77 sub filter_crud($)
79 my $a = shift;
81 $a =~ /~$/ && return;
82 $a =~ /\#$/ && return;
83 $a =~ /\.orig$/ && return;
84 $a =~ /unxlng.*\.pro$/ && return;
85 $a =~ /wntmsc.*\.pro$/ && return;
86 $a =~ /.swp$/ && return;
87 $a =~ /POSITION/ && return;
88 $a =~ /ReadMe/ && return;
89 $a =~ /.tmp$/ && return;
90 $a =~ /\.svn/ && return;
91 $a eq 'CVS' && return;
92 $a eq '.' && return;
93 $a eq '..' && return;
95 return $a;
97 sub slurp_dir($);
99 sub slurp_dir($)
101 my $dir = shift;
102 my ($dirhandle, $fname);
103 my @files = ();
105 opendir ($dirhandle, $dir) || die "Can't open $dir";
106 while ($fname = readdir ($dirhandle)) {
107 $fname = filter_crud($fname);
108 defined $fname || next;
109 # if (-d "$dir/$fname") {
110 # push @files, slurp_dir("$dir/$fname");
111 # } else
113 push @files, "$dir/$fname";
116 closedir ($dirhandle);
118 return @files;
121 if (-d $testlogdir) {
122 push @files, slurp_dir($testlogdir);
125 my $processed = 0;
126 my $passed = 0;
127 my @passedTests=();
128 my @skippedTests=();
129 my @failedTests=();
131 my $failureCmd="";
132 my $testfile = shift @ARGV;
133 my $testfilepath = "$testlogdir/$testfile";
134 $testfilepath =~ s/\.xls/\.log/;
135 print "$testfilepath\n";
136 for $a (@files) {
137 $filename = $a;
138 if ( "$testfilepath" eq "$filename" )
140 $processed++;
141 my $testcase = $a;
142 $testcase =~ s/\.log/\.xls/;
143 my $result = testLog( $a, $logdir );
144 if ( $result == 0 ) {
145 push @failedTests, basename($testcase);
146 if ( $failureCmd eq "" ) { $failureCmd = " diff -up $a $logdir "; }
148 elsif ( $result == 2 ) {
149 #print "skipped $a\n";
150 push @skippedTests, $testcase;
152 else {
153 $passed++;
154 push @passedTests, $testcase;
155 #print "Test document for $a \t \t passed. \n";
159 my $compared=@passedTests+@failedTests;
160 my $skip = @skippedTests;
161 print "skipped $skip test-cases(s)\n";
162 print "compared $compared test-case documents\n";
163 print "\t \t $passed tests $@passedTests\n";
164 if ( @failedTests > 0 ) {
165 print "the following test-case documents failed, please examine the logs manually\n";
167 for $a (@failedTests) {
168 print "\t$a\n";
170 print "e.g. $failureCmd\n"