-
Notifications
You must be signed in to change notification settings - Fork 2
/
build_dita2unit-test_template.xml
215 lines (213 loc) · 6.84 KB
/
build_dita2unit-test_template.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<?xml version="1.0" encoding="UTF-8"?>
<!--ant-->
<!--
This file is part of the DITA-OT Unit Test Plug-in project.
See the accompanying LICENSE file for applicable licenses.
-->
<project name="fox.jason.unit-test" xmlns:if="ant:if" xmlns:unless="ant:unless">
<target name="unit-test.log.init">
<typedef file="${dita.plugin.fox.jason.unit-test.dir}/resource/antlib.xml"/>
</target>
<target name="unit-test.init">
<dita-ot-fail id="DOTA069F">
<condition>
<not>
<available file="${args.input}" type="dir"/>
</not>
</condition>
<param name="1" value="${args.input}"/>
</dita-ot-fail>
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement
location="${dita.plugin.fox.jason.unit-test.dir}/lib/ant-contrib-1.0b3.jar"
/>
</classpath>
</taskdef>
<taskdef classname="com.oopsconsultancy.xmltask.ant.XmlTask" name="xmltask">
<classpath>
<pathelement location="${dita.plugin.fox.jason.unit-test.dir}/lib/xmltask.jar"/>
</classpath>
</taskdef>
<property name="test.root.dir" value="${dita.temp.dir}/unit-test/fixtures"/>
<basename file="${args.input}" property="args.input.dirname"/>
<condition property="testsuite.found">
<available file="${args.input}/test" type="dir"/>
</condition>
<!-- If args.input is a test suite, copy over the test suite to temp -->
<mkdir
dir="${test.root.dir}/${args.input.dirname}/test"
if:set="testsuite.found"
/>
<copy
if:set="testsuite.found"
todir="${test.root.dir}/${args.input.dirname}/test"
>
<fileset dir="${args.input}/test"/>
</copy>
<!--
If args.input was a directory, copy over a every test suite found underneath
it to temp.
-->
<mkdir dir="${test.root.dir}" unless:set="testsuite.found"/>
<for param="test-suite.dir" trim="true" unless:set="testsuite.found">
<path>
<dirset dir="${args.input}">
<include name="*"/>
</dirset>
</path>
<sequential>
<local name="testsuite.found"/>
<condition property="testsuite.found">
<available file="@{test-suite.dir}/test" type="dir"/>
</condition>
<condition property="test.coverage.report" value="true">
<available file="@{test-suite.dir}/test/template-coverage.xml" type="file"/>
</condition>
<propertyregex
casesensitive="false"
input="@{test-suite.dir}"
override="true"
property="test-suite"
regexp="([^/]*)$"
select="\1"
/>
<mkdir dir="${test.root.dir}/${test-suite}/test" if:set="testsuite.found"/>
<copy if:set="testsuite.found" todir="${test.root.dir}/${test-suite}/test">
<fileset dir="@{test-suite.dir}/test"/>
</copy>
</sequential>
</for>
<condition property="test.coverage.report" value="true" else="false">
<available file="${args.input}/test/template-coverage.xml" type="file"/>
</condition>
</target>
<!--
Target to create a unit-test fixture for each suite.
-->
<target
depends="unit-test.log.init"
name="generate-fixtures"
description="Create Unit Test Fixtures" >
<!-- Now iterate across each test suite and generate the fixtures -->
<for param="test-suite.dir" trim="true">
<path>
<dirset dir="${test.root.dir}">
<include name="*"/>
</dirset>
</path>
<sequential>
<propertyregex
casesensitive="false"
input="@{test-suite.dir}"
override="true"
property="test-suite"
regexp="([^/]*)$"
select="\1"
/>
<local name="test-suite.disabled"/>
<available
file="@{test-suite.dir}/test/disabled.txt"
property="test-suite.disabled"
/>
<dita-ot-echo id="UNIT004W" if:set="test-suite.disabled">
<param name="1" value="The test suite '${test-suite}' is disabled"/>
</dita-ot-echo>
<dita-ot-echo id="UNIT002I" unless:set="test-suite.disabled">
<param name="1" value="Generating fixtures for '${test-suite}'"/>
</dita-ot-echo>
<create-fixture
dir="@{test-suite.dir}"
suite="${test-suite}"
unless:set="test-suite.disabled"
/>
</sequential>
</for>
</target>
<!--
Iterate across each test suite in turn and run the unit tests using ant-unit.
-->
<target name="unit-test" description="Run a unit test suite">
<property name="test.copy.dir" value="${args.input}"/>
<property name="test.copy" value="false"/>
<condition
property="test.suite.run.message"
value="Updating test expectations"
else="Running tests"
>
<istrue value="${test.copy}"/>
</condition>
<propertyset id="test-properties">
<propertyref name="test.copy.dir"/>
<propertyref name="test.copy"/>
<propertyref name="test.propertyfile"/>
<propertyref name="test.coverage.report"/>
<propertyref name="dita.dir"/>
</propertyset>
<taskdef resource="org/apache/ant/antunit/antlib.xml">
<classpath>
<pathelement
location="${dita.plugin.fox.jason.unit-test.dir}/lib/ant-antunit-1.4.jar"
/>
</classpath>
</taskdef>
<mkdir dir="${dita.temp.dir}/unit-test/report"/>
<for keepgoing="true" param="test-suite.dir">
<path>
<dirset dir="${test.root.dir}">
<present targetdir="${test.root.dir}">
<mapper from="*" to="*/fixture.xml" type="glob"/>
</present>
</dirset>
</path>
<sequential>
<xmltask source="@{test-suite.dir}/fixture.xml">
<call path="//project/description">
<param default="" name="description" path="text()"/>
<actions>
<dita-ot-echo id="UNIT002I">
<param name="1" value="${test.suite.run.message} for '@{description}'"/>
</dita-ot-echo>
<antunit taskname="test-suite" errorproperty="test-failure" failOnError="false">
<file file="@{test-suite.dir}/fixture.xml"/>
<xmllistener logLevel="warning" toDir="${dita.temp.dir}/unit-test/report"/>
<plainlistener/>
<propertyset refid="test-properties"/>
</antunit>
</actions>
</call>
</xmltask>
</sequential>
</for>
</target>
<!--
Creates a formatted HTML report using the optional JUnitReport task.
-->
<target name="unit-test.report" description="Create test results HTML">
<junitreport
taskname="test-report"
todir="${dita.temp.dir}"
unless:true="test.copy"
>
<fileset dir="${dita.temp.dir}/unit-test/report" includes="*.xml"/>
<report
format="noframes"
styledir="${dita.plugin.fox.jason.unit-test.dir}/xsl"
todir="${output.dir}"
/>
</junitreport>
<move
file="${output.dir}/junit-noframes.html"
tofile="${output.dir}/test-results.html"
/>
<dita-ot-fail id="UNIT001F" if:set="test-failure" unless:true="test.copy"/>
<unit-test-success-echo/>
</target>
<!--
Ant target executed to run a unit test suite.
-->
<target
depends="build-init,unit-test.init,generate-fixtures,unit-test,coverage.report,unit-test.report"
name="dita2unit-test"
/>
</project>