This is an automated email from the ASF dual-hosted git repository. mbeckerle pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/daffodil.git
commit 0f3793a94a9f3f24257aaeb350a4e7242b581d2d Author: Michael Beckerle <[email protected]> AuthorDate: Tue Nov 19 15:58:01 2024 -0500 Various cleanups in core TestUtils and FuzzData Moved TestUtils and FuzzData in core to src/main so FuzzData can be used outside of daffodil proper. Removed unused and trivial methods from TestUtils. Made private all methods possible. We're left with minimum footprint of public methods. Removed dependency on JUnit from TestUtils and FuzzData so they don't have to be in src/test. Tested for and removed a couple of TODOs that are no longer needed. Reducing the number of TODOs and FIXMEs is DAFFODIL-1569. DAFFODIL-2959, DAFFODIL-1569 --- .../apache/daffodil/core/dpath/Conversions.scala | 7 +- .../apache/daffodil/core/dpath/Expression.scala | 6 +- .../org/apache/daffodil/core/util/FuzzData.scala | 9 +- .../org/apache/daffodil/core/util/TestUtils.scala | 184 +++++---------------- .../org/apache/daffodil/core/api/TestAPI.scala | 5 +- .../org/apache/daffodil/core/api/TestAPI1.scala | 59 +++---- .../daffodil/core/dsom/TestAppinfoSyntax.scala | 6 +- .../daffodil/core/dsom/TestDsomCompiler.scala | 2 +- .../core/dsom/TestDsomCompilerUnparse1.scala | 3 +- .../daffodil/core/dsom/TestInputValueCalc.scala | 9 +- .../dsom/TestInteriorAlignmentElimination.scala | 5 +- .../core/dsom/TestMiddleEndAttributes2.scala | 3 +- .../TestPolymorphicUpwardRelativeExpressions.scala | 5 +- .../daffodil/core/dsom/TestPropertyScoping.scala | 1 - .../daffodil/core/dsom/TestSimpleTypeUnions.scala | 19 +-- .../daffodil/core/general/TestPrimitives.scala | 21 +-- .../core/general/TestRuntimeProperties.scala | 5 +- .../daffodil/core/infoset/TestInfoset2.scala | 5 +- .../core/layers/TestBoundaryMarkLayer.scala | 2 +- .../core/layers/TestFixedLengthLayer.scala | 2 +- .../daffodil/core/layers/TestGzipErrors.scala | 12 +- .../apache/daffodil/core/layers/TestLayers.scala | 20 +-- .../TestStreamingUnparserCompilerAttributes.scala | 3 +- .../apache/daffodil/lib/exceptions/Assert.scala | 25 +++ .../scala/org/apache/daffodil/lib/util/Misc.scala | 20 ++- .../org/apache/daffodil/lib/xml/XMLUtils.scala | 5 + .../daffodil/runtime1/layers/TestCheckDigit.scala | 19 ++- .../daffodil/runtime1/layers/TestLayers2.scala | 4 +- 28 files changed, 200 insertions(+), 266 deletions(-) diff --git a/daffodil-core/src/main/scala/org/apache/daffodil/core/dpath/Conversions.scala b/daffodil-core/src/main/scala/org/apache/daffodil/core/dpath/Conversions.scala index 40fa54f8e..edab0d114 100644 --- a/daffodil-core/src/main/scala/org/apache/daffodil/core/dpath/Conversions.scala +++ b/daffodil-core/src/main/scala/org/apache/daffodil/core/dpath/Conversions.scala @@ -280,12 +280,11 @@ object Conversion { // case (AnyAtomic, Date) => AnyAtomicToString +: conversionOps(String, tt, context) // case (AnyAtomic, DateTime) => AnyAtomicToString +: conversionOps(String, tt, context) - // TODO: Is this a valid solution for DFDL-1074 and the like? - // Essentially, all of the 'types' should fall under AnyAtomic and there - // is no need to conver to an AnyAtomic. So anything converted to AnyAtomic + // All of the 'types' should fall under AnyAtomic and there + // is no need to convert to an AnyAtomic. So anything converted to AnyAtomic // should be itself. // - case (_, AnyAtomic) => Nil // is this correct? + case (_, AnyAtomic) => Nil case (_, Exists) => Nil case (_, other) => { diff --git a/daffodil-core/src/main/scala/org/apache/daffodil/core/dpath/Expression.scala b/daffodil-core/src/main/scala/org/apache/daffodil/core/dpath/Expression.scala index db3cdce36..00646fd52 100644 --- a/daffodil-core/src/main/scala/org/apache/daffodil/core/dpath/Expression.scala +++ b/daffodil-core/src/main/scala/org/apache/daffodil/core/dpath/Expression.scala @@ -2836,14 +2836,10 @@ case class XSConverterExpr( override def targetTypeForSubexpression(childExpr: Expression): NodeInfo.Kind = resultType // NodeInfo.AnyType - // TODO: this should work... why do we need to call an additional converter. The - // args(0).compiledDPath should already have taken into account converting into - // their target types which are the same as this conversion's output result type. - override lazy val compiledDPath = { checkArgCount(1) val arg0Recipe = args(0).compiledDPath - val c = conversions + val c = conversions // additional final conversions are added val res = new CompiledDPath(arg0Recipe.ops.toList ++ c) res } diff --git a/daffodil-core/src/test/scala/org/apache/daffodil/core/util/FuzzData.scala b/daffodil-core/src/main/scala/org/apache/daffodil/core/util/FuzzData.scala similarity index 97% rename from daffodil-core/src/test/scala/org/apache/daffodil/core/util/FuzzData.scala rename to daffodil-core/src/main/scala/org/apache/daffodil/core/util/FuzzData.scala index dde72b828..d6cb29db8 100644 --- a/daffodil-core/src/test/scala/org/apache/daffodil/core/util/FuzzData.scala +++ b/daffodil-core/src/main/scala/org/apache/daffodil/core/util/FuzzData.scala @@ -22,13 +22,12 @@ import scala.util.Random import scala.xml.Elem import scala.xml.Node -import org.apache.daffodil.core.util.TestUtils.getAMessage import org.apache.daffodil.lib.exceptions.Assert +import org.apache.daffodil.lib.util.Misc.getAMessage +import org.apache.daffodil.lib.xml.XMLUtils import org.apache.daffodil.lib.xml.XMLUtils.XMLDifferenceException import org.apache.daffodil.runtime1.processors.parsers.ParseError -import org.junit.Assert.fail - /** * Utility base class to support fuzz testing. Given a piece of data, * it fuzzes it (without modifying the original data) each time next() is @@ -187,7 +186,7 @@ class FuzzParseTester( } if (pr ne null) { try { - TestUtils.assertEqualsXMLElements(expected, node) + XMLUtils.compareAndReport(expected, node) } catch { case e: XMLDifferenceException => handleUnexpectedSuccess(node, testData, e) @@ -230,6 +229,6 @@ class LayerParseTester( if (okParses.size > 0) println(s"Parse succeeded on fuzzed data ${okParses.size} times.") if (shouldFail) - fail("errors were found") + throw new AssertionError("errors were found") } } diff --git a/daffodil-core/src/test/scala/org/apache/daffodil/core/util/TestUtils.scala b/daffodil-core/src/main/scala/org/apache/daffodil/core/util/TestUtils.scala similarity index 72% rename from daffodil-core/src/test/scala/org/apache/daffodil/core/util/TestUtils.scala rename to daffodil-core/src/main/scala/org/apache/daffodil/core/util/TestUtils.scala index 39495e1ad..12ecf34f6 100644 --- a/daffodil-core/src/test/scala/org/apache/daffodil/core/util/TestUtils.scala +++ b/daffodil-core/src/main/scala/org/apache/daffodil/core/util/TestUtils.scala @@ -18,25 +18,23 @@ package org.apache.daffodil.core.util import java.io.ByteArrayInputStream -import java.io.File -import java.io.FileNotFoundException import java.io.InputStream import java.nio.channels.Channels import java.nio.channels.ReadableByteChannel import java.nio.channels.WritableByteChannel -import java.nio.file.Paths import scala.collection.mutable.ArrayBuffer import scala.util.Try import scala.xml._ import org.apache.daffodil.core.compiler.Compiler +import org.apache.daffodil.core.compiler.ProcessorFactory import org.apache.daffodil.core.dsom._ import org.apache.daffodil.io.InputSourceDataInputStream import org.apache.daffodil.lib.Implicits._ import org.apache.daffodil.lib.api._ +import org.apache.daffodil.lib.exceptions.MultiException import org.apache.daffodil.lib.externalvars.Binding import org.apache.daffodil.lib.util._ -import org.apache.daffodil.lib.xml.XMLUtils import org.apache.daffodil.lib.xml._ import org.apache.daffodil.runtime1.api.DFDL import org.apache.daffodil.runtime1.api.MetadataHandler @@ -48,9 +46,6 @@ import org.apache.daffodil.runtime1.infoset.ScalaXMLInfosetOutputter import org.apache.daffodil.runtime1.processors.DataProcessor import org.apache.daffodil.runtime1.processors.VariableMap -import org.apache.commons.io.output.NullOutputStream -import org.junit.Assert.assertEquals - object INoWarnU2 { ImplicitsSuppressUnusedImportWarning() } /* @@ -60,31 +55,8 @@ object INoWarnU2 { ImplicitsSuppressUnusedImportWarning() } */ object TestUtils { - /** - * Compares two XML Elements, after having (optionally) stripped off all attributes. - */ - def assertEqualsXMLElements(expected: Node, actual: Node): Unit = { - XMLUtils.compareAndReport(expected, actual) - } - - /** - * We want to be able to run tests from Eclipse or from batch builds that - * are rooted in a different directory, so, since Java/JVMs don't have a notion - * of setting the current directory to a specific value for interpreting things, - * we have to do that ourselves manually like this. - * - * When you specify a file for use in a test, you want to specify it - * relative to the root of the sub-project of which it is part. I.e., within core, - * the file you specify should be relative to daffodil/sub-projects/core. - * - * Returns null if the file cannot be found. - */ - def findFile(fn: String): File = findFile(new File(fn)) - def findFile(f: File): File = { - if (f.exists()) return f - val cwd = new File("").getAbsolutePath - throw new FileNotFoundException("Couldn't find file " + f + " relative to " + cwd + ".") - } + def assertEquals[T](expected: T, actual: T) = + if (expected != actual) throw new AssertionError("assertEquals failed.") def testString(testSchema: Node, data: String, areTracing: Boolean = false) = { runSchemaOnRBC(testSchema, Misc.stringToReadableByteChannel(data), areTracing) @@ -108,11 +80,7 @@ object TestUtils { runSchemaOnRBC(testSchema, rbc, areTracing) } - def testFile(testSchema: Node, fileName: String) = { - runSchemaOnRBC(testSchema, Misc.fileToReadableByteChannel(new java.io.File(fileName))) - } - - val useSerializedProcessor = true + private val useSerializedProcessor = true def testUnparsing( testSchema: scala.xml.Elem, @@ -122,15 +90,9 @@ object TestUtils { ): Seq[Diagnostic] = { val compiler = Compiler().withTunable("allowExternalPathExpressions", "true") val pf = compiler.compileNode(testSchema) - if (pf.isError) { - val msgs = pf.getDiagnostics.map(_.getMessage()).mkString("\n") - throw new Exception(msgs) - } + if (pf.isError) throwDiagnostics(pf.getDiagnostics) var u = saveAndReload(pf.onPath("/").asInstanceOf[DataProcessor]) - if (u.isError) { - val msgs = u.getDiagnostics.map(_.getMessage()).mkString("\n") - throw new Exception(msgs) - } + if (u.isError) throwDiagnostics(u.getDiagnostics) val outputStream = new java.io.ByteArrayOutputStream() val out = java.nio.channels.Channels.newChannel(outputStream) u = if (areTracing) { @@ -138,9 +100,7 @@ object TestUtils { } else u val inputter = new ScalaXMLInfosetInputter(infosetXML) val actual = u.unparse(inputter, out) - if (actual.isProcessingError) { - throwDiagnostics(actual.getDiagnostics) - } + if (actual.isProcessingError) throwDiagnostics(actual.getDiagnostics) val unparsed = outputStream.toString // System.err.println("parsed: " + infoset) // System.err.println("unparsed: " + unparsed) @@ -149,12 +109,8 @@ object TestUtils { actual.getDiagnostics } - def throwDiagnostics(ds: Seq[Diagnostic]): Unit = { - if (ds.length == 1) throw (ds(0)) - else { - val msgs = ds.map(_.getMessage()).mkString("\n") - throw new Exception(msgs) - } + private def throwDiagnostics(ds: Seq[Diagnostic]): Nothing = { + new MultiException(ds).toss } def testUnparsingBinary( @@ -208,22 +164,13 @@ object TestUtils { def compileSchema(testSchema: Node) = { val compiler = Compiler() val pf = compiler.compileNode(testSchema) - val isError = pf.isError - val msgs = pf.getDiagnostics.map(_.getMessage()).mkString("\n") - - if (isError) { - throw new Exception(msgs) - } + if (pf.isError) throwDiagnostics(pf.getDiagnostics) val p = saveAndReload(pf.onPath("/").asInstanceOf[DataProcessor]) - val pIsError = p.isError - if (pIsError) { - val msgs = pf.getDiagnostics.map(_.getMessage()).mkString("\n") - throw new Exception(msgs) - } + if (p.isError) throwDiagnostics(p.getDiagnostics) p } - def runSchemaOnRBC( + private def runSchemaOnRBC( testSchema: Node, data: ReadableByteChannel, areTracing: Boolean = false @@ -231,7 +178,7 @@ object TestUtils { runSchemaOnInputStream(testSchema, Channels.newInputStream(data), areTracing) } - def runSchemaOnInputStream( + private def runSchemaOnInputStream( testSchema: Node, is: InputStream, areTracing: Boolean = false @@ -255,12 +202,7 @@ object TestUtils { val outputter = new ScalaXMLInfosetOutputter() val input = InputSourceDataInputStream(is) val actual = p.parse(input, outputter) - if (actual.isProcessingError) { - val diags = actual.getDiagnostics - if (diags.length == 1) throw diags(0) - val msgs = diags.map(_.getMessage()).mkString("\n") - throw new Exception(msgs) - } + if (actual.isProcessingError) throwDiagnostics(actual.getDiagnostics) (actual, outputter.getResult) } @@ -292,52 +234,16 @@ object TestUtils { compiler: Compiler, schemaSource: URISchemaSource, output: WritableByteChannel - ) = { + ): Try[(ProcessorFactory, DFDL.DataProcessor)] = { Try { val pf = compiler.compileSource(schemaSource) - if (!pf.isError) { - val dp = pf.onPath("/") - dp.save(output) - if (!dp.isError) { - (pf, dp) - } else { - throw new Exception( - (dp.getDiagnostics ++ pf.getDiagnostics).map { _.getMessage() }.mkString("\n") - ) - } - } else - throw new Exception(pf.getDiagnostics.map { _.getMessage() }.mkString("\n")) + if (pf.isError) throwDiagnostics(pf.getDiagnostics) + val dp = pf.onPath("/") + dp.save(output) + if (dp.isError) throwDiagnostics(dp.getDiagnostics ++ pf.getDiagnostics) + (pf, dp) } } - - def testCompileTime(resourcePathString: String): Unit = { - val nos = NullOutputStream.INSTANCE - val nullChannel = java.nio.channels.Channels.newChannel(nos) - val compiler = Compiler() - val uri = Misc.getRequiredResource(resourcePathString) - val schemaSource = URISchemaSource(Paths.get(resourcePathString).toFile, uri) - val theTry = Timer.getResult(compileAndSave(compiler, schemaSource, nullChannel)) - theTry.get - } - - /** - * Gets some sort of a message from a throwable. Includes messages from all - * classes in the cause chain. If there is no message, just uses the class name. - * @param cause - * @return - */ - def getAMessage(cause: Throwable): String = { - val n1 = Misc.getNameFromClass(cause) - val m = cause.getMessage - val c = cause.getCause - val s = (m, c) match { - case (null, null) => Misc.getNameFromClass(cause) - case (null, c) => getAMessage(c) - case (m, null) => m - case (m, c) => m + " " + getAMessage(c) - } - n1 + s"($s)" - } } /** @@ -397,7 +303,7 @@ class Fakes private () { lazy val fakeSequenceGroupRef = fs3.asInstanceOf[SequenceGroupRef] lazy val fakeGroupRefFactory = GroupRefFactory(fs1.xml, fs1, 1, false) - class FakeDataProcessor extends DFDL.DataProcessor { + private class FakeDataProcessor extends DFDL.DataProcessor { override def save(output: DFDL.Output): Unit = {} override def parse( input: InputSourceDataInputStream, @@ -428,7 +334,7 @@ class Fakes private () { ): DFDL.DaffodilUnparseContentHandler = null } - lazy val fakeDP = new FakeDataProcessor + lazy val fakeDP: DFDL.DataProcessor = new FakeDataProcessor } @@ -436,10 +342,7 @@ class Fakes private () { * Testing class for streaming message parse behavior */ object StreamParser { - case class CompileFailure(diags: Seq[Diagnostic]) - extends Exception("DFDL Schema Compile Failure") { - override def getMessage() = diags.map { _.toString }.mkString(",\n") - } + case class CompileFailure(diags: Seq[Diagnostic]) extends MultiException(diags) /** * Result object for parse calls. Just a tuple. @@ -473,37 +376,38 @@ object StreamParser { } } - def doStreamTest(schema: Node, data: String): Seq[Result] = { + def doStreamTest(schema: Node, data: String): Stream[Result] = { val mp = new StreamParser(schema) val is: InputStream = new ByteArrayInputStream(data.getBytes("ascii")) mp.setInputStream(is) var r: StreamParser.Result = null val results = new ArrayBuffer[Result] val resStream = Stream.continually(mp.parse).takeWhile(r => !r.isProcessingError) - resStream.toSeq + resStream } } -class StreamParser(val schema: Node) { +class StreamParser private (val schema: Node) { + + private lazy val outputter = new ScalaXMLInfosetOutputter() + private var dis: InputSourceDataInputStream = _ - val outputter = new ScalaXMLInfosetOutputter() - var dis: InputSourceDataInputStream = _ - var dp: DFDL.DataProcessor = _ // // First compile the DFDL Schema - val c = Compiler() - val pf = c.compileNode(schema) - val pfDiags = pf.getDiagnostics - if (pf.isError) throw new StreamParser.CompileFailure(pfDiags) - dp = pf - .onPath("/") - .withValidationMode(ValidationMode.Full) - // .withDebuggerRunner(new TraceDebuggerRunner()) // DAFFODIL-2624 - cannot trace in streaming SAPI - // .withDebugging(true) - val dpDiags = dp.getDiagnostics - if (dp.isError) throw new StreamParser.CompileFailure(dpDiags) - val compilationWarnings = - if (!pfDiags.isEmpty) pfDiags else dpDiags // dpDiags might be empty. That's ok. + private lazy val c = Compiler() + private lazy val pf = c.compileNode(schema) + private val dp = { + if (pf.isError) throw new StreamParser.CompileFailure(pf.getDiagnostics) + val dataproc = pf + .onPath("/") + .withValidationMode(ValidationMode.Full) + // .withDebuggerRunner(new TraceDebuggerRunner()) // DAFFODIL-2624 - cannot trace in streaming SAPI + // .withDebugging(true) + if (dataproc.isError) throw new StreamParser.CompileFailure(dataproc.getDiagnostics) + dataproc + } + + lazy val compilationWarnings: Seq[Diagnostic] = pf.getDiagnostics ++ dp.getDiagnostics def setInputStream(inputStream: InputStream): Unit = { dis = InputSourceDataInputStream(inputStream) diff --git a/daffodil-core/src/test/scala/org/apache/daffodil/core/api/TestAPI.scala b/daffodil-core/src/test/scala/org/apache/daffodil/core/api/TestAPI.scala index 76a44ce74..d2c37e180 100644 --- a/daffodil-core/src/test/scala/org/apache/daffodil/core/api/TestAPI.scala +++ b/daffodil-core/src/test/scala/org/apache/daffodil/core/api/TestAPI.scala @@ -19,6 +19,7 @@ package org.apache.daffodil.core.api import org.apache.daffodil.lib.Implicits._ import org.apache.daffodil.lib.util._ +import org.apache.daffodil.lib.xml.XMLUtils import org.junit.Test; object INoWarn7 { ImplicitsSuppressUnusedImportWarning() } import org.apache.daffodil.core.util.TestUtils @@ -40,7 +41,7 @@ class TestDFDLParser_New { ) val (_, actual) = TestUtils.testString(sch, "5;6;7;8;.") val expected = <e1><s1>5</s1><s1>6</s1><s1>7</s1><s1>8</s1></e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } @Test def testParseOccursCountKindOfParsedDelimitedBySeparatorImplicitWithMaxOccurs2() @@ -58,6 +59,6 @@ class TestDFDLParser_New { ) val (_, actual) = TestUtils.testString(sch, "5;6;7;8!.") val expected = <e1><s1>5</s1><s1>6</s1><s1>7</s1><s1>8</s1></e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } } diff --git a/daffodil-core/src/test/scala/org/apache/daffodil/core/api/TestAPI1.scala b/daffodil-core/src/test/scala/org/apache/daffodil/core/api/TestAPI1.scala index d1c8dcd42..14564fbec 100644 --- a/daffodil-core/src/test/scala/org/apache/daffodil/core/api/TestAPI1.scala +++ b/daffodil-core/src/test/scala/org/apache/daffodil/core/api/TestAPI1.scala @@ -19,9 +19,10 @@ package org.apache.daffodil.core.api import scala.xml._ -import org.apache.daffodil.core.util._ +import org.apache.daffodil.core.util.TestUtils import org.apache.daffodil.lib.Implicits._ import org.apache.daffodil.lib.util._ +import org.apache.daffodil.lib.xml.XMLUtils import org.junit.Assert._ import org.junit.Test @@ -36,7 +37,7 @@ class TestDFDLParser { ) val (_, actual) = TestUtils.testString(sch, "5678") val expected: Node = <e1>5678</e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } @Test def testParseSequenceOfJustOneScalar(): Unit = { @@ -53,7 +54,7 @@ class TestDFDLParser { ) val (_, actual) = TestUtils.testString(sch, "5") val expected = <e1><s1>5</s1></e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } @Test def testParseSequence1(): Unit = { @@ -71,7 +72,7 @@ class TestDFDLParser { ) val (_, actual) = TestUtils.testString(sch, "56") val expected = <e1><s1>5</s1><s2>6</s2></e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } @Test def testParseSequence2(): Unit = { @@ -88,7 +89,7 @@ class TestDFDLParser { ) val (_, actual) = TestUtils.testString(sch, "567") val expected = <e1><s1>5</s1><s1>6</s1><s1>7</s1></e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } @Test def testParseSequence3(): Unit = { @@ -105,7 +106,7 @@ class TestDFDLParser { ) val (_, actual) = TestUtils.testString(sch, "5,6,7") val expected = <e1><s1>5</s1><s1>6</s1><s1>7</s1></e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } @Test def testInt1(): Unit = { @@ -122,7 +123,7 @@ class TestDFDLParser { </xs:element> ) val (_, actual) = TestUtils.testString(sch, "55,000") - TestUtils.assertEqualsXMLElements(<e1><s1>5</s1><s2>5000</s2></e1>, actual) + XMLUtils.compareAndReport(<e1><s1>5</s1><s2>5000</s2></e1>, actual) } @Test def testInt2(): Unit = { @@ -158,7 +159,7 @@ class TestDFDLParser { </xs:element> ) val (_, actual) = TestUtils.testString(sch, "55,000") - TestUtils.assertEqualsXMLElements(<e1><s1>5</s1><s2>5000</s2></e1>, actual) + XMLUtils.compareAndReport(<e1><s1>5</s1><s2>5000</s2></e1>, actual) } @Test def testShort2(): Unit = { @@ -193,7 +194,7 @@ class TestDFDLParser { </xs:element> ) val (_, actual) = TestUtils.testString(sch, "55123") - TestUtils.assertEqualsXMLElements(<e1><s1>55</s1><s2>123</s2></e1>, actual) + XMLUtils.compareAndReport(<e1><s1>55</s1><s2>123</s2></e1>, actual) } @Test def testNumber1(): Unit = { @@ -212,7 +213,7 @@ class TestDFDLParser { </xs:element> ) val (_, actual) = TestUtils.testString(sch, "1-800-555-1212") - TestUtils.assertEqualsXMLElements( + XMLUtils.compareAndReport( <e1><country>1</country><area>-800</area><region>-555</region><number>-1212</number></e1>, actual ) @@ -225,7 +226,7 @@ class TestDFDLParser { <xs:element name="mersenne" type="xs:byte" dfdl:lengthKind="explicit" dfdl:length="{ 4 }"/> ) val (_, actual) = TestUtils.testString(sch, "-127") - TestUtils.assertEqualsXMLElements(<mersenne>-127</mersenne>, actual) + XMLUtils.compareAndReport(<mersenne>-127</mersenne>, actual) } @Test def testNumber3(): Unit = { @@ -235,7 +236,7 @@ class TestDFDLParser { <xs:element name="perfect" type="xs:byte" dfdl:textNumberPattern="+0" dfdl:lengthKind="explicit" dfdl:length="{ 2 }"/> ) val (_, actual) = TestUtils.testString(sch, "+3") - TestUtils.assertEqualsXMLElements(<perfect>3</perfect>, actual) + XMLUtils.compareAndReport(<perfect>3</perfect>, actual) } @Test def testUnsignedLong1(): Unit = { @@ -319,7 +320,7 @@ class TestDFDLParser { ) val (_, actual) = TestUtils.testString(sch, "[[{{((55)),,((66)),,((77))}}]]") val expected = <e1><s1>55</s1><s1>66</s1><s1>77</s1></e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } @Test def testParseSequenceInt3Operands(): Unit = { @@ -336,7 +337,7 @@ class TestDFDLParser { ) val (_, actual) = TestUtils.testString(sch, "[[{{((55)),,((66)),,((77))}}]]") val expected = <e1><s1>55</s1><s1>66</s1><s1>77</s1></e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } @Test def testBadInt(): Unit = { @@ -366,7 +367,7 @@ class TestDFDLParser { ) val (_, actual) = TestUtils.testString(sch, "5678A") val expected = <e1><s1>5</s1><s1>6</s1><s1>7</s1><s1>8</s1><s2>A</s2></e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } @Test def testParseOccursCountKindOfParsedWithTerminator(): Unit = { @@ -384,7 +385,7 @@ class TestDFDLParser { ) val (_, actual) = TestUtils.testString(sch, "5;6;7;8;A") val expected = <e1><s1>5</s1><s1>6</s1><s1>7</s1><s1>8</s1><s2>A</s2></e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } @Test def testParseOccursCountKindOfParsedDelimitedByTerminator(): Unit = { @@ -403,7 +404,7 @@ class TestDFDLParser { val areTracing = false val (_, actual) = TestUtils.testString(sch, "5;6;7;8;A.", areTracing) val expected = <e1><s1>5</s1><s1>6</s1><s1>7</s1><s1>8</s1><s2>A</s2></e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } @Test def testParseOccursCountKindOfParsedDelimitedByTerminator2(): Unit = { @@ -421,7 +422,7 @@ class TestDFDLParser { val areTracing = false val (_, actual) = TestUtils.testString(sch, "5;6;7;8;.", areTracing) val expected = <e1><s1>5</s1><s1>6</s1><s1>7</s1><s1>8</s1></e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } @Test def testParseOccursCountKindOfParsedDelimitedBySeparator(): Unit = { @@ -440,7 +441,7 @@ class TestDFDLParser { val (_, actual) = TestUtils.testString(sch, "5;6;7;8;.", areTracing) val expected = <e1><s1>5</s1><s1>6</s1><s1>7</s1><s1>8</s1></e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } @Test def testParseOccursCountKindOfParsedDelimitedBySeparator3(): Unit = { @@ -459,7 +460,7 @@ class TestDFDLParser { val (_, actual) = TestUtils.testString(sch, "5;6;7;8!.", areTracing) val expected = <e1><s1>5</s1><s1>6</s1><s1>7</s1><s1>8</s1></e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } @Test def testBinaryIntMinusOne(): Unit = { @@ -476,7 +477,7 @@ class TestDFDLParser { ) val (_, actual) = TestUtils.testBinary(sch, "FFFFFFFF") val expected = <e1><s1>-1</s1></e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } @Test def testBinaryInts(): Unit = { @@ -496,7 +497,7 @@ class TestDFDLParser { val (_, actual) = TestUtils.testBinary(sch, "000000013bFFFFFFFF3b080402013b000000003bFFFFFF7F", areTracing) val expected = <e1><s1>1</s1><s1>-1</s1><s1>134480385</s1><s1>0</s1><s2>2147483647</s2></e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } @Test def testBinaryDoubleOne(): Unit = { @@ -507,7 +508,7 @@ class TestDFDLParser { ) val (_, actual) = TestUtils.testBinary(sch, "3FF0000000000000") val expected = <e1>1.0</e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } @Test def testBinaryDoubleMinusOne(): Unit = { @@ -518,7 +519,7 @@ class TestDFDLParser { ) val (_, actual) = TestUtils.testBinary(sch, "BFF0000000000000") val expected = <e1>-1.0</e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } @Test def testBinaryDoubleLSB(): Unit = { @@ -529,7 +530,7 @@ class TestDFDLParser { ) val (_, actual) = TestUtils.testBinary(sch, "0000000000000001") val expected = <e1>4.9E-324</e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } @Test def testBinaryDoubles(): Unit = { @@ -551,7 +552,7 @@ class TestDFDLParser { ) val expected = <e1><s1>1.0</s1><s1>-1.0</s1><s1>4.7340609871421765E-270</s1><s1>0.0</s1><s2>NaN</s2></e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } @Test def testTextDoubles(): Unit = { @@ -571,7 +572,7 @@ class TestDFDLParser { val (_, actual) = TestUtils.testString(sch, "01.0;-1.0;4.15;0.31;8.6E-2001,234.9") val expected = <e1><s1>1.0</s1><s1>-1.0</s1><s1>4.15</s1><s1>0.31</s1><s2>8.6E-200</s2><s3>1234.9</s3></e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } @Test def testBinaryFloats(): Unit = { @@ -591,7 +592,7 @@ class TestDFDLParser { TestUtils.testBinary(sch, "3F8000003bBF8000003b080402013b000000003b0000C07F") val expected = <e1><s1>1.0</s1><s1>-1.0</s1><s1>3.972466E-34</s1><s1>0.0</s1><s2>NaN</s2></e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } @Test def testTextFloats(): Unit = { @@ -612,7 +613,7 @@ class TestDFDLParser { val (_, actual) = TestUtils.testString(sch, "01.0;-1.0;4.15;0.31;-7.1E81,234.9", areTracing) val expected = <e1><s1>1.0</s1><s1>-1.0</s1><s1>4.15</s1><s1>0.31</s1><s2>-7.1E8</s2><s3>1234.9</s3></e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } } diff --git a/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestAppinfoSyntax.scala b/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestAppinfoSyntax.scala index 277459659..cfb5a6e48 100644 --- a/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestAppinfoSyntax.scala +++ b/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestAppinfoSyntax.scala @@ -68,7 +68,7 @@ class TestAppinfoSyntax { assertEquals(expected, ns.toString()) val (_, actual) = TestUtils.testString(sc, "5") val expectedParseInfoset = <root>5</root> - TestUtils.assertEqualsXMLElements(expectedParseInfoset, actual) + XMLUtils.compareAndReport(expectedParseInfoset, actual) } /** @@ -198,7 +198,7 @@ class TestAppinfoSyntax { assertEquals(expected, anna.toString()) val (_, actual) = TestUtils.testString(sc, "5") val expectedParseInfoset = <root>5</root> - TestUtils.assertEqualsXMLElements(expectedParseInfoset, actual) + XMLUtils.compareAndReport(expectedParseInfoset, actual) } /** @@ -248,7 +248,7 @@ class TestAppinfoSyntax { assertEquals(expected, anna.toString()) val (_, actual) = TestUtils.testString(sc, "5") val expectedParseInfoset = <root>5</root> - TestUtils.assertEqualsXMLElements(expectedParseInfoset, actual) + XMLUtils.compareAndReport(expectedParseInfoset, actual) } } diff --git a/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestDsomCompiler.scala b/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestDsomCompiler.scala index 6eb3e80b4..51a001ed1 100644 --- a/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestDsomCompiler.scala +++ b/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestDsomCompiler.scala @@ -22,7 +22,7 @@ import scala.xml.Node import scala.xml.Utility import scala.xml.XML -import org.apache.daffodil.core.util._ +import org.apache.daffodil.core.util.TestUtils import org.apache.daffodil.lib.Implicits._ import org.junit.Assert._ diff --git a/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestDsomCompilerUnparse1.scala b/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestDsomCompilerUnparse1.scala index b81cfc7ff..f596440a4 100644 --- a/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestDsomCompilerUnparse1.scala +++ b/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestDsomCompilerUnparse1.scala @@ -16,8 +16,7 @@ */ package org.apache.daffodil.core.dsom - -import org.apache.daffodil.core.util._ +import org.apache.daffodil.core.util.TestUtils import org.apache.daffodil.lib.Implicits._ import org.apache.daffodil.lib.util._ import org.apache.daffodil.lib.xml.XMLUtils diff --git a/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestInputValueCalc.scala b/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestInputValueCalc.scala index 56b64db47..1e8f4a208 100644 --- a/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestInputValueCalc.scala +++ b/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestInputValueCalc.scala @@ -19,8 +19,9 @@ package org.apache.daffodil.core.dsom import scala.xml.Node -import org.apache.daffodil.core.util._ +import org.apache.daffodil.core.util.TestUtils import org.apache.daffodil.lib.util._ +import org.apache.daffodil.lib.xml.XMLUtils import org.junit.Test @@ -35,7 +36,7 @@ class TestInputValueCalc { ) val (_, actual) = TestUtils.testString(testSchema, "") val expected: Node = <data>42</data> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } // @Test @@ -55,7 +56,7 @@ class TestInputValueCalc { val (_, actual) = TestUtils.testString(testSchema, "A") val expected: Node = <data><e1>A</e1><e2>A</e2></data> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } // @Test @@ -75,6 +76,6 @@ class TestInputValueCalc { val (_, actual) = TestUtils.testString(testSchema, "8") val expected: Node = <data><e1>8</e1><e2>8</e2></data> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } } diff --git a/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestInteriorAlignmentElimination.scala b/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestInteriorAlignmentElimination.scala index 31bb46e0e..54767fbff 100644 --- a/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestInteriorAlignmentElimination.scala +++ b/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestInteriorAlignmentElimination.scala @@ -16,8 +16,7 @@ */ package org.apache.daffodil.core.dsom - -import org.apache.daffodil.core.util._ +import org.apache.daffodil.core.util.TestUtils import org.apache.daffodil.lib.util._ import org.apache.daffodil.lib.xml.XMLUtils @@ -106,7 +105,7 @@ class TestInteriorAlignmentElimination { <int1>4</int1> <ex:e2><ex:eShared><int1>5</int1><aligned>7</aligned></ex:eShared></ex:e2> </ex:r> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } } diff --git a/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestMiddleEndAttributes2.scala b/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestMiddleEndAttributes2.scala index 44c39800c..9950a00cd 100644 --- a/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestMiddleEndAttributes2.scala +++ b/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestMiddleEndAttributes2.scala @@ -19,6 +19,7 @@ package org.apache.daffodil.core.dsom import org.apache.daffodil.core.util.TestUtils import org.apache.daffodil.lib.util.SchemaUtils +import org.apache.daffodil.lib.xml.XMLUtils import org.junit.Test @@ -52,7 +53,7 @@ class TestMiddleEndAttributes2 { t1.asInstanceOf[LocalSequence] val (_, actual) = TestUtils.testString(testSchema, "/5") val expected = <e1><x>5</x></e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } } diff --git a/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestPolymorphicUpwardRelativeExpressions.scala b/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestPolymorphicUpwardRelativeExpressions.scala index 394e88f75..5026f91a7 100644 --- a/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestPolymorphicUpwardRelativeExpressions.scala +++ b/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestPolymorphicUpwardRelativeExpressions.scala @@ -16,8 +16,7 @@ */ package org.apache.daffodil.core.dsom - -import org.apache.daffodil.core.util._ +import org.apache.daffodil.core.util.TestUtils import org.apache.daffodil.lib.Implicits._ import org.apache.daffodil.lib.util._ import org.apache.daffodil.lib.xml.XMLUtils @@ -264,6 +263,6 @@ class TestPolymorphicUpwardRelativeExpressions { </ex:eShared> </ex:e2> </ex:r> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } } diff --git a/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestPropertyScoping.scala b/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestPropertyScoping.scala index 372d165ca..ff20cdf53 100644 --- a/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestPropertyScoping.scala +++ b/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestPropertyScoping.scala @@ -20,7 +20,6 @@ package org.apache.daffodil.core.dsom import scala.xml.Node import org.apache.daffodil.core.util.Fakes -import org.apache.daffodil.core.util._ import org.junit.Assert._ import org.junit.Test diff --git a/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestSimpleTypeUnions.scala b/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestSimpleTypeUnions.scala index d62e085e9..8e3adfce7 100644 --- a/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestSimpleTypeUnions.scala +++ b/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestSimpleTypeUnions.scala @@ -16,8 +16,7 @@ */ package org.apache.daffodil.core.dsom - -import org.apache.daffodil.core.util._ +import org.apache.daffodil.core.util.TestUtils import org.apache.daffodil.lib.util._ import org.apache.daffodil.lib.xml.XMLUtils import org.apache.daffodil.runtime1.dpath.NodeInfo._ @@ -110,7 +109,7 @@ class TestSimpleTypeUnions { assertEquals("int1Type", umstrd.diagnosticDebugName) assertTrue(i.valid.get) val expected = <e1>1</e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } @Test def testUnionSecondUnionMemberOk(): Unit = { @@ -125,7 +124,7 @@ class TestSimpleTypeUnions { assertEquals("int2Type", umstrd.diagnosticDebugName) assertTrue(i.valid.get) val expected = <e1>2</e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } @Test def testUnionNoUnionMemberOK(): Unit = { @@ -263,7 +262,7 @@ class TestSimpleTypeUnions { assertEquals("int12Type", umstrd.diagnosticDebugName) assertTrue(i.valid.get) val expected = <e1>1</e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } @Test def testUnionNot3_02(): Unit = { @@ -278,7 +277,7 @@ class TestSimpleTypeUnions { assertEquals("int12Type", umstrd.diagnosticDebugName) assertTrue(i.valid.get) val expected = <e1>2</e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } @Test def testUnionNot3_03(): Unit = { @@ -296,7 +295,7 @@ class TestSimpleTypeUnions { ) // anonymous simple type gets this name from base. assertTrue(i.valid.get) val expected = <e1>-1</e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } val testSchema3 = SchemaUtils.dfdlTestSchema( @@ -358,7 +357,7 @@ class TestSimpleTypeUnions { assertEquals("ex:foo3or4bar", umstrd.diagnosticDebugName) assertTrue(i.valid.get) val expected = <e1>foo3bar</e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } @Test def testRestrictionOnUnion_02(): Unit = { @@ -373,7 +372,7 @@ class TestSimpleTypeUnions { assertEquals("foo1or2bar", umstrd.diagnosticDebugName) assertTrue(i.valid.get) val expected = <e1>foo1bar</e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } @Test def testRestrictionOnUnion_03(): Unit = { @@ -388,7 +387,7 @@ class TestSimpleTypeUnions { assertEquals("foo1or2bar", umstrd.diagnosticDebugName) assertTrue(i.valid.get) val expected = <e1>foo2bar</e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } @Test def testRestrictionOnUnionFail_01(): Unit = { diff --git a/daffodil-core/src/test/scala/org/apache/daffodil/core/general/TestPrimitives.scala b/daffodil-core/src/test/scala/org/apache/daffodil/core/general/TestPrimitives.scala index ae78700ac..339dbc40a 100644 --- a/daffodil-core/src/test/scala/org/apache/daffodil/core/general/TestPrimitives.scala +++ b/daffodil-core/src/test/scala/org/apache/daffodil/core/general/TestPrimitives.scala @@ -21,6 +21,7 @@ import scala.xml._ import org.apache.daffodil.core.util.TestUtils import org.apache.daffodil.lib.Implicits._ +import org.apache.daffodil.lib.xml.XMLUtils import org.junit.Test; object INoWarn9 { ImplicitsSuppressUnusedImportWarning() } import org.apache.daffodil.lib.util.SchemaUtils @@ -37,7 +38,7 @@ class TestPrimitives { val areTracing = false val (_, actual) = TestUtils.testString(sch, "abcdefgh", areTracing) val expected: Node = <e1>efgh</e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } @Test def testTerminator(): Unit = { @@ -50,7 +51,7 @@ class TestPrimitives { val areTracing = false val (_, actual) = TestUtils.testString(sch, "abcdefgh", areTracing) val expected: Node = <e1>abcd</e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } @Test def testSeparator(): Unit = { @@ -69,7 +70,7 @@ class TestPrimitives { val areTracing = false val (_, actual) = TestUtils.testString(sch, "abcd,efgh", areTracing) val expected: Node = <e1><s1>abcd</s1><s2>efgh</s2></e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } @Test def testLengthKindDelimited(): Unit = { @@ -88,7 +89,7 @@ class TestPrimitives { val areTracing = false val (_, actual) = TestUtils.testString(sch, "abcd,efgh", areTracing) val expected: Node = <e1><s1>abcd</s1><s2>efgh</s2></e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } @Test def testLengthKindDelimited2(): Unit = { @@ -106,7 +107,7 @@ class TestPrimitives { ) val (_, actual) = TestUtils.testString(sch, "abcd \\\n efgh") val expected: Node = <e1><s1>abcd</s1><s2>efgh</s2></e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } @Test def testLengthKindDelimited3(): Unit = { @@ -132,7 +133,7 @@ class TestPrimitives { val areTracing = false val (_, actual) = TestUtils.testString(sch, "abcd}efgh}}}ijkl", areTracing) val expected: Node = <e1><s1><ss1>abcd</ss1><ss2>efgh</ss2></s1><s2>ijkl</s2></e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } @Test def testDelimiterInheritance(): Unit = { @@ -172,7 +173,7 @@ class TestPrimitives { // a,b,c./d//:: val expected: Node = <root><e1>a</e1><e2>b</e2><e3><e3_1>c</e3_1><e3_2>d</e3_2></e3></root> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } @Test def testEntityReplacementSeparator(): Unit = { @@ -191,7 +192,7 @@ class TestPrimitives { val (_, actual) = TestUtils.testString(sch, "abcd\u0000efgh") val expected: Node = <e1><s1>abcd</s1><s2>efgh</s2></e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } @Test def testEntityReplacementInitiator(): Unit = { @@ -203,7 +204,7 @@ class TestPrimitives { ) val (_, actual) = TestUtils.testString(sch, "\u0000efgh") val expected: Node = <e1>efgh</e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } @Test def testEntityReplacementTerminator(): Unit = { @@ -216,7 +217,7 @@ class TestPrimitives { val (_, actual) = TestUtils.testString(sch, "abcd\u0000") val expected: Node = <e1>abcd</e1> - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } } diff --git a/daffodil-core/src/test/scala/org/apache/daffodil/core/general/TestRuntimeProperties.scala b/daffodil-core/src/test/scala/org/apache/daffodil/core/general/TestRuntimeProperties.scala index 4b908ad36..0a302c5f8 100644 --- a/daffodil-core/src/test/scala/org/apache/daffodil/core/general/TestRuntimeProperties.scala +++ b/daffodil-core/src/test/scala/org/apache/daffodil/core/general/TestRuntimeProperties.scala @@ -21,6 +21,7 @@ import org.apache.daffodil.core.util.TestUtils import org.apache.daffodil.io.InputSourceDataInputStream import org.apache.daffodil.lib.Implicits.intercept import org.apache.daffodil.lib.util.SchemaUtils +import org.apache.daffodil.lib.xml.XMLUtils import org.apache.daffodil.runtime1.api.InfosetSimpleElement import org.apache.daffodil.runtime1.dpath.NodeInfo import org.apache.daffodil.runtime1.infoset.ScalaXMLInfosetInputter @@ -113,7 +114,7 @@ class TestRuntimeProperties { assertFalse(pr.isError) val actual = outputter.getResult() - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } @Test def testRuntimeProperties_02(): Unit = { @@ -226,7 +227,7 @@ class TestRuntimeProperties { assertFalse(pr.isError) val actual = outputter.getResult() - TestUtils.assertEqualsXMLElements(expected, actual) + XMLUtils.compareAndReport(expected, actual) } } diff --git a/daffodil-core/src/test/scala/org/apache/daffodil/core/infoset/TestInfoset2.scala b/daffodil-core/src/test/scala/org/apache/daffodil/core/infoset/TestInfoset2.scala index 7ca0c2487..f63d34f26 100644 --- a/daffodil-core/src/test/scala/org/apache/daffodil/core/infoset/TestInfoset2.scala +++ b/daffodil-core/src/test/scala/org/apache/daffodil/core/infoset/TestInfoset2.scala @@ -16,8 +16,7 @@ */ package org.apache.daffodil.core.infoset - -import org.apache.daffodil.core.util._ +import org.apache.daffodil.core.util.TestUtils import org.apache.daffodil.lib.Implicits._ import org.apache.daffodil.lib.util._ import org.apache.daffodil.lib.xml.XMLUtils @@ -59,7 +58,7 @@ class TestInfoset2 { // make sure that is resolved. assertFalse(xmlStr.contains("No_Namespace")) assertTrue(xmlStr.contains("xmlns=\"\"")) - TestUtils.assertEqualsXMLElements(<b><c>2</c><a>A</a><a>B</a></b>, xml) + XMLUtils.compareAndReport(<b><c>2</c><a>A</a><a>B</a></b>, xml) } finally { // Debugger.setDebugging(false) } diff --git a/daffodil-core/src/test/scala/org/apache/daffodil/core/layers/TestBoundaryMarkLayer.scala b/daffodil-core/src/test/scala/org/apache/daffodil/core/layers/TestBoundaryMarkLayer.scala index eb42c5f84..46a3a02ad 100644 --- a/daffodil-core/src/test/scala/org/apache/daffodil/core/layers/TestBoundaryMarkLayer.scala +++ b/daffodil-core/src/test/scala/org/apache/daffodil/core/layers/TestBoundaryMarkLayer.scala @@ -73,7 +73,7 @@ class TestBoundaryMarkLayer { val infoset = abcInfoset val (_, actual) = TestUtils.testString(sch, data, areTracing = false) - TestUtils.assertEqualsXMLElements(infoset, actual) + XMLUtils.compareAndReport(infoset, actual) TestUtils.testUnparsing(sch, infoset, data, areTracing = false) } diff --git a/daffodil-core/src/test/scala/org/apache/daffodil/core/layers/TestFixedLengthLayer.scala b/daffodil-core/src/test/scala/org/apache/daffodil/core/layers/TestFixedLengthLayer.scala index e414e2fd3..63f7fb57d 100644 --- a/daffodil-core/src/test/scala/org/apache/daffodil/core/layers/TestFixedLengthLayer.scala +++ b/daffodil-core/src/test/scala/org/apache/daffodil/core/layers/TestFixedLengthLayer.scala @@ -70,7 +70,7 @@ class TestFixedLengthLayer { val infoset = abcInfoset val (_, actual) = TestUtils.testString(sch, data, areTracing = false) - TestUtils.assertEqualsXMLElements(infoset, actual) + XMLUtils.compareAndReport(infoset, actual) TestUtils.testUnparsing(sch, infoset, data, areTracing = false) } diff --git a/daffodil-core/src/test/scala/org/apache/daffodil/core/layers/TestGzipErrors.scala b/daffodil-core/src/test/scala/org/apache/daffodil/core/layers/TestGzipErrors.scala index 400258f4e..a4f311b28 100644 --- a/daffodil-core/src/test/scala/org/apache/daffodil/core/layers/TestGzipErrors.scala +++ b/daffodil-core/src/test/scala/org/apache/daffodil/core/layers/TestGzipErrors.scala @@ -125,7 +125,7 @@ a few lines of pointless text like this.""".replace("\r\n", "\n").replace("\n", </e1> </ex:root> val (_, actual) = TestUtils.testBinary(sch, data, areTracing = false) - TestUtils.assertEqualsXMLElements(infoset, actual) + XMLUtils.compareAndReport(infoset, actual) } @Test def testGZIPLayerErr1(): Unit = { @@ -139,7 +139,7 @@ a few lines of pointless text like this.""".replace("\r\n", "\n").replace("\n", <hex xmlns=""><![CDATA[000000D41F8B08000000000000FF4D904176C3200C44AF3207C8F33DBA6F0F40CCD85683918B44D3DC3EC2C9A2EFB1013EF3357C6E6288F5DDCD61BA137BCA443FE0FC73F8967C5C4B75D6CC0C575C8984857714A93414ADEB848F25D800B794036045632A67C605E2B86B2F19553D800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000]]></hex> </ex:root> val (_, actual) = TestUtils.testBinary(sch, data, areTracing = false) - TestUtils.assertEqualsXMLElements(infoset, actual) + XMLUtils.compareAndReport(infoset, actual) } @Test def testGZIPLayerErr2(): Unit = { @@ -153,7 +153,7 @@ a few lines of pointless text like this.""".replace("\r\n", "\n").replace("\n", <hex xmlns=""><![CDATA[000000D41F8B08000000000000FF4D904176C3200C44AF3207C8F33DBA6F0F40CCD85683918B44D3DC3EC2C9A2EFB1013EF3357C6E6288F5DDCD61BA137BCA443FE0FC73F8967C5C4B75D6CC0C575C8984857714A93414ADEB848F25D800B794036045632A67C605E2B86B2F19553D805FBE889F2ECE70E2AA4DEA3AA2E3519EF065842E58D2AEDD02530F8DB640832A8F26F3B94DF511CA712437BE27ADDE34F739F8598F20D7CD875566460BEBB4CB10CAD989C9846D684DF6A33CA2F9ED6CFEBF5DCC7168C4169ABDBEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF]]></hex> </ex:root> val (_, actual) = TestUtils.testBinary(sch, data, areTracing = false) - TestUtils.assertEqualsXMLElements(infoset, actual) + XMLUtils.compareAndReport(infoset, actual) } val GZIPLayerErrSchema = @@ -279,7 +279,9 @@ a few lines of pointless text like this.""".replace("\r\n", "\n").replace("\n", // which only takes a few seconds, and // all errors thrown were converted to parse errors // so that means they were all IOExceptions from the gzip layer. - @Test def testGZIPLayerFuzz3(): Unit = - fuzz3(10, sch = GZIPLayerErrSchema, data = makeGZIPLayer1Data()._1, expected) + @Test def testGZIPLayerFuzz3(): Unit = { + // 2000 trials gives us good test coverage of the fuzz testing framework. + fuzz3(2000, sch = GZIPLayerErrSchema, data = makeGZIPLayer1Data()._1, expected) + } } diff --git a/daffodil-core/src/test/scala/org/apache/daffodil/core/layers/TestLayers.scala b/daffodil-core/src/test/scala/org/apache/daffodil/core/layers/TestLayers.scala index 040c8d244..302fe3fbd 100644 --- a/daffodil-core/src/test/scala/org/apache/daffodil/core/layers/TestLayers.scala +++ b/daffodil-core/src/test/scala/org/apache/daffodil/core/layers/TestLayers.scala @@ -89,7 +89,7 @@ class TestLayers { val data = "cGxl!" // encoding of "ple" + "!" val infoset = <ex:e1 xmlns:ex={example}><s1>ple</s1></ex:e1> val (_, actual) = TestUtils.testString(sch, data) - TestUtils.assertEqualsXMLElements(infoset, actual) + XMLUtils.compareAndReport(infoset, actual) val areTracing = false TestUtils.testUnparsing(sch, infoset, data, areTracing) @@ -126,7 +126,7 @@ class TestLayers { val data = "cGxl!" // encoding of "ple" + "!" val infoset = <ex:e1 xmlns:ex={example}><s1>ple</s1></ex:e1> val (_, actual) = TestUtils.testString(sch, data) - TestUtils.assertEqualsXMLElements(infoset, actual) + XMLUtils.compareAndReport(infoset, actual) val areTracing = false TestUtils.testUnparsing(sch, infoset, data, areTracing) @@ -166,7 +166,7 @@ class TestLayers { val data = "cGxl" + "!" + "moreDataAfter" val infoset = <ex:e1 xmlns:ex={example}><s1>ple</s1><s2>moreDataAfter</s2></ex:e1> val (_, actual) = TestUtils.testString(sch, data) - TestUtils.assertEqualsXMLElements(infoset, actual) + XMLUtils.compareAndReport(infoset, actual) val areTracing = false TestUtils.testUnparsing(sch, infoset, data, areTracing) @@ -230,7 +230,7 @@ a few lines of pointless text like this.""".replace("\r\n", "\n").replace("\n", text }</s1></ex:e1> val (_, actual) = TestUtils.testBinary(sch, data, areTracing = false) - TestUtils.assertEqualsXMLElements(infoset, actual) + XMLUtils.compareAndReport(infoset, actual) TestUtils.testUnparsingBinary(sch, infoset, data) } @@ -288,7 +288,7 @@ a few lines of pointless text like this.""".replace("\r\n", "\n").replace("\n", text }</s1></data></x1><s2>afterGzip</s2></ex:e1> val (_, actual) = TestUtils.testBinary(sch, data, areTracing = false) - TestUtils.assertEqualsXMLElements(infoset, actual) + XMLUtils.compareAndReport(infoset, actual) TestUtils.testUnparsingBinary(sch, infoset, data) } @@ -385,7 +385,7 @@ a few lines of pointless text like this.""".replace("\r\n", "\n").replace("\n", }</len><x1><data><s2>{ text }</s2></data></x1><s3>{after}</s3></ex:e1> - TestUtils.assertEqualsXMLElements(infoset, actual) + XMLUtils.compareAndReport(infoset, actual) TestUtils.testUnparsingBinary(sch, infoset, data) } @@ -422,7 +422,7 @@ a few lines of pointless text like this.""".replace("\r\n", "\n").replace("\n", val data = ipsumLorem1 val infoset = <e1 xmlns={example}><s1>{ipsumLorem1Unfolded}</s1></e1> val (_, actual) = TestUtils.testString(sch, data) - TestUtils.assertEqualsXMLElements(infoset, actual) + XMLUtils.compareAndReport(infoset, actual) } val ipsumLorem2 = @@ -472,7 +472,7 @@ a few lines of pointless text like this.""".replace("\r\n", "\n").replace("\n", val data = ipsumLorem3 val infoset = <e1 xmlns={example}><s1>{ipsumLorem3Unfolded}</s1></e1> val (_, actual) = TestUtils.testString(sch, data) - TestUtils.assertEqualsXMLElements(infoset, actual) + XMLUtils.compareAndReport(infoset, actual) } val ipsumLorem4 = @@ -524,7 +524,7 @@ a few lines of pointless text like this.""".replace("\r\n", "\n").replace("\n", val data = ipsumLorem5 val infoset = <e1 xmlns={example}><s1>{ipsumLorem5Unfolded}</s1></e1> val (_, actual) = TestUtils.testString(sch, data) - TestUtils.assertEqualsXMLElements(infoset, actual) + XMLUtils.compareAndReport(infoset, actual) } val ipsumLorem6 = @@ -603,7 +603,7 @@ a few lines of pointless text like this.""".replace("\r\n", "\n").replace("\n", </e1> val (_, actual) = TestUtils.testBinary(sch, data, areTracing = false) - TestUtils.assertEqualsXMLElements(infoset, actual) + XMLUtils.compareAndReport(infoset, actual) TestUtils.testUnparsingBinary(sch, infoset, data) } diff --git a/daffodil-core/src/test/scala/org/apache/daffodil/core/runtime1/TestStreamingUnparserCompilerAttributes.scala b/daffodil-core/src/test/scala/org/apache/daffodil/core/runtime1/TestStreamingUnparserCompilerAttributes.scala index c8780f043..21d7aee31 100644 --- a/daffodil-core/src/test/scala/org/apache/daffodil/core/runtime1/TestStreamingUnparserCompilerAttributes.scala +++ b/daffodil-core/src/test/scala/org/apache/daffodil/core/runtime1/TestStreamingUnparserCompilerAttributes.scala @@ -24,13 +24,12 @@ import org.apache.daffodil.core.dsom.LocalElementDecl import org.apache.daffodil.core.dsom.LocalSequence import org.apache.daffodil.core.dsom.SequenceGroupRef import org.apache.daffodil.core.dsom.Term +import org.apache.daffodil.core.util.TestUtils.getRoot import org.junit.Test class TestStreamingUnparserCompilerAttributes { - import org.apache.daffodil.core.util.TestUtils._ - import PossibleNextElements._ private def poss(t: Term) = t.possibleNextLexicalSiblingStreamingUnparserElements diff --git a/daffodil-lib/src/main/scala/org/apache/daffodil/lib/exceptions/Assert.scala b/daffodil-lib/src/main/scala/org/apache/daffodil/lib/exceptions/Assert.scala index 37941c0c9..bbcdaee94 100644 --- a/daffodil-lib/src/main/scala/org/apache/daffodil/lib/exceptions/Assert.scala +++ b/daffodil-lib/src/main/scala/org/apache/daffodil/lib/exceptions/Assert.scala @@ -45,6 +45,31 @@ abstract class ThinException protected (dummy: Int, cause: Throwable, fmt: Strin def this(cause: Throwable) = this(1, cause, null) } +/** + * Used for when multiple diagnostic or exception/throwable objects have been + * gathered and we want to throw all of them. + * @param causes + * @tparam T + */ +class MultiException[T <: Throwable] private (causes: Seq[T], msg: String, cause: T) + extends ThinException(msg, cause) { + def this(causes: Seq[T]) = this( + causes, + null, + causes.headOption.getOrElse( + Assert.usageError("There must be one or more causes.") + ) + ) + private lazy val msgs = causes.map { Misc.getAMessage(_) }.mkString("\n") + override def getMessage(): String = msgs + def getCauses(): Seq[T] = causes + def toss: Nothing = + if (causes.length == 1) + throw cause + else + throw this +} + // $COVERAGE-OFF$ These exception objects should never be created by tests. abstract class UnsuppressableException(m: String, th: Throwable) extends Exception(m, th) { def this(msg: String) = this(msg, null) diff --git a/daffodil-lib/src/main/scala/org/apache/daffodil/lib/util/Misc.scala b/daffodil-lib/src/main/scala/org/apache/daffodil/lib/util/Misc.scala index 26ead1009..0ab579a0d 100644 --- a/daffodil-lib/src/main/scala/org/apache/daffodil/lib/util/Misc.scala +++ b/daffodil-lib/src/main/scala/org/apache/daffodil/lib/util/Misc.scala @@ -696,32 +696,36 @@ object Misc { * gets the message from that, if that has no message, it chases further. * Ultimately, if there's no message, it just uses the innermost cause object's class name. */ - - def getSomeMessage(th: Throwable): Some[String] = { + def getAMessage(th: Throwable): String = { val m = th.getMessage() val c = th.getCause() val res = (m, c) match { case (null, null) => Misc.getNameFromClass(th) case ("", null) => Misc.getNameFromClass(th) case (m, null) => m - case (null, c) => getSomeMessage(c).get + case (null, c) => getAMessage(c) case (m, c) => { - val Some(cmsg) = getSomeMessage(c) + val cmsg = getAMessage(c) cmsg + " (within " + th.getClass.getSimpleName + " " + m + ")" } } - Some(res) + Assert.invariant(res != null) + res } - def getSomeCause(th: Throwable): Some[Throwable] = { + def getSomeMessage(th: Throwable): Some[String] = Some(getAMessage(th)) + + def getACause(th: Throwable): Throwable = { val c = th.getCause() val res = c match { case null => th - case _ => getSomeCause(c).get + case _ => getACause(c) } - Some(res) + res } + def getSomeCause(th: Throwable): Some[Throwable] = Some(getACause(th)) + /** * Get the diagnosticFilepath from a uri */ diff --git a/daffodil-lib/src/main/scala/org/apache/daffodil/lib/xml/XMLUtils.scala b/daffodil-lib/src/main/scala/org/apache/daffodil/lib/xml/XMLUtils.scala index dc41c6504..7a0841d1b 100644 --- a/daffodil-lib/src/main/scala/org/apache/daffodil/lib/xml/XMLUtils.scala +++ b/daffodil-lib/src/main/scala/org/apache/daffodil/lib/xml/XMLUtils.scala @@ -814,6 +814,11 @@ object XMLUtils { class XMLDifferenceException(message: String) extends Exception(message) + /** + * Compares two XML Elements, after having (optionally) stripped off all attributes. + * + * Throws XMLDifferenceException if not the same. + */ def compareAndReport( expected: Node, actual: Node, diff --git a/daffodil-test/src/test/scala/org/apache/daffodil/runtime1/layers/TestCheckDigit.scala b/daffodil-test/src/test/scala/org/apache/daffodil/runtime1/layers/TestCheckDigit.scala index 740f58006..17a24ed9e 100644 --- a/daffodil-test/src/test/scala/org/apache/daffodil/runtime1/layers/TestCheckDigit.scala +++ b/daffodil-test/src/test/scala/org/apache/daffodil/runtime1/layers/TestCheckDigit.scala @@ -20,6 +20,7 @@ import scala.xml.Elem import org.apache.daffodil.core.util.TestUtils import org.apache.daffodil.lib.Implicits.intercept +import org.apache.daffodil.lib.util.Misc.getAMessage import org.apache.daffodil.lib.util.SchemaUtils import org.apache.daffodil.lib.xml.XMLUtils import org.apache.daffodil.runtime1.processors.parsers.ParseError @@ -137,7 +138,7 @@ class TestCheckDigit { val infoset = okInfoset val (_, actual) = TestUtils.testString(sch, data, areTracing = false) - TestUtils.assertEqualsXMLElements(infoset, actual) + XMLUtils.compareAndReport(infoset, actual) TestUtils.testUnparsing(sch, infoset, data, areTracing = false) } @@ -151,7 +152,7 @@ class TestCheckDigit { val e = intercept[ParseError] { TestUtils.testString(sch, data, areTracing = false) } - val msg = TestUtils.getAMessage(e) + val msg = getAMessage(e) assertTrue(msg.contains("length is negative")) } // unparse @@ -159,7 +160,7 @@ class TestCheckDigit { val e = intercept[UnparseError] { TestUtils.testUnparsing(sch, infoset, data, areTracing = false) } - val msg = TestUtils.getAMessage(e) + val msg = getAMessage(e) assertTrue(msg.contains("length is negative")) } } @@ -173,7 +174,7 @@ class TestCheckDigit { val e = intercept[ParseError] { TestUtils.testString(sch, data, areTracing = false) } - val msg = TestUtils.getAMessage(e) + val msg = getAMessage(e) assertTrue(msg.contains("out of range for type")) } // unparse @@ -181,7 +182,7 @@ class TestCheckDigit { val e = intercept[UnparseError] { TestUtils.testUnparsing(sch, infoset, data, areTracing = false) } - val msg = TestUtils.getAMessage(e) + val msg = getAMessage(e) assertTrue(msg.contains("out of range for type")) } } @@ -193,7 +194,7 @@ class TestCheckDigit { val e = intercept[ParseError] { TestUtils.testString(sch, data, areTracing = false) } - val msg = TestUtils.getAMessage(e) + val msg = getAMessage(e) assertTrue(msg.toLowerCase.contains("insufficient data")) } @@ -231,7 +232,7 @@ class TestCheckDigit { val e = intercept[UnparseError] { TestUtils.testUnparsing(sch, infoset, data, areTracing = false) } - val msg = TestUtils.getAMessage(e) + val msg = getAMessage(e) assertTrue(msg.toLowerCase.contains("exceeded fixed layer length")) } @@ -248,13 +249,13 @@ class TestCheckDigit { val e = intercept[Throwable] { TestUtils.testString(sch, data, areTracing = false) } - val msg = TestUtils.getAMessage(e) + val msg = getAMessage(e) assertTrue(msg.contains("notACharsetName")) val f = intercept[UnparseError] { TestUtils.testUnparsing(sch, infoset, data, areTracing = false) } - val m = TestUtils.getAMessage(f) + val m = getAMessage(f) assertTrue(m.contains("notACharsetName")) } diff --git a/daffodil-test/src/test/scala/org/apache/daffodil/runtime1/layers/TestLayers2.scala b/daffodil-test/src/test/scala/org/apache/daffodil/runtime1/layers/TestLayers2.scala index 7a3ab2e6c..f04e48c1f 100644 --- a/daffodil-test/src/test/scala/org/apache/daffodil/runtime1/layers/TestLayers2.scala +++ b/daffodil-test/src/test/scala/org/apache/daffodil/runtime1/layers/TestLayers2.scala @@ -17,9 +17,9 @@ package org.apache.daffodil.runtime1.layers -import org.apache.daffodil.core.util.TestUtils import org.apache.daffodil.lib.Implicits.intercept import org.apache.daffodil.lib.exceptions.Abort +import org.apache.daffodil.lib.util.Misc import org.apache.daffodil.tdml.Runner import org.apache.daffodil.tdml.TDMLException @@ -152,7 +152,7 @@ class TestLayers2 { .replace("WithSuspension", "") .toLowerCase val e = f(testName) - val cMsg = TestUtils.getAMessage(e) + val cMsg = Misc.getAMessage(e) // println(s">>>>\n $cMsg\n<<<<<") // keep this. if (cMsg == null) fail("no cause message")
