From 2ce9fc6e31c76e47aa192d115f9625005f69bb06 Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Sun, 7 Jun 2015 13:50:11 -0700 Subject: [PATCH 1/3] SI-7696 Restore --show-log Look for the diff line in the transcript, which diffs the log file and the check file, to pick off the log file name, then just display the contents. For --show-diff output ``` \# starting 1 test in run !! 1 - run/foo.scala [output differs] % diff /home/apm/projects/snytt/test/files/run/foo-run.log /home/apm/projects/snytt/test/files/run/foo.check--- empty +++ foo-run.log @@ -1,0 +1,1 @@ +oops \# 0/1 passed, 1 failed in run ``` --show-log shows ``` \# starting 1 test in run !! 1 - run/foo.scala [output differs] \##### Log file '/home/apm/projects/snytt/test/files/run/foo-run.log' from failed test ##### oops \# 0/1 passed, 1 failed in run ``` where comment lines are prefixed by \ for purposes of commit message. --- .../tools/partest/nest/AbstractRunner.scala | 1 + .../scala/tools/partest/nest/NestUI.scala | 25 ++++++++++++++++--- .../scala/tools/partest/nest/RunnerSpec.scala | 1 + 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/main/scala/scala/tools/partest/nest/AbstractRunner.scala b/src/main/scala/scala/tools/partest/nest/AbstractRunner.scala index bfc364f..d26413c 100644 --- a/src/main/scala/scala/tools/partest/nest/AbstractRunner.scala +++ b/src/main/scala/scala/tools/partest/nest/AbstractRunner.scala @@ -94,6 +94,7 @@ abstract class AbstractRunner(argstr: String) extends { if (optVerbose) NestUI.setVerbose() if (optTerse) NestUI.setTerse() if (optShowDiff) NestUI.setDiffOnFail() + if (optShowLog) NestUI.setLogOnFail() // Early return on no args, version, or invalid args if (optVersion) return echo(versionMsg) diff --git a/src/main/scala/scala/tools/partest/nest/NestUI.scala b/src/main/scala/scala/tools/partest/nest/NestUI.scala index a22351e..a4c9e3b 100644 --- a/src/main/scala/scala/tools/partest/nest/NestUI.scala +++ b/src/main/scala/scala/tools/partest/nest/NestUI.scala @@ -86,9 +86,23 @@ object NestUI { } else { echo(statusLine(state)) - if (!state.isOk && isDiffy) { - val differ = bold(red("% ")) + "diff " - state.transcript find (_ startsWith differ) foreach (echo(_)) + if (!state.isOk) { + if (isDiffy) { + val differ = bold(red("% ")) + "diff " + state.transcript find (_ startsWith differ) foreach (echo(_)) + } + if (isLogging) { + import scala.util.matching.Regex + def log(f: File) = { + echo(bold(cyan(s"##### Log file '$f' from failed test #####\n"))) + echo(f.fileContents) + } + val prompt = bold(red("% ")) + val differ = raw"(?s)${Regex.quote(prompt)}diff (\S*).*".r + state.transcript.collect { + case differ(f) => f + } foreach (log(_)) + } } } } @@ -153,11 +167,13 @@ object NestUI { var _debug = false var _terse = false var _diff = false + var _logging = false def isVerbose = _verbose def isDebug = _debug def isTerse = _terse def isDiffy = _diff + def isLogging = _logging def setVerbose() { _verbose = true @@ -171,6 +187,9 @@ object NestUI { def setDiffOnFail() { _diff = true } + def setLogOnFail() { + _logging = true + } def verbose(msg: String) { if (isVerbose) System.err.println(msg) diff --git a/src/main/scala/scala/tools/partest/nest/RunnerSpec.scala b/src/main/scala/scala/tools/partest/nest/RunnerSpec.scala index 46d0088..974a5e9 100644 --- a/src/main/scala/scala/tools/partest/nest/RunnerSpec.scala +++ b/src/main/scala/scala/tools/partest/nest/RunnerSpec.scala @@ -36,6 +36,7 @@ trait RunnerSpec extends Spec with Meta.StdOpts with Interpolation { heading("Test output options:") val optShowDiff = "show-diff" / "show diffs for failed tests" --? + val optShowLog = "show-log" / "show log files for failed tests" --? val optVerbose = "verbose" / "show verbose progress information" --? val optTerse = "terse" / "show terse progress information" --? val optDebug = "debug" / "enable debugging output" --? From 2ff0930744ecaa9e6099f17ca469bcdad2eba53e Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Sat, 4 Jun 2016 11:15:27 -0700 Subject: [PATCH 2/3] SI-7696 --show-log on bad failure On non-zero exit, no transcript is recorded. Show log in that important use case. TestInfo encapsulates a bit of useful interface. --- .../scala/tools/partest/nest/NestUI.scala | 15 +++------ .../scala/tools/partest/nest/Runner.scala | 31 +++++++++++++++++-- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/main/scala/scala/tools/partest/nest/NestUI.scala b/src/main/scala/scala/tools/partest/nest/NestUI.scala index a4c9e3b..2e2ff92 100644 --- a/src/main/scala/scala/tools/partest/nest/NestUI.scala +++ b/src/main/scala/scala/tools/partest/nest/NestUI.scala @@ -73,18 +73,16 @@ object NestUI { f"$word $testNumber - $testIdent%-40s$reasonString" } - def reportTest(state: TestState) = { + def reportTest(state: TestState, info: TestInfo) = { if (isTerse && state.isOk) { if (dotCount >= DotWidth) { outline("\n.") dotCount = 1 - } - else { + } else { outline(".") dotCount += 1 } - } - else { + } else { echo(statusLine(state)) if (!state.isOk) { if (isDiffy) { @@ -92,16 +90,11 @@ object NestUI { state.transcript find (_ startsWith differ) foreach (echo(_)) } if (isLogging) { - import scala.util.matching.Regex def log(f: File) = { echo(bold(cyan(s"##### Log file '$f' from failed test #####\n"))) echo(f.fileContents) } - val prompt = bold(red("% ")) - val differ = raw"(?s)${Regex.quote(prompt)}diff (\S*).*".r - state.transcript.collect { - case differ(f) => f - } foreach (log(_)) + if (info.logFile.canRead) log(info.logFile) } } } diff --git a/src/main/scala/scala/tools/partest/nest/Runner.scala b/src/main/scala/scala/tools/partest/nest/Runner.scala index d83a931..7a54ef0 100644 --- a/src/main/scala/scala/tools/partest/nest/Runner.scala +++ b/src/main/scala/scala/tools/partest/nest/Runner.scala @@ -42,8 +42,35 @@ class TestTranscript { } } +trait TestInfo { + /** pos/t1234 */ + def testIdent: String + + /** pos */ + def kind: String + + // inputs + + /** pos/t1234.scala or pos/t1234 if dir */ + def testFile: File + + /** pos/t1234.check */ + def checkFile: File + + /** pos/t1234.flags */ + def flagsFile: File + + // outputs + + /** pos/t1234-pos.obj */ + def outFile: File + + /** pos/t1234-pos.log */ + def logFile: File +} + /** Run a single test. Rubber meets road. */ -class Runner(val testFile: File, val suiteRunner: SuiteRunner) { +class Runner(val testFile: File, val suiteRunner: SuiteRunner) extends TestInfo { import suiteRunner.{fileManager => fm, _} val fileManager = fm @@ -802,7 +829,7 @@ class SuiteRunner( catch { case t: Throwable => throw new RuntimeException(s"Error running $testFile", t) } - NestUI.reportTest(state) + NestUI.reportTest(state, runner) runner.cleanup() state } From f443386bc24669ad9cefe3aff9ca9174072af63d Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Sat, 4 Jun 2016 13:24:25 -0700 Subject: [PATCH 3/3] SI-7696 --show-diff shows log on crash If a test throws (and exits non-zero), you can see the log with `--verbose` (which shows the whole transcript), `--show-log`, and now also `--show-diff` (which will show log if the other options aren't set, the test failed and there's no diff to view. --- .../scala/tools/partest/nest/NestUI.scala | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/scala/scala/tools/partest/nest/NestUI.scala b/src/main/scala/scala/tools/partest/nest/NestUI.scala index 2e2ff92..e70f4e9 100644 --- a/src/main/scala/scala/tools/partest/nest/NestUI.scala +++ b/src/main/scala/scala/tools/partest/nest/NestUI.scala @@ -73,7 +73,7 @@ object NestUI { f"$word $testNumber - $testIdent%-40s$reasonString" } - def reportTest(state: TestState, info: TestInfo) = { + def reportTest(state: TestState, info: TestInfo) = if (isTerse && state.isOk) { if (dotCount >= DotWidth) { outline("\n.") @@ -85,20 +85,22 @@ object NestUI { } else { echo(statusLine(state)) if (!state.isOk) { + def showLog() = if (info.logFile.canRead) { + echo(bold(cyan(s"##### Log file '${info.logFile}' from failed test #####\n"))) + echo(info.logFile.fileContents) + } if (isDiffy) { val differ = bold(red("% ")) + "diff " - state.transcript find (_ startsWith differ) foreach (echo(_)) - } - if (isLogging) { - def log(f: File) = { - echo(bold(cyan(s"##### Log file '$f' from failed test #####\n"))) - echo(f.fileContents) + val diffed = state.transcript find (_ startsWith differ) + diffed match { + case Some(diff) => echo(diff) + case None if !isLogging && !isPartestVerbose => showLog() + case _ => () } - if (info.logFile.canRead) log(info.logFile) } + if (isLogging) showLog() } } - } def echo(message: String): Unit = synchronized { leftFlush()