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

Commit 0e63ce5

Browse files
committed
Address review feedback
- Comment for Stopwatch - Delete commented out debug code - Refactor properties save/restore - DRY up console scraping
1 parent 7c19dd7 commit 0e63ce5

File tree

3 files changed

+22
-27
lines changed

3 files changed

+22
-27
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,6 @@ class Runner(val testFile: File, val suiteRunner: SuiteRunner, val nestUI: NestU
293293

294294
TrapExit(() => run()) match {
295295
case Left((status, throwable)) if status != 0 =>
296-
// Files.readAllLines(log.toPath).forEach(println(_))
297-
// val error = new AssertionError(s"System.exit(${status}) was called.")
298-
// error.setStackTrace(throwable.getStackTrace)
299296
setLastState(genFail("non-zero exit code"))
300297
false
301298
case _ =>

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package scala.tools.partest.nest
22

3-
class Stopwatch {
3+
/**
4+
* Measured elapsed time between between calls to `start` and `stop`.
5+
* May be `pause`-ed and re-`started` before `stop` is eventually called.
6+
*/
7+
final class Stopwatch {
48
private var base: Option[Long] = None
59
private var elapsed = 0L
610
def pause(): Unit = {

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

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -52,30 +52,14 @@ object StreamCapture {
5252
Captured(stdoutFn(), stderrFn(), result)
5353
}
5454

55-
def withExtraProperties[A](extra: Map[String, String])(action: => A): A = {
56-
val saved = System.getProperties()
57-
val modified = new java.util.Properties()
58-
saved.stringPropertyNames().forEach((k) => modified.setProperty(k, saved.getProperty(k)))
59-
extra.foreach { case (k, v) => modified.setProperty(k, v) }
60-
System.setProperties(modified)
61-
try {
62-
action
63-
} finally {
64-
System.setProperties(saved)
65-
}
66-
}
67-
68-
// TODO merge with code above
6955
def capturingOutErr[A](output: OutputStream)(f: => A): A = {
7056
import java.io._
71-
val savedOut = System.out
72-
val savedErr = System.err
73-
try {
74-
val charset = Charset.defaultCharset()
75-
val printStream = new PrintStream(output, true, charset.name())
57+
val charset = Charset.defaultCharset()
58+
val printStream = new PrintStream(output, true, charset.name())
59+
savingSystem {
60+
System.setOut(printStream)
61+
System.setErr(printStream)
7662
try {
77-
System.setOut(printStream)
78-
System.setErr(printStream)
7963
scala.Console.withErr(printStream) {
8064
scala.Console.withOut(printStream) {
8165
f
@@ -84,9 +68,19 @@ object StreamCapture {
8468
} finally {
8569
printStream.close()
8670
}
71+
}
72+
}
73+
74+
def withExtraProperties[A](extra: Map[String, String])(action: => A): A = {
75+
val saved = System.getProperties()
76+
val modified = new java.util.Properties()
77+
modified.putAll(saved)
78+
extra.foreach { case (k, v) => modified.setProperty(k, v) }
79+
System.setProperties(modified)
80+
try {
81+
action
8782
} finally {
88-
System.setOut(savedOut)
89-
System.setOut(savedErr)
83+
System.setProperties(saved)
9084
}
9185
}
9286
}

0 commit comments

Comments
 (0)