@@ -12,31 +12,45 @@ import scala.tools.nsc.Properties.{ versionMsg, propOrFalse, setProp }
12
12
import scala .collection .{ mutable , immutable }
13
13
import TestKinds ._
14
14
import scala .reflect .internal .util .Collections .distinctBy
15
- import scala .tools .cmd .{ CommandLine , CommandLineParser , Instance }
16
15
17
- abstract class AbstractRunner (argstr : String ) extends {
18
- val parsed = RunnerSpec .creator(CommandLineParser tokenize argstr)
19
- } with RunnerSpec with Instance {
16
+ abstract class AbstractRunner {
17
+
18
+ val config : RunnerSpec .Config
19
+
20
+ val nestUI : NestUI = new NestUI (
21
+ verbose = config.optVerbose,
22
+ debug = config.optDebug || propOrFalse(" partest.debug" ),
23
+ terse = config.optTerse,
24
+ diffOnFail = config.optShowDiff,
25
+ colorEnabled = sys.props contains " partest.colors"
26
+ )
20
27
21
28
val suiteRunner : SuiteRunner
22
29
23
- import suiteRunner ._
24
- import NestUI ._
25
- import NestUI .color ._
30
+ protected val printSummary = true
31
+ protected val partestCmd = " test/partest"
32
+
33
+ private [this ] var totalTests = 0
34
+ private [this ] val passedTests = mutable.ListBuffer [TestState ]()
35
+ private [this ] val failedTests = mutable.ListBuffer [TestState ]()
36
+
37
+ private [this ] var summarizing = false
38
+ private [this ] var elapsedMillis = 0L
39
+ private [this ] var expectedFailures = 0
26
40
27
- private var totalTests = 0
28
- private val passedTests = mutable.ListBuffer [TestState ]()
29
- private val failedTests = mutable.ListBuffer [TestState ]()
41
+ import nestUI ._
42
+ import nestUI .color ._
30
43
31
- def comment (s : String ) = echo(magenta(" # " + s))
32
- def levyJudgment () = {
44
+ private [this ] def comment (s : String ) = echo(magenta(" # " + s))
45
+
46
+ private [this ] def levyJudgment () = {
33
47
if (totalTests == 0 ) echoMixed(" No tests to run." )
34
48
else if (elapsedMillis == 0 ) echoMixed(" Test Run ABORTED" )
35
49
else if (isSuccess) echoPassed(" Test Run PASSED" )
36
50
else echoFailed(" Test Run FAILED" )
37
51
}
38
52
39
- def passFailString (passed : Int , failed : Int , skipped : Int ): String = {
53
+ private [ this ] def passFailString (passed : Int , failed : Int , skipped : Int ): String = {
40
54
val total = passed + failed + skipped
41
55
val isSuccess = failed == 0
42
56
def p0 = s " $passed/ $total"
@@ -47,12 +61,7 @@ abstract class AbstractRunner(argstr: String) extends {
47
61
oempty(p, f, s) mkString " , "
48
62
}
49
63
50
- protected var partestCmd = " test/partest"
51
- protected var summarizing = false
52
- protected var printSummary = true
53
- private var elapsedMillis = 0L
54
- private var expectedFailures = 0
55
- protected def isSuccess = failedTests.size == expectedFailures
64
+ private [this ] def isSuccess = failedTests.size == expectedFailures
56
65
57
66
def issueSummaryReport () {
58
67
// Don't run twice
@@ -69,7 +78,7 @@ abstract class AbstractRunner(argstr: String) extends {
69
78
val message = passFail + elapsed
70
79
71
80
if (failed0.nonEmpty) {
72
- if (isPartestVerbose ) {
81
+ if (nestUI.verbose ) {
73
82
echo(bold(cyan(" ##### Transcripts from failed tests #####\n " )))
74
83
failed0 foreach { state =>
75
84
comment(partestCmd + " " + state.testFile)
@@ -89,96 +98,93 @@ abstract class AbstractRunner(argstr: String) extends {
89
98
}
90
99
}
91
100
92
- def run (): Unit = {
93
- if (optDebug || propOrFalse(" partest.debug" )) NestUI .setDebug()
94
- if (optVerbose) NestUI .setVerbose()
95
- if (optTerse) NestUI .setTerse()
96
- if (optShowDiff) NestUI .setDiffOnFail()
97
-
98
- // Early return on no args, version, or invalid args
99
- if (optVersion) return echo(versionMsg)
100
- if (optHelp) return NestUI .usage()
101
-
102
- val (individualTests, invalid) = parsed.residualArgs map (p => Path (p)) partition denotesTestPath
103
- if (invalid.nonEmpty) {
104
- if (isPartestVerbose)
105
- invalid foreach (p => echoWarning(s " Discarding invalid test path " + p))
106
- else if (! isPartestTerse)
107
- echoWarning(s " Discarding ${invalid.size} invalid test paths " )
108
- }
101
+ /** Run the tests and return the success status */
102
+ def run (): Boolean = {
103
+ if (config.optVersion) echo(versionMsg)
104
+ else if (config.optHelp) nestUI.usage()
105
+ else {
106
+ val (individualTests, invalid) = config.parsed.residualArgs map (p => Path (p)) partition denotesTestPath
107
+ if (invalid.nonEmpty) {
108
+ if (nestUI.verbose)
109
+ invalid foreach (p => echoWarning(s " Discarding invalid test path " + p))
110
+ else if (! nestUI.terse)
111
+ echoWarning(s " Discarding ${invalid.size} invalid test paths " )
112
+ }
109
113
110
- optTimeout foreach (x => setProp(" partest.timeout" , x))
114
+ config. optTimeout foreach (x => setProp(" partest.timeout" , x))
111
115
112
- if (! isPartestTerse )
113
- NestUI echo banner
116
+ if (! nestUI.terse )
117
+ nestUI.echo(suiteRunner. banner)
114
118
115
- val partestTests = (
116
- if (optSelfTest) TestKinds .testsForPartest
117
- else Nil
118
- )
119
+ val partestTests = (
120
+ if (config. optSelfTest) TestKinds .testsForPartest
121
+ else Nil
122
+ )
119
123
120
- val grepExpr = optGrep getOrElse " "
124
+ val grepExpr = config. optGrep getOrElse " "
121
125
122
- // If --grep is given we suck in every file it matches.
123
- // TODO: intersect results of grep with specified kinds, if any
124
- val greppedTests = if (grepExpr == " " ) Nil else {
125
- val paths = grepFor(grepExpr)
126
- if (paths.isEmpty)
127
- echoWarning(s " grep string ' $grepExpr' matched no tests. \n " )
126
+ // If --grep is given we suck in every file it matches.
127
+ // TODO: intersect results of grep with specified kinds, if any
128
+ val greppedTests = if (grepExpr == " " ) Nil else {
129
+ val paths = grepFor(grepExpr)
130
+ if (paths.isEmpty)
131
+ echoWarning(s " grep string ' $grepExpr' matched no tests. \n " )
128
132
129
- paths.sortBy(_.toString)
130
- }
133
+ paths.sortBy(_.toString)
134
+ }
131
135
132
- val isRerun = optFailed
133
- val rerunTests = if (isRerun) TestKinds .failedTests else Nil
134
- def miscTests = partestTests ++ individualTests ++ greppedTests ++ rerunTests
135
-
136
- val givenKinds = standardKinds filter parsed.isSet
137
- val kinds = (
138
- if (givenKinds.nonEmpty) givenKinds
139
- else if (miscTests.isEmpty) standardKinds // If no kinds, --grep, or individual tests were given, assume --all
140
- else Nil
141
- )
142
- val kindsTests = kinds flatMap testsFor
143
-
144
- def testContributors = {
145
- List (
146
- if (partestTests.isEmpty) " " else " partest self-tests" ,
147
- if (rerunTests.isEmpty) " " else " previously failed tests" ,
148
- if (kindsTests.isEmpty) " " else s " ${kinds.size} named test categories " ,
149
- if (greppedTests.isEmpty) " " else s " ${greppedTests.size} tests matching ' $grepExpr' " ,
150
- if (individualTests.isEmpty) " " else " specified tests"
151
- ) filterNot (_ == " " ) mkString " , "
152
- }
136
+ val isRerun = config. optFailed
137
+ val rerunTests = if (isRerun) TestKinds .failedTests else Nil
138
+ def miscTests = partestTests ++ individualTests ++ greppedTests ++ rerunTests
139
+
140
+ val givenKinds = standardKinds filter config. parsed.isSet
141
+ val kinds = (
142
+ if (givenKinds.nonEmpty) givenKinds
143
+ else if (miscTests.isEmpty) standardKinds // If no kinds, --grep, or individual tests were given, assume --all
144
+ else Nil
145
+ )
146
+ val kindsTests = kinds flatMap testsFor
147
+
148
+ def testContributors = {
149
+ List (
150
+ if (partestTests.isEmpty) " " else " partest self-tests" ,
151
+ if (rerunTests.isEmpty) " " else " previously failed tests" ,
152
+ if (kindsTests.isEmpty) " " else s " ${kinds.size} named test categories " ,
153
+ if (greppedTests.isEmpty) " " else s " ${greppedTests.size} tests matching ' $grepExpr' " ,
154
+ if (individualTests.isEmpty) " " else " specified tests"
155
+ ) filterNot (_ == " " ) mkString " , "
156
+ }
153
157
154
- val allTests : Array [Path ] = distinctBy(miscTests ++ kindsTests)(_.toCanonical) sortBy (_.toString) toArray
155
- val grouped = (allTests groupBy kindOf).toArray sortBy (x => standardKinds indexOf x._1)
158
+ val allTests : Array [Path ] = distinctBy(miscTests ++ kindsTests)(_.toCanonical) sortBy (_.toString) toArray
159
+ val grouped = (allTests groupBy kindOf).toArray sortBy (x => standardKinds indexOf x._1)
156
160
157
- totalTests = allTests.size
158
- expectedFailures = propOrNone(" partest.errors" ) match {
159
- case Some (num) => num.toInt
160
- case _ => 0
161
- }
162
- val expectedFailureMessage = if (expectedFailures == 0 ) " " else s " (expecting $expectedFailures to fail) "
163
- echo(s " Selected $totalTests tests drawn from $testContributors$expectedFailureMessage\n " )
164
-
165
- val (_, millis) = timed {
166
- for ((kind, paths) <- grouped) {
167
- val num = paths.size
168
- val ss = if (num == 1 ) " " else " s"
169
- comment(s " starting $num test $ss in $kind" )
170
- val results = runTestsForFiles(paths map (_.jfile.getAbsoluteFile), kind)
171
- val (passed, failed) = results partition (_.isOk)
172
-
173
- passedTests ++= passed
174
- failedTests ++= failed
175
- if (failed.nonEmpty) {
176
- comment(passFailString(passed.size, failed.size, 0 ) + " in " + kind)
161
+ totalTests = allTests.size
162
+ expectedFailures = propOrNone(" partest.errors" ) match {
163
+ case Some (num) => num.toInt
164
+ case _ => 0
165
+ }
166
+ val expectedFailureMessage = if (expectedFailures == 0 ) " " else s " (expecting $expectedFailures to fail) "
167
+ echo(s " Selected $totalTests tests drawn from $testContributors$expectedFailureMessage\n " )
168
+
169
+ val (_, millis) = timed {
170
+ for ((kind, paths) <- grouped) {
171
+ val num = paths.size
172
+ val ss = if (num == 1 ) " " else " s"
173
+ comment(s " starting $num test $ss in $kind" )
174
+ val results = suiteRunner.runTestsForFiles(paths map (_.jfile.getAbsoluteFile), kind)
175
+ val (passed, failed) = results partition (_.isOk)
176
+
177
+ passedTests ++= passed
178
+ failedTests ++= failed
179
+ if (failed.nonEmpty) {
180
+ comment(passFailString(passed.size, failed.size, 0 ) + " in " + kind)
181
+ }
182
+ echo(" " )
177
183
}
178
- echo(" " )
179
184
}
185
+ this .elapsedMillis = millis
186
+ issueSummaryReport()
180
187
}
181
- this .elapsedMillis = millis
182
- issueSummaryReport()
188
+ isSuccess
183
189
}
184
190
}
0 commit comments