From 97d9cea4cb833591e26062ff314351a93fcf534e Mon Sep 17 00:00:00 2001 From: olabusayoT <50379531+olabusayoT@users.noreply.github.com> Date: Tue, 12 Nov 2024 15:40:23 -0500 Subject: [PATCH] Add TDML Exception when there's no Expected Data - note this only gets thrown where there is a warning as well, as UnparserTestCase requires 2 children. So if you just have an infoset and nothing else, you'll get an XSD error. DAFFODIL-2289 --- .../org/apache/daffodil/tdml/TDMLRunner.scala | 6 ++- .../processor/tdml/TestTDMLRunner2.scala | 43 ++++++++++++++++++- 2 files changed, 47 insertions(+), 2 deletions(-) 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 ad25deacf6..e984765d96 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 @@ -1597,7 +1597,11 @@ case class UnparserTestCase(ptc: NodeSeq, parentArg: DFDLTestSuite) } } } - case _ => Assert.impossibleCase() + case _ => + throw TDMLException( + "Either tdml:document or tdml:errors must be present in the test.", + implString + ) } } diff --git a/daffodil-tdml-processor/src/test/scala/org/apache/daffodil/processor/tdml/TestTDMLRunner2.scala b/daffodil-tdml-processor/src/test/scala/org/apache/daffodil/processor/tdml/TestTDMLRunner2.scala index 691e299249..2a9c336ea0 100644 --- a/daffodil-tdml-processor/src/test/scala/org/apache/daffodil/processor/tdml/TestTDMLRunner2.scala +++ b/daffodil-tdml-processor/src/test/scala/org/apache/daffodil/processor/tdml/TestTDMLRunner2.scala @@ -22,6 +22,7 @@ import org.apache.daffodil.lib.Implicits.using import org.apache.daffodil.lib.xml.XMLUtils import org.apache.daffodil.tdml.Document import org.apache.daffodil.tdml.Runner +import org.apache.daffodil.tdml.TDMLException import org.junit.AfterClass import org.junit.Assert.assertEquals @@ -534,7 +535,7 @@ abc # a comment runner.reset } - @Test def testTDMLUnparse(): Unit = { + @Test def testTDMLUnparse1(): Unit = { val testSuite = @@ -558,6 +559,46 @@ abc # a comment runner.reset } + @Test def testTDMLUnparse2(): Unit = { + val testSuite = + + + + + + + + + + + + + + + + + 123456789 + + + + + + + + + + + val runner = Runner(testSuite) + val err = intercept[TDMLException] { + runner.runOneTest("testTDMLUnparse") + } + val actualMessage = err.getMessage() + assertTrue(actualMessage.contains("Either tdml:document or tdml:errors must be present")) + runner.reset + } + @Test def test_quote_test1() = { val runner = Runner("/test/tdml/", "tdmlQuoting.tdml") runner.runOneTest("quote_test1")