xref: /trunk/main/sc/source/ui/vba/testvba/testResults.pl (revision bb113e63)
1#!/usr/bin/perl -w
2# *************************************************************
3#
4#  Licensed to the Apache Software Foundation (ASF) under one
5#  or more contributor license agreements.  See the NOTICE file
6#  distributed with this work for additional information
7#  regarding copyright ownership.  The ASF licenses this file
8#  to you under the Apache License, Version 2.0 (the
9#  "License"); you may not use this file except in compliance
10#  with the License.  You may obtain a copy of the License at
11#
12#    http://www.apache.org/licenses/LICENSE-2.0
13#
14#  Unless required by applicable law or agreed to in writing,
15#  software distributed under the License is distributed on an
16#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17#  KIND, either express or implied.  See the License for the
18#  specific language governing permissions and limitations
19#  under the License.
20#
21# *************************************************************
22use File::Temp qw/ tempfile tempdir /;
23use File::Basename;
24use File::stat;
25use File::Copy;
26
27my $binDir = dirname($0);
28my $timestampclean= "perl $binDir/timestampsClean.pl";
29#sub gen_diff($)
30
31sub testLog
32{
33   # 2 No Log to compare against
34   # 1 Log passed
35   # 0 Log failed
36   my $result = 0;
37   my $testfile = shift;
38   my $dirtocheck = shift;
39   my $filename = basename($testfile);
40   $filename = "$logdir/$filename";
41   print "processing $testfile $filename\n";
42   if ( -f $filename )  {
43      my $tmpFile;
44      $dir = tempdir( CLEANUP => 1 );
45      ($fh, $tmpFile) = tempfile( DIR => $dir );
46      close($fh);
47      #
48      my $status = system("diff -U 0 -p $testfile $filename |  $timestampclean > $tmpFile");
49      my $info = stat($tmpFile) or die "no $tmpFile: $!";
50      if ( ($status >>=8) == 0 &&  ( $info->size == 0)  ) {
51         #print "diff worked size is 0\n";
52         $result = 1;
53      }
54      elsif ( ($status >>=8) == 0 &&  ( $info->size > 0)  )
55      {
56         #print "diff worked size > 0\n";
57         $result = 0;
58      }
59      else
60      {
61         #print "diff failed size > 0\n";
62         $result = 0;
63      }
64   }
65   else
66   {
67      #print "not file > 0\n";
68      $result = 2;
69   }
70   #print "diff result = $result\n";
71   return $result;
72}
73
74if ( ! ( $logdir = shift @ARGV ) ) {
75    print STDERR "No logdir specified!\n";
76    usage();
77    exit 1;
78}
79
80if ( ! ( $testlogdir = shift @ARGV ) ) {
81    print STDERR "No testdocuments dir to compare against specified!\n";
82    usage();
83    exit 1;
84}
85
86if ( !(-d $logdir ) ) {
87   print STDERR "No output directory $logdir exists, please create it!!!!\n";
88   exit 1;
89}
90if ( !(-d $testlogdir ) ) {
91   print STDERR "the directory containing the logfiles to compare against \"$logdir\" does not exist\n";
92    usage();
93    exit 1;
94}
95print "logdir $logdir\n";
96print "testlogdir $testlogdir\n";
97sub filter_crud($)
98{
99    my $a = shift;
100
101    $a =~ /~$/ && return;
102    $a =~ /\#$/ && return;
103    $a =~ /\.orig$/ && return;
104    $a =~ /unxlng.*\.pro$/ && return;
105    $a =~ /wntmsc.*\.pro$/ && return;
106    $a =~ /.swp$/ && return;
107    $a =~ /POSITION/ && return;
108    $a =~ /ReadMe/ && return;
109    $a =~ /.tmp$/ && return;
110    $a =~ /\.svn/ && return;
111    $a eq 'CVS' && return;
112    $a eq '.' && return;
113    $a eq '..' && return;
114
115    return $a;
116}
117sub slurp_dir($);
118
119sub slurp_dir($)
120{
121    my $dir = shift;
122    my ($dirhandle, $fname);
123    my @files = ();
124
125    opendir ($dirhandle, $dir) || die "Can't open $dir";
126    while ($fname = readdir ($dirhandle)) {
127	$fname = filter_crud($fname);
128	defined $fname || next;
129#	if (-d "$dir/$fname") {
130#	    push @files, slurp_dir("$dir/$fname");
131#	} else
132        {
133	    push @files, "$dir/$fname";
134	}
135    }
136    closedir ($dirhandle);
137
138    return @files;
139}
140
141if (-d $testlogdir) {
142    push @files, slurp_dir($testlogdir);
143}
144
145my $processed = 0;
146my $passed = 0;
147my @passedTests=();
148my @skippedTests=();
149my @failedTests=();
150
151my $failureCmd="";
152for $a (@files) {
153   $processed++;
154   my $testcase = $a;
155   $testcase =~ s/\.log/\.xls/;
156   my $result = testLog( $a, $logdir );
157   if ( $result == 0 ) {
158      push @failedTests, basename($testcase);
159      if ( $failureCmd eq "" ) { $failureCmd = " diff -up $a $logdir "; }
160   }
161   elsif ( $result == 2 ) {
162      #print "skipped $a\n";
163      push @skippedTests, $testcase;
164   }
165   else {
166      $passed++;
167      push @passedTests, $testcase;
168      #print "Test document for $a \t \t passed. \n";
169   }
170}
171my $compared=@passedTests+@failedTests;
172my $skip = @skippedTests;
173print "skipped $skip test-cases(s)\n";
174print "compared $compared test-case documents\n";
175print "\t \t $passed tests $@passedTests\n";
176if ( @failedTests > 0 ) {
177   print "the following test-case documents failed, please examine the logs manually\n";
178
179   for $a (@failedTests) {
180      print "\t$a\n";
181   }
182   print "e.g. $failureCmd\n"
183}
184