aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dotty/tools/dotc/Driver.scala19
-rw-r--r--src/dotty/tools/dotc/Main.scala11
-rw-r--r--src/dotty/tools/dotc/Run.scala8
-rw-r--r--test/dotc/tests.scala27
-rw-r--r--test/test/CompilerTest.scala23
-rw-r--r--test/test/ScannerTest.scala16
-rw-r--r--test/test/ShowClassTests.scala24
-rw-r--r--test/test/desugarTests.scala36
-rw-r--r--test/test/parserTests.scala34
-rw-r--r--test/test/scanPackage.scala8
-rw-r--r--test/test/showClass.scala6
-rw-r--r--test/x/names.scala2
12 files changed, 106 insertions, 108 deletions
diff --git a/src/dotty/tools/dotc/Driver.scala b/src/dotty/tools/dotc/Driver.scala
index 13604d9cc..e5e031e79 100644
--- a/src/dotty/tools/dotc/Driver.scala
+++ b/src/dotty/tools/dotc/Driver.scala
@@ -3,6 +3,7 @@ package dotty.tools.dotc
import config.CompilerCommand
import core.Contexts.{Context, ContextBase}
import core.DotClass
+import reporting._
abstract class Driver extends DotClass {
@@ -10,33 +11,37 @@ abstract class Driver extends DotClass {
protected def newCompiler(): Compiler
- protected def doCompile(compiler: Compiler, fileNames: List[String])(implicit ctx: Context) =
+ protected def emptyReporter = new StoreReporter
+
+ protected def doCompile(compiler: Compiler, fileNames: List[String])(implicit ctx: Context): Reporter =
if (fileNames.nonEmpty) {
val run = compiler.newRun
run.compile(fileNames)
run.printSummary()
- }
+ } else emptyReporter
protected def initCtx = (new ContextBase).initialCtx
- def process(args: Array[String]): Boolean = {
+ def process(args: Array[String]): Reporter = {
val summary = CompilerCommand.distill(args)(initCtx)
implicit val ctx = initCtx.fresh.withSettings(summary.sstate)
val fileNames = CompilerCommand.checkUsage(summary)
try {
doCompile(newCompiler(), fileNames)
- !ctx.reporter.hasErrors
} catch {
case ex: Throwable =>
ex match {
- case ex: FatalError => ctx.error(ex.getMessage); false // signals that we should fail compilation.
- case _ => throw ex // unexpected error, tell the outside world.
+ case ex: FatalError =>
+ ctx.error(ex.getMessage) // signals that we should fail compilation.
+ ctx.typerState.reporter
+ case _ =>
+ throw ex // unexpected error, tell the outside world.
}
}
}
def main(args: Array[String]): Unit =
- sys.exit(if (process(args)) 1 else 0)
+ sys.exit(if (process(args).hasErrors) 1 else 0)
}
class FatalError(msg: String) extends Exception
diff --git a/src/dotty/tools/dotc/Main.scala b/src/dotty/tools/dotc/Main.scala
index 627fc0cfa..ddb422a0d 100644
--- a/src/dotty/tools/dotc/Main.scala
+++ b/src/dotty/tools/dotc/Main.scala
@@ -6,9 +6,10 @@ package dotty.tools
package dotc
import core.Contexts.Context
+import reporting.Reporter
object Main extends Driver {
- def resident(compiler: Compiler): Unit = unsupported("resident") /*loop { line =>
+ def resident(compiler: Compiler): Reporter = unsupported("resident") /*loop { line =>
val command = new CompilerCommand(line split "\\s+" toList, new Settings(scalacError))
compiler.reporter.reset()
new compiler.Run() compile command.files
@@ -16,8 +17,10 @@ object Main extends Driver {
override def newCompiler(): Compiler = new Compiler
- override def doCompile(compiler: Compiler, fileNames: List[String])(implicit ctx: Context): Unit = {
- if (new config.Settings.Setting.SettingDecorator[Boolean](ctx.base.settings.resident).value(ctx)) resident(compiler)
- else super.doCompile(compiler, fileNames)
+ override def doCompile(compiler: Compiler, fileNames: List[String])(implicit ctx: Context): Reporter = {
+ if (new config.Settings.Setting.SettingDecorator[Boolean](ctx.base.settings.resident).value(ctx))
+ resident(compiler)
+ else
+ super.doCompile(compiler, fileNames)
}
}
diff --git a/src/dotty/tools/dotc/Run.scala b/src/dotty/tools/dotc/Run.scala
index b12511478..c662aabfa 100644
--- a/src/dotty/tools/dotc/Run.scala
+++ b/src/dotty/tools/dotc/Run.scala
@@ -5,6 +5,7 @@ import core._
import Contexts._, Periods._, Symbols._
import io.PlainFile
import util.{SourceFile, NoSource, Stats, SimpleMap}
+import reporting.Reporter
class Run(comp: Compiler)(implicit ctx: Context) {
@@ -28,8 +29,11 @@ class Run(comp: Compiler)(implicit ctx: Context) {
}
}
- def printSummary(): Unit = {
- ctx.typerState.reporter.printSummary
+ /** Print summary; return # of errors encountered */
+ def printSummary(): Reporter = {
Constraint.printMax()
+ val r = ctx.typerState.reporter
+ r.printSummary
+ r
}
} \ No newline at end of file
diff --git a/test/dotc/tests.scala b/test/dotc/tests.scala
new file mode 100644
index 000000000..b830471e5
--- /dev/null
+++ b/test/dotc/tests.scala
@@ -0,0 +1,27 @@
+package dotc
+
+import org.junit.Test
+import test._
+
+class tests extends CompilerTest {
+
+ override val defaultOptions =
+ List("-verbose", "-Ylog:frontend", "-explaintypes", "-Yshow-suppressed-errors", "-pagewidth", "160")
+
+ val posDir = "/Users/odersky/workspace/dotty/tests/pos/"
+ val negDir = "/Users/odersky/workspace/dotty/tests/neg/"
+
+
+ @Test def pos_Coder() = compileFile(posDir, "Coder")
+ @Test def pos_blockescapes() = compileFile(posDir, "blockescapes")
+ @Test def pos_collections() = compileFile(posDir, "collections")
+ @Test def pos_functions1() = compileFile(posDir, "functions1")
+ @Test def pos_implicits1() = compileFile(posDir, "implicits1")
+ @Test def pos_inferred() = compileFile(posDir, "inferred")
+ @Test def pos_Patterns() = compileFile(posDir, "Patterns")
+ @Test def pos_selftypes() = compileFile(posDir, "selftypes")
+ @Test def pos_varargs() = compileFile(posDir, "varargs")
+
+ @Test def neg_blockescapes() = compileFile(negDir, "blockescapesNeg", xerrors = 2)
+
+} \ No newline at end of file
diff --git a/test/test/CompilerTest.scala b/test/test/CompilerTest.scala
new file mode 100644
index 000000000..00c288546
--- /dev/null
+++ b/test/test/CompilerTest.scala
@@ -0,0 +1,23 @@
+package test
+
+import scala.reflect.io._
+import org.junit.Test
+import scala.collection.mutable.ListBuffer
+import dotty.tools.dotc.Main
+import dotty.tools.dotc.reporting.Reporter
+
+class CompilerTest extends DottyTest {
+
+ def defaultOptions: List[String] = Nil
+
+ def compileArgs(args: Array[String], xerrors: Int = 0): Unit = {
+ val nerrors = Main.process(args ++ defaultOptions).count(Reporter.ERROR.level)
+ assert(nerrors == xerrors, s"Wrong # of errors. Expected: $xerrors, found: $nerrors")
+ }
+
+ def compileLine(cmdLine: String, xerrors: Int = 0): Unit = compileArgs(cmdLine.split("\n"), xerrors)
+
+ def compileFile(prefix: String, fileName: String, args: List[String] = Nil, xerrors: Int = 0): Unit =
+ compileArgs((s"$prefix$fileName.scala" :: args).toArray, xerrors)
+
+} \ No newline at end of file
diff --git a/test/test/ScannerTest.scala b/test/test/ScannerTest.scala
index 68886694d..aafc2ee54 100644
--- a/test/test/ScannerTest.scala
+++ b/test/test/ScannerTest.scala
@@ -8,6 +8,11 @@ import org.junit.Test
class ScannerTest extends DottyTest {
+ val blackList = List(
+ "/Users/odersky/workspace/scala/src/scaladoc/scala/tools/nsc/doc/html/page/Index.scala",
+ "/Users/odersky/workspace/scala/src/scaladoc/scala/tools/nsc/doc/html/page/Template.scala"
+ )
+
def scan(name: String): Unit = scan(new PlainFile(name))
def scan(file: PlainFile): Unit = {
@@ -26,8 +31,15 @@ class ScannerTest extends DottyTest {
def scanDir(path: String): Unit = scanDir(Directory(path))
def scanDir(dir: Directory): Unit = {
- for (f <- dir.files)
- if (f.name.endsWith(".scala")) scan(new PlainFile(f))
+ if (blackList contains dir.jfile.getAbsolutePath)
+ println(s"blacklisted package: ${dir.jfile.getAbsolutePath}")
+ else
+ for (f <- dir.files)
+ if (f.name.endsWith(".scala"))
+ if (blackList contains f.jfile.getAbsolutePath)
+ println(s"blacklisted file: ${f.jfile.getAbsolutePath}")
+ else
+ scan(new PlainFile(f))
for (d <- dir.dirs)
scanDir(d.path)
}
diff --git a/test/test/ShowClassTests.scala b/test/test/ShowClassTests.scala
index 779c2daf9..e736aada1 100644
--- a/test/test/ShowClassTests.scala
+++ b/test/test/ShowClassTests.scala
@@ -55,8 +55,11 @@ class ShowClassTests extends DottyTest {
}
}
- def showPackage(path: String)(implicit ctx: Context): Unit = doTwice { implicit ctx =>
+ def showPackage(path: String, expectedStubs: Int)(implicit ctx: Context): Unit = doTwice { implicit ctx =>
showPackage(ctx.requiredPackage(path))
+ val nstubs = Symbols.stubs.length
+ println(s"$nstubs stubs")
+ assert(nstubs == expectedStubs, s"stubs found $nstubs, expected: $expectedStubs")
}
def showClass(cls: Symbol)(implicit ctx: Context) = {
@@ -78,7 +81,7 @@ class ShowClassTests extends DottyTest {
showClass(cls)
showClass(cls.linkedClass)
}
-
+/*
@Test
def loadSimpleClasses() = {
showClasses("scala.Array")
@@ -87,7 +90,7 @@ class ShowClassTests extends DottyTest {
@Test
def loadJavaClasses() = {
- showPackage("scala.tools.jline")
+ showPackage("scala.tools.jline", 0)
}
@Test
@@ -114,20 +117,21 @@ class ShowClassTests extends DottyTest {
def loadScalaCollection() = {
showPackage(ctx.requiredPackage("scala.collection"))
}
-
+*/
@Test
- def loadClassWithPrivateInnerAndSubSelf() = {
- showClasses("scala.tools.nsc.settings.ScalaSettings")
- showClasses("scala.tools.jline.console.history.MemoryHistory")
+ def showScala() = {
+ showPackage("scala", 17)
}
@Test
def loadDotty() = {
- showPackage("dotty")
+ showPackage("dotty", 18)
}
- @Test
+
+ /*
+ * @Test
def showReflectAliases() = { // tests for cycles during findMember
showClasses("scala.reflect.macros.runtime.Aliases")
- }
+ }*/
}
diff --git a/test/test/desugarTests.scala b/test/test/desugarTests.scala
deleted file mode 100644
index 25f2e5624..000000000
--- a/test/test/desugarTests.scala
+++ /dev/null
@@ -1,36 +0,0 @@
-package test
-
-import scala.reflect.io._
-import dotty.tools.dotc.util._
-import dotty.tools.dotc.core._
-import dotty.tools.dotc.parsing._
-import Tokens._, Parsers._
-import dotty.tools.dotc.ast.untpd._
-import org.junit.Test
-import scala.collection.mutable.ListBuffer
-
-class desugarTests extends DeSugarTest {
-
- @Test
- def parseList(): Unit = {
- println(System.getProperty("user.dir"))
- parse("src/dotty/tools/dotc/core/Symbols.scala")
- parse("src/dotty/tools/dotc/core/Types.scala")
- desugarAll()
- reset()
- }
-
- @Test
- def parseDotty(): Unit = {
- parseDir("src")
- desugarAll()
- reset()
- }
-
- @Test
- def parseScala() = {
- parseDir("/Users/odersky/workspace/scala/src")
- desugarAll()
- reset()
- }
-} \ No newline at end of file
diff --git a/test/test/parserTests.scala b/test/test/parserTests.scala
deleted file mode 100644
index 7f337bc1a..000000000
--- a/test/test/parserTests.scala
+++ /dev/null
@@ -1,34 +0,0 @@
-package test
-
-import scala.reflect.io._
-import dotty.tools.dotc.util._
-import dotty.tools.dotc.core._
-import dotty.tools.dotc.parsing._
-import Tokens._, Parsers._
-import dotty.tools.dotc.ast.untpd._
-import org.junit.Test
-import scala.collection.mutable.ListBuffer
-
-class parserTests extends ParserTest {
-
- @Test
- def parseList(): Unit = {
- println(System.getProperty("user.dir"))
- parse("src/dotty/tools/dotc/core/Symbols.scala")
- parse("src/dotty/tools/dotc/core/Types.scala")
- reset()
- }
-
- @Test
- def parseDotty(): Unit = {
- parseDir("src")
- reset()
- }
-
- @Test
- def parseScala() = {
- parseDir("/Users/odersky/workspace/scala/src")
- reset()
- }
-
-} \ No newline at end of file
diff --git a/test/test/scanPackage.scala b/test/test/scanPackage.scala
deleted file mode 100644
index c6a7709b8..000000000
--- a/test/test/scanPackage.scala
+++ /dev/null
@@ -1,8 +0,0 @@
-package test
-
-object scanPackage extends ScannerTest {
-
- def main(args: Array[String]): Unit =
- scanDir("src")
-
-} \ No newline at end of file
diff --git a/test/test/showClass.scala b/test/test/showClass.scala
index fc7057780..4824523dc 100644
--- a/test/test/showClass.scala
+++ b/test/test/showClass.scala
@@ -12,9 +12,7 @@ object showClass extends ShowClassTests {
// showPackage("scala.reflect")
// showPackage("scala.collection")
- showPackage("dotty")
- showPackage("scala")
- println(s"${Symbols.stubs.length} stubs")
- println(Symbols.stubs mkString " ")
+ showPackage("dotty", 1)
+ showPackage("scala", 18)
}
}
diff --git a/test/x/names.scala b/test/x/names.scala
index 0caf8ff43..c80c3e51d 100644
--- a/test/x/names.scala
+++ b/test/x/names.scala
@@ -8,7 +8,7 @@ object Bar {
def foo = 2
}
-object Test {
+object Test123 {
import Foo.foo