poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cen...@apache.org
Subject svn commit: r1510243 - in /poi/trunk: ./ src/excelant/testcases/org/apache/poi/ss/excelant/util/ src/scratchpad/testcases/org/apache/poi/hwpf/model/
Date Sun, 04 Aug 2013 16:38:01 GMT
Author: centic
Date: Sun Aug  4 16:38:01 2013
New Revision: 1510243

URL: http://svn.apache.org/r1510243
Log:
Adjust build.xml to run JaCoCo coverage when running unit tests when
flag coverage.enabled is set to true, download necessary jars, add jacoco:coverage
to junit targets and a testcoveragereport target which produces the coverage report.
Also fix a test that is affected by JaCoCo and add slightly more coverage in another test.

Modified:
    poi/trunk/build.xml
    poi/trunk/src/excelant/testcases/org/apache/poi/ss/excelant/util/ExcelAntWorkbookUtilTestHelper.java
    poi/trunk/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtil.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestDocumentProperties.java

Modified: poi/trunk/build.xml
URL: http://svn.apache.org/viewvc/poi/trunk/build.xml?rev=1510243&r1=1510242&r2=1510243&view=diff
==============================================================================
--- poi/trunk/build.xml (original)
+++ poi/trunk/build.xml Sun Aug  4 16:38:01 2013
@@ -151,6 +151,12 @@ under the License.
     <property name="ooxml.jsr173.jar" location="${ooxml.lib}/stax-api-1.0.1.jar"/>
     <property name="ooxml.jsr173.url" value="${repository.m2}/maven2/stax/stax-api/1.0.1/stax-api-1.0.1.jar"/>
 
+    <!-- coverage libs -->
+    <property name="jacoco.zip" location="${main.lib}/jacoco-0.6.2.201302030002.zip"/>
+    <property name="jacoco.url" value="${repository.m2}/maven2/org/jacoco/jacoco/0.6.2.201302030002/jacoco-0.6.2.201302030002.zip"/>
+    <property name="asm.jar" location="${main.lib}/asm-all-4.0.jar"/>
+    <property name="asm.url" value="${repository.m2}/maven2/org/ow2/asm/asm-all/4.0/asm-all-4.0.jar"/>
+
     <!-- See http://www.ecma-international.org/publications/standards/Ecma-376.htm -->
     <!-- "Copy these file(s), free of charge" -->
     <property name="ooxml.xsds.ozip" location="${ooxml.lib}/OfficeOpenXML-Part4.zip"/>
@@ -164,6 +170,11 @@ under the License.
     <property name="maven.ooxml.xsds.version.id" value="1.0"/>
     <property name="maven.ooxml.xsds.jar" value="ooxml-schemas-${maven.ooxml.xsds.version.id}.jar"/>
 
+    <!-- Coverage -->
+    <property name="coverage.dir" value="build/coverage"/>
+    <!-- Exclude some uninteresting classes from coverage-instrumentation as we do not
want to measure coverage in those packages anyway -->
+    <property name="coverage.excludes" value="org.openxmlformats.*:com.*:org.junit.*:junit.*:"/>
+
     <!-- build and distro settings -->
     <property name="jar.name" value="poi"/>
     <property name="build.site" location="build/tmp/site/build/site"/>
@@ -255,6 +266,13 @@ under the License.
         <pathelement location="${main.output.test.dir}"/>
     </path>
 
+    <path id="lib.jacoco">
+        <fileset dir="lib">
+            <include name="org.jacoco*.jar" />
+            <include name="asm-all-4*.jar" />
+        </fileset>
+    </path>
+
     <!-- Prints POI's Ant usage help -->
     <target name="help" description="Prints Apache POI's Ant usage help">
       <echo>
@@ -316,6 +334,8 @@ under the License.
                     <available file="${main.junit.jar}"/>
                     <available file="${main.hamcrest.jar}"/>
                     <available file="${main.ant.jar}"/>
+                    <available file="${asm.jar}"/>
+                    <available file="${jacoco.zip}"/>
                 </and>
                 <isset property="disconnected"/>
             </or>
@@ -349,6 +369,19 @@ under the License.
             <param name="sourcefile" value="${main.ant.url}"/>
             <param name="destfile" value="${main.ant.jar}"/>
         </antcall>
