aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-04-05 12:15:45 +0200
committerMartin Odersky <odersky@gmail.com>2013-04-05 12:15:45 +0200
commitf8d5c8401ab7e4a31c9f4430ad64e27d8cb08bac (patch)
tree64d0916d98f35a63da221bbdf95d44bc4467e759
parent2dcae86ae6937ad2f8cd8b05734eb9feb964404e (diff)
downloaddotty-f8d5c8401ab7e4a31c9f4430ad64e27d8cb08bac.tar.gz
dotty-f8d5c8401ab7e4a31c9f4430ad64e27d8cb08bac.tar.bz2
dotty-f8d5c8401ab7e4a31c9f4430ad64e27d8cb08bac.zip
Refactored test framework
Moves worksheets to test. Factored out class DottyTest and made it usable from worksheets. Added worksheet test for signatures.
-rw-r--r--src/dotty/tools/dotc/core/Names.scala3
-rw-r--r--test/test/DottyTest.scala32
-rw-r--r--test/test/ShowClassTests.scala18
-rw-r--r--test/test/SignatureTests.scala5
-rw-r--r--test/test/flagtest.sc (renamed from src/dotty/tools/dotc/core/flagtest.sc)4
-rw-r--r--test/test/nesting.sc (renamed from src/dotty/tools/dotc/core/nesting.sc)0
-rw-r--r--test/test/periodtest.sc (renamed from src/dotty/tools/dotc/core/periodtest.sc)6
-rw-r--r--test/test/showClass.scala4
-rw-r--r--test/test/sigtest.sc31
-rw-r--r--test/test/testnames.sc (renamed from src/dotty/tools/dotc/core/testnames.sc)9
10 files changed, 82 insertions, 30 deletions
diff --git a/src/dotty/tools/dotc/core/Names.scala b/src/dotty/tools/dotc/core/Names.scala
index b61f5ee06..5d78ce88c 100644
--- a/src/dotty/tools/dotc/core/Names.scala
+++ b/src/dotty/tools/dotc/core/Names.scala
@@ -79,7 +79,8 @@ object Names {
*/
def fromName(name: Name): ThisName = fromChars(chrs, name.start, name.length)
- override def toString = new String(chrs, start, length)
+ override def toString =
+ if (length == 0) "" else new String(chrs, start, length)
def show(implicit ctx: Context): String = ctx.nameString(this)
diff --git a/test/test/DottyTest.scala b/test/test/DottyTest.scala
new file mode 100644
index 000000000..b5793a7eb
--- /dev/null
+++ b/test/test/DottyTest.scala
@@ -0,0 +1,32 @@
+package test
+
+import dotty.tools.dotc.core._
+import dotty.tools.dotc.core.Contexts._
+import dotty.tools.dotc.core.Symbols._
+import dotty.tools.dotc.core.Flags._
+import Types._, Symbols._, Decorators._
+import dotty.tools.dotc.util.Texts._
+import dotty.tools.dotc.core.Decorators._
+import org.junit.Test
+
+class DottyTest {
+
+ implicit val ctx: Context = {
+ val base = Context.theBase
+ import base.settings._
+ val ctx = base.initialCtx.fresh
+ .withSetting(verbose, true)
+ .withSetting(debug, true)
+ .withSetting(debugTrace, true)
+ .withSetting(Ylogcp, true)
+ .withSetting(printtypes, true)
+ .withSetting(pageWidth, 90)
+ .withSetting(log, List("<some"))
+ println(ctx.settings)
+ base.definitions.init()
+ ctx
+ }
+
+ def methType(names: String*)(paramTypes: Type*)(resultType: Type = defn.UnitType) =
+ MethodType(names.toList map (_.toTermName), paramTypes.toList, resultType)
+}
diff --git a/test/test/ShowClassTests.scala b/test/test/ShowClassTests.scala
index c887f158e..830f4011c 100644
--- a/test/test/ShowClassTests.scala
+++ b/test/test/ShowClassTests.scala
@@ -9,7 +9,7 @@ import dotty.tools.dotc.util.Texts._
import dotty.tools.dotc.core.Decorators._
import org.junit.Test
-class ShowClassTests {
+class ShowClassTests extends DottyTest {
private val blackList = List(
// the following classes cannot be read correctly because they
@@ -71,22 +71,6 @@ class ShowClassTests {
showClass(cls.linkedClass)
}
- implicit val ctx: Context = {
- val base = Context.theBase
- import base.settings._
- val ctx = base.initialCtx.fresh
- .withSetting(verbose, true)
- .withSetting(debug, true)
- // .withSetting(settings.debugNames, true)
- .withSetting(Ylogcp, true)
- .withSetting(printtypes, true)
- .withSetting(pageWidth, 90)
- .withSetting(log, List("<some"))
- println(ctx.settings)
- base.definitions.init()
- ctx
- }
-
@Test
def loadSimpleClasses() = {
showClasses("scala.Array")
diff --git a/test/test/SignatureTests.scala b/test/test/SignatureTests.scala
new file mode 100644
index 000000000..78f44aa60
--- /dev/null
+++ b/test/test/SignatureTests.scala
@@ -0,0 +1,5 @@
+package test
+
+class SignatureTests extends DottyTest {
+
+} \ No newline at end of file
diff --git a/src/dotty/tools/dotc/core/flagtest.sc b/test/test/flagtest.sc
index bd1a9bd25..ac3a6ab13 100644
--- a/src/dotty/tools/dotc/core/flagtest.sc
+++ b/test/test/flagtest.sc
@@ -20,6 +20,8 @@ object flagtest {
Method == Abstract //> res8: Boolean = false
Method.toCommonFlags //> res9: dotty.tools.dotc.core.Flags.FlagSet = <method> abstract
FromStartFlags //> res10: dotty.tools.dotc.core.Flags.FlagSet = private protected <deferred> <p
- //| aram> <local> module <package> <existential>
+ //| aram> <accessor> sealed <local> module <package> <expandedname> <covariant>
+ //| <contravariant> <static> <touched> <frozen> <existential>
AccessFlags <= FromStartFlags //> res11: Boolean = true
+ FromStartFlags <= AccessFlags //> res12: Boolean = false
} \ No newline at end of file
diff --git a/src/dotty/tools/dotc/core/nesting.sc b/test/test/nesting.sc
index a6fc92432..a6fc92432 100644
--- a/src/dotty/tools/dotc/core/nesting.sc
+++ b/test/test/nesting.sc
diff --git a/src/dotty/tools/dotc/core/periodtest.sc b/test/test/periodtest.sc
index 38dccdfc3..09c02da19 100644
--- a/src/dotty/tools/dotc/core/periodtest.sc
+++ b/test/test/periodtest.sc
@@ -5,10 +5,8 @@ object periodtest {
import Periods._
- val p1 = Period(1, 2, 7) //> p1 : dotty.tools.dotc.core.Periods.Period = dotty.tools.dotc.core.Periods$P
- //| eriod@4e5
- val p2 = Period(1, 3, 7) //> p2 : dotty.tools.dotc.core.Periods.Period = dotty.tools.dotc.core.Periods$P
- //| eriod@4e4
+ val p1 = Period(1, 2, 7) //> p1 : dotty.tools.dotc.core.Periods.Period = Period(2..7, run = 1)
+ val p2 = Period(1, 3, 7) //> p2 : dotty.tools.dotc.core.Periods.Period = Period(3..7, run = 1)
p1 contains p2 //> res0: Boolean = true
p1 contains p1 //> res1: Boolean = true
p2 contains p1 //> res2: Boolean = false
diff --git a/test/test/showClass.scala b/test/test/showClass.scala
index d15125e77..39ffd496c 100644
--- a/test/test/showClass.scala
+++ b/test/test/showClass.scala
@@ -6,8 +6,8 @@ object showClass extends ShowClassTests {
def main(args: Array[String]) = {
for (arg <- args) showPackage(ctx.requiredPackage(arg))
- //showPackage("scala.reflect")
- showClasses("scala.collection.convert.Wrappers")
+ showClasses("scala.reflect.runtime.SynchronizedOps")
+// showPackage("scala.reflect")
// showPackage("scala")
println("done")
}
diff --git a/test/test/sigtest.sc b/test/test/sigtest.sc
new file mode 100644
index 000000000..44fa4f110
--- /dev/null
+++ b/test/test/sigtest.sc
@@ -0,0 +1,31 @@
+package test
+
+import dotty.tools.dotc._
+import core._
+import Decorators._
+import Types._, Symbols._
+
+object sigtest extends DottyTest {
+ println("Welcome to the Scala worksheet") //> Welcome to the Scala worksheet
+ val int = ctx.requiredClass("scala.Int") //> int : dotty.tools.dotc.core.Symbols.ClassSymbol = class Int
+ int.signature //> res0: dotty.tools.dotc.core.Denotations.Signature = List()
+ val intmeth = methType("x")(int.symbolicRef)() //> intmeth : dotty.tools.dotc.core.Types.MethodType = MethodType(List(x), List
+ //| (TypeRef(ThisType(module class scala),Int)), TypeRef(ThisType(module class s
+ //| cala),Unit))
+ intmeth.signature //> res1: dotty.tools.dotc.core.Denotations.Signature = List(Int)
+ val arraymeth = methType("x")(defn.ArrayType.appliedTo(int.symbolicRef))()
+ //> arraymeth : dotty.tools.dotc.core.Types.MethodType = MethodType(List(x), Li
+ //| st(RefinedType(TypeRef(ThisType(module class scala),Array), scala$Array$$T,
+ //| TypeAlias(TypeRef(ThisType(module class scala),Int)) | hash = -634207123)),
+ //| TypeRef(ThisType(module class scala),Unit))
+ arraymeth.signature //> res2: dotty.tools.dotc.core.Denotations.Signature = List(Object[])
+ val curriedmeth = methType("x", "y")(defn.IntType, defn.BooleanType)(methType("z")(defn.ArrayType.appliedTo(defn.IntType))())
+ //> curriedmeth : dotty.tools.dotc.core.Types.MethodType = MethodType(List(x, y
+ //| ), List(TypeRef(ThisType(module class scala),Int), TypeRef(ThisType(module c
+ //| lass scala),Boolean)), MethodType(List(z), List(RefinedType(TypeRef(ThisType
+ //| (module class scala),Array), scala$Array$$T, TypeAlias(TypeRef(ThisType(modu
+ //| le class scala),Int)) | hash = -250095115)), TypeRef(ThisType(module class s
+ //| cala),Unit)))
+ curriedmeth.signature //> res3: dotty.tools.dotc.core.Denotations.Signature = List(Int, Boolean, Objec
+ //| t[])
+} \ No newline at end of file
diff --git a/src/dotty/tools/dotc/core/testnames.sc b/test/test/testnames.sc
index 21c4a0ee6..282b07d4e 100644
--- a/src/dotty/tools/dotc/core/testnames.sc
+++ b/test/test/testnames.sc
@@ -41,10 +41,9 @@ object testnames {
val local = "local".toTermName.toLocalName //> local : dotty.tools.dotc.core.Names.LocalName = local
val local1 = local ++ "!" //> local1 : dotty.tools.dotc.core.testnames.local.ThisName = local!
- local1.showDetailed //> res21: String = local!/L
+ local1 //> res21: dotty.tools.dotc.core.testnames.local.ThisName = local!
val local2 = "Foo.".toTermName ++: local1 //> local2 : dotty.tools.dotc.core.Names.Name = Foo.local!
- local2.showDetailed //> res22: String = Foo.local!/V
- local1.dropRight(2).showDetailed //> res23: String = loca/L
- local1.fromName("Foo.".toTermName ++ local1).showDetailed
- //> res24: String = Foo.local!/L
+ local2 //> res22: dotty.tools.dotc.core.Names.Name = Foo.local!
+ local1.dropRight(2) //> res23: dotty.tools.dotc.core.Names.Name = loca
+ local1.fromName("Foo.".toTermName ++ local1) //> res24: dotty.tools.dotc.core.testnames.local1.ThisName = Foo.local!
} \ No newline at end of file