Skip to content
This repository was archived by the owner on Sep 8, 2022. It is now read-only.

Commit f278cc0

Browse files
committed
Merge pull request #63 from som-snytt/issue/7696-show-log
SI-7696 Restore --show-log
2 parents 026af33 + f443386 commit f278cc0

File tree

4 files changed

+54
-11
lines changed

4 files changed

+54
-11
lines changed

src/main/scala/scala/tools/partest/nest/AbstractRunner.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ abstract class AbstractRunner(argstr: String) extends {
9494
if (optVerbose) NestUI.setVerbose()
9595
if (optTerse) NestUI.setTerse()
9696
if (optShowDiff) NestUI.setDiffOnFail()
97+
if (optShowLog) NestUI.setLogOnFail()
9798

9899
// Early return on no args, version, or invalid args
99100
if (optVersion) return echo(versionMsg)

src/main/scala/scala/tools/partest/nest/NestUI.scala

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,25 +73,34 @@ object NestUI {
7373
f"$word $testNumber - $testIdent%-40s$reasonString"
7474
}
7575

76-
def reportTest(state: TestState) = {
76+
def reportTest(state: TestState, info: TestInfo) =
7777
if (isTerse && state.isOk) {
7878
if (dotCount >= DotWidth) {
7979
outline("\n.")
8080
dotCount = 1
81-
}
82-
else {
81+
} else {
8382
outline(".")
8483
dotCount += 1
8584
}
86-
}
87-
else {
85+
} else {
8886
echo(statusLine(state))
89-
if (!state.isOk && isDiffy) {
90-
val differ = bold(red("% ")) + "diff "
91-
state.transcript find (_ startsWith differ) foreach (echo(_))
87+
if (!state.isOk) {
88+
def showLog() = if (info.logFile.canRead) {
89+
echo(bold(cyan(s"##### Log file '${info.logFile}' from failed test #####\n")))
90+
echo(info.logFile.fileContents)
91+
}
92+
if (isDiffy) {
93+
val differ = bold(red("% ")) + "diff "
94+
val diffed = state.transcript find (_ startsWith differ)
95+
diffed match {
96+
case Some(diff) => echo(diff)
97+
case None if !isLogging && !isPartestVerbose => showLog()
98+
case _ => ()
99+
}
100+
}
101+
if (isLogging) showLog()
92102
}
93103
}
94-
}
95104

96105
def echo(message: String): Unit = synchronized {
97106
leftFlush()
@@ -153,11 +162,13 @@ object NestUI {
153162
var _debug = false
154163
var _terse = false
155164
var _diff = false
165+
var _logging = false
156166

157167
def isVerbose = _verbose
158168
def isDebug = _debug
159169
def isTerse = _terse
160170
def isDiffy = _diff
171+
def isLogging = _logging
161172

162173
def setVerbose() {
163174
_verbose = true
@@ -171,6 +182,9 @@ object NestUI {
171182
def setDiffOnFail() {
172183
_diff = true
173184
}
185+
def setLogOnFail() {
186+
_logging = true
187+
}
174188
def verbose(msg: String) {
175189
if (isVerbose)
176190
System.err.println(msg)

src/main/scala/scala/tools/partest/nest/Runner.scala

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,35 @@ class TestTranscript {
4242
}
4343
}
4444

45+
trait TestInfo {
46+
/** pos/t1234 */
47+
def testIdent: String
48+
49+
/** pos */
50+
def kind: String
51+
52+
// inputs
53+
54+
/** pos/t1234.scala or pos/t1234 if dir */
55+
def testFile: File
56+
57+
/** pos/t1234.check */
58+
def checkFile: File
59+
60+
/** pos/t1234.flags */
61+
def flagsFile: File
62+
63+
// outputs
64+
65+
/** pos/t1234-pos.obj */
66+
def outFile: File
67+
68+
/** pos/t1234-pos.log */
69+
def logFile: File
70+
}
71+
4572
/** Run a single test. Rubber meets road. */
46-
class Runner(val testFile: File, val suiteRunner: SuiteRunner) {
73+
class Runner(val testFile: File, val suiteRunner: SuiteRunner) extends TestInfo {
4774

4875
import suiteRunner.{fileManager => fm, _}
4976
val fileManager = fm
@@ -810,7 +837,7 @@ class SuiteRunner(
810837
catch {
811838
case t: Throwable => throw new RuntimeException(s"Error running $testFile", t)
812839
}
813-
NestUI.reportTest(state)
840+
NestUI.reportTest(state, runner)
814841
runner.cleanup()
815842
state
816843
}

src/main/scala/scala/tools/partest/nest/RunnerSpec.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ trait RunnerSpec extends Spec with Meta.StdOpts with Interpolation {
3636

3737
heading("Test output options:")
3838
val optShowDiff = "show-diff" / "show diffs for failed tests" --?
39+
val optShowLog = "show-log" / "show log files for failed tests" --?
3940
val optVerbose = "verbose" / "show verbose progress information" --?
4041
val optTerse = "terse" / "show terse progress information" --?
4142
val optDebug = "debug" / "enable debugging output" --?

0 commit comments

Comments
 (0)