+        <antcall target="downloadfile">
+            <param name="sourcefile" value="${asm.url}"/>
+            <param name="destfile" value="${asm.jar}"/>
+        </antcall>
+        <antcall target="downloadfile">
+            <param name="sourcefile" value="${jacoco.url}"/>
+            <param name="destfile" value="${jacoco.zip}"/>
+        </antcall>
+        <unzip src="${jacoco.zip}" dest=".">
+            <patternset>
+                <include name="lib/*.jar"/>
+            </patternset>
+        </unzip>
     </target>
 
     <target name="check-ooxml-jars">
@@ -622,9 +655,77 @@ under the License.
         <delete file="${version.java}"/>
     </target>
 
-    <target name="test" depends="compile,test-main,test-scratchpad,test-ooxml,test-excelant"
+    <target name="jacocotask" depends="">
+        <taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
+            <classpath refid="lib.jacoco"/>
+        </taskdef>
+    </target>
+
+    <target name="test" depends="compile,jacocotask,test-main,test-scratchpad,test-ooxml,test-excelant"
             description="Tests main, scratchpad and ooxml"/>
-    <target name="test-all" depends="test,test-ooxml-lite"/>
+    <target name="test-all" depends="test,test-ooxml-lite,testcoveragereport"/>
+
+    <target name="testcoveragereport" depends="jacocotask" description="create test-report"
xmlns:jacoco="antlib:org.jacoco.ant" if="${coverage.enabled}">
+        <delete dir="${coverage.dir}"/>
+        <mkdir dir="${coverage.dir}"/>
+
+        <jacoco:report>
+            <executiondata>
+                <fileset dir="build">
+                    <include name="*.exec"/>
+                </fileset>
+            </executiondata>
+                               
+            <structure name="Apache POI">
+                <group name="Main">
+                    <classfiles>
+                        <fileset dir="${main.output.dir}">
+                            <exclude name=""/>
+                        </fileset>
+                    </classfiles>
+                    <sourcefiles encoding="UTF-8">
+                        <fileset dir="${main.src}"/>
+                    </sourcefiles>
+                </group>
+                <group name="Scratchpad">
+                    <classfiles>
+                        <fileset dir="${scratchpad.output.dir}"/>
+                    </classfiles>
+                    <sourcefiles encoding="UTF-8">
+                        <fileset dir="${scratchpad.src}"/>
+                    </sourcefiles>
+                </group>
+                <group name="OOXML">
+                    <classfiles>
+                        <fileset dir="${ooxml.output.dir}">
+                            <exclude name=""/>
+                        </fileset>
+                        <fileset dir="${ooxml.lite.output.dir}">
+                            <exclude name="org/openxmlformats/**"/>
+                            <exclude name="schema*/**"/>
+                        </fileset>
+                    </classfiles>
+                    <sourcefiles encoding="UTF-8">
+                        <fileset dir="${ooxml.src}"/>
+                        <!--fileset dir="${ooxml.lite.src}"/-->
+                    </sourcefiles>
+                </group>
+                <group name="Excelant">
+                    <classfiles>
+                        <fileset dir="${excelant.output.dir}"/>
+                    </classfiles>
+                    <sourcefiles encoding="UTF-8">
+                        <fileset dir="${excelant.src}"/>
+                    </sourcefiles>
+                </group>
+            </structure>
+        
+            <html destdir="${coverage.dir}"/>
+            <xml destfile="${coverage.dir}/coverage.xml"/>
+        </jacoco:report>        
+        
+        <echo message="Coverage results are available at coverage\index.html, coverage/coverage.xml"
/>
+    </target>
 
     <target name="-test-main-check">
         <uptodate property="main.test.notRequired" targetfile="${main.testokfile}">
@@ -634,24 +735,27 @@ under the License.
     </target>
 
     <target name="test-main" unless="main.test.notRequired"
