1 <?xml version="1.0" encoding="UTF-8"?> 2 3 <!-- 4 Copyright (c) 2009, 2015 Mountainminds GmbH & Co. KG and Contributors 5 All rights reserved. This program and the accompanying materials 6 are made available under the terms of the Eclipse Public License v1.0 7 which accompanies this distribution, and is available at 8 http://www.eclipse.org/legal/epl-v10.html 9 10 Contributors: 11 Marc R. Hoffmann - initial API and implementation 12 13 $Id: $ 14 --> 15 16 <project name="JaCoCo Instrument Task Tests" xmlns:au="antlib:org.apache.ant.antunit" xmlns:jacoco="antlib:org.jacoco.ant"> 17 18 <target name="setUp"> 19 <tempfile property="temp.dir" prefix="jacocoTest" destdir="${java.io.tmpdir}" /> 20 <mkdir dir="${temp.dir}"/> 21 <property name="exec.file" location="${temp.dir}/exec.file" /> 22 </target> 23 24 <target name="tearDown"> 25 <delete dir="${temp.dir}" quiet="false" failonerror="true"/> 26 </target> 27 28 <target name="testInstrumentNoDestination"> 29 <au:expectfailure expectedMessage="Destination directory must be supplied"> 30 <jacoco:instrument/> 31 </au:expectfailure> 32 </target> 33 34 <target name="testInstrumentInvalidClassFile"> 35 <mkdir dir="${temp.dir}/output"/> 36 <property name="broken.file" location="${temp.dir}/broken.class"/> 37 <copy file="${org.jacoco.ant.instrumentTaskTest.classes.dir}/TestTargetInDefault.class" tofile="${broken.file}"/> 38 <truncate file="${broken.file}" length="8"/> 39 <au:expectfailure expectedMessage="Error while instrumenting ${broken.file}"> 40 <jacoco:instrument destdir="${temp.dir}/output"> 41 <fileset dir="${temp.dir}" includes="broken.class"/> 42 </jacoco:instrument> 43 </au:expectfailure> 44 <au:assertFileDoesntExist file="${temp.dir}/output/broken.class" /> 45 </target> 46 47 <target name="testInstrumentIgnoreDirectories"> 48 <jacoco:instrument destdir="${temp.dir}"> 49 <dirset dir="${org.jacoco.ant.instrumentTaskTest.classes.dir}" includes="**"/> 50 </jacoco:instrument> 51 </target> 52 53 <target name="testInstrumentRemoveSignatures"> 54 <property name="lib.dir" location="${temp.dir}/lib"/> 55 <property name="instr.dir" location="${temp.dir}/instr"/> 56 <mkdir dir="${lib.dir}"/> 57 <mkdir dir="${instr.dir}"/> 58 59 <jar destfile="${lib.dir}/test.jar"> 60 <fileset dir="${org.jacoco.ant.instrumentTaskTest.classes.dir}" includes="**/*.class"/> 61 </jar> 62 <signjar jar="${lib.dir}/test.jar" keystore="${basedir}/data/keystore.jks" alias="test" storepass="password"/> 63 64 <jacoco:instrument destdir="${instr.dir}"> 65 <fileset dir="${lib.dir}" includes="*.jar"/> 66 </jacoco:instrument> 67 <au:assertLogContains text="Instrumented 15 classes to ${temp.dir}"/> 68 69 <unzip src="${instr.dir}/test.jar" dest="${instr.dir}"/> 70 <au:assertFileDoesntExist file="${instr.dir}/META-INF/TEST.RSA" /> 71 <au:assertFileDoesntExist file="${instr.dir}/META-INF/TEST.SF" /> 72 </target> 73 74 <target name="testInstrumentKeepSignatures"> 75 <property name="lib.dir" location="${temp.dir}/lib"/> 76 <property name="instr.dir" location="${temp.dir}/instr"/> 77 <mkdir dir="${lib.dir}"/> 78 <mkdir dir="${instr.dir}"/> 79 80 <jar destfile="${lib.dir}/test.jar"> 81 <fileset dir="${org.jacoco.ant.instrumentTaskTest.classes.dir}" includes="**/*.class"/> 82 </jar> 83 <signjar jar="${lib.dir}/test.jar" keystore="${basedir}/data/keystore.jks" alias="test" storepass="password"/> 84 85 <jacoco:instrument destdir="${instr.dir}" removesignatures="false"> 86 <fileset dir="${lib.dir}" includes="*.jar"/> 87 </jacoco:instrument> 88 <au:assertLogContains text="Instrumented 15 classes to ${temp.dir}"/> 89 90 <unzip src="${instr.dir}/test.jar" dest="${instr.dir}"/> 91 <au:assertFileExists file="${instr.dir}/META-INF/TEST.RSA" /> 92 <au:assertFileExists file="${instr.dir}/META-INF/TEST.SF" /> 93 </target> 94 95 <target name="testInstrumentAndRunWithConfigFile"> 96 <jacoco:instrument destdir="${temp.dir}"> 97 <fileset dir="${org.jacoco.ant.instrumentTaskTest.classes.dir}" includes="**/*.class"/> 98 </jacoco:instrument> 99 <au:assertLogContains text="Instrumented 15 classes to ${temp.dir}"/> 100 <au:assertFileExists file="${temp.dir}/org/jacoco/ant/InstrumentTaskTest.class" /> 101 102 <echo file="${temp.dir}/jacoco-agent.properties">destfile=test.exec</echo> 103 <java classname="org.jacoco.ant.TestTarget" failonerror="true" fork="true" dir="${temp.dir}"> 104 <classpath> 105 <pathelement path="${org.jacoco.ant.instrumentTaskTest.agent.file}"/> 106 <pathelement path="${temp.dir}"/> 107 </classpath> 108 </java> 109 <au:assertFileExists file="${temp.dir}/test.exec" /> 110 </target> 111 112 <target name="testInstrumentAndRunWithSystemProperties"> 113 <jacoco:instrument destdir="${temp.dir}"> 114 <fileset dir="${org.jacoco.ant.instrumentTaskTest.classes.dir}" includes="**/*.class"/> 115 </jacoco:instrument> 116 <au:assertLogContains text="Instrumented 15 classes to ${temp.dir}"/> 117 <au:assertFileExists file="${temp.dir}/org/jacoco/ant/InstrumentTaskTest.class" /> 118 119 <java classname="org.jacoco.ant.TestTarget" failonerror="true" fork="true"> 120 <sysproperty key="jacoco-agent.destfile" file="${temp.dir}/test.exec"/> 121 <classpath> 122 <pathelement path="${org.jacoco.ant.instrumentTaskTest.agent.file}"/> 123 <pathelement path="${temp.dir}"/> 124 </classpath> 125 </java> 126 <au:assertFileExists file="${temp.dir}/test.exec" /> 127 </target> 128 129 </project>