This is an automated email from the ASF dual-hosted git repository.

slawrence 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 63c4318e9 Include the input buffer in ExpectIt failure messages
63c4318e9 is described below

commit 63c4318e9845246cc34a912726d8d0362236f922
Author: Steve Lawrence <[email protected]>
AuthorDate: Fri Feb 23 14:59:21 2024 -0500

    Include the input buffer in ExpectIt failure messages
    
    When ExpectIt fails to find a match in CLI tests, it adds the input
    buffer that scanned in the exception object it throws. Unfortunately, it
    does not include that buffer in the actual message, likely because it
    could be pretty verbose.
    
    Most of our CLI test outputs are fairly small, so we add the input
    buffer to the actual exception message so it can be seen by users. This
    should make debugging failing CLI tests a bit easier without having to
    enable the debug parameter in runCLI and re-run the test.
    
    DAFFODIL-2878
---
 .../apache/daffodil/cli/cliTest/TestCLIParsing.scala    | 17 +++++++++++++++++
 .../scala/org/apache/daffodil/cli/cliTest/Util.scala    | 11 ++++++++++-
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git 
a/daffodil-cli/src/test/scala/org/apache/daffodil/cli/cliTest/TestCLIParsing.scala
 
b/daffodil-cli/src/test/scala/org/apache/daffodil/cli/cliTest/TestCLIParsing.scala
index d11a8c518..1de7a5397 100644
--- 
a/daffodil-cli/src/test/scala/org/apache/daffodil/cli/cliTest/TestCLIParsing.scala
+++ 
b/daffodil-cli/src/test/scala/org/apache/daffodil/cli/cliTest/TestCLIParsing.scala
@@ -21,6 +21,7 @@ import java.nio.charset.StandardCharsets.UTF_8
 
 import org.apache.daffodil.cli.Main.ExitCode
 import org.apache.daffodil.cli.cliTest.Util._
+import org.apache.daffodil.lib.Implicits._
 
 import org.apache.commons.io.FileUtils
 import org.junit.Assert._
@@ -940,4 +941,20 @@ class TestCLIParsing {
       cli.expectErr("Unexpected exception in layer transformer 'buggy'")
     }(ExitCode.LayerExecutionError)
   }
+
+  @Test def test_CLI_util_expectException(): Unit = {
+    val schema = path(
+      
"daffodil-test/src/test/resources/org/apache/daffodil/section00/general/elementFormDefaultQualified.dfdl.xsd",
+    )
+
+    val e = intercept[net.sf.expectit.ExpectIOException] {
+      runCLI(args"parse -s $schema -r s1") { cli =>
+        cli.sendLine("strng", inputDone = true)
+        cli.expect("Does Not Exist")
+      }(ExitCode.Failure)
+    }
+    assertTrue(
+      e.getMessage.contains("""Input Buffer: <?xml version="1.0" 
encoding="UTF-8"?>"""),
+    )
+  }
 }
diff --git 
a/daffodil-cli/src/test/scala/org/apache/daffodil/cli/cliTest/Util.scala 
b/daffodil-cli/src/test/scala/org/apache/daffodil/cli/cliTest/Util.scala
index ba97f018d..888cac7d7 100644
--- a/daffodil-cli/src/test/scala/org/apache/daffodil/cli/cliTest/Util.scala
+++ b/daffodil-cli/src/test/scala/org/apache/daffodil/cli/cliTest/Util.scala
@@ -40,6 +40,7 @@ import org.apache.daffodil.cli.Main.ExitCode
 import com.fasterxml.jackson.core.io.JsonStringEncoder
 import net.sf.expectit.Expect
 import net.sf.expectit.ExpectBuilder
+import net.sf.expectit.ExpectIOException
 import net.sf.expectit.Result
 import net.sf.expectit.filter.Filters.replaceInString
 import net.sf.expectit.matcher.Matcher
@@ -311,7 +312,15 @@ object Util {
     // if the test thread didn't end cleanly then it must have thrown an 
exception
     // (e.g. assertion failed, interrupted exception). Just rethrow that 
exception
     // and cause the test to fail
-    testThread.optException.map { e => throw e }
+    testThread.optException.map {
+      case e: ExpectIOException => {
+        // if an expect match fails then we include the input buffer in the 
exceptions message.
+        // This could be pretty verbose for large infosets, but makes 
debugging easier
+        val msg = e.getMessage() + ", Input Buffer: " + e.getInputBuffer()
+        throw new ExpectIOException(msg, e.getInputBuffer())
+      }
+      case e => throw e
+    }
 
     // if the test thread didn't throw an exception then that means all of its 
tests
     // passed. We just need to verify the CLI exit code

Reply via email to