-            depends="compile-main, -test-main-check">
-        <junit fork="yes" forkmode="once" printsummary="yes" haltonfailure="${halt.on.test.failure}"
-               failureproperty="main.test.failed" showoutput="true">
-            <classpath refid="test.classpath"/>
-            <syspropertyset refid="junit.properties"/>
-            <jvmarg value="${poi.test.locale}"/>
-            <jvmarg value="-ea"/>
-            <jvmarg value="-Xmx256m"/>
-            <formatter type="plain"/>
-            <batchtest todir="${main.reports.test}">
-                <fileset dir="${main.src.test}">
-                    <include name="**/${testpattern}.java"/>
-                    <exclude name="**/All*Tests.java"/>
-                    <exclude name="**/TestUnfixedBugs.java"/>
-                    <exclude name="**/TestcaseRecordInputStream.java"/>
-                </fileset>
-            </batchtest>
-        </junit>
+            depends="compile-main, -test-main-check,jacocotask" xmlns:jacoco="antlib:org.jacoco.ant">
+        <jacoco:coverage enabled="${coverage.enabled}" excludes="${coverage.excludes}"
destfile="build/jacoco-main.exec">
+            <junit fork="yes" forkmode="once" printsummary="yes" haltonfailure="${halt.on.test.failure}"
+                   failureproperty="main.test.failed" showoutput="true">
+                <classpath refid="test.classpath"/>
+                <syspropertyset refid="junit.properties"/>
+                <jvmarg value="${poi.test.locale}"/>
+                <jvmarg value="-ea"/>
+                <jvmarg value="-Xmx256m"/>
+                <formatter type="plain"/>
+                <formatter type="xml"/>
+                <batchtest todir="${main.reports.test}">
+                    <fileset dir="${main.src.test}">
+                        <include name="**/${testpattern}.java"/>
+                        <exclude name="**/All*Tests.java"/>
+                        <exclude name="**/TestUnfixedBugs.java"/>
+                        <exclude name="**/TestcaseRecordInputStream.java"/>
+                    </fileset>
+                </batchtest>
+            </junit>
+        </jacoco:coverage>
         <delete file="${main.testokfile}"/>
         <antcall target="-test-main-write-testfile"/>
     </target>
@@ -672,28 +776,31 @@ under the License.
         </uptodate>
     </target>
 
-    <target name="test-scratchpad" depends="compile-main,compile-scratchpad,-test-scratchpad-check"
-            unless="scratchpad.test.notRequired">
-        <junit printsummary="yes" fork="yes" forkmode="once" haltonfailure="${halt.on.test.failure}"
-               failureproperty="scratchpad.test.failed">
-            <classpath refid="test.scratchpad.classpath"/>
-            <syspropertyset refid="junit.properties"/>
-            <jvmarg value="${poi.test.locale}"/>
-            <jvmarg value="-ea"/>
-            <!-- 
-              YK: ensure that JUnit has enough memory to run tests. 
-              Without the line below tests fail on Mac OS X with jdk-1.6.26 
-              and on Windows with jdk-1.5.22 
-            -->
-            <jvmarg value="-Xmx256M"/>            
-            <formatter type="plain"/>
-            <batchtest todir="${scratchpad.reports.test}">
-                <fileset dir="${scratchpad.src.test}">
-                    <include name="**/${testpattern}.java"/>
-                    <exclude name="**/AllTests.java"/>
-                </fileset>
-            </batchtest>
-        </junit>
+    <target name="test-scratchpad" depends="compile-main,compile-scratchpad,-test-scratchpad-check,jacocotask"
+            unless="scratchpad.test.notRequired" xmlns:jacoco="antlib:org.jacoco.ant">
+        <jacoco:coverage enabled="${coverage.enabled}" excludes="${coverage.excludes}"
destfile="build/jacoco-scratchpad.exec">
+            <junit printsummary="yes" fork="yes" forkmode="once" haltonfailure="${halt.on.test.failure}"
+                   failureproperty="scratchpad.test.failed">
+                <classpath refid="test.scratchpad.classpath"/>
+                <syspropertyset refid="junit.properties"/>
+                <jvmarg value="${poi.test.locale}"/>
+                <jvmarg value="-ea"/>
+                <!-- 
+                  YK: ensure that JUnit has enough memory to run tests. 
+                  Without the line below tests fail on Mac OS X with jdk-1.6.26 
+                  and on Windows with jdk-1.5.22 
+                -->
+                <jvmarg value="-Xmx256M"/>            
+                <formatter type="plain"/>
+                <formatter type="xml"/>
+                <batchtest todir="${scratchpad.reports.test}">
+                    <fileset dir="${scratchpad.src.test}">
+                        <include name="**/${testpattern}.java"/>
+                        <exclude name="**/AllTests.java"/>
+                    </fileset>
+                </batchtest>
+            </junit>
+        </jacoco:coverage>
         <delete file="${scratchpad.testokfile}"/>
         <antcall target="-test-scratchpad-write-testfile"/>
     </target>
@@ -709,29 +816,33 @@ under the License.
         </uptodate>
     </target>
 
-    <macrodef name="ooxml-test-runner">    
+    <macrodef name="ooxml-test-runner" xmlns:jacoco="antlib:org.jacoco.ant">    
         <attribute name="classpath"/>
+        <attribute name="type"/>
         <sequential>
