/
CoverageTaskTest.xml
161 lines (133 loc) · 5.61 KB
/
CoverageTaskTest.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2009, 2021 Mountainminds GmbH & Co. KG and Contributors
This program and the accompanying materials are made available under
the terms of the Eclipse Public License 2.0 which is available at
http://www.eclipse.org/legal/epl-2.0
SPDX-License-Identifier: EPL-2.0
Contributors:
Brock Janiczak - initial API and implementation
-->
<project name="JaCoCo Coverage 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}/jacoco.exec" />
</target>
<target name="tearDown">
<delete dir="${temp.dir}" quiet="false" failonerror="true"/>
</target>
<target name="testNoSubTasks">
<au:expectfailure expectedMessage="A child task must be supplied for the coverage task">
<jacoco:coverage/>
</au:expectfailure>
</target>
<target name="testMultipleSubTasks">
<au:expectfailure expectedMessage="Only one child task can be supplied to the coverge task">
<jacoco:coverage>
<java classname="org.jacoco.ant.TestTarget" fork="true" failonerror="true">
<classpath path="${org.jacoco.ant.coverageTaskTest.classes.dir}"/>
</java>
<java classname="org.jacoco.ant.TestTarget" fork="true" failonerror="true">
<classpath path="${org.jacoco.ant.coverageTaskTest.classes.dir}"/>
</java>
</jacoco:coverage>
</au:expectfailure>
<au:assertLogDoesntContain text="Target executed"/>
</target>
<target name="testInvalidSubTask">
<au:expectfailure expectedMessage="jar is not a valid child of the coverage task">
<jacoco:coverage>
<jar destfile="test.jar"/>
</jacoco:coverage>
</au:expectfailure>
</target>
<target name="testCoverageOfForkedJava">
<jacoco:coverage destfile="${exec.file}">
<java classname="org.jacoco.ant.TestTarget" fork="true" failonerror="true">
<classpath path="${org.jacoco.ant.coverageTaskTest.classes.dir}"/>
</java>
</jacoco:coverage>
<au:assertLogContains text="Enhancing java with coverage"/>
<au:assertFileExists file="${exec.file}"/>
<au:assertLogContains text="Target executed"/>
</target>
<target name="testCoverageOfForkedJavaWithVariable">
<property name="trueProperty" value="true"/>
<jacoco:coverage destfile="${exec.file}">
<java classname="org.jacoco.ant.TestTarget" fork="${trueProperty}" failonerror="true">
<classpath path="${org.jacoco.ant.coverageTaskTest.classes.dir}"/>
</java>
</jacoco:coverage>
<au:assertLogContains text="Enhancing java with coverage"/>
<au:assertFileExists file="${exec.file}"/>
<au:assertLogContains text="Target executed"/>
</target>
<target name="testCoverageOfForkedJavaDisabled">
<jacoco:coverage enabled="false" destfile="${exec.file}">
<java classname="org.jacoco.ant.TestTarget" fork="true" failonerror="true">
<classpath path="${org.jacoco.ant.coverageTaskTest.classes.dir}"/>
</java>
</jacoco:coverage>
<au:assertLogDoesntContain text="Enhancing java with coverage"/>
<au:assertFileDoesntExist file="${exec.file}"/>
<au:assertLogContains text="Target executed"/>
</target>
<target name="testCoverageOfNonForkedJava">
<au:expectfailure expectedMessage="Coverage can only be applied on a forked VM">
<jacoco:coverage>
<java classname="org.jacoco.ant.TestTarget" fork="false" failonerror="true">
<classpath path="${org.jacoco.ant.coverageTaskTest.classes.dir}"/>
</java>
</jacoco:coverage>
</au:expectfailure>
<au:assertLogDoesntContain text="Target executed"/>
</target>
<target name="testCoverageOfForkedJUnit">
<jacoco:coverage destfile="${exec.file}">
<junit fork="true" haltonfailure="true" showoutput="true">
<classpath path="${java.class.path}"/>
<test name="org.jacoco.ant.TestTarget" />
</junit>
</jacoco:coverage>
<au:assertLogContains text="Enhancing junit with coverage"/>
<au:assertFileExists file="${exec.file}"/>
<au:assertLogContains text="Target executed"/>
</target>
<target name="testCoverageOfForkedJUnitDisabled">
<jacoco:coverage enabled="false" destfile="${exec.file}">
<junit fork="true" haltonfailure="true" showoutput="true">
<classpath path="${java.class.path}"/>
<test name="org.jacoco.ant.TestTarget" />
</junit>
</jacoco:coverage>
<au:assertLogDoesntContain text="Enhancing junit with coverage"/>
<au:assertFileDoesntExist file="${exec.file}"/>
<au:assertLogContains text="Target executed"/>
</target>
<target name="testCoverageOfNonForkedJUnit">
<au:expectfailure expectedMessage="Coverage can only be applied on a forked VM">
<jacoco:coverage>
<junit fork="false" haltonfailure="true" showoutput="true">
<classpath path="${java.class.path}"/>
<test name="org.jacoco.ant.TestTarget" />
</junit>
</jacoco:coverage>
</au:expectfailure>
<au:assertLogDoesntContain text="Target executed"/>
</target>
<target name="testInclBootstrapClasses">
<jacoco:coverage destfile="${exec.file}" inclbootstrapclasses="true" includes="java/sql/*">
<java classname="org.jacoco.ant.TestTarget" fork="true" failonerror="true">
<classpath path="${org.jacoco.ant.coverageTaskTest.classes.dir}"/>
</java>
</jacoco:coverage>
<au:assertLogContains text="Enhancing java with coverage"/>
<au:assertFileExists file="${exec.file}"/>
<au:assertLogContains text="Target executed"/>
<java classname="org.jacoco.ant.DumpExecClassNames" fork="true" classpath="${java.class.path}" failonerror="true">
<arg value="${exec.file}" />
</java>
<au:assertLogContains text="java/sql/Timestamp"/>
</target>
</project>