diff options
author | Vladimir Glazounov <vg@openoffice.org> | 2007-12-07 10:16:00 +0000 |
---|---|---|
committer | Vladimir Glazounov <vg@openoffice.org> | 2007-12-07 10:16:00 +0000 |
commit | 1c32a353cf34e90c9580dcc6bbfcf33f497518ed (patch) | |
tree | 103017a38b8fa60d922a43950a5b9d76f457092f /sc/source/ui/vba/testvba | |
parent | a841c6553cfad9c021acf943a347ea35bafd7292 (diff) |
INTEGRATION: CWS npower8 (1.1.2); FILE ADDED
2007/10/30 17:43:50 npower 1.1.2.1: some regression/unit testing bits
Diffstat (limited to 'sc/source/ui/vba/testvba')
-rw-r--r-- | sc/source/ui/vba/testvba/README | 35 | ||||
-rw-r--r-- | sc/source/ui/vba/testvba/TestVBA.java | 198 | ||||
-rw-r--r-- | sc/source/ui/vba/testvba/build.xml | 101 | ||||
-rw-r--r-- | sc/source/ui/vba/testvba/launchTest.pl | 53 | ||||
-rw-r--r-- | sc/source/ui/vba/testvba/makefile.mk | 61 | ||||
-rwxr-xr-x | sc/source/ui/vba/testvba/testResults.pl | 159 | ||||
-rwxr-xr-x | sc/source/ui/vba/testvba/timestampsClean.pl | 73 |
7 files changed, 680 insertions, 0 deletions
diff --git a/sc/source/ui/vba/testvba/README b/sc/source/ui/vba/testvba/README new file mode 100644 index 000000000000..6668f049d8dc --- /dev/null +++ b/sc/source/ui/vba/testvba/README @@ -0,0 +1,35 @@ +running dmake in this directory runs a set of regression (unit) tests. + +Note: + o you need to set OFFICEPATH env variable to the install directory of your office installation e.g. + +export OFFICEPATH="/cygdrive/f/Program\ Files/OpenOffice.org\ 2.3" + + o naturally in order to run the tests you need to source the build env scripts in the top level build directory [1] + + o the testclient runs looks for testdocuments in the '../TestDocuments' [3] directory. For each document the test client runs the macro 'Standard.TestMacros.Main' located in that test document. The macro(s) write a log file, the log files end up in the Logs sub-directory ( in this directory ). A logfile exists for each testdocument that has successfully run. The log files are compared against benchmark logfiles to ensure no regressions have occured ( see [4] for directory structure and location of benchmark files ). At this point we are not concerned with known failures [5] + + +[1] Ideally this should not be necessary and you should be able to run the tests without a build env - future + +[2] The test client should be re-written in C++ to get a better handle on lifecycle issues. E.g. currently on windows and sometimes on linux the client won't exit, also the office process doesn't alway exit + +[3] + +The TestDocument directory contains + o test documents ( *.xls ) + o logs directory ( contains the benchmark logs to compare against ) + +[4] + +The logs directory contains the following sub-directories + o excel ( the orig logs produced by an excel file ) + o unix ( the log produced by OpenOffice running imported Excel document under unix ) + o win ( the log produced by OpenOffice running imported Excel document under windows ) + +[*] the seperate win & unix directories are to facilate tests that will produce different results under the different platforms e.g. paths etc. + +[5] + +o Currently the logs in the excel directory are only stored for comparison, they are not used by the tooling +o Currently we don't measure how many tests pass or fail, the immediate focus is that we don't get any regressions ( but of course we do look at these manually and try and get all tests to pass ) diff --git a/sc/source/ui/vba/testvba/TestVBA.java b/sc/source/ui/vba/testvba/TestVBA.java new file mode 100644 index 000000000000..1e6bb2fa769a --- /dev/null +++ b/sc/source/ui/vba/testvba/TestVBA.java @@ -0,0 +1,198 @@ +//package org.openoffice.vba; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.script.provider.*; +import com.sun.star.beans.XPropertySet; +import com.sun.star.uno.AnyConverter; +import java.io.File; +import java.io.InputStream; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.OutputStream; +public class TestVBA +{ +private com.sun.star.lang.XMultiComponentFactory xMCF = null; +private com.sun.star.uno.XComponentContext xContext = null; +private com.sun.star.frame.XComponentLoader xCompLoader = null; +private File outDir; + +public TestVBA( com.sun.star.uno.XComponentContext _xContext, com.sun.star.lang.XMultiComponentFactory _xMCF, com.sun.star.frame.XComponentLoader _xCompLoader, File _outDir +) +{ + xMCF = _xMCF; + xContext = _xContext; + xCompLoader = _xCompLoader; + outDir = _outDir; +} + +public String getLogLocation() throws com.sun.star.beans.UnknownPropertyException, com.sun.star.lang.IllegalArgumentException, com.sun.star.lang.WrappedTargetException, com.sun.star.uno.Exception +{ + XPropertySet pathSettings = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xMCF.createInstanceWithContext( "com.sun.star.comp.framework.PathSettings", xContext) ); + String sLogLocation = AnyConverter.toString ( pathSettings.getPropertyValue( "Work" ) ); + sLogLocation = sLogLocation + "/" + "HelperAPI-test.log"; + return sLogLocation; +} + +public void init() +{ + // blow away previous logs? +} + +public void traverse( File fileDirectory ) +{ + if ( !fileDirectory.isDirectory() ) + { + throw new IllegalArgumentException( + "not a directory: " + fileDirectory.getName() + ); + } + + // Getting all files and directories in the current directory + File[] entries = fileDirectory.listFiles(); + + + // Iterating for each file and directory + for ( int i = 0; i < entries.length; ++i ) + { + // Testing, if the entry in the list is a directory +/* + if ( entries[ i ].isDirectory() ) + { + // ignore Recursive call for the new directory + // traverse( entries[ i ] ); + } + else +*/ + if ( !entries[ i ].isDirectory() && + entries[ i ].getName().endsWith(".xls") ) + { + try + { + // Composing the URL by replacing all backslashs + String sUrl = "file:///" + + entries[ i ].getAbsolutePath().replace( '\\', '/' ); + System.out.println( "processing " + sUrl ); + // Loading the wanted document + com.sun.star.beans.PropertyValue propertyValues[] = + new com.sun.star.beans.PropertyValue[1]; + propertyValues[0] = new com.sun.star.beans.PropertyValue(); + propertyValues[0].Name = "Hidden"; + propertyValues[0].Value = new Boolean(true); + propertyValues[0].Value = new Boolean(false); + + Object oDoc = + xCompLoader.loadComponentFromURL( + sUrl, "_blank", 0, propertyValues); + String logFileURL = getLogLocation(); + java.net.URI logURI = new java.net.URI( logFileURL ); + java.net.URL logURL = logURI.toURL(); + try + { + XScriptProviderSupplier xSupplier = + (XScriptProviderSupplier)UnoRuntime.queryInterface( + XScriptProviderSupplier.class, oDoc ); + File logFile = new File( logURI ); + if ( logFile.exists() ) + { + if ( !logFile.delete() ) + throw new java.lang.RuntimeException("failed to delete " + logFileURL ); + } + + XScriptProvider xProv = xSupplier.getScriptProvider(); + XScript xScript = xProv.getScript("vnd.sun.star.script:Standard.TestMacros.Main?language=Basic&location=document"); + System.out.println("Got script for doc " + entries[ i ] ); + Object[][] out = new Object[1][0]; + out[0] = new Object[0]; + + short[][] num = new short[1][0]; + num[0] = new short[0]; + + xScript.invoke(new Object[0], num, out); + + logFile = new File( logURI ); + System.out.println( "fileName is " + entries[ i ].getName().substring(0, entries[ i ].getName().lastIndexOf( ".xls" ) ) ); + File newLoc = new File( outDir, entries[ i ].getName().substring(0, entries[ i ].getName().lastIndexOf( ".xls" ) ) + ".log" ); + System.out.println("Moving logfile to " + newLoc.getAbsolutePath() ); + boolean ret = logFile.renameTo( newLoc ); + + System.out.println("Have run and move of log file worked = " + ret ); + } + catch ( Exception ex ) + { + ex.printStackTrace(System.err); + + } + // interface is supported, otherwise use XComponent.dispose + com.sun.star.util.XCloseable xCloseable = + (com.sun.star.util.XCloseable)UnoRuntime.queryInterface( + com.sun.star.util.XCloseable.class, oDoc); + + if ( xCloseable != null ) + { + xCloseable.close(false); + } + else + { + com.sun.star.lang.XComponent xComp = + (com.sun.star.lang.XComponent)UnoRuntime.queryInterface( + com.sun.star.lang.XComponent.class, oDoc); + + xComp.dispose(); + } + } + catch( Exception e ) + { + e.printStackTrace(System.err); + } + + } + } +} +public static void usage() +{ + System.out.println("usage: java TestVba.java " + + "\"<path to testdocument dir>\" " + + " \"<output_directory>\""); + System.exit(1); + +} +public static void main( String[] args ) +{ + if ( !( args.length > 1 ) ) + usage(); + + com.sun.star.uno.XComponentContext xContext = null; + + try + { + // get the remote office component context + xContext = com.sun.star.comp.helper.Bootstrap.bootstrap(); + System.out.println("Connected to a running office ..."); + + // get the remote office service manager + com.sun.star.lang.XMultiComponentFactory xMCF = + xContext.getServiceManager(); + + Object oDesktop = xMCF.createInstanceWithContext( + "com.sun.star.frame.Desktop", xContext); + + com.sun.star.frame.XComponentLoader xCompLoader = (com.sun.star.frame.XComponentLoader) + UnoRuntime.queryInterface(com.sun.star.frame.XComponentLoader.class, + oDesktop); + + File testDir = new File(args[0]); + File outDir = new File(args[1]); + if ( !testDir.isDirectory() || !outDir.isDirectory() ) + usage(); + TestVBA inst = new TestVBA( xContext, xMCF, xCompLoader, outDir ); + inst.traverse( testDir ); + System.out.println("Log dir is " + inst.getLogLocation() ); + + } + catch( Exception e ) + { + System.out.println("Caught exception"); + System.out.println(e); + } + System.exit(0); +} +} diff --git a/sc/source/ui/vba/testvba/build.xml b/sc/source/ui/vba/testvba/build.xml new file mode 100644 index 000000000000..22e52daa915a --- /dev/null +++ b/sc/source/ui/vba/testvba/build.xml @@ -0,0 +1,101 @@ +<!-- + + OpenOffice.org - a multi-platform office productivity suite + + $RCSfile: build.xml,v $ + + $Revision: 1.2 $ + + last change: $Author: vg $ $Date: 2007-12-07 11:15:20 $ + + The Contents of this file are made available subject to + the terms of GNU Lesser General Public License Version 2.1. + + + GNU Lesser General Public License Version 2.1 + ============================================= + Copyright 2005 by Sun Microsystems, Inc. + 901 San Antonio Road, Palo Alto, CA 94303, USA + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License version 2.1, as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, + MA 02111-1307 USA + +--> +<project name="testvba" default="all" basedir="."> + + <!-- =================== Environmental Properties ======================= --> + + <property name="prj" value=".."/> + <property name="build.compiler" value="classic"/> + <property name="optimize" value="off"/> + <property name="debug" value="on"/> + <property name="jardir" value="${out}/class"/> + <property name="bindir" value="${out}/bin"/> + + <!-- ==================== build classpath setting ======================= --> + <path id="idlclasspath"> + <pathelement location="${solar.jar}/jurt.jar"/> + <pathelement location="${solar.jar}/unoil.jar"/> + <pathelement location="${solar.jar}/jut.jar"/> + <pathelement location="${solar.jar}/juh.jar"/> + <pathelement location="${solar.jar}/java_uno.jar"/> + <pathelement location="${solar.jar}/ridl.jar"/> + </path> + + <!-- ==================== build classpath setting ======================= --> + <path id="clientclasspath"> + <pathelement location="${test.officepath}/program/classes/jurt.jar"/> + <pathelement location="${test.officepath}/program/classes/unoil.jar"/> + <pathelement location="${test.officepath}/program/classes/jut.jar"/> + <pathelement location="${test.officepath}/program/classes/juh.jar"/> + <pathelement location="${test.officepath}/program/classes/java_uno.jar"/> + <pathelement location="${test.officepath}/program/classes/ridl.jar"/> + <pathelement location="${out}/class"/> + </path> + + <property name="debugcp" refid="clientclasspath"/> + <!-- ===================== Prepare Directories ========================= --> + <target name="prepare"> + <mkdir dir="${jardir}"/> + </target> + + <!-- ======================== Compile Classes ========================== --> + <target name="compile" depends="prepare"> + <javac srcdir="." destdir="${jardir}" + includes="**/*.java" classpathref="idlclasspath" + debug="${debug}" optimize="${optimize}" deprecation="off"> + </javac> + </target> + + <!-- ====================== Clean Generated Files ===================== --> + <target name="clean"> + <delete dir="${jardir}"/> + </target> + <!-- ========================= All In One Build ======================= --> + + <!-- + <target name="all" depends="compile"/> +--> + + <target name="all" depends="test"/> + + <target name="test" depends="compile"> + <echo> testcp = ${debugcp}" + </echo> + <java classname="TestVBA" fork="true" dir="." classpathref="clientclasspath"> + <arg value="${test.documents}"/> + <arg value="${test.out}"/> + </java> + </target> +</project> diff --git a/sc/source/ui/vba/testvba/launchTest.pl b/sc/source/ui/vba/testvba/launchTest.pl new file mode 100644 index 000000000000..ca18fc61bdd7 --- /dev/null +++ b/sc/source/ui/vba/testvba/launchTest.pl @@ -0,0 +1,53 @@ +#************************************************************************* +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: launchTest.pl,v $ +# +# $Revision: 1.2 $ +# +# last change: $Author: vg $ $Date: 2007-12-07 11:15:30 $ +# +# The Contents of this file are made available subject to +# the terms of GNU Lesser General Public License Version 2.1. +# +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2005 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +#************************************************************************* + +use File::Basename; + +my $test_class = shift || die 'must provide a ext name'; +my $TESTDOCUMENT = shift || die 'must provide a path to testdocument dirs'; +my $OUTPUTDIR = shift || die 'must provide an output path to deposit logs in'; + +die "can't access TestClass $test_class/TestVBA.class" unless -f "$test_class/TestVBA.class"; +die "can't access officepath env variable \$OFFICEPATH" unless -d $ENV{OFFICEPATH}; +die "can't access testdocuments" unless -d $TESTDOCUMENT; +die "testdocument not of the correct structure $TESTDOCUMENT/logs/excel" unless -d "$TESTDOCUMENT/logs/excel"; +die "can't access output dir" unless -d $OUTPUTDIR; + + +my $officeclasspath = "$ENV{OFFICEPATH}/program/classes/"; +my $classpath = "$officeclasspath/jurt.jar:$officeclasspath/unoil.jar:$officeclasspath/jut.jar:$officeclasspath/juh.jar:$officeclasspath/java_uno.jar:$officeclasspath/ridl.jar:$test_class:$ENV{CLASSPATH}"; +$ENV{CLASSPATH}=$classpath; +print "classpath $ENV{CLASSPATH}\n"; +my $status = system("java -classpath $ENV{CLASSPATH} TestVBA $TESTDOCUMENT $OUTPUTDIR" ); diff --git a/sc/source/ui/vba/testvba/makefile.mk b/sc/source/ui/vba/testvba/makefile.mk new file mode 100644 index 000000000000..7e9ff3323dae --- /dev/null +++ b/sc/source/ui/vba/testvba/makefile.mk @@ -0,0 +1,61 @@ +#************************************************************************* +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.2 $ +# +# last change: $Author: vg $ $Date: 2007-12-07 11:15:40 $ +# +# The Contents of this file are made available subject to +# the terms of GNU Lesser General Public License Version 2.1. +# +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2005 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +#************************************************************************* + +PRJ=..$/..$/..$/..$/ +PRJNAME=sc +TARGET=testvba + +.INCLUDE : ant.mk + +.IF "$(SOLAR_JAVA)"!="" + +ALLTAR : PROCESSRESULTS + +TESTDOCUMENTS=..$/TestDocuments +.IF "$(GUI)"=="UNX" || "$(GUI)"=="MAC" +TESTDOCUMENTLOGS=$(TESTDOCUMENTS)$/logs$/unix +.ELSE +TESTDOCUMENTLOGS=$(TESTDOCUMENTS)$/logs$/win +.ENDIF + +OUTPUTDIR:=..$/$(TARGET)$/Logs +ANT_FLAGS+=-Dtest.documents=$(TESTDOCUMENTS) +ANT_FLAGS+=-Dtest.out=$(OUTPUTDIR) +ANT_FLAGS+=-Dtest.officepath=$(OFFICEPATH) +#UNITTEST : $(LOCAL_COMMON_OUT)$/class/TestVBA.class +PROCESSRESULTS : ANTBUILD + $(PERL) testResults.pl $(OUTPUTDIR) $(TESTDOCUMENTLOGS) + +.ENDIF diff --git a/sc/source/ui/vba/testvba/testResults.pl b/sc/source/ui/vba/testvba/testResults.pl new file mode 100755 index 000000000000..ea57296dbd04 --- /dev/null +++ b/sc/source/ui/vba/testvba/testResults.pl @@ -0,0 +1,159 @@ +#!/usr/bin/perl -w + +use File::Basename; +use File::stat; +use File::Copy; +my $binDir = dirname($0); +my $timestampclean= "$binDir/timestampsClean.pl"; +#sub gen_diff($) + +sub testLog +{ + # 2 No Log to compare against + # 1 Log passed + # 0 Log failed + my $result = 0; + my $testfile = shift; + my $dirtocheck = shift; + my $filename = basename($testfile); + $filename = "$logdir/$filename"; + print "processing $testfile $filename\n"; + if ( -f $filename ) { + #print "diffing\n"; + my $tmpFile = "/tmp/gen_diff"; + my $status = system("diff -U 0 -p $testfile $filename | $timestampclean > $tmpFile"); + my $info = stat($tmpFile) or die "no $tmpFile: $!"; + if ( ($status >>=8) == 0 && ( $info->size == 0) ) { + #print "diff worked size is 0\n"; + $result = 1; + } + elsif ( ($status >>=8) == 0 && ( $info->size > 0) ) + { + #print "diff worked size > 0\n"; + $result = 0; + } + else + { + #print "diff failed size > 0\n"; + $result = 0; + } + } + else + { + #print "not file > 0\n"; + $result = 2; + } + #print "diff result = $result\n"; + return $result; +} + +if ( ! ( $logdir = shift @ARGV ) ) { + print STDERR "No logdir specified!\n"; + usage(); + exit 1; +} + +if ( ! ( $testlogdir = shift @ARGV ) ) { + print STDERR "No testdocuments dir to compare against specified!\n"; + usage(); + exit 1; +} + +if ( !(-d $logdir ) ) { + print STDERR "No output directory $logdir exists, please create it!!!!\n"; + exit 1; +} +if ( !(-d $testlogdir ) ) { + print STDERR "the directory containing the logfiles to compare against \"$logdir\" does not exist\n"; + usage(); + exit 1; +} +print "logdir $logdir\n"; +print "testlogdir $testlogdir\n"; +sub filter_crud($) +{ + my $a = shift; + + $a =~ /~$/ && return; + $a =~ /\#$/ && return; + $a =~ /\.orig$/ && return; + $a =~ /unxlng.*\.pro$/ && return; + $a =~ /wntmsc.*\.pro$/ && return; + $a =~ /.swp$/ && return; + $a =~ /POSITION/ && return; + $a =~ /ReadMe/ && return; + $a =~ /.tmp$/ && return; + $a =~ /\.svn/ && return; + $a eq 'CVS' && return; + $a eq '.' && return; + $a eq '..' && return; + + return $a; +} +sub slurp_dir($); + +sub slurp_dir($) +{ + my $dir = shift; + my ($dirhandle, $fname); + my @files = (); + + opendir ($dirhandle, $dir) || die "Can't open $dir"; + while ($fname = readdir ($dirhandle)) { + $fname = filter_crud($fname); + defined $fname || next; +# if (-d "$dir/$fname") { +# push @files, slurp_dir("$dir/$fname"); +# } else + { + push @files, "$dir/$fname"; + } + } + closedir ($dirhandle); + + return @files; +} + +if (-d $testlogdir) { + push @files, slurp_dir($testlogdir); +} + +my $processed = 0; +my $passed = 0; +my @passedTests=(); +my @skippedTests=(); +my @failedTests=(); + +my $failureCmd=""; +for $a (@files) { + $processed++; + my $testcase = $a; + $testcase =~ s/\.log/\.xls/; + my $result = testLog( $a, $logdir ); + if ( $result == 0 ) { + push @failedTests, basename($testcase); + if ( $failureCmd eq "" ) { $failureCmd = " diff -up $a $logdir "; } + } + elsif ( $result == 2 ) { + #print "skipped $a\n"; + push @skippedTests, $testcase; + } + else { + $passed++; + push @passedTests, $testcase; + #print "Test document for $a \t \t passed. \n"; + } +} +my $compared=@passedTests+@failedTests; +my $skip = @skippedTests; +print "skipped $skip test-cases(s)\n"; +print "compared $compared test-case documents\n"; +print "\t \t $passed tests $@passedTests\n"; +if ( @failedTests > 0 ) { + print "the following test-case documents failed, please examine the logs manually\n"; + + for $a (@failedTests) { + print "\t$a\n"; + } + print "e.g. $failureCmd\n" +} diff --git a/sc/source/ui/vba/testvba/timestampsClean.pl b/sc/source/ui/vba/testvba/timestampsClean.pl new file mode 100755 index 000000000000..dade65c7200f --- /dev/null +++ b/sc/source/ui/vba/testvba/timestampsClean.pl @@ -0,0 +1,73 @@ +#!/usr/bin/perl -w + +my @output_buffer = (); +my $fname; +my $detectedSomeGuff = 0; +sub pure_guff($) +{ + my $array = shift; + my @lines = @{$array}; + my $contains_sense = ''; + my $contains_guff = ''; + while (scalar @lines) + { + my $line = pop @lines; + if ($line =~ m/Test run started :/ || + $line =~ m/ITEM Assertion OK/ || + $line =~ m/Test run finished :/) { + $contains_guff = '1'; + } elsif ($line =~ m/^[\+\-][^\-\+]/) { + $contains_sense = '1'; + } + } + if ($contains_guff && $contains_sense) { + print STDERR "Patch fragment with mixed good/bad changes in '$ARGV' near $line_index\n"; + $contains_guff = ''; + } + elsif ( $contains_guff ) { + $detectedSomeGuff++; + } +# print "contains guff: $contains_guff\n"; + return $contains_guff; +} + +sub output_lines($) +{ + my $array = shift; + my @lines = @{$array}; + + if (pure_guff (\@lines)) { + return; + } + + while (scalar @lines) + { + my $line = pop @lines; + push @output_buffer, $line; + } +} + +my $header; +my @lines; +my $frag_count = 0; +$line_index = 0; + +while (<>) { + if (/^\@\@/ || /^[^ \-\+]/) { + output_lines (\@lines); + @lines = (); + $frag_count++; + } + unshift @lines, $_; + $line_index++; + close ARGV if eof; +} +output_lines(\@lines); + +# $detectedSomeGuff contains the skipped hunks that contain acceptable diff +# e.g. a timestamp or an OK assertion that contains different content +# like perhaps a path +#print "frag_count = $frag_count fragstocount = $fragstocount detectedSomeGuff = $detectedSomeGuff \n"; +if ($frag_count > $detectedSomeGuff) { + print @output_buffer; +} |