stevedlawrence commented on a change in pull request #755:
URL: https://github.com/apache/daffodil/pull/755#discussion_r807887187



##########
File path: 
daffodil-runtime1/src/test/scala/org/apache/daffodil/dpath/TestDFDLXFunctions.scala
##########
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.daffodil.dpath
+
+import org.junit.Test
+import sys.process._
+import java.nio.file.Paths
+import org.apache.daffodil.xml.XMLUtils
+
+class TestDFDLXFunctions{
+
+    val DAFFODIL_JAVA_OPTS = Map("DAFFODIL_JAVA_OPTS" -> "-Xms256m -Xmx2048m 
-Dfile.encoding=UTF-8")
+
+      def cmdConvert(str: String): String = {
+    if (isWindows)
+      str.replaceAll("/", "\\\\")
+    else
+      str
+  }
+
+    val isWindows = 
System.getProperty("os.name").toLowerCase().startsWith("windows")
+
+  val dafRoot = sys.env.get("DAFFODIL_HOME").getOrElse(".")
+
+  def daffodilPath(dafRelativePath: String): String = {
+    XMLUtils.slashify(dafRoot) + dafRelativePath
+  }
+
+   def devNull(): String = {
+    if (isWindows) {
+      "NUL"
+    } else {
+      "/dev/null"
+    }
+  }
+
+  val binPath = Paths.get(dafRoot, "daffodil-cli", "target", "universal", 
"stage", "bin", String.format("daffodil%s", (if (isWindows) ".bat" else 
""))).toString()
+
+  @Test def test_2575_DFDLX_Trace_output(): Unit = {
+    val schemaFile = 
daffodilPath("daffodil-runtime1/src/main/resources/test/validation/trace_output.dfdl.xsd")
+    val inputFile = 
daffodilPath("daffodil-runtime1/src/main/resources/test/validation/trace_output.txt.xml")
+    val (testSchemaFile, testInputFile) = if (isWindows) 
(cmdConvert(schemaFile), cmdConvert(inputFile)) else (schemaFile, inputFile)
+
+    try{
+      
+      val cmd = String.format("%s unparse -r output -s %s -o %s %s", binPath, 
testSchemaFile, devNull, testInputFile)
+
+      val stdout = new StringBuilder
+      val stderr = new StringBuilder
+      val status = cmd ! ProcessLogger(stdout append _, stderr append _)
+      assert(stderr.toString.equals(""))
+    } finally {
+    }
+  }
+
+}

Review comment:
       Tests that run the daffodil CLI are part of the `IntegrationTest` 
configuration, and must be in the `daffodil-cli/src/it/` directory and can be 
run with `sbt IntegrationTest/test`. The tests in that directory aso already 
have infrastructure for testing the CLI, so much of the logic you have (e.g. 
slashes, .bat, capturing output) is already implemented.  I'd recommend 
creating a new test in that repo using an existing CLI test as an example.

##########
File path: 
daffodil-runtime1/src/test/scala/org/apache/daffodil/dpath/TestDFDLXFunctions.scala
##########
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.daffodil.dpath
+
+import org.junit.Test
+import sys.process._
+import java.nio.file.Paths
+import org.apache.daffodil.xml.XMLUtils
+
+class TestDFDLXFunctions{
+
+    val DAFFODIL_JAVA_OPTS = Map("DAFFODIL_JAVA_OPTS" -> "-Xms256m -Xmx2048m 
-Dfile.encoding=UTF-8")
+
+      def cmdConvert(str: String): String = {
+    if (isWindows)
+      str.replaceAll("/", "\\\\")
+    else
+      str
+  }
+
+    val isWindows = 
System.getProperty("os.name").toLowerCase().startsWith("windows")
+
+  val dafRoot = sys.env.get("DAFFODIL_HOME").getOrElse(".")
+
+  def daffodilPath(dafRelativePath: String): String = {
+    XMLUtils.slashify(dafRoot) + dafRelativePath
+  }
+
+   def devNull(): String = {
+    if (isWindows) {
+      "NUL"
+    } else {
+      "/dev/null"
+    }
+  }
+
+  val binPath = Paths.get(dafRoot, "daffodil-cli", "target", "universal", 
"stage", "bin", String.format("daffodil%s", (if (isWindows) ".bat" else 
""))).toString()
+
+  @Test def test_2575_DFDLX_Trace_output(): Unit = {
+    val schemaFile = 
daffodilPath("daffodil-runtime1/src/main/resources/test/validation/trace_output.dfdl.xsd")
+    val inputFile = 
daffodilPath("daffodil-runtime1/src/main/resources/test/validation/trace_output.txt.xml")
+    val (testSchemaFile, testInputFile) = if (isWindows) 
(cmdConvert(schemaFile), cmdConvert(inputFile)) else (schemaFile, inputFile)
+
+    try{
+      
+      val cmd = String.format("%s unparse -r output -s %s -o %s %s", binPath, 
testSchemaFile, devNull, testInputFile)
+
+      val stdout = new StringBuilder
+      val stderr = new StringBuilder
+      val status = cmd ! ProcessLogger(stdout append _, stderr append _)
+      assert(stderr.toString.equals(""))

Review comment:
       This doesn't test that we actually get trace output. We want to make 
sure that we get the right error message to stderror. Mentioned in another 
comment, we can do that with ExpectIt and the existing test infrastructure.

##########
File path: 
daffodil-runtime1/src/test/scala/org/apache/daffodil/dpath/TestDFDLXFunctions.scala
##########
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.daffodil.dpath
+
+import org.junit.Test
+import sys.process._
+import java.nio.file.Paths
+import org.apache.daffodil.xml.XMLUtils
+
+class TestDFDLXFunctions{
+
+    val DAFFODIL_JAVA_OPTS = Map("DAFFODIL_JAVA_OPTS" -> "-Xms256m -Xmx2048m 
-Dfile.encoding=UTF-8")
+
+      def cmdConvert(str: String): String = {
+    if (isWindows)
+      str.replaceAll("/", "\\\\")
+    else
+      str
+  }
+
+    val isWindows = 
System.getProperty("os.name").toLowerCase().startsWith("windows")
+
+  val dafRoot = sys.env.get("DAFFODIL_HOME").getOrElse(".")
+
+  def daffodilPath(dafRelativePath: String): String = {
+    XMLUtils.slashify(dafRoot) + dafRelativePath
+  }
+
+   def devNull(): String = {
+    if (isWindows) {
+      "NUL"
+    } else {
+      "/dev/null"
+    }
+  }
+
+  val binPath = Paths.get(dafRoot, "daffodil-cli", "target", "universal", 
"stage", "bin", String.format("daffodil%s", (if (isWindows) ".bat" else 
""))).toString()
+
+  @Test def test_2575_DFDLX_Trace_output(): Unit = {
+    val schemaFile = 
daffodilPath("daffodil-runtime1/src/main/resources/test/validation/trace_output.dfdl.xsd")
+    val inputFile = 
daffodilPath("daffodil-runtime1/src/main/resources/test/validation/trace_output.txt.xml")
+    val (testSchemaFile, testInputFile) = if (isWindows) 
(cmdConvert(schemaFile), cmdConvert(inputFile)) else (schemaFile, inputFile)
+
+    try{
+      
+      val cmd = String.format("%s unparse -r output -s %s -o %s %s", binPath, 
testSchemaFile, devNull, testInputFile)

Review comment:
       Your schema calls `dfdlx:trace` in the `dfdl:inputValueCalc` property. 
That property is only evaluated when parsing, but this is an unparse test, so 
it will never see the output. `dfdlx:trace` doesn't care about parse vs 
unparse, so it seems reasonable to just make this a parse test.

##########
File path: 
daffodil-runtime1/src/main/resources/test/validation/trace_output.dfdl.xsd
##########
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+<xs:schema
+  targetNamespace="http://example.com";
+  xmlns:xs="http://www.w3.org/2001/XMLSchema";
+  xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/";
+  xmlns:dfdlx="http://www.ogf.org/dfdl/dfdl-1.0/extensions";
+  xmlns:ex="http://example.com";
+  xmlns="http://example.com";
+  elementFormDefault="unqualified"> 
+
+  <xs:include 
schemaLocation="org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd"/>
+
+  <xs:annotation> 
+    <xs:appinfo source="http://www.ogf.org/dfdl/"; >
+      <dfdl:format ref="ex:GeneralFormat" representation="text" />
+    </xs:appinfo>
+  </xs:annotation>
+        
+       <xs:element name="output">
+               <xs:complexType>
+                       <xs:sequence>
+                               <xs:element name="message" type="xs:string" 
dfdl:inputValueCalc="{dfdlx:trace('hello', 'input')}" />
+                       </xs:sequence>
+               </xs:complexType>
+       </xs:element>
+</xs:schema>

Review comment:
       We aren't that strict about this, but we usually prefer files end with a 
newline. There should be a setting in your IDE to make sure files are saved 
with a newline.




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to