This is an automated email from the ASF dual-hosted git repository.
olabusayo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/daffodil.git
The following commit(s) were added to refs/heads/main by this push:
new 65bf6db85 Restrict what TDML Runner Searches
65bf6db85 is described below
commit 65bf6db85e2fb243fdbc3beddeb17d1bcd4d30ca
Author: olabusayoT <[email protected]>
AuthorDate: Thu Jul 13 12:56:01 2023 -0400
Restrict what TDML Runner Searches
- exclude location information
- update failing tests
- add diagnosticsStripLocationInfo test flag that is set to true as a
default, and add as false to test that need to check the location info
- pass in diagnosticStripFileInfo to verifyAllDiagnosticsFound function
DAFFODIL-541
---
.../resources/org/apache/daffodil/xsd/tdml.xsd | 15 ++++
.../org/apache/daffodil/tdml/TDMLRunner.scala | 79 ++++++++++++++++++++--
.../SchemaDefinitionErrors.tdml | 5 +-
.../daffodil/section06/namespaces/namespaces.tdml | 18 ++---
4 files changed, 100 insertions(+), 17 deletions(-)
diff --git a/daffodil-lib/src/main/resources/org/apache/daffodil/xsd/tdml.xsd
b/daffodil-lib/src/main/resources/org/apache/daffodil/xsd/tdml.xsd
index 5a9c157e3..d46450f5d 100644
--- a/daffodil-lib/src/main/resources/org/apache/daffodil/xsd/tdml.xsd
+++ b/daffodil-lib/src/main/resources/org/apache/daffodil/xsd/tdml.xsd
@@ -184,6 +184,21 @@
<attribute name="unsupported" type="xs:boolean" use="optional"
default="false"/>
<attribute name="validation" type="tns:validationType" use="optional"/>
<attribute name="implementations" type="tns:implementationsType"
use="optional"/>
+ <attribute name="diagnosticsStripLocationInfo" type="xs:boolean"
use="optional" default="true">
+ <annotation>
+ <documentation>We strip the file info from the diagnostics to prevent
false
+ positive matches against the test case's error and warning strings
+ coming from file/dir names.
+
+ As there are tests that look for correct file/dir names, those
+ tests will need to NOT strip them and can do so by setting the
+ test flag to false.
+
+ This is only for purposes of comparing error/warning strings
+ to the diagnostic messages. Users would always see, displayed,
+ the full diagnostic messages.</documentation>
+ </annotation>
+ </attribute>
</attributeGroup>
diff --git
a/daffodil-tdml-lib/src/main/scala/org/apache/daffodil/tdml/TDMLRunner.scala
b/daffodil-tdml-lib/src/main/scala/org/apache/daffodil/tdml/TDMLRunner.scala
index 007e93b1c..2c587913a 100644
--- a/daffodil-tdml-lib/src/main/scala/org/apache/daffodil/tdml/TDMLRunner.scala
+++ b/daffodil-tdml-lib/src/main/scala/org/apache/daffodil/tdml/TDMLRunner.scala
@@ -707,6 +707,13 @@ abstract class TestCase(testCaseXML: NodeSeq, val parent:
DFDLTestSuite) {
}
case other => Assert.invariantFailed("unrecognized validation enum string:
" + other)
}
+ lazy val avoidFalsePositiveMatchesWithLocationInfo =
+ (testCaseXML \ "@diagnosticsStripLocationInfo").text match {
+ case "true" => true
+ case "false" => false
+ case _ => true
+ }
+
lazy val shouldValidate = validationMode != ValidationMode.Off
lazy val expectsValidationError =
if (optExpectedValidationErrors.isDefined)
optExpectedValidationErrors.get.hasDiagnostics
@@ -939,13 +946,23 @@ abstract class TestCase(testCaseXML: NodeSeq, val parent:
DFDLTestSuite) {
!isCrossTest(implString.get) ||
parent.shouldDoErrorComparisonOnCrossTests
)
- VerifyTestCase.verifyAllDiagnosticsFound(diagnostics, Some(errors),
implString)
+ VerifyTestCase.verifyAllDiagnosticsFound(
+ diagnostics,
+ Some(errors),
+ implString,
+ avoidFalsePositiveMatchesWithLocationInfo,
+ )
if (
!isCrossTest(implString.get) ||
parent.shouldDoWarningComparisonOnCrossTests
)
- VerifyTestCase.verifyAllDiagnosticsFound(diagnostics, optWarnings,
implString)
+ VerifyTestCase.verifyAllDiagnosticsFound(
+ diagnostics,
+ optWarnings,
+ implString,
+ avoidFalsePositiveMatchesWithLocationInfo,
+ )
}
}
@@ -1162,6 +1179,7 @@ case class ParserTestCase(ptc: NodeSeq, parentArg:
DFDLTestSuite)
actual.getDiagnostics,
optExpectedValidationErrors,
implString,
+ avoidFalsePositiveMatchesWithLocationInfo,
) // verify all validation errors were found
Assert.invariant(actual.isValidationError)
}
@@ -1180,7 +1198,12 @@ case class ParserTestCase(ptc: NodeSeq, parentArg:
DFDLTestSuite)
!isCrossTest(implString.get) ||
parent.shouldDoWarningComparisonOnCrossTests
)
- VerifyTestCase.verifyAllDiagnosticsFound(allDiags, optExpectedWarnings,
implString)
+ VerifyTestCase.verifyAllDiagnosticsFound(
+ allDiags,
+ optExpectedWarnings,
+ implString,
+ avoidFalsePositiveMatchesWithLocationInfo,
+ )
}
/**
@@ -1541,7 +1564,12 @@ case class UnparserTestCase(ptc: NodeSeq, parentArg:
DFDLTestSuite)
!isCrossTest(implString.get) ||
parent.shouldDoWarningComparisonOnCrossTests
)
- VerifyTestCase.verifyAllDiagnosticsFound(allDiags, optWarnings,
implString)
+ VerifyTestCase.verifyAllDiagnosticsFound(
+ allDiags,
+ optWarnings,
+ implString,
+ avoidFalsePositiveMatchesWithLocationInfo,
+ )
if (roundTrip eq OnePassRoundTrip) {
@@ -1581,7 +1609,12 @@ case class UnparserTestCase(ptc: NodeSeq, parentArg:
DFDLTestSuite)
!isCrossTest(implString.get) ||
parent.shouldDoWarningComparisonOnCrossTests
)
- VerifyTestCase.verifyAllDiagnosticsFound(actual.getDiagnostics,
optWarnings, implString)
+ VerifyTestCase.verifyAllDiagnosticsFound(
+ actual.getDiagnostics,
+ optWarnings,
+ implString,
+ avoidFalsePositiveMatchesWithLocationInfo,
+ )
(shouldValidate, expectsValidationError) match {
case (_, true) => {
@@ -1592,6 +1625,7 @@ case class UnparserTestCase(ptc: NodeSeq, parentArg:
DFDLTestSuite)
actual.getDiagnostics,
optExpectedValidationErrors,
implString,
+ avoidFalsePositiveMatchesWithLocationInfo,
) // verify all validation errors were found
Assert.invariant(actual.isValidationError)
}
@@ -1741,14 +1775,31 @@ object VerifyTestCase {
}
}
+ /**
+ * Do diagnostics verification
+ *
+ * @param actualDiags Actual diagnostics
produced
+ * @param expectedDiags Expected diagnostics
from test cases
+ * @param implString Implementation string
+ * @param avoidFalsePositiveMatchesWithLocationInfo We strip the file info
from the diagnostics to prevent false
+ * positive matches against
the test case's error and warning strings
+ * coming from file/dir
names.
+ * As there are tests that
look for correct file/dir names, those
+ * tests will need to NOT
strip them and can do so by setting the
+ * test flag to false.
+ * This is only for
purposes of comparing error/warning strings
+ * to the diagnostic
messages. Users would always see, displayed,
+ * the full diagnostic
messages.
+ */
def verifyAllDiagnosticsFound(
actualDiags: Seq[Diagnostic],
expectedDiags: Option[ErrorWarningBase],
implString: Option[String],
+ avoidFalsePositiveMatchesWithLocationInfo: Boolean = true,
) = {
val actualDiagMsgs = actualDiags.map {
- _.toString
+ _.toString()
}
val expectedDiagMsgs = expectedDiags
.map {
@@ -1775,8 +1826,13 @@ object VerifyTestCase {
expectedDiag.messages.foreach { expectedMsg =>
{
val wasFound = actualDiags.exists { actualDiag =>
+ val actualDiagMsg = if
(avoidFalsePositiveMatchesWithLocationInfo) {
+ stripLocationInformation(actualDiag.getMessage())
+ } else {
+ actualDiag.getMessage()
+ }
actualDiag.isError == expectedDiag.isError &&
-
actualDiag.getMessage.toLowerCase.contains(expectedMsg.toLowerCase)
+ actualDiagMsg.toLowerCase.contains(expectedMsg.toLowerCase)
}
if (!wasFound) {
throw TDMLException(
@@ -1793,6 +1849,15 @@ object VerifyTestCase {
}
}
+ /**
+ * Strip location info from schema context off diag string message
+ * @param msg diag string message
+ * @return diag message without location information
+ */
+ def stripLocationInformation(msg: String): String = {
+ msg.replaceAll("Location line.*", "")
+ }
+
def verifyNoValidationErrorsFound(actual: TDMLResult, implString:
Option[String]) = {
val actualDiags = actual.getDiagnostics.filter(d => d.isValidation)
if (actualDiags.nonEmpty) {
diff --git
a/daffodil-test/src/test/resources/org/apache/daffodil/section02/schema_definition_errors/SchemaDefinitionErrors.tdml
b/daffodil-test/src/test/resources/org/apache/daffodil/section02/schema_definition_errors/SchemaDefinitionErrors.tdml
index ef3d319b2..1b119ce9f 100644
---
a/daffodil-test/src/test/resources/org/apache/daffodil/section02/schema_definition_errors/SchemaDefinitionErrors.tdml
+++
b/daffodil-test/src/test/resources/org/apache/daffodil/section02/schema_definition_errors/SchemaDefinitionErrors.tdml
@@ -222,8 +222,9 @@
-->
<tdml:parserTestCase name="schema_line_number" root="e1"
- model="lineNumber.dfdl.xsd"
- description="">
+ model="lineNumber.dfdl.xsd"
+ description=""
+ diagnosticsStripLocationInfo="false">
<tdml:document />
<tdml:errors>
diff --git
a/daffodil-test/src/test/resources/org/apache/daffodil/section06/namespaces/namespaces.tdml
b/daffodil-test/src/test/resources/org/apache/daffodil/section06/namespaces/namespaces.tdml
index b65ed3a7a..120de5a87 100644
---
a/daffodil-test/src/test/resources/org/apache/daffodil/section06/namespaces/namespaces.tdml
+++
b/daffodil-test/src/test/resources/org/apache/daffodil/section06/namespaces/namespaces.tdml
@@ -714,7 +714,9 @@
-->
<tdml:parserTestCase name="long_chain_05" root="rabbitHole5"
- model="multi_base_03.dfdl.xsd" description="import a schema - DFDL-6-007R">
+ model="multi_base_03.dfdl.xsd"
+ description="import a schema - DFDL-6-007R"
+ diagnosticsStripLocationInfo="false">
<tdml:document><![CDATA[5632]]></tdml:document>
<tdml:errors>
<tdml:error>Schema Definition Error</tdml:error>
@@ -2141,11 +2143,13 @@
This test shows we get a diagnostic pointing at right file and line number.
-->
<tdml:parserTestCase name="junkAnnotation01" root="x"
- model="junk-annotation-01.dfdl.xsd"
- description="Diagnostic provides proper line number and file when a junk
annotation is found - DFDL-6-007R">
+ model="junk-annotation-01.dfdl.xsd"
+ description="Diagnostic provides proper line number and
file when a junk annotation is found - DFDL-6-007R"
+ diagnosticsStripLocationInfo="false">
<tdml:document />
<tdml:errors>
<tdml:error>Schema Definition Error</tdml:error>
+ <tdml:error>Invalid dfdl annotation</tdml:error>
<tdml:error>junk-annotation-01.dfdl.xsd</tdml:error>
</tdml:errors>
</tdml:parserTestCase>
@@ -2177,8 +2181,6 @@
<tdml:error>Schema Definition Error</tdml:error>
<tdml:error>Invalid dfdl annotation</tdml:error>
<tdml:error>xs:format</tdml:error>
- <tdml:error>Schema context:</tdml:error>
-
<tdml:error>section06/namespaces/multi_base_04_invalid.dfdl.xsd</tdml:error>
</tdml:errors>
</tdml:parserTestCase>
@@ -2197,8 +2199,6 @@
<tdml:error>Schema Definition Error</tdml:error>
<tdml:error>Invalid dfdl annotation</tdml:error>
<tdml:error>xs:format</tdml:error>
- <tdml:error>Schema context:</tdml:error>
-
<tdml:error>section06/namespaces/multi_B_04_invalid.dfdl.xsd</tdml:error>
</tdml:errors>
</tdml:parserTestCase>
@@ -2210,7 +2210,9 @@
-->
<tdml:parserTestCase name="errorLocations_01" root="rabbitHole"
- model="multi_base_13.dfdl.xsd" description="import a schema - DFDL-6-007R">
+ model="multi_base_13.dfdl.xsd"
+ description="import a schema - DFDL-6-007R"
+ diagnosticsStripLocationInfo="false">
<tdml:document><![CDATA[temp]]></tdml:document>
<tdml:errors>
<tdml:error>nonExistent</tdml:error>