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

olabusayo 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 81de17089 Implement Trace/Debug functionality for CLI TDML test
81de17089 is described below

commit 81de17089a175f518b91ac5e6a8c3a8d29b6add7
Author: olabusayoT <[email protected]>
AuthorDate: Tue Jul 11 16:57:55 2023 -0400

    Implement Trace/Debug functionality for CLI TDML test
    
    - fix bug with debugger where we were casting the data processor as an 
instance of the Debugger instead of the passed in debugger
    - fix DAFFODIL-2833 by using TraceDebuggerRunner instead of TDMLRunner.trace
    - set areDebuggingFlag when a debugger is set with withDebugger
    - add debug.txt to rat excludes
    
    DAFFODIL-2694 DAFFODIL-2833
---
 .../main/scala/org/apache/daffodil/cli/Main.scala  | 23 ++++++++++++-
 .../resources/org/apache/daffodil/cli/debug.txt    |  2 ++
 .../apache/daffodil/cli/cliTest/TestCLItdml.scala  | 40 ++++++++++++++++++++++
 .../runtime1/processors/DataProcessor.scala        |  2 +-
 .../processor/tdml/DaffodilTDMLDFDLProcessor.scala |  6 ++--
 project/Rat.scala                                  |  1 +
 6 files changed, 69 insertions(+), 5 deletions(-)