-          <junit printsummary="yes" fork="yes" forkmode="once" haltonfailure="${halt.on.test.failure}"
-                 failureproperty="ooxml.test.failed">
-              <classpath refid="@{classpath}"/>
-              <syspropertyset refid="junit.properties"/>
-              <jvmarg value="${poi.test.locale}"/>
-<!--              <jvmarg value="-ea"/> -->
-              <formatter type="plain"/>
-              <batchtest todir="${ooxml.reports.test}">
-                  <fileset dir="${ooxml.src.test}">
-                      <include name="**/${testpattern}.java"/>
-                      <exclude name="**/TestUnfixedBugs.java"/>
-                      <exclude name="**/All*Tests.java"/>
-                  </fileset>
-              </batchtest>
-          </junit>
+            <jacoco:coverage enabled="${coverage.enabled}" excludes="${coverage.excludes}"
destfile="build/jacoco-@{type}.exec">
+              <junit printsummary="yes" fork="yes" forkmode="once" haltonfailure="${halt.on.test.failure}"
+                     failureproperty="ooxml.test.failed">
+                  <classpath refid="@{classpath}"/>
+                  <syspropertyset refid="junit.properties"/>
+                  <jvmarg value="${poi.test.locale}"/>
+    <!--              <jvmarg value="-ea"/> -->
+                  <formatter type="plain"/>
+                  <formatter type="xml"/>
+                  <batchtest todir="${ooxml.reports.test}">
+                      <fileset dir="${ooxml.src.test}">
+                          <include name="**/${testpattern}.java"/>
+                          <exclude name="**/TestUnfixedBugs.java"/>
+                          <exclude name="**/All*Tests.java"/>
+                      </fileset>
+                  </batchtest>
+              </junit>
+            </jacoco:coverage>
         </sequential>
     </macrodef>    
 
-    <target name="test-ooxml" depends="compile-main,compile-ooxml,-test-ooxml-check" unless="ooxml.test.notRequired">
-        <ooxml-test-runner classpath="test.ooxml.classpath"/>
+    <target name="test-ooxml" depends="compile-main,compile-ooxml,-test-ooxml-check,jacocotask"
unless="ooxml.test.notRequired">
+        <ooxml-test-runner classpath="test.ooxml.classpath" type="ooxml"/>
         <delete file="${ooxml.testokfile}"/>
         <antcall target="-test-ooxml-write-testfile"/>
     </target>
@@ -754,10 +865,10 @@ under the License.
         </java>
     </target>
 
-    <target name="test-ooxml-lite">
+    <target name="test-ooxml-lite" depends="jacocotask">
         <delete file="${ooxml.testokfile}"/>
         <echo message="Running ooxml tests against 'poi-ooxml-schemas'"/>
-        <ooxml-test-runner classpath="ooxml-lite.classpath"/>
+        <ooxml-test-runner classpath="ooxml-lite.classpath" type="ooxml-lite"/>
     </target>
     
     <target name="-test-excelant-check">
@@ -771,21 +882,24 @@ under the License.
         <echo file="${excelant.testokfile}" append="false" message="testok"/>
     </target>
 
-    <target name="test-excelant" depends="compile-excelant,-test-excelant-check"
-            unless="excelant.test.notRequired">
-        <junit printsummary="yes" fork="yes" forkmode="once" haltonfailure="${halt.on.test.failure}"
-               failureproperty="excelant.test.failed">
-            <classpath refid="test.excelant.classpath"/>
-            <syspropertyset refid="junit.properties"/>
-            <jvmarg value="${poi.test.locale}"/>
-            <jvmarg value="-ea"/>
-            <formatter type="plain"/>
-            <batchtest todir="${excelant.reports.test}">
-                <fileset dir="${excelant.src.test}">
-                    <include name="**/${testpattern}.java"/>
-                </fileset>
-            </batchtest>
-        </junit>
+    <target name="test-excelant" depends="compile-excelant,-test-excelant-check,jacocotask"
+            unless="excelant.test.notRequired" xmlns:jacoco="antlib:org.jacoco.ant">
+        <jacoco:coverage enabled="${coverage.enabled}" excludes="${coverage.excludes}"
destfile="build/jacoco-excelant.exec">
+            <junit printsummary="yes" fork="yes" forkmode="once" haltonfailure="${halt.on.test.failure}"
+                   failureproperty="excelant.test.failed">
+                <classpath refid="test.excelant.classpath"/>
+                <syspropertyset refid="junit.properties"/>
+                <jvmarg value="${poi.test.locale}"/>
+                <jvmarg value="-ea"/>
+                <formatter type="plain"/>
+                <formatter type="xml"/>
+                <batchtest todir="${excelant.reports.test}">
+                    <fileset dir="${excelant.src.test}">
+                        <include name="**/${testpattern}.java"/>
+                    </fileset>
+                </batchtest>
+            </junit>
+        </jacoco:coverage>
         <delete file="${excelant.testokfile}"/>
         <antcall target="-test-excelant-write-testfile"/>
     </target>

