Skip to content

Commit 5d04d44

Browse files
committed
fix #24: use custom nsc reporter in neg tests
1 parent 2ade08b commit 5d04d44

File tree

7 files changed

+26
-18
lines changed

7 files changed

+26
-18
lines changed

src/tastytest/scala/tools/tastytest/TastyTest.scala

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import scala.collection.mutable
44
import scala.jdk.CollectionConverters._
55
import scala.tools.nsc
66
import scala.util.{ Try, Success, Failure }
7+
import scala.util.chaining._
78

89
import dotty.tools.dotc
910
import dotc.reporting.{ Reporter => DottyReporter }
@@ -16,6 +17,7 @@ import jl.reflect.Modifier
1617
import CommandLineParsers._
1718
import SourceKind._
1819
import Files._
20+
import scala.tools.nsc.{Global, Settings, reporters}, reporters.ConsoleReporter
1921

2022
object TastyTest {
2123

@@ -166,15 +168,30 @@ object TastyTest {
166168
}
167169

168170
private def scalac(out: String, dottyLibrary: String, sources: String*): Boolean = {
171+
172+
def runCompile(global: Global): Boolean = {
173+
global.reporter.reset()
174+
new global.Run() compile sources.toList
175+
!global.reporter.hasErrors
176+
}
177+
178+
def newCompiler(args: String*): Global =
179+
fromSettings(new Settings().tap(_ processArguments(args.toList, true)))
180+
181+
def fromSettings(settings: Settings): Global =
182+
Global(settings, new ConsoleReporter(settings).tap(_.shortname = true))
183+
184+
def compile(args: String*) =
185+
Try(runCompile(newCompiler(args: _*))).getOrElse(false)
186+
169187
sources.isEmpty || {
170-
val args = Array(
188+
compile(
171189
"-d", out,
172190
"-classpath", classpaths(out, dottyLibrary),
173191
"-deprecation",
174192
"-Xfatal-warnings",
175193
"-usejavacp"
176-
) ++ sources
177-
Try(nsc.Main.process(args)).getOrElse(false)
194+
)
178195
}
179196
}
180197

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/Users/jamie/workspace/scala/test/tasty/neg-false/src-2/NewJVMEnv_fail.scala:9: error: class type required but tastytest.printing#AnyHash with tastytest.printing#AnyClassName found
1+
NewJVMEnv_fail.scala:9: error: class type required but tastytest.printing#AnyHash with tastytest.printing#AnyClassName found
22
new Env.JVMEnv {} // error: class type required but tastytest.printing#AnyHash with tastytest.printing#AnyClassName found
33
^
4-
1 error

test/tasty/neg/src-2/SColourOps.check

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
/Users/jamie/workspace/scala/test/tasty/neg/src-2/SColourOps_fail.scala:6: warning: match may not be exhaustive.
1+
SColourOps_fail.scala:6: warning: match may not be exhaustive.
22
It would fail on the following inputs: Blue, CMYK(_, _, _, _), Green, RGB(_, _, _)
33
def red: Int = c match { // error: non-exhaustive
44
^
55
error: No warnings can be incurred under -Werror.
6-
1 warning
7-
1 error
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
/Users/jamie/workspace/scala/test/tasty/neg/src-2/SColourOpsUnreachable_fail.scala:8: warning: unreachable code
1+
SColourOpsUnreachable_fail.scala:8: warning: unreachable code
22
case SColour.Blue => -1 // error: unreachable
33
^
44
error: No warnings can be incurred under -Werror.
5-
1 warning
6-
1 error
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
/Users/jamie/workspace/scala/test/tasty/neg/src-2/TestDeprecations_fail.scala:5: warning: method unused in class Old is deprecated
1+
TestDeprecations_fail.scala:5: warning: method unused in class Old is deprecated
22
def test1 = new Deprecations.Old().unused() // error: unused is deprecated
33
^
4-
/Users/jamie/workspace/scala/test/tasty/neg/src-2/TestDeprecations_fail.scala:6: warning: method completelyUseless in class Old is deprecated: this is useless
4+
TestDeprecations_fail.scala:6: warning: method completelyUseless in class Old is deprecated: this is useless
55
def test2 = new Deprecations.Old().completelyUseless() // error: completelyUseless is deprecated: this is useless
66
^
77
error: No warnings can be incurred under -Werror.
8-
2 warnings
9-
1 error

test/tasty/neg/src-2/TestHello.check

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
error: Scala 2 incompatible TASTy signature of HelloWorld.tasty in object HelloWorld: inline val msg with non-constant type String
2-
/Users/jamie/workspace/scala/test/tasty/neg/src-2/TestHello_fail.scala:5: error: type mismatch;
2+
TestHello_fail.scala:5: error: type mismatch;
33
found : helloworld.TestHello.helloworld.type (with underlying type String)
44
required: helloworld.HelloWorld.msg1.type
55
HelloWorld.acceptsOnlyMsg1(helloworld)
66
^
7-
2 errors

test/tasty/neg/src-2/TestIntent.check

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
error: Scala 2 incompatible TASTy signature of Position.tasty in object Position: unsupported Scala 3 flags on method here: inline | <tastymacro>
2-
1 error

0 commit comments

Comments
 (0)