-
Notifications
You must be signed in to change notification settings - Fork 2
/
buildTest.xml
306 lines (285 loc) · 11.6 KB
/
buildTest.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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
<project name="atopTests" basedir=".">
<description>
This is the ant build file for running tests used for ATOP development.
</description>
<!-- Globals file which defines various properties and also imports build.properties. -->
<import file="buildGlobals.xml"/>
<fileset id="xspec-files" dir="${basedir}/Tests/xspec" includes="*.xspec"/>
<target name="runXSpecTests" description="Run all XSpec tests" depends="setWindowsAntPath, setUnixAntPath">
<description>
TARGET runXSpecTests
This target is intended to run all XSpec tests by creating an ant build
file which then runs the XSpec project's build file passing the parameter
files containing our tests. [Note: this is not working as of 2022-10-25,
possibly because of the switch to Saxon 11.]
</description>
<pathconvert refid="xspec-files" property="xspec.files" pathsep="${sequenceSeparator}"/>
<!--<xslt style="${basedir}/Tests/xspec_runner.xslt" in="build.xml" out="${basedir}/Tests/xspec_runner.xml">
<classpath location="${saxon}"/>
<param name="files" expression="${xspec.files}"/>
</xslt>-->
<java fork="true" classname="net.sf.saxon.Transform" classpath="${saxon}" failonerror="true">
<jvmarg value="-Xmx1024m"/>
<arg value="-s:build.xml"/>
<arg value="-xsl:${basedir}/Tests/xspec_runner.xslt"/>
<arg value="-o:${basedir}/Tests/xspec_runner.xml"/>
<arg value="files=${xspec.files}"/>
<arg value="sequencesSeparator=${sequenceSeparator}"/>
<arg value="--suppressXsltNamespaceCheck:on"/>
</java>
<!--<subant antfile="xspec_runner.xml" buildpath="Tests" target="xspec_runner"/>-->
<exec executable="${antPath}" dir="Tests" failonerror="true" failifexecutionfails="true">
<arg value="-f"/>
<arg file="${basedir}/Tests/xspec_runner.xml"/>
<arg value="-Dbuildpath=${basedir}/Tests"/>
<arg line="-lib ${basedir}/Lib/saxon"/>
<arg value="xspec_runner"/>
</exec>
</target>
<!-- Targets for generating PLODD test files to test the
PLODD-to-RNG process before we have actually written the
customization-to-PLODD process. I.e., this chunk is not
intended to be permanent or user-facing. (Although it might
grow up in the future.)
-->
<target name="odds2plodds" depends="preplodd,copy_ODDs,deriveAll,transformAll,validateResults"/>
<target name="preplodd">
<echo>Cleaning up temporary test files...</echo>
<delete dir="${basedir}/tmp/CODDs"/>
<delete dir="${basedir}/tmp/PLODDs"/>
</target>
<target name="copy_ODDs">
<echo>Copying ODDs to temporary directories...</echo>
<mkdir dir="${basedir}/tmp/CODDs"/>
<mkdir dir="${basedir}/tmp/PLODDs"/>
<copy todir="${basedir}/tmp/CODDs">
<fileset dir="${basedir}/Tests/resources/" includes="**/*.odd"/>
<flattenmapper/>
</copy>
</target>
<target name="deriveAll">
<echo>Derive all ODD files in temporary directory...</echo>
<foreach target="derive" param="inFile">
<path>
<fileset dir="${basedir}/tmp/CODDs" includes="*.odd"/>
</path>
</foreach>
</target>
<target name="derive">
<echo message="Deriving ${inFile}..."/>
<?syd /path/to/Stylesheets/bin/teitoodd --odd --debug $f `basename $f .odd`.derodd ?>
<basename file="${inFile}" property="plainFileName" suffix=".odd"/>
<property name="outFile" value="${basedir}/tmp/CODDs/${plainFileName}.derodd"/>
<exec executable="${stylesheetsPath}/bin/teitoodd">
<arg value="--odd"/>
<!-- arg value="- - debug"/-->
<arg value="${inFile}"/>
<arg value="${outFile}"/>
</exec>
</target>
<target name="transformAll">
<echo>Transform all derived files to PLODDS...</echo>
<foreach target="transform" param="inFile">
<path>
<fileset dir="${basedir}/tmp/CODDs" includes="*.derodd"/>
</path>
</foreach>
</target>
<target name="transform">
<echo message="Pruning ${inFile}..."/>
<basename file="${inFile}" property="plainFileName" suffix=".derodd"/>
<property name="outFile" value="${basedir}/tmp/PLODDs/${plainFileName}.odd"/>
<xslt style="${basedir}/XSLT/prune_compiled_to_PLODD.xslt" in="${inFile}" out="${outFile}">
<classpath location="${saxon}"/>
</xslt>
</target>
<target name="validateResults">
<echo>Validating output files...</echo>
<if>
<not>
<available file="${basedir}/Schemas/ploddSchemaSpecification.rng"/>
</not>
<then>
<exec executable="${stylesheetsPath}/bin/teitorelaxng">
<arg value="${basedir}/Schemas/ploddSchemaSpecification.odd"/>
<arg value="${basedir}/Schemas/ploddSchemaSpecification.rng"/>
</exec>
</then>
</if>
<jing rngfile="${basedir}/Schemas/ploddSchemaSpecification.rng">
<fileset dir="${basedir}/tmp/PLODDs" includes="*.odd"/>
</jing>
</target>
<target name="transpilePloddTestSchemas">
<description>
TARGET transpilePloddTestSchemas
This target invokes the transpile step to compile
rng schemas from the PLODD files in the transpile_test_suite
folder.
</description>
<foreach target="transpilePloddTestSchema" param="inFile">
<path>
<fileset dir="${basedir}/Tests/transpile_test_suite">
<include name="**/*.plodd"/>
<exclude name="**/*_preprocessed.plodd"/>
</fileset>
</path>
</foreach>
</target>
<target name="transpilePloddTestSchema">
<description>
TARGET transpilePloddTestSchema
This target invokes the transpile step to compile
a single rng schema from the transpile_test_suite.
folder.
</description>
<echo message="Transpiling ${inFile}"/>
<ant antfile="${basedir}/build.xml" target="transpilePlodd">
<property name="inputPlodd" value="${inFile}"/>
</ant>
<dirname property="ploddDir" file="${inFile}"/>
<basename property="ploddName" file="${inFile}" suffix=".plodd"/>
<echo message="Validating generated RNG file ${ploddDir}/${ploddName}.rng"/>
<jing rngfile="${basedir}/Schemas/relaxng.rng">
<fileset dir="${ploddDir}" includes="${ploddName}.rng"/>
</jing>
<echo message="Validating generated Schematron file ${ploddDir}/${ploddName}.sch"/>
<jing rngfile="${basedir}/Schemas/schematron.rng">
<fileset dir="${ploddDir}" includes="${ploddName}.sch"/>
</jing>
</target>
<target name="checkValidInstances">
<description>
TARGET checkValidInstances
This target validates every file found in a Tests/.../instances_valid folder
against the schema found in the folder above it.
</description>
<foreach target="checkValidInstance" param="inFile">
<path>
<fileset dir="${basedir}/Tests">
<include name="**/instances_valid/*.xml"/>
</fileset>
</path>
</foreach>
</target>
<target name="checkValidInstance">
<description>
TARGET checkValidInstance
This target validates a single valid instance file against the schema found
in the folder above it.
</description>
<echo>Validating ${inFile}...</echo>
<propertyregex
property="testSchema"
input="${inFile}"
regexp="^(.+\/)([^\/]+)\/instances_valid\/.+\.xml$"
replace="\1\2/\2.rng"
global="true"/>
<echo>Schema is: ${testSchema}...</echo>
<jing rngfile="${testSchema}" file="${inFile}"/>
</target>
<target name="checkInvalidInstances">
<description>
TARGET checkInvalidInstances
This target validates every file found in a Tests/.../instances_invalid folder
against the schema found in the folder above it, outputs the error messages
to a file, and diffs that file against an expected result.
</description>
<foreach target="checkInvalidInstance" param="inFile">
<path>
<fileset dir="${basedir}/Tests">
<include name="**/instances_invalid/*.xml"/>
</fileset>
</path>
</foreach>
</target>
<target name="checkInvalidInstance">
<description>
TARGET checkInvalidInstance
This target validates a single invalid instance file against the schema found
in the folder above it, outputs the error messages to a file, and diffs that
file against an expected result. Because we need the output in a file to diff
it, we must call jing using java.
</description>
<echo>Validating ${inFile}...</echo>
<propertyregex
property="testSchema"
input="${inFile}"
regexp="^(.+\/)([^\/]+)\/instances_invalid\/.+\.xml$"
replace="\1\2/\2.rng"
global="true"/>
<propertyregex
property="folder"
input="${inFile}"
regexp="^(.+\/)([^\/]+)\/instances_invalid\/.+\.xml$"
replace="\1\2/"
global="true"/>
<mkdir dir="${folder}actual_results"/>
<basename property="messagesFile" file="${inFile}" suffix=".xml"/>
<echo>Schema is: ${testSchema}, and results will go to: ${folder}actual_results/${messagesFile}.txt.</echo>
<java fork="true" failonerror="false" jar="${jing}" output="${folder}actual_results/${messagesFile}.txt">
<arg value="${testSchema}"/>
<arg value="${inFile}"/>
</java>
<!-- Having generated the errors file, we need to strip all local paths
from it. -->
<replaceregexp file="${folder}actual_results/${messagesFile}.txt" match="^.+\/instances_invalid\/" replace="" flags="gmi" byline="true"/>
<!-- Now diff against expected-results. -->
<antcall target="diffFile">
<param name="inFile" value="${folder}actual_results/${messagesFile}.txt"/>
</antcall>
</target>
<target name="diffFile">
<description>
TARGET diffFile
The diffFile target is passed the name of a transformation result
or other output file from a validation operation. It infers the
location of the expected results against which to diff this file,
and then does a comparison between the two, using the ant filesmatch
condition. If that fails, it then reports the results and fails
the build.
</description>
<basename property="inFileName" file="${inFile}"/>
<propertyregex
property="expectedResults"
input="${inFile}"
regexp="^(.+\/[^\/]+)\/actual_results\/(.+\.txt)$"
replace="\1/expected_results/\2"
global="true"
/>
<trycatch>
<try>
<echo message="about to compare files:"/>
<!--
Note: the format of the following message is designed to allow
the user to copy-and-paste the two file paths into a `diff` or
`cp` command. Just select everything after the '='.
-->
<echo message="actual results, expected results = ${inFile} ${expectedResults}"/>
<fail message="Sadly, ${inFile} is different from ${expectedResults}.">
<condition>
<not>
<filesmatch textfile="true" file1="${inFile}" file2="${expectedResults}"/>
</not>
</condition>
</fail>
</try>
<catch>
<echo message="ERROR: DIFF FAILURE..."/>
<fail message="Build failed because of differences between ${inFile} and ${expectedResults}. Diff these files to diagnose the problem."/>
</catch>
</trycatch>
</target>
<target name="runTranspileTests">
<description>
TARGET runTranspileTests
This target first calls the transpile step to create
rng schemas from all of the .plodd files in the PLODD_test_suite
folder, then it runs the validation tests to check all the valid
instances and invalid instances.
</description>
<antcall target="transpilePloddTestSchemas"/>
<antcall target="checkValidInstances"/>
<antcall target="checkInvalidInstances"/>
</target>
</project>