You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by "mbeckerle (via GitHub)" <gi...@apache.org> on 2024/11/01 21:14:44 UTC

[PR] Improve diagnostic in TDML Runner [daffodil]

mbeckerle opened a new pull request, #1357:
URL: https://github.com/apache/daffodil/pull/1357

   I decided to fix an ancient bug. 
   
   Note that this change enforces the syntax of TDML better. 
   The dfdlInfoset element used to tolerate having spurious text in it, so long as it also had a root element.
   Two TDML files had to be fixed in Daffodil.
   
   If TDML files in schema projects have these spurious characters that were formerly ignored, this change will break
   those tests.
   
   DAFFODIL-533


-- 
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: commits-unsubscribe@daffodil.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Improve diagnostic in TDML Runner [daffodil]

Posted by "mbeckerle (via GitHub)" <gi...@apache.org>.
mbeckerle merged PR #1357:
URL: https://github.com/apache/daffodil/pull/1357


-- 
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: commits-unsubscribe@daffodil.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Improve diagnostic in TDML Runner [daffodil]

Posted by "stevedlawrence (via GitHub)" <gi...@apache.org>.
stevedlawrence commented on code in PR #1357:
URL: https://github.com/apache/daffodil/pull/1357#discussion_r1827834606


##########
daffodil-tdml-lib/src/main/scala/org/apache/daffodil/tdml/TDMLRunner.scala:
##########
@@ -2769,41 +2770,52 @@ case class Infoset(i: NodeSeq, parent: TestCase) {
 
 case class DFDLInfoset(di: Node, parent: Infoset) {
 
-  private lazy val infosetNodeSeq = {
-    val testCase: TestCase = parent.parent
-    val loader = testCase.parent.loader
-    val optDataSchema: Option[URI] = {
-      testCase.optSchemaFileURI.orElse(testCase.optEmbeddedSchema.map { _.uriForLoading })
-    }
-    val src =
-      (di \ "@type").toString match {
-        case "infoset" | "" => {
-          val rawElem = di.child.filter {
-            _.isInstanceOf[scala.xml.Elem]
-          }.head
-          UnitTestSchemaSource(rawElem, testCase.tcName)
-        }
-        case "file" => {
-          val path = di.text.trim()
-          val maybeURI = parent.parent.parent.findTDMLResource(path)
-          val uri = maybeURI.getOrElse(
-            throw new FileNotFoundException(
-              "TDMLRunner: infoset file '" + path + "' was not found"
-            )
-          )
-          URISchemaSource(uriToDiagnosticFile(uri), uri)
-        }
-        case value => Assert.abort("Unknown value for type attribute on dfdlInfoset: " + value)
-      }
+  private lazy val testCase: TestCase = parent.parent
+  private lazy val loader = testCase.parent.loader
+  private val ty: String = {
+    val t = (di \ "@type").text.trim
+    if (t.isEmpty) "infoset" else t
+  }
+
+  private val elemOrStr: Either[Elem, String] = {
+    val (elems, others) = di.child.partition(_.isInstanceOf[scala.xml.Elem])
+    (elems, others.text.trim) match {
+      case (Seq(elem: Elem), "") if (ty == "infoset") => Left(elem)
+      case (Seq(), str) if (ty == "file") => Right(str)
+      case _ =>
+        Assert.usageError(
+          """dfdlInfoset element must contain a single root element or a file path (when 'type="file"')."""
+        )
+    }
+  }

Review Comment:
   Semi related, I wonder if we made a mistake by adding a `type` attribute to `dfdlInfoset`? Maybe instead `tdml:infoset` should be a choice of different children, so for example a file type would be specified like this instead:
   
   ```xml
   <tdml:infoset>
     <tdml:file>/path/to/file.xml</tdml:file>
   </tdml:infoset>
   ```
   
   It's maybe too late now since lots of things use `type="file"` but maybe in the future the use of `type="foo"` to define the format of the children should be avoided? It probably would have simplified this logic a bit.



-- 
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: commits-unsubscribe@daffodil.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Improve diagnostic in TDML Runner [daffodil]

Posted by "mbeckerle (via GitHub)" <gi...@apache.org>.
mbeckerle commented on code in PR #1357:
URL: https://github.com/apache/daffodil/pull/1357#discussion_r1828033479


##########
daffodil-tdml-lib/src/main/scala/org/apache/daffodil/tdml/TDMLRunner.scala:
##########
@@ -2769,41 +2770,52 @@ case class Infoset(i: NodeSeq, parent: TestCase) {
 
 case class DFDLInfoset(di: Node, parent: Infoset) {
 
-  private lazy val infosetNodeSeq = {
-    val testCase: TestCase = parent.parent
-    val loader = testCase.parent.loader
-    val optDataSchema: Option[URI] = {
-      testCase.optSchemaFileURI.orElse(testCase.optEmbeddedSchema.map { _.uriForLoading })
-    }
-    val src =
-      (di \ "@type").toString match {
-        case "infoset" | "" => {
-          val rawElem = di.child.filter {
-            _.isInstanceOf[scala.xml.Elem]
-          }.head
-          UnitTestSchemaSource(rawElem, testCase.tcName)
-        }
-        case "file" => {
-          val path = di.text.trim()
-          val maybeURI = parent.parent.parent.findTDMLResource(path)
-          val uri = maybeURI.getOrElse(
-            throw new FileNotFoundException(
-              "TDMLRunner: infoset file '" + path + "' was not found"
-            )
-          )
-          URISchemaSource(uriToDiagnosticFile(uri), uri)
-        }
-        case value => Assert.abort("Unknown value for type attribute on dfdlInfoset: " + value)
-      }
+  private lazy val testCase: TestCase = parent.parent
+  private lazy val loader = testCase.parent.loader
+  private val ty: String = {
+    val t = (di \ "@type").text.trim
+    if (t.isEmpty) "infoset" else t
+  }
+
+  private val elemOrStr: Either[Elem, String] = {
+    val (elems, others) = di.child.partition(_.isInstanceOf[scala.xml.Elem])
+    (elems, others.text.trim) match {
+      case (Seq(elem: Elem), "") if (ty == "infoset") => Left(elem)
+      case (Seq(), str) if (ty == "file") => Right(str)
+      case _ =>
+        Assert.usageError(
+          """dfdlInfoset element must contain a single root element or a file path (when 'type="file"')."""
+        )
+    }
+  }

Review Comment:
   Agreed. Things in XSD should be designed so that XSD can validate them rather than more complex rules being required in code. It's a shame that XSD 1.1 has not caught on, because it can validate such co-constraints. 
   
   The right thing would have been a different element, e.g, dfdlInfosetFile which could only have a file path as its value. 



-- 
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: commits-unsubscribe@daffodil.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Improve diagnostic in TDML Runner [daffodil]

Posted by "mbeckerle (via GitHub)" <gi...@apache.org>.
mbeckerle commented on code in PR #1357:
URL: https://github.com/apache/daffodil/pull/1357#discussion_r1826304114


##########
daffodil-tdml-lib/src/main/scala/org/apache/daffodil/tdml/TDMLRunner.scala:
##########
@@ -2818,17 +2830,9 @@ case class DFDLInfoset(di: Node, parent: Infoset) {
       val newExceptions = (testSuite.loadingExceptions -- before).toSeq
       testCase.toss(TDMLException(newExceptions, None), None)
     }
-    elem
+    elem.asInstanceOf[scala.xml.Elem]

Review Comment:
   Can just be 'Elem'



-- 
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: commits-unsubscribe@daffodil.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org