Compare formatted XML files in the Doxygen test.

Comparing formatted XML files makes the comparison less sensitive
to whitespace and newline differences between XML documents, and
also makes the subsequent diff more informative, if any differences
are found.
This commit is contained in:
Andrey Semashev 2024-05-14 03:02:12 +03:00
parent 5bdebb90a4
commit fe6f1a818f
3 changed files with 68 additions and 4 deletions

View File

@ -1 +1,2 @@
html
autodoc.xml

View File

@ -1,10 +1,12 @@
# Copyright 2009 Daniel James.
# Copyright 2024 Andrey Semashev
# Distributed under the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
using boostbook ;
using doxygen ;
import xsltproc ;
import make ;
import os ;
doxygen autodoc
@ -14,13 +16,22 @@ doxygen autodoc
<xsl:param>"boost.doxygen.reftitle=Example Reference"
;
# Applies format.xsl to an XML file to reduce potential newline/whitespace
# differences and make the subsequent diff more informative.
rule format-xml ( target : source : properties * )
{
xsltproc.xslt $(target) : $(source) format.xsl : $(properties) ;
}
make autodoc.xml.formatted : autodoc.xml : format-xml ;
make autodoc.gold.formatted : autodoc.gold : format-xml ;
if [ os.name ] = NT
{
actions compare
{
comp /A $(>[1]) $(>[2]) && echo "Stamped" >$(<)
}
}
else
{
@ -30,7 +41,7 @@ else
}
}
make check : autodoc.xml autodoc.gold : @compare ;
make check : autodoc.xml.formatted autodoc.gold.formatted : @compare ;
boostbook standalone
:

52
test/doxygen/format.xsl Normal file
View File

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (c) 2024 Andrey Semashev
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" encoding="utf-8"/>
<xsl:param name="indent-step" select="' '"/>
<xsl:template match="processing-instruction() | comment()">
<xsl:param name="indent" select="''"/>
<xsl:text>&#10;</xsl:text><!-- Newline -->
<xsl:value-of select="$indent"/>
<xsl:copy/>
</xsl:template>
<xsl:template match="text()">
<xsl:param name="indent" select="''"/>
<xsl:if test="normalize-space(.) != ''">
<xsl:text>&#10;</xsl:text><!-- Newline -->
<xsl:value-of select="$indent"/>
<xsl:value-of select="normalize-space(.)"/>
</xsl:if>
</xsl:template>
<xsl:template match="*">
<xsl:param name="indent" select="''"/>
<xsl:text>&#10;</xsl:text><!-- Newline -->
<xsl:value-of select="$indent"/>
<xsl:choose>
<xsl:when test="count(./*) &gt; 0">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates>
<xsl:with-param name="indent" select="concat($indent, $indent-step)"/>
</xsl:apply-templates>
<xsl:text>&#10;</xsl:text><!-- Newline -->
<xsl:value-of select="$indent"/>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>