stevedlawrence commented on code in PR #1301:
URL: https://github.com/apache/daffodil/pull/1301#discussion_r1763664458
##########
daffodil-tdml-lib/src/main/scala/org/apache/daffodil/tdml/TDMLRunner.scala:
##########
@@ -730,6 +740,16 @@ abstract class TestCase(testCaseXML: NodeSeq, val parent:
DFDLTestSuite) {
lazy val ignoreUnexpectedWarnings: Boolean =
if (tcIgnoreUnexpectedWarnings == "") defaultIgnoreUnexpectedWarnings
else tcIgnoreUnexpectedWarnings.toBoolean
+ lazy val tcIgnoreUnexpectedValidationErrors: String =
+ (testCaseXML \ "@ignoreUnexpectedValidationErrors").text
+ lazy val ignoreUnexpectedValidationErrors: Boolean =
+ if (
+ optExpectedValidationErrors.isDefined
+ && !optExpectedValidationErrors.get.exists(_.hasDiagnostics)
+ ) { // <tdml:validationErrors/>
+ false // ignore unexpected validation errors will be false if
<tdml:validationErrors />
Review Comment:
Is it worth adding a `System.err.println()` that says something like
> Use of <tdml:validationErrors /> is deprecated, use
ignoreUnexpectedValidationError="false" instead.
Then eventually we can remove support for this.
Or maybe we should just remove support for it now? No tests in our
regression suite use `<tdml:validationErrors />` and I only see a handful of
Daffodil tests use this that should be pretty straightforward to update.
##########
daffodil-tdml-processor/src/test/scala/org/apache/daffodil/processor/tdml/TestTDMLRunnerValidationErrors.scala:
##########
@@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.daffodil.processor.tdml
+
+import org.apache.daffodil.lib.Implicits.intercept
+import org.apache.daffodil.lib.xml.XMLUtils
+import org.apache.daffodil.tdml.Runner
+import org.apache.daffodil.tdml.TDMLException
+
+import org.junit.Assert.assertTrue
+import org.junit.Test
+
+class TestTDMLRunnerValidationErrors {
+
+ lazy val testSuite1 =
+ <ts:testSuite xmlns:dfdl={XMLUtils.DFDL_NAMESPACE} xmlns:xs={
+ XMLUtils.XSD_NAMESPACE
+ } xmlns:ex={XMLUtils.EXAMPLE_NAMESPACE} xmlns:ts={
+ XMLUtils.TDML_NAMESPACE
+ } suiteName="theSuiteName"
+ defaultValidation="on"
+ defaultIgnoreUnexpectedValidationErrors="false">
+ <ts:defineSchema name="schema1">
+ <xs:include
schemaLocation="/org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd"/>
+ <dfdl:format ref="ex:GeneralFormat"/>
+ <xs:element name="r" dfdl:lengthKind="delimited">
+ <xs:simpleType>
+ <xs:restriction base="xs:string">
+ <xs:enumeration value="YES"/>
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:element>
+ </ts:defineSchema>
+
+ <ts:parserTestCase name="expectsNoValidationErrorGetsValidationError"
root="r" model="schema1" roundTrip="onePass">
+ <ts:infoset>
+ <ts:dfdlInfoset>
+ <ex:r>foo</ex:r>
+ </ts:dfdlInfoset>
+ </ts:infoset>
+ <ts:document>foo</ts:document>
+ </ts:parserTestCase>
+
+ <ts:parserTestCase name="expectsValidationErrorGetsNoValidationError"
root="r" model="schema1" roundTrip="onePass">
+ <ts:infoset>
+ <ts:dfdlInfoset>
+ <ex:r>YES</ex:r>
+ </ts:dfdlInfoset>
+ </ts:infoset>
+ <ts:document>YES</ts:document>
+
+ <ts:validationErrors>
+ <ts:error>Validation Error</ts:error>
+ <ts:error>r failed</ts:error>
+ </ts:validationErrors>
+ </ts:parserTestCase>
+
+ <ts:parserTestCase name="expectsValidationErrorGetsValidationError"
root="r" model="schema1" roundTrip="onePass">
+ <ts:infoset>
+ <ts:dfdlInfoset>
+ <ex:r>foo</ex:r>
+ </ts:dfdlInfoset>
+ </ts:infoset>
+ <ts:document>foo</ts:document>
+
+ <ts:validationErrors>
+ <ts:error>Validation Error</ts:error>
+ <ts:error>r failed</ts:error>
+ </ts:validationErrors>
+ </ts:parserTestCase>
+
+ <ts:parserTestCase name="expectsNoValidationErrorGetsNoValidationError"
root="r" model="schema1" roundTrip="onePass">
+ <ts:infoset>
+ <ts:dfdlInfoset>
+ <ex:r>YES</ex:r>
+ </ts:dfdlInfoset>
+ </ts:infoset>
+ <ts:document>YES</ts:document>
+ </ts:parserTestCase>
+ </ts:testSuite>
+
+ lazy val testSuite2 =
+ <ts:testSuite xmlns:dfdl={XMLUtils.DFDL_NAMESPACE} xmlns:xs={
+ XMLUtils.XSD_NAMESPACE
+ } xmlns:ex={XMLUtils.EXAMPLE_NAMESPACE} xmlns:ts={
+ XMLUtils.TDML_NAMESPACE
+ } suiteName="theSuiteName"
+ defaultValidation="on">
+ <ts:defineSchema name="schema1">
+ <xs:include
schemaLocation="/org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd"/>
+ <dfdl:format ref="ex:GeneralFormat"/>
+ <xs:element name="r" dfdl:lengthKind="delimited">
+ <xs:simpleType>
+ <xs:restriction base="xs:string">
+ <xs:enumeration value="YES"/>
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:element>
+ </ts:defineSchema>
+
+ <ts:parserTestCase name="expectsNoValidationErrorGetsValidationError2"
+ root="r" model="schema1" roundTrip="onePass"
+ ignoreUnexpectedValidationErrors="true">
+ <ts:infoset>
+ <ts:dfdlInfoset>
+ <ex:r>foo</ex:r>
+ </ts:dfdlInfoset>
+ </ts:infoset>
+ <ts:document>foo</ts:document>
+ </ts:parserTestCase>
+
+ <ts:parserTestCase name="expectsNoValidationErrorGetsValidationError3"
+ root="r" model="schema1" roundTrip="onePass"
+ ignoreUnexpectedValidationErrors="false">
+ <ts:infoset>
+ <ts:dfdlInfoset>
+ <ex:r>foo</ex:r>
+ </ts:dfdlInfoset>
+ </ts:infoset>
+ <ts:document>foo</ts:document>
+ </ts:parserTestCase>
+ </ts:testSuite>
+
+ @Test def test_expectsNoValidationErrorGetsValidationError(): Unit = {
+ val runner = new Runner(testSuite1)
+ val e = intercept[TDMLException] {
+ runner.runOneTest("expectsNoValidationErrorGetsValidationError")
+ }
+ runner.reset
+ val msg = e.getMessage()
+ assertTrue(
+ msg.contains(
+ "ignoreUnexpectedDiags = false and test does not expect
ValidationError diagnostics"
Review Comment:
Can we change the error message so this says
"ignoreUnexpectedValidationErrors = false instead of "ignoreUnexpectedDiags".
`ignoreUnexpectedDiags` is kindof an internal flag that might confuse users
since it doesn't map directly to what appears in tdml files.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]