diff options
author | Marc R. Hoffmann <hoffmann@mountainminds.com> | 2012-12-23 15:57:16 +0100 |
---|---|---|
committer | Marc R. Hoffmann <hoffmann@mountainminds.com> | 2012-12-23 15:57:16 +0100 |
commit | 235a09e3dd342588990400fefa99a1ebd74ca47d (patch) | |
tree | 229f36d943c6b088135710a279253baccfb12faa /org.jacoco.ant.test | |
parent | 25fb3d4e2bac150627f091d310bafb6be465f37b (diff) | |
download | jacoco-235a09e3dd342588990400fefa99a1ebd74ca47d.tar.gz |
Ant task for offline instrumentation.
Diffstat (limited to 'org.jacoco.ant.test')
-rw-r--r-- | org.jacoco.ant.test/src/org/jacoco/ant/InstrumentTaskTest.java | 36 | ||||
-rw-r--r-- | org.jacoco.ant.test/src/org/jacoco/ant/InstrumentTaskTest.xml | 69 |
2 files changed, 105 insertions, 0 deletions
diff --git a/org.jacoco.ant.test/src/org/jacoco/ant/InstrumentTaskTest.java b/org.jacoco.ant.test/src/org/jacoco/ant/InstrumentTaskTest.java new file mode 100644 index 00000000..a418f72f --- /dev/null +++ b/org.jacoco.ant.test/src/org/jacoco/ant/InstrumentTaskTest.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2009, 2012 Mountainminds GmbH & Co. KG and Contributors + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Brock Janiczak - initial API and implementation + * + *******************************************************************************/ +package org.jacoco.ant; + +import java.io.File; +import java.io.IOException; + +import junit.framework.TestSuite; + +import org.apache.ant.antunit.junit3.AntUnitSuite; +import org.apache.ant.antunit.junit4.AntUnitSuiteRunner; +import org.jacoco.agent.AgentJar; +import org.junit.runner.RunWith; + +@RunWith(AntUnitSuiteRunner.class) +public class InstrumentTaskTest { + + public static TestSuite suite() throws IOException { + System.setProperty("org.jacoco.ant.instrumentTaskTest.classes.dir", + TestTarget.getClassPath()); + System.setProperty("org.jacoco.ant.instrumentTaskTest.agent.file", + AgentJar.extractToTempLocation().getAbsolutePath()); + final File file = new File("src/org/jacoco/ant/InstrumentTaskTest.xml"); + return new AntUnitSuite(file, InstrumentTaskTest.class); + } + +} diff --git a/org.jacoco.ant.test/src/org/jacoco/ant/InstrumentTaskTest.xml b/org.jacoco.ant.test/src/org/jacoco/ant/InstrumentTaskTest.xml new file mode 100644 index 00000000..ba61b720 --- /dev/null +++ b/org.jacoco.ant.test/src/org/jacoco/ant/InstrumentTaskTest.xml @@ -0,0 +1,69 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- + Copyright (c) 2009, 2012 Mountainminds GmbH & Co. KG and Contributors + All rights reserved. This program and the accompanying materials + are made available under the terms of the Eclipse Public License v1.0 + which accompanies this distribution, and is available at + http://www.eclipse.org/legal/epl-v10.html + + Contributors: + Brock Janiczak - initial API and implementation + + $Id: $ +--> + +<project name="JaCoCo Instrument Task Tests" xmlns:au="antlib:org.apache.ant.antunit" xmlns:jacoco="antlib:org.jacoco.ant"> + + <target name="setUp"> + <tempfile property="temp.dir" prefix="jacocoTest" destdir="${java.io.tmpdir}" /> + <mkdir dir="${temp.dir}"/> + <property name="exec.file" location="${temp.dir}/exec.file" /> + </target> + + <target name="tearDown"> + <delete dir="${temp.dir}" quiet="false" failonerror="true"/> + </target> + + <target name="testInstrumentNoDestination"> + <au:expectfailure expectedMessage="Destination directory must be supplied"> + <jacoco:instrument/> + </au:expectfailure> + </target> + + <target name="testInstrumentInvalidClassFile"> + <mkdir dir="${temp.dir}/output"/> + <property name="broken.file" location="${temp.dir}/broken.class"/> + <echo file="${broken.file}">Not a class.</echo> + <au:expectfailure expectedMessage="Error while instrumenting ${broken.file}"> + <jacoco:instrument destdir="${temp.dir}/output"> + <fileset dir="${temp.dir}" includes="broken.class"/> + </jacoco:instrument> + </au:expectfailure> + <au:assertFileDoesntExist file="${temp.dir}/output/broken.class" /> + </target> + + <target name="testInstrumentIgnoreDirectories"> + <jacoco:instrument destdir="${temp.dir}"> + <dirset dir="${org.jacoco.ant.instrumentTaskTest.classes.dir}" includes="**"/> + </jacoco:instrument> + </target> + + <target name="testInstrumentAndRun"> + <jacoco:instrument destdir="${temp.dir}"> + <fileset dir="${org.jacoco.ant.instrumentTaskTest.classes.dir}" includes="**/*.class"/> + </jacoco:instrument> + <au:assertLogContains text="Instrumented 12 classes to ${temp.dir}"/> + <au:assertFileExists file="${temp.dir}/org/jacoco/ant/InstrumentTaskTest.class" /> + + <java classname="org.jacoco.ant.TestTarget" failonerror="true" fork="true"> + <sysproperty key="jacoco.destfile" file="${temp.dir}/test.exec"/> + <classpath> + <pathelement path="${org.jacoco.ant.instrumentTaskTest.agent.file}"/> + <pathelement path="${temp.dir}"/> + </classpath> + </java> + <au:assertFileExists file="${temp.dir}/test.exec" /> + </target> + +</project>
\ No newline at end of file |