6
6
** |/ **
7
7
\* */
8
8
9
-
10
9
package scala .tools .partest
11
10
package nest
12
11
12
+ import sbt .testing .EventHandler
13
+ import sbt .testing .Logger
14
+ import sbt .testing .Event
15
+ import sbt .testing .Fingerprint
16
+ import sbt .testing .Selector
17
+ import sbt .testing .Status
18
+ import sbt .testing .OptionalThrowable
19
+ import sbt .testing .SuiteSelector
20
+ import sbt .testing .TestSelector
21
+
13
22
// not using any Scala types to ease calling across different scala versions
14
23
abstract class AntRunner (compilationPaths : Array [String ], javaCmd : File , javacCmd : File , scalacArgs : Array [String ]) extends DirectRunner {
24
+ def error (msg : String ): Nothing = sys.error(msg)
25
+ def echo (msg : String ): Unit
26
+ def log (msg : String ): Unit
27
+ def onFinishKind (kind : String , passed : Array [TestState ], failed : Array [TestState ]): Unit
28
+ def onFinishTest (testFile : File , result : TestState ): TestState = result
29
+
15
30
private val cpfiles = compilationPaths map { fs => new File (fs) } toList
16
31
private def findCp (name : String ) = cpfiles find (f =>
17
- (f.getName == s " scala- $name.jar " )
18
- || (f.absolutePathSegments endsWith Seq (" classes" , name))
32
+ (f.getName == s " scala- $name.jar " )
33
+ || (f.absolutePathSegments endsWith Seq (" classes" , name))
19
34
) map (_.getAbsolutePath) getOrElse error(s " Provided compilationPath does not contain a Scala $name element. \n Looked in: ${compilationPaths.mkString(" :" )}" )
20
35
21
-
22
- val fileManager = new FileManager {
23
- val COMPILATION_CLASSPATH : String = ClassPath .join(compilationPaths : _* )
24
- val LATEST_LIB : String = findCp(" library" )
25
- val LATEST_REFLECT : String = findCp(" reflect" )
26
- val LATEST_COMP : String = findCp(" compiler" )
27
- val testRootPath : String = " test"
28
- val testRootDir : Directory = Directory (testRootPath)
36
+ final val fileManager = new FileManager {
37
+ val COMPILATION_CLASSPATH : String = ClassPath .join(compilationPaths : _* )
38
+ val LATEST_LIB : String = findCp(" library" )
39
+ val LATEST_REFLECT : String = findCp(" reflect" )
40
+ val LATEST_COMP : String = findCp(" compiler" )
41
+ val testRootPath : String = " test"
42
+ val testRootDir : Directory = Directory (testRootPath)
29
43
30
44
def failed = false
31
45
def updateCheck = false
32
46
33
- override val JAVACMD : String = Option (javaCmd) map (_.getAbsolutePath) getOrElse " java"
34
- override val JAVAC_CMD : String = Option (javacCmd) map (_.getAbsolutePath) getOrElse " javac"
47
+ override val JAVACMD : String = Option (javaCmd) map (_.getAbsolutePath) getOrElse " java"
48
+ override val JAVAC_CMD : String = Option (javacCmd) map (_.getAbsolutePath) getOrElse " javac"
35
49
override def SCALAC_OPTS : Seq [String ] = super .SCALAC_OPTS ++ scalacArgs
36
50
}
37
51
52
+ final override def runTest (manager : RunnerManager , testFile : File ): TestState =
53
+ onFinishTest(testFile, manager runTest testFile)
38
54
39
- def error (msg : String ): Nothing = sys.error(msg)
40
- def echo (msg : String ): Unit
41
- def log (msg : String ): Unit
42
- def onFinishKind (kind : String , passed : Array [TestState ], failed : Array [TestState ])
43
-
44
- def runSet (kind : String , files : Array [File ]): (Int , Int , Array [String ]) = {
55
+ final def runSet (kind : String , files : Array [File ]): (Int , Int , Array [String ]) = {
45
56
if (files.isEmpty) (0 , 0 , Array .empty[String ])
46
57
else {
47
58
log(s " Running ${files.length} tests in ' $kind' at $now" )
@@ -58,19 +69,46 @@ abstract class AntRunner(compilationPaths: Array[String], javaCmd: File, javacCm
58
69
}
59
70
}
60
71
61
- def execute (kinds : List [String ]): String = {
72
+ final def execute (kinds : Array [String ]): String = {
62
73
echo(banner)
63
74
64
- val _results = kinds map (k => runSet(k, TestKinds testsFor k map (_.jfile) toArray))
75
+ val _results = kinds map (k => runSet(k, TestKinds testsFor k map (_.jfile) toArray))
65
76
66
- val allSuccesses = _results map (_._1) sum
67
- val allFailures = _results map (_._2) sum
77
+ val allSuccesses = _results map (_._1) sum
78
+ val allFailures = _results map (_._2) sum
68
79
val allFailedPaths = _results flatMap (_._3)
69
80
70
81
if (allFailures > 0 )
71
- s " Test suite finished with $allFailures case ${if (allFailures > 1 ) " s" else " " } failing: \n " +
72
- allFailedPaths.mkString(" \n " )
82
+ s " Test suite finished with $allFailures case ${if (allFailures > 1 ) " s" else " " } failing: \n " +
83
+ allFailedPaths.mkString(" \n " )
73
84
else if (allSuccesses == 0 ) " There were no tests to run."
74
85
else " Test suite finished with no failures."
75
86
}
76
87
}
88
+
89
+ class SBTRunner (partestFingerprint : Fingerprint , eventHandler : EventHandler , loggers : Array [Logger ], compilationPaths : Array [String ], javaCmd : File , javacCmd : File , scalacArgs : Array [String ]) extends AntRunner (compilationPaths, javaCmd, javacCmd, scalacArgs) {
90
+ override def error (msg : String ): Nothing = sys.error(msg)
91
+ def echo (msg : String ): Unit = loggers foreach { l => l.info(msg) }
92
+ def log (msg : String ): Unit = loggers foreach { l => l.debug(msg) }
93
+ def onFinishKind (kind : String , passed : Array [TestState ], failed : Array [TestState ]): Unit =
94
+ eventHandler.handle(new Event {
95
+ def fullyQualifiedName : String = kind
96
+ def fingerprint : Fingerprint = partestFingerprint
97
+ def selector : Selector = new SuiteSelector
98
+ def status : Status = if (failed.isEmpty) Status .Success else Status .Failure
99
+ def throwable : OptionalThrowable = new OptionalThrowable
100
+ def duration : Long = - 1
101
+ })
102
+
103
+ override def onFinishTest (testFile : File , result : TestState ): TestState = {
104
+ eventHandler.handle(new Event {
105
+ def fullyQualifiedName : String = testFile.testIdent
106
+ def fingerprint : Fingerprint = partestFingerprint
107
+ def selector : Selector = new TestSelector (testFile.testIdent)
108
+ def status : Status = if (result.isOk) Status .Success else Status .Failure
109
+ def throwable : OptionalThrowable = new OptionalThrowable
110
+ def duration : Long = - 1
111
+ })
112
+ result
113
+ }
114
+ }
0 commit comments