1#!/usr/bin/perl -w 2use File::Temp qw/ tempfile tempdir /; 3use File::Basename; 4use File::stat; 5use File::Copy; 6 7my $binDir = dirname($0); 8my $timestampclean= "perl $binDir/timestampsClean.pl"; 9#sub gen_diff($) 10 11sub testLog 12{ 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); 27 # 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; 33 } 34 elsif ( ($status >>=8) == 0 && ( $info->size > 0) ) 35 { 36 #print "diff worked size > 0\n"; 37 $result = 0; 38 } 39 else 40 { 41 #print "diff failed size > 0\n"; 42 $result = 0; 43 } 44 } 45 else 46 { 47 #print "not file > 0\n"; 48 $result = 2; 49 } 50 #print "diff result = $result\n"; 51 return $result; 52} 53 54if ( ! ( $logdir = shift @ARGV ) ) { 55 print STDERR "No logdir specified!\n"; 56 usage(); 57 exit 1; 58} 59 60if ( ! ( $testlogdir = shift @ARGV ) ) { 61 print STDERR "No testdocuments dir to compare against specified!\n"; 62 usage(); 63 exit 1; 64} 65 66if ( !(-d $logdir ) ) { 67 print STDERR "No output directory $logdir exists, please create it!!!!\n"; 68 exit 1; 69} 70if ( !(-d $testlogdir ) ) { 71 print STDERR "the directory containing the logfiles to compare against \"$logdir\" does not exist\n"; 72 usage(); 73 exit 1; 74} 75print "logdir $logdir\n"; 76print "testlogdir $testlogdir\n"; 77sub filter_crud($) 78{ 79 my $a = shift; 80 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; 94 95 return $a; 96} 97sub slurp_dir($); 98 99sub slurp_dir($) 100{ 101 my $dir = shift; 102 my ($dirhandle, $fname); 103 my @files = (); 104 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 112 { 113 push @files, "$dir/$fname"; 114 } 115 } 116 closedir ($dirhandle); 117 118 return @files; 119} 120 121if (-d $testlogdir) { 122 push @files, slurp_dir($testlogdir); 123} 124 125my $processed = 0; 126my $passed = 0; 127my @passedTests=(); 128my @skippedTests=(); 129my @failedTests=(); 130 131my $failureCmd=""; 132my $testfile = shift @ARGV; 133my $testfilepath = "$testlogdir/$testfile"; 134$testfilepath =~ s/\.xls/\.log/; 135print "$testfilepath\n"; 136for $a (@files) { 137 $filename = $a; 138 if ( "$testfilepath" eq "$filename" ) 139 { 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 "; } 147 } 148 elsif ( $result == 2 ) { 149 #print "skipped $a\n"; 150 push @skippedTests, $testcase; 151 } 152 else { 153 $passed++; 154 push @passedTests, $testcase; 155 #print "Test document for $a \t \t passed. \n"; 156 } 157 } 158} 159my $compared=@passedTests+@failedTests; 160my $skip = @skippedTests; 161print "skipped $skip test-cases(s)\n"; 162print "compared $compared test-case documents\n"; 163print "\t \t $passed tests $@passedTests\n"; 164if ( @failedTests > 0 ) { 165 print "the following test-case documents failed, please examine the logs manually\n"; 166 167 for $a (@failedTests) { 168 print "\t$a\n"; 169 } 170 print "e.g. $failureCmd\n" 171} 172