Modified: poi/trunk/src/excelant/testcases/org/apache/poi/ss/excelant/util/ExcelAntWorkbookUtilTestHelper.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/excelant/testcases/org/apache/poi/ss/excelant/util/ExcelAntWorkbookUtilTestHelper.java?rev=1510243&r1=1510242&r2=1510243&view=diff
==============================================================================
--- poi/trunk/src/excelant/testcases/org/apache/poi/ss/excelant/util/ExcelAntWorkbookUtilTestHelper.java
(original)
+++ poi/trunk/src/excelant/testcases/org/apache/poi/ss/excelant/util/ExcelAntWorkbookUtilTestHelper.java
Sun Aug  4 16:38:01 2013
@@ -30,23 +30,19 @@ public class ExcelAntWorkbookUtilTestHel
 
 	public ExcelAntWorkbookUtilTestHelper(String fName) {
 		super(fName);
-		// TODO Auto-generated constructor stub
 	}
 
 	public ExcelAntWorkbookUtilTestHelper(Workbook wb) {
 		super(wb);
-		// TODO Auto-generated constructor stub
 	}
 
 	@Override
 	public UDFFinder getFunctions() {
-		// TODO Auto-generated method stub
 		return super.getFunctions();
 	}
 
 	@Override
 	public FormulaEvaluator getEvaluator(String excelFileName) {
-		// TODO Auto-generated method stub
 		return super.getEvaluator(excelFileName);
 	}
 

Modified: poi/trunk/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtil.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtil.java?rev=1510243&r1=1510242&r2=1510243&view=diff
==============================================================================
--- poi/trunk/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtil.java
(original)
+++ poi/trunk/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtil.java
Sun Aug  4 16:38:01 2013
@@ -16,14 +16,21 @@
 ==================================================================== */
 package org.apache.poi.ss.excelant.util;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
 import java.util.ArrayList;
 
 import junit.framework.TestCase;
 
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 import org.apache.poi.ss.examples.formula.CalculateMortgageFunction;
 import org.apache.poi.ss.formula.udf.UDFFinder;
 import org.apache.poi.ss.usermodel.FormulaEvaluator;
 import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.usermodel.WorkbookFactory;
+import org.apache.tools.ant.BuildException;
 
 public class TestExcelAntWorkbookUtil extends TestCase {
 	
@@ -43,6 +50,17 @@ public class TestExcelAntWorkbookUtil ex
 		assertNotNull( fixture ) ;
 		
 	}
+
+	public void testWorkbookConstructor() throws InvalidFormatException, IOException {
+        File workbookFile = new File(mortgageCalculatorFileName);
+        FileInputStream fis = new FileInputStream(workbookFile);
+        Workbook workbook = WorkbookFactory.create(fis);
+
+		fixture = new ExcelAntWorkbookUtilTestHelper( workbook ) ;
+		
+		assertNotNull( fixture ) ;
+		
+	}
 	
 	public void testAddFunction() {
 		fixture = new ExcelAntWorkbookUtilTestHelper( 

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestDocumentProperties.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestDocumentProperties.java?rev=1510243&r1=1510242&r2=1510243&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestDocumentProperties.java
(original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestDocumentProperties.java
Sun Aug  4 16:38:01 2013
@@ -46,6 +46,11 @@ public final class TestDocumentPropertie
 
     for (int x = 0; x < fields.length; x++)
     {
+      // JaCoCo Code Coverage adds it's own field, don't look at this one here
+      if(fields[x].getName().equals("$jacocoData")) {
+    	  continue;
+      }
+
       if (!fields[x].getType().isArray())
       {
         assertEquals(fields[x].get(_documentProperties),
@@ -53,6 +58,10 @@ public final class TestDocumentPropertie
       }
       else
       {
+    	// ensure that the class was not changed/enhanced, e.g. by code instrumentation like
coverage tools
+    	assertEquals("Invalid type for field: " + fields[x].getName(), 
+    			"[B", fields[x].getType().getName());
+    	
         byte[] buf1 = (byte[])fields[x].get(_documentProperties);
         byte[] buf2 = (byte[])fields[x].get(newDocProperties);
         Arrays.equals(buf1, buf2);



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message