You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by GitBox <gi...@apache.org> on 2021/08/10 11:38:17 UTC

[GitHub] [daffodil] stevedlawrence commented on a change in pull request #601: Distinct return codes for CLI

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



##########
File path: daffodil-cli/src/it/scala/org/apache/daffodil/CLI/Util.scala
##########
@@ -203,4 +171,30 @@ object Util {
     }
     inputFile
   }
+
+  def expectExitCode(expectedExitCode: ExitCode.Value, shell: Expect): Unit = {
+    val expectedCode = expectedExitCode.id
+
+    val keyWord = "EXITCODE:"
+
+    //Escaped characters ^| for windows and \\! for linux makes the echo outputs different text than the command,
+    //That way the expect function can tell the difference.
+    val exitCodeCmd = "echo " + keyWord + (if (Util.isWindows) "^|%errorlevel%" else "\\!$?")
+    val exitCodeExpectation = keyWord + (if (Util.isWindows) "|" else "!")
+
+    shell.sendLine(exitCodeCmd)
+    shell.expect(contains(exitCodeExpectation))
+
+    val sExitCode = shell.expect(contains("\n")).getBefore().trim()
+    val actualInt = Integer.parseInt(sExitCode)
+
+    if (actualInt != expectedCode) {
+      val expectedExitCodeName = expectedExitCode.toString
+      val actualExitCodeName = ExitCode(actualInt)

Review comment:
       If the `actualInt` does not match the expected exit code, then that likely means there's some bug, and it's possible that `actualInt` doesn't even map to an ExitCode. This line would then will result in a NoSuchElement exception.
   
   We could just not output an actual exit code name, but it probably is useful information to have when it's available. So instead we could do something like this to get an ExitCode name if it exists, otherwise just display "Unknown:
   ```scala
   val actualExitCodeName = ExitCode.values.find { _.id == actualInt }.map { _.toString }.getOrElse("Unknown")
   ```




-- 
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: commits-unsubscribe@daffodil.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org