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

Commit e3e3a4a

Browse files
committed
Enable colors from sbt
1 parent fb7c37d commit e3e3a4a

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,18 +17,19 @@ 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,
25-
colorEnabled = sys.props contains "partest.colors"
25+
colorEnabled = colorEnabled
2626
)
2727

2828
val suiteRunner: SuiteRunner
2929

3030
protected val printSummary = true
3131
protected val partestCmd = "test/partest"
32+
protected val colorEnabled = sys.props contains "partest.colors"
3233

3334
private[this] var totalTests = 0
3435
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],
@@ -22,6 +25,18 @@ class SBTRunner(val config: RunnerSpec.Config,
2225
override protected val printSummary = false
2326
override protected val partestCmd = "partest"
2427

28+
// Enable colors if there's an explicit override or all loggers support them
29+
override protected val colorEnabled = {
30+
val ptOverride = args.filter(_.startsWith("-Dpartest.colors=")).map(_.substring(17).toBoolean).lastOption
31+
ptOverride.getOrElse {
32+
val sbtOverride1 = sys.props.get("sbt.log.format").map(_.toBoolean)
33+
val sbtOverride2 = sys.props.get("sbt.log.noformat").map(s => !s.toBoolean)
34+
sbtOverride1.orElse(sbtOverride2).getOrElse {
35+
loggers.forall(_.ansiCodesSupported())
36+
}
37+
}
38+
}
39+
2540
val javaOpts = {
2641
val l = args.filter(_.startsWith("-Dpartest.java_opts=")).map(_.substring(20))
2742
if(l.isEmpty) PartestDefaults.javaOpts

0 commit comments

Comments
 (0)