diff --git a/daffodil-cli/src/main/scala/org/apache/daffodil/cli/Main.scala 
b/daffodil-cli/src/main/scala/org/apache/daffodil/cli/Main.scala
index 1aa8e345c..2d1fb0029 100644
--- a/daffodil-cli/src/main/scala/org/apache/daffodil/cli/Main.scala
+++ b/daffodil-cli/src/main/scala/org/apache/daffodil/cli/Main.scala
@@ -1516,7 +1516,28 @@ class Main(
 
         val tdmlFile = testOpts.tdmlfile()
         val optTDMLImplementation = testOpts.implementation.toOption
-        val tdmlRunner = Runner(tdmlFile, optTDMLImplementation)
+        val tdmlRunnerInit = Runner(tdmlFile, optTDMLImplementation)
+
+        val tdmlRunner = if (conf.trace() || conf.debug.isDefined) {
+          val db = if (conf.trace()) {
+            new TraceDebuggerRunner(STDOUT)
+          } else {
+            if (System.console == null) {
+              Logger.log.warn(
+                s"Using --debug on a non-interactive console may result in 
display issues",
+              )
+            }
+            conf.debug() match {
+              case Some(f) => new CLIDebuggerRunner(new File(f), STDIN, STDOUT)
+              case None => new CLIDebuggerRunner(STDIN, STDOUT)
+            }
+          }
+          val id = new InteractiveDebugger(db, ExpressionCompilers)
+          tdmlRunnerInit.setDebugger(id)
+          tdmlRunnerInit
+        } else {
+          tdmlRunnerInit
+        }
 
         val tests = {
           if (testOpts.testnames.isDefined) {
diff --git a/daffodil-cli/src/test/resources/org/apache/daffodil/cli/debug.txt 
b/daffodil-cli/src/test/resources/org/apache/daffodil/cli/debug.txt
new file mode 100644
index 000000000..d7f407da7
--- /dev/null
+++ b/daffodil-cli/src/test/resources/org/apache/daffodil/cli/debug.txt
@@ -0,0 +1,2 @@
+help display
+continue
\ No newline at end of file
diff --git 
a/daffodil-cli/src/test/scala/org/apache/daffodil/cli/cliTest/TestCLItdml.scala 
b/daffodil-cli/src/test/scala/org/apache/daffodil/cli/cliTest/TestCLItdml.scala
index cb087f669..b6e7f1cc8 100644
--- 
a/daffodil-cli/src/test/scala/org/apache/daffodil/cli/cliTest/TestCLItdml.scala
+++ 
b/daffodil-cli/src/test/scala/org/apache/daffodil/cli/cliTest/TestCLItdml.scala
@@ -110,6 +110,46 @@ class TestCLItdml {
     }(ExitCode.Success)
   }
 
+  @Test def test_CLI_Tdml_Trace_singleTest(): Unit = {
+    val tdml = path(
+      
"daffodil-test/src/test/resources/org/apache/daffodil/section06/entities/Entities.tdml",
+    )
+
+    runCLI(args"-t test $tdml byte_entities_6_08") { cli =>
+      cli.expect("parser:")
+      cli.expect("bitPosition:")
+      cli.expect("data:")
+      cli.expect("[Pass] byte_entities_6_08")
+    }(ExitCode.Success)
+  }
+
+  @Test def test_CLI_Tdml_Debug_singleTest(): Unit = {
+    val tdml = path(
+      
"daffodil-test/src/test/resources/org/apache/daffodil/section06/entities/Entities.tdml",
+    )
+
+    runCLI(args"-d test $tdml byte_entities_6_08") { cli =>
+      cli.expect("(debug)")
+      cli.sendLine("continue")
+      cli.expect("[Pass] byte_entities_6_08")
+    }(ExitCode.Success)
+  }
+
+  @Test def test_CLI_Tdml_DebugFile_singleTest(): Unit = {
+    val tdml = path(
+      
"daffodil-test/src/test/resources/org/apache/daffodil/section06/entities/Entities.tdml",
+    )
+    val debugFile = path(
+      "daffodil-cli/src/test/resources/org/apache/daffodil/cli/debug.txt",
+    )
+
+    runCLI(args"-d $debugFile test $tdml byte_entities_6_08") { cli =>
+      cli.expect("(debug)")
+      cli.expect("Usage:")
+      cli.expect("[Pass] byte_entities_6_08")
+    }(ExitCode.Success)
+  }
+
   @Test def test_CLI_catch_TestNotCompatible(): Unit = {
     val tdml = path(
       
"daffodil-cli/src/test/resources/org/apache/daffodil/cli/testNonCompatibleImplementation.tdml",
diff --git 
a/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/processors/DataProcessor.scala
 
b/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/processors/DataProcessor.scala
index c32ab1671..015e614df 100644
--- 
a/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/processors/DataProcessor.scala
+++ 
b/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/processors/DataProcessor.scala
@@ -232,7 +232,7 @@ class DataProcessor(
 
   def withDebugger(dbg: AnyRef): DataProcessor = {
     val optDbg = if (dbg eq null) None else Some(dbg.asInstanceOf[Debugger])
-    copy(optDebugger = optDbg)
+    copy(areDebugging = optDbg.isDefined, optDebugger = optDbg)
   }
 
   def withDebugging(flag: Boolean): DataProcessor = {
diff --git 
a/daffodil-tdml-processor/src/main/scala/org/apache/daffodil/processor/tdml/DaffodilTDMLDFDLProcessor.scala
 
b/daffodil-tdml-processor/src/main/scala/org/apache/daffodil/processor/tdml/DaffodilTDMLDFDLProcessor.scala
index d4189b8f7..b1f933130 100644
--- 
a/daffodil-tdml-processor/src/main/scala/org/apache/daffodil/processor/tdml/DaffodilTDMLDFDLProcessor.scala
+++ 
b/daffodil-tdml-processor/src/main/scala/org/apache/daffodil/processor/tdml/DaffodilTDMLDFDLProcessor.scala
@@ -189,9 +189,9 @@ class DaffodilTDMLDFDLProcessor private (private var dp: 
DataProcessor)
       dp.withDebugging(false)
     }
 
-  override def withDebugger(db: AnyRef): DaffodilTDMLDFDLProcessor = {
-    Assert.usage(dp ne null)
-    val d = dp.asInstanceOf[Debugger]
+  override def withDebugger(debugger: AnyRef): DaffodilTDMLDFDLProcessor = {
+    Assert.usage(debugger ne null)
+    val d = debugger.asInstanceOf[Debugger]
     copy(dp = dp.withDebugger(d))
   }
 
diff --git a/project/Rat.scala b/project/Rat.scala
index e03e4985f..30e7d421a 100644
--- a/project/Rat.scala
+++ b/project/Rat.scala
@@ -196,6 +196,7 @@ object Rat {
     ),
     file("test-stdLayout/src/test/resources/org1/test-outer-data1.txt"),
     file("test-stdLayout/src/test/resources/org2/test-data1.txt"),
+    file("daffodil-cli/src/test/resources/org/apache/daffodil/cli/debug.txt"),
   )
 
   lazy val BSD2_LICENSE_NAME = "BSD 2-Clause License"

Reply via email to