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

Commit c0ec7fa

Browse files
committed
Enable colors from sbt
1 parent e790f97 commit c0ec7fa

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,20 @@ abstract class AbstractRunner {
1717

1818
val config: RunnerSpec.Config
1919

20-
val nestUI: NestUI = new NestUI(
20+
lazy val nestUI: NestUI = new NestUI(
2121
verbose = config.optVerbose,
2222
debug = config.optDebug || propOrFalse("partest.debug"),
2323
terse = config.optTerse,
2424
diffOnFail = config.optShowDiff,
2525
logOnFail = config.optShowLog,
26-
colorEnabled = sys.props contains "partest.colors"
26+
colorEnabled = colorEnabled
2727
)
2828

2929
val suiteRunner: SuiteRunner
3030

3131
protected val printSummary = true
3232
protected val partestCmd = "test/partest"
33+
protected val colorEnabled = sys.props contains "partest.colors"
3334

3435
private[this] var totalTests = 0
3536
private[this] val passedTests = mutable.ListBuffer[TestState]()

src/main/scala/scala/tools/partest/sbt/Framework.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package scala.tools.partest.sbt
22

3-
import scala.tools.partest.nest.{SBTRunner, RunnerSpec}
3+
import scala.tools.partest.nest.RunnerSpec
44
import _root_.sbt.testing._
55
import java.net.URLClassLoader
66
import java.io.File

src/main/scala/scala/tools/partest/nest/SBTRunner.scala renamed to src/main/scala/scala/tools/partest/sbt/SBTRunner.scala

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
** |/ **
77
\* */
88

9-
package scala.tools.partest
10-
package nest
9+
package scala.tools.partest.sbt
1110

12-
import _root_.sbt.testing._
1311
import java.net.URLClassLoader
14-
import TestState._
12+
13+
import _root_.sbt.testing._
14+
15+
import scala.tools.partest.TestState._
16+
import scala.tools.partest._
17+
import scala.tools.partest.nest.{AbstractRunner, FileManager, RunnerSpec, SuiteRunner}
1518

1619
class SBTRunner(val config: RunnerSpec.Config,
1720
partestFingerprint: Fingerprint, eventHandler: EventHandler, loggers: Array[Logger],
@@ -27,6 +30,18 @@ class SBTRunner(val config: RunnerSpec.Config,
2730
args.collect { case Def(k, v) => (k, v) }
2831
}
2932

33+
// Enable colors if there's an explicit override or all loggers support them
34+
override protected val colorEnabled = {
35+
val ptOverride = defs.collect { case ("partest.colors", v) => v.toBoolean }.lastOption
36+
ptOverride.getOrElse {
37+
val sbtOverride1 = sys.props.get("sbt.log.format").map(_.toBoolean)
38+
val sbtOverride2 = sys.props.get("sbt.log.noformat").map(s => !s.toBoolean)
39+
sbtOverride1.orElse(sbtOverride2).getOrElse {
40+
loggers.forall(_.ansiCodesSupported())
41+
}
42+
}
43+
}
44+
3045
val javaOpts = {
3146
val l = defs.collect { case ("partest.java_opts", v) => v }
3247
if(l.isEmpty) PartestDefaults.javaOpts

0 commit comments

Comments
 (0)