Parsing output of sbt to detect success/fail

I have (I believe) successfully created a script to run sbt in batch and compile and test my automatically assembled scala code. I’d now like to understand the output printed by sbt.
I get something like the following. How do I know whether “it worked”? and what does “it worked” mean?

For example I see the lines

[info] Done compiling.
[success] Total time: 6 s, completed May 11, 2019 12:31:55 PM

Does this mean compile succeeded with no errors, or does it mean sbt successfully ran the compiler which itself might have reported errors and failed to compile?

Also I see the following lines

[info] All tests passed.
[info] Passed: Total 2, Failed 0, Errors 0, Passed 2
[success] Total time: 4 s, completed May 11, 2019 12:32:00 PM

What does success mean? Is it that all tests passed, or that sbt successfully ran the tests, which might have themselves failed.

Is there a way for me to check for success better than grepping the output for certain patterns?

Here is the actual output?

[info] Updated file /private/tmp/jimka/scalain_e/24693/project/build.properties: set sbt.version to 1.2.8
[info] Loading settings for project global-plugins from idea.sbt ...
[info] Loading global plugins from /Users/jimka/.sbt/1.0/plugins
[info] Loading project definition from /private/tmp/jimka/scalain_e/24693/project
[info] Updating ProjectRef(uri("file:/private/tmp/jimka/scalain_e/24693/project/"), "root-24693-build")...
[info] Done updating.
[info] Loading settings for project root-24693 from build.sbt ...
[info] Set current project to greeting (in build file:/private/tmp/jimka/scalain_e/24693/)
[info] Executing in batch mode. For better performance use sbt's shell
[info] Updating ...
[info] Done updating.
[info] Compiling 2 Scala sources to /private/tmp/jimka/scalain_e/24693/target/scala-2.12/classes ...
[info] Done compiling.
[success] Total time: 6 s, completed May 11, 2019 12:31:55 PM
[info] Compiling 1 Scala source to /private/tmp/jimka/scalain_e/24693/target/scala-2.12/test-classes ...
[info] Done compiling.
hello world 
hello jim!
[info] GreetingTestSuite:
[info] - greeting
[info] - HW customized greeting
[info] ScalaTest
[info] Run completed in 676 milliseconds.
[info] Total number of tests run: 2
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 2, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
[info] Passed: Total 2, Failed 0, Errors 0, Passed 2
[success] Total time: 4 s, completed May 11, 2019 12:32:00 PM

How much detail do you need? If you just need success / fail, can you use the return code for the sbt shell command ($?) and check?

If you need more detail, “sbt test” outputs JUnit-style XML reports as described in the docs - there are many tools that can parse and interpret those, or you could write your own in a pinch.

@wrbriggs, thanks for the suggestion, but I’m missing just a bit of information. Does success mean that running the tests succeeded, or that the tests themselves succeeded? For the moment I’m just searching the output by regular expression to find the number of passed as I expected. In particular I’m parsing the line

[info] Passed: Total 2, Failed 0, Errors 0, Passed 2

But later it occurred to me that that might be overkill.

However, it turns out that if sbt successfully determines that some tests failed, then it does not report success.

[info] ScalaTest
[info] Run completed in 1 second, 414 milliseconds.
[info] Total number of tests run: 19
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 18, failed 1, canceled 0, ignored 0, pending 0
[info] *** 1 TEST FAILED ***
[error] Failed: Total 19, Failed 1, Errors 0, Passed 18
[error] Failed tests:
[error] 	BddTestSuite
[error] (Test / testOnly) sbt.TestsFailedException: Tests unsuccessful
[error] Total time: 6 s, completed May 11, 2019 1:12:56 PM