Skip to content

Commit 685bb16

Browse files
authored
Merge pull request doxygen#6889 from albert-github/feature/bug_xml_xsd_tests
Add possibility of checking XML against XSD in doxygen tests
2 parents 431bef0 + 109fcea commit 685bb16

File tree

1 file changed

+66
-9
lines changed

1 file changed

+66
-9
lines changed

testing/runtests.py

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def prepare_test(self):
9191
if 'config' in self.config:
9292
for option in self.config['config']:
9393
print(option, file=f)
94-
if (self.args.xml):
94+
if (self.args.xml or self.args.xmlxsd):
9595
print('GENERATE_XML=YES', file=f)
9696
print('XML_OUTPUT=%s/out' % self.test_out, file=f)
9797
else:
@@ -182,11 +182,13 @@ def perform_test(self,testmgr):
182182
failed_latex=False
183183
failed_docbook=False
184184
failed_rtf=False
185+
failed_xmlxsd=False
185186
msg = ()
186187
# look for files to check against the reference
187-
if self.args.xml:
188-
failed_xml=True
189-
if 'check' in self.config:
188+
if self.args.xml or self.args.xmlxsd:
189+
failed_xml=False
190+
if 'check' in self.config and self.args.xml:
191+
failed_xml=True
190192
for check in self.config['check']:
191193
check_file='%s/out/%s' % (self.test_out,check)
192194
# check if the file we need to check is actually generated
@@ -215,9 +217,62 @@ def perform_test(self,testmgr):
215217
if failed_xml:
216218
msg+= (xml_msg,)
217219
break
218-
if not failed_xml and not self.args.keep:
219-
xml_output='%s/out' % self.test_out
220-
shutil.rmtree(xml_output,ignore_errors=True)
220+
failed_xmlxsd=False
221+
if self.args.xmlxsd:
222+
xmlxsd_output='%s/out' % self.test_out
223+
if (sys.platform == 'win32'):
224+
redirx=' 2> %s/temp >nul:'%xmlxsd_output
225+
else:
226+
redirx='2>%s/temp >/dev/null'%xmlxsd_output
227+
#
228+
index_xml = []
229+
index_xml.append(glob.glob('%s/index.xml' % (xmlxsd_output)))
230+
index_xml.append(glob.glob('%s/*/*/index.xml' % (xmlxsd_output)))
231+
index_xml = ' '.join(list(itertools.chain.from_iterable(index_xml))).replace(self.args.outputdir +'/','').replace('\\','/')
232+
index_xsd = []
233+
index_xsd.append(glob.glob('%s/index.xsd' % (xmlxsd_output)))
234+
index_xsd.append(glob.glob('%s/*/*/index.xsd' % (xmlxsd_output)))
235+
index_xsd = ' '.join(list(itertools.chain.from_iterable(index_xsd))).replace(self.args.outputdir +'/','').replace('\\','/')
236+
exe_string = '%s --noout --schema %s %s %s' % (self.args.xmllint,index_xsd,index_xml,redirx)
237+
exe_string += ' %s more "%s/temp"' % (separ,xmlxsd_output)
238+
239+
xmllint_out = os.popen(exe_string).read()
240+
if xmllint_out:
241+
xmllint_out = re.sub(r'.*validates','',xmllint_out).rstrip('\n')
242+
else:
243+
msg += ('Failed to run %s with schema %s for files: %s' % (self.args.xmllint,index_xsd,index_xml),)
244+
failed_xmlxsd=True
245+
if xmllint_out:
246+
msg += (xmllint_out,)
247+
failed_xmlxsd=True
248+
#
249+
compound_xml = []
250+
compound_xml.append(glob.glob('%s/*.xml' % (xmlxsd_output)))
251+
compound_xml.append(glob.glob('%s/*/*/*.xml' % (xmlxsd_output)))
252+
compound_xml = ' '.join(list(itertools.chain.from_iterable(compound_xml))).replace(self.args.outputdir +'/','').replace('\\','/')
253+
compound_xml = re.sub(r' [^ ]*/index.xml','',compound_xml)
254+
compound_xml = re.sub(r'[^ ]*/index.xml ','',compound_xml)
255+
256+
compound_xsd = []
257+
compound_xsd.append(glob.glob('%s/compound.xsd' % (xmlxsd_output)))
258+
compound_xsd.append(glob.glob('%s/*/*/compound.xsd' % (xmlxsd_output)))
259+
compound_xsd = ' '.join(list(itertools.chain.from_iterable(compound_xsd))).replace(self.args.outputdir +'/','').replace('\\','/')
260+
exe_string = '%s --noout --schema %s %s %s' % (self.args.xmllint,compound_xsd,compound_xml,redirx)
261+
exe_string += ' %s more "%s/temp"' % (separ,xmlxsd_output)
262+
263+
xmllint_out = os.popen(exe_string).read()
264+
if xmllint_out:
265+
xmllint_out = re.sub(r'.*validates','',xmllint_out).rstrip('\n')
266+
else:
267+
msg += ('Failed to run %s with schema %s for files: %s' % (self.args.xmllint,compound_xsd,compound_xml),)
268+
failed_xmlxsd=True
269+
if xmllint_out:
270+
msg += (xmllint_out,)
271+
failed_xmlxsd=True
272+
273+
if not failed_xml and not failed_xmlxsd and not self.args.keep:
274+
xml_output='%s/out' % self.test_out
275+
shutil.rmtree(xml_output,ignore_errors=True)
221276

222277
if (self.args.rtf):
223278
# no tests defined yet
@@ -282,7 +337,7 @@ def perform_test(self,testmgr):
282337
elif not self.args.keep:
283338
shutil.rmtree(latex_output,ignore_errors=True)
284339

285-
if failed_xml or failed_html or failed_latex or failed_docbook or failed_rtf:
340+
if failed_xml or failed_html or failed_latex or failed_docbook or failed_rtf or failed_xmlxsd:
286341
testmgr.ok(False,self.test_name,msg)
287342
return
288343

@@ -374,6 +429,8 @@ def main():
374429
'create docbook output and check with xmllint',action="store_true")
375430
parser.add_argument('--xhtml',help=
376431
'create xhtml output and check with xmllint',action="store_true")
432+
parser.add_argument('--xmlxsd',help=
433+
'create xml output and check with xmllint against xsd',action="store_true")
377434
parser.add_argument('--pdf',help='create LaTeX output and create pdf from it',
378435
action="store_true")
379436
parser.add_argument('--subdirs',help='use the configuration parameter CREATE_SUBDIRS=YES',
@@ -387,7 +444,7 @@ def main():
387444
args = parser.parse_args(test_flags + sys.argv[1:])
388445

389446
# sanity check
390-
if (not args.xml) and (not args.pdf) and (not args.xhtml) and (not args.docbook and (not args.rtf)):
447+
if (not args.xml) and (not args.pdf) and (not args.xhtml) and (not args.docbook and (not args.rtf) and (not args.xmlxsd)):
391448
args.xml=True
392449
if (not args.updateref is None) and (args.ids is None) and (args.all is None):
393450
parser.error('--updateref requires either --id or --all')

0 commit comments

Comments
 (0)