diff options
author | Martin Odersky <odersky@gmail.com> | 2013-11-18 19:27:18 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2013-11-18 19:27:36 +0100 |
commit | acc9d750d1776d8d1c864fb3ddaadbaec34d286e (patch) | |
tree | c5129664583164aef17f0c42a634ae9e6dbf8e62 /test | |
parent | b6d7b28403c34f61c5317c37acce1b4118a4181c (diff) | |
download | dotty-acc9d750d1776d8d1c864fb3ddaadbaec34d286e.tar.gz dotty-acc9d750d1776d8d1c864fb3ddaadbaec34d286e.tar.bz2 dotty-acc9d750d1776d8d1c864fb3ddaadbaec34d286e.zip |
Added unit testing support
Diffstat (limited to 'test')
-rw-r--r-- | test/dotc/tests.scala | 27 | ||||
-rw-r--r-- | test/test/CompilerTest.scala | 23 | ||||
-rw-r--r-- | test/test/ScannerTest.scala | 16 | ||||
-rw-r--r-- | test/test/ShowClassTests.scala | 24 | ||||
-rw-r--r-- | test/test/desugarTests.scala | 36 | ||||
-rw-r--r-- | test/test/parserTests.scala | 34 | ||||
-rw-r--r-- | test/test/scanPackage.scala | 8 | ||||
-rw-r--r-- | test/test/showClass.scala | 6 | ||||
-rw-r--r-- | test/x/names.scala | 2 |
9 files changed, 81 insertions, 95 deletions
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 |