summaryrefslogtreecommitdiff
path: root/test/files/jvm
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2012-03-14 10:00:30 -0700
committerPaul Phillips <paulp@improving.org>2012-03-14 10:08:36 -0700
commit3ab383ae01a66208df4955bf2117dd2ea8eb2afe (patch)
treeac83e7e89310955ccbc317f57f34165f9781117c /test/files/jvm
parentb6dde2b6cf5f66e96fc92c09c1fbe3b4a8dc348c (diff)
parent5dca64cefeed4bc3289e641949b103e5e806aa32 (diff)
downloadscala-3ab383ae01a66208df4955bf2117dd2ea8eb2afe.tar.gz
scala-3ab383ae01a66208df4955bf2117dd2ea8eb2afe.tar.bz2
scala-3ab383ae01a66208df4955bf2117dd2ea8eb2afe.zip
Merge branch 'master' into merge-inline
Conflicts: lib/scala-compiler.jar.desired.sha1 lib/scala-library-src.jar.desired.sha1 lib/scala-library.jar.desired.sha1 src/compiler/scala/reflect/internal/Definitions.scala src/compiler/scala/reflect/internal/Importers.scala src/compiler/scala/reflect/internal/Symbols.scala src/compiler/scala/reflect/internal/Trees.scala src/compiler/scala/reflect/internal/Types.scala src/compiler/scala/tools/nsc/Global.scala src/compiler/scala/tools/nsc/transform/Erasure.scala src/compiler/scala/tools/nsc/transform/LiftCode.scala src/compiler/scala/tools/nsc/transform/UnCurry.scala src/compiler/scala/tools/nsc/typechecker/RefChecks.scala src/compiler/scala/tools/nsc/typechecker/Typers.scala test/files/run/programmatic-main.check test/files/speclib/instrumented.jar.desired.sha1
Diffstat (limited to 'test/files/jvm')
-rw-r--r--test/files/jvm/concurrent-future.check16
-rw-r--r--test/files/jvm/concurrent-future.scala122
-rw-r--r--test/files/jvm/scala-concurrent-tck.scala413
-rw-r--r--test/files/jvm/serialization.check16
-rw-r--r--test/files/jvm/serialization.scala12
-rw-r--r--test/files/jvm/typerep.scala2
6 files changed, 575 insertions, 6 deletions
diff --git a/test/files/jvm/concurrent-future.check b/test/files/jvm/concurrent-future.check
new file mode 100644
index 0000000000..c55e824818
--- /dev/null
+++ b/test/files/jvm/concurrent-future.check
@@ -0,0 +1,16 @@
+test1: hai world
+test1: kthxbye
+test2: hai world
+test2: awsum thx
+test2: kthxbye
+test3: hai world
+test4: hai world
+test4: kthxbye
+test5: hai world
+test5: kthxbye
+test6: hai world
+test6: kthxbye
+test7: hai world
+test7: kthxbye
+test8: hai world
+test8: im in yr loop
diff --git a/test/files/jvm/concurrent-future.scala b/test/files/jvm/concurrent-future.scala
new file mode 100644
index 0000000000..b44d054219
--- /dev/null
+++ b/test/files/jvm/concurrent-future.scala
@@ -0,0 +1,122 @@
+
+
+
+import scala.concurrent._
+
+
+
+object Test extends App {
+
+ def once(body: (() => Unit) => Unit) {
+ val sv = new SyncVar[Boolean]
+ body(() => sv put true)
+ sv.take()
+ }
+
+ def output(num: Int, msg: String) {
+ println("test" + num + ": " + msg)
+ }
+
+ def testOnSuccess(): Unit = once {
+ done =>
+ val f = future {
+ output(1, "hai world")
+ }
+ f onSuccess { case _ =>
+ output(1, "kthxbye")
+ done()
+ }
+ }
+
+ def testOnSuccessWhenCompleted(): Unit = once {
+ done =>
+ val f = future {
+ output(2, "hai world")
+ }
+ f onSuccess { case _ =>
+ output(2, "awsum thx")
+ f onSuccess { case _ =>
+ output(2, "kthxbye")
+ done()
+ }
+ }
+ }
+
+ def testOnSuccessWhenFailed(): Unit = once {
+ done =>
+ val f = future[Unit] {
+ output(3, "hai world")
+ done()
+ throw new Exception
+ }
+ f onSuccess { case _ =>
+ output(3, "onoes")
+ }
+ }
+
+ def testOnFailure(): Unit = once {
+ done =>
+ val f = future[Unit] {
+ output(4, "hai world")
+ throw new Exception
+ }
+ f onSuccess { case _ =>
+ output(4, "onoes")
+ done()
+ }
+ f onFailure { case _ =>
+ output(4, "kthxbye")
+ done()
+ }
+ }
+
+ def testOnFailureWhenSpecialThrowable(num: Int, cause: Throwable): Unit = once {
+ done =>
+ val f = future[Unit] {
+ output(num, "hai world")
+ throw cause
+ }
+ f onSuccess { case _ =>
+ output(num, "onoes")
+ done()
+ }
+ f onFailure {
+ case e: ExecutionException if (e.getCause == cause) =>
+ output(num, "kthxbye")
+ done()
+ case _ =>
+ output(num, "onoes")
+ done()
+ }
+ }
+
+ def testOnFailureWhenFutureTimeoutException(): Unit = once {
+ done =>
+ val f = future[Unit] {
+ output(8, "hai world")
+ throw new FutureTimeoutException(null)
+ }
+ f onSuccess { case _ =>
+ output(8, "onoes")
+ done()
+ }
+ f onFailure {
+ case e: FutureTimeoutException =>
+ output(8, "im in yr loop")
+ done()
+ case other =>
+ output(8, "onoes: " + other)
+ done()
+ }
+ }
+
+ testOnSuccess()
+ testOnSuccessWhenCompleted()
+ testOnSuccessWhenFailed()
+ testOnFailure()
+ testOnFailureWhenSpecialThrowable(5, new Error)
+ testOnFailureWhenSpecialThrowable(6, new scala.util.control.ControlThrowable { })
+ testOnFailureWhenSpecialThrowable(7, new InterruptedException)
+ testOnFailureWhenFutureTimeoutException()
+
+}
diff --git a/test/files/jvm/scala-concurrent-tck.scala b/test/files/jvm/scala-concurrent-tck.scala
new file mode 100644
index 0000000000..ba7dffbcb0
--- /dev/null
+++ b/test/files/jvm/scala-concurrent-tck.scala
@@ -0,0 +1,413 @@
+
+
+
+import scala.concurrent.{
+ Future,
+ Promise,
+ TimeoutException,
+ SyncVar,
+ ExecutionException
+}
+import scala.concurrent.future
+import scala.concurrent.promise
+import scala.concurrent.blocking
+import scala.util.{ Try, Success, Failure }
+
+import scala.util.Duration
+
+
+trait TestBase {
+
+ def once(body: (() => Unit) => Unit) {
+ val sv = new SyncVar[Boolean]
+ body(() => sv put true)
+ sv.take()
+ }
+
+ // def assert(cond: => Boolean) {
+ // try {
+ // Predef.assert(cond)
+ // } catch {
+ // case e => e.printStackTrace()
+ // }
+ // }
+
+}
+
+
+trait FutureCallbacks extends TestBase {
+
+ def testOnSuccess(): Unit = once {
+ done =>
+ var x = 0
+ val f = future {
+ x = 1
+ }
+ f onSuccess {
+ case _ =>
+ done()
+ assert(x == 1)
+ }
+ }
+
+ def testOnSuccessWhenCompleted(): Unit = once {
+ done =>
+ var x = 0
+ val f = future {
+ x = 1
+ }
+ f onSuccess {
+ case _ =>
+ assert(x == 1)
+ x = 2
+ f onSuccess {
+ case _ =>
+ assert(x == 2)
+ done()
+ }
+ }
+ }
+
+ def testOnSuccessWhenFailed(): Unit = once {
+ done =>
+ val f = future[Unit] {
+ done()
+ throw new Exception
+ }
+ f onSuccess {
+ case _ => assert(false)
+ }
+ }
+
+ def testOnFailure(): Unit = once {
+ done =>
+ var x = 0
+ val f = future[Unit] {
+ x = 1
+ throw new Exception
+ }
+ f onSuccess {
+ case _ =>
+ done()
+ assert(false)
+ }
+ f onFailure {
+ case _ =>
+ done()
+ assert(x == 1)
+ }
+ }
+
+ def testOnFailureWhenSpecialThrowable(num: Int, cause: Throwable): Unit = once {
+ done =>
+ val f = future[Unit] {
+ throw cause
+ }
+ f onSuccess {
+ case _ =>
+ done()
+ assert(false)
+ }
+ f onFailure {
+ case e: ExecutionException if (e.getCause == cause) =>
+ done()
+ case _ =>
+ done()
+ assert(false)
+ }
+ }
+
+ def testOnFailureWhenTimeoutException(): Unit = once {
+ done =>
+ val f = future[Unit] {
+ throw new TimeoutException()
+ }
+ f onSuccess {
+ case _ =>
+ done()
+ assert(false)
+ }
+ f onFailure {
+ case e: TimeoutException =>
+ done()
+ case other =>
+ done()
+ assert(false)
+ }
+ }
+
+ testOnSuccess()
+ testOnSuccessWhenCompleted()
+ testOnSuccessWhenFailed()
+ testOnFailure()
+ testOnFailureWhenSpecialThrowable(5, new Error)
+ testOnFailureWhenSpecialThrowable(6, new scala.util.control.ControlThrowable { })
+ testOnFailureWhenSpecialThrowable(7, new InterruptedException)
+ testOnFailureWhenTimeoutException()
+
+}
+
+
+trait FutureCombinators extends TestBase {
+
+ // map: stub
+ def testMapSuccess(): Unit = once {
+ done =>
+ done()
+ }
+
+ def testMapFailure(): Unit = once {
+ done =>
+ done()
+ }
+
+ // flatMap: stub
+ def testFlatMapSuccess(): Unit = once {
+ done =>
+ done()
+ }
+
+ def testFlatMapFailure(): Unit = once {
+ done =>
+ done()
+ }
+
+ // filter: stub
+ def testFilterSuccess(): Unit = once {
+ done =>
+ done()
+ }
+
+ def testFilterFailure(): Unit = once {
+ done =>
+ done()
+ }
+
+ // collect: stub
+ def testCollectSuccess(): Unit = once {
+ done =>
+ done()
+ }
+
+ def testCollectFailure(): Unit = once {
+ done =>
+ done()
+ }
+
+ // foreach: stub
+ def testForeachSuccess(): Unit = once {
+ done =>
+ done()
+ }
+
+ def testForeachFailure(): Unit = once {
+ done =>
+ done()
+ }
+
+ def testRecoverSuccess(): Unit = once {
+ done =>
+ val cause = new RuntimeException
+ val f = future {
+ throw cause
+ } recover {
+ case re: RuntimeException =>
+ "recovered"
+ } onSuccess {
+ case x =>
+ done()
+ assert(x == "recovered")
+ } onFailure { case any =>
+ done()
+ assert(false)
+ }
+ }
+
+ def testRecoverFailure(): Unit = once {
+ done =>
+ val cause = new RuntimeException
+ val f = future {
+ throw cause
+ } recover {
+ case te: TimeoutException => "timeout"
+ } onSuccess {
+ case x =>
+ done()
+ assert(false)
+ } onFailure { case any =>
+ done()
+ assert(any == cause)
+ }
+ }
+
+ testMapSuccess()
+ testMapFailure()
+ testFlatMapSuccess()
+ testFlatMapFailure()
+ testFilterSuccess()
+ testFilterFailure()
+ testCollectSuccess()
+ testCollectFailure()
+ testForeachSuccess()
+ testForeachFailure()
+ testRecoverSuccess()
+ testRecoverFailure()
+
+}
+
+
+trait FutureProjections extends TestBase {
+
+ def testFailedFailureOnComplete(): Unit = once {
+ done =>
+ val cause = new RuntimeException
+ val f = future {
+ throw cause
+ }
+ f.failed onComplete {
+ case Success(t) =>
+ assert(t == cause)
+ done()
+ case Failure(t) =>
+ assert(false)
+ }
+ }
+
+ def testFailedFailureOnSuccess(): Unit = once {
+ done =>
+ val cause = new RuntimeException
+ val f = future {
+ throw cause
+ }
+ f.failed onSuccess {
+ case t =>
+ assert(t == cause)
+ done()
+ }
+ }
+
+ def testFailedSuccessOnComplete(): Unit = once {
+ done =>
+ val f = future { 0 }
+ f.failed onComplete {
+ case Success(t) =>
+ assert(false)
+ case Failure(t) =>
+ assert(t.isInstanceOf[NoSuchElementException])
+ done()
+ }
+ }
+
+ def testFailedSuccessOnFailure(): Unit = once {
+ done =>
+ val f = future { 0 }
+ f.failed onFailure {
+ case nsee: NoSuchElementException =>
+ done()
+ }
+ }
+
+ def testFailedFailureAwait(): Unit = once {
+ done =>
+ val cause = new RuntimeException
+ val f = future {
+ throw cause
+ }
+ assert(blocking(f.failed, Duration(500, "ms")) == cause)
+ done()
+ }
+
+ def testFailedSuccessAwait(): Unit = once {
+ done =>
+ val f = future { 0 }
+ try {
+ blocking(f.failed, Duration(500, "ms"))
+ assert(false)
+ } catch {
+ case nsee: NoSuchElementException => done()
+ }
+ }
+
+ testFailedFailureOnComplete()
+ testFailedFailureOnSuccess()
+ testFailedSuccessOnComplete()
+ testFailedSuccessOnFailure()
+ testFailedFailureAwait()
+ testFailedSuccessAwait()
+
+}
+
+
+trait Blocking extends TestBase {
+
+ def testAwaitSuccess(): Unit = once {
+ done =>
+ val f = future { 0 }
+ blocking(f, Duration(500, "ms"))
+ done()
+ }
+
+ def testAwaitFailure(): Unit = once {
+ done =>
+ val cause = new RuntimeException
+ val f = future {
+ throw cause
+ }
+ try {
+ blocking(f, Duration(500, "ms"))
+ assert(false)
+ } catch {
+ case t =>
+ assert(t == cause)
+ done()
+ }
+ }
+
+ testAwaitSuccess()
+ testAwaitFailure()
+
+}
+
+
+trait Promises extends TestBase {
+
+ def testSuccess(): Unit = once {
+ done =>
+ val p = promise[Int]()
+ val f = p.future
+
+ f.onSuccess {
+ case x =>
+ done()
+ assert(x == 5)
+ } onFailure {
+ case any =>
+ done()
+ assert(false)
+ }
+
+ p.success(5)
+ }
+
+ testSuccess()
+
+}
+
+
+trait Exceptions extends TestBase {
+
+}
+
+
+object Test
+extends App
+with FutureCallbacks
+with FutureCombinators
+with FutureProjections
+with Promises
+with Exceptions
+{
+ System.exit(0)
+}
+
+
diff --git a/test/files/jvm/serialization.check b/test/files/jvm/serialization.check
index f58f763a76..81b68f0f5d 100644
--- a/test/files/jvm/serialization.check
+++ b/test/files/jvm/serialization.check
@@ -156,8 +156,8 @@ x = BitSet(0, 8, 9)
y = BitSet(0, 8, 9)
x equals y: true, y equals x: true
-x = Map(C -> 3, B -> 2, A -> 1)
-y = Map(C -> 3, A -> 1, B -> 2)
+x = Map(A -> 1, C -> 3, B -> 2)
+y = Map(A -> 1, C -> 3, B -> 2)
x equals y: true, y equals x: true
x = Set(buffers, title, layers)
@@ -192,6 +192,10 @@ x = TreeSet(1, 2, 3)
y = TreeSet(1, 2, 3)
x equals y: true, y equals x: true
+x = Ctrie(1 -> one, 2 -> two, 3 -> three)
+y = Ctrie(1 -> one, 2 -> two, 3 -> three)
+x equals y: true, y equals x: true
+
x = xml:src="hello"
y = xml:src="hello"
x equals y: true, y equals x: true
@@ -279,8 +283,12 @@ x = ParArray(abc, def, etc)
y = ParArray(abc, def, etc)
x equals y: true, y equals x: true
-x = ParHashMap(1 -> 2, 2 -> 4)
-y = ParHashMap(1 -> 2, 2 -> 4)
+x = ParHashMap(2 -> 4, 1 -> 2)
+y = ParHashMap(2 -> 4, 1 -> 2)
+x equals y: true, y equals x: true
+
+x = ParCtrie(1 -> 2, 2 -> 4)
+y = ParCtrie(1 -> 2, 2 -> 4)
x equals y: true, y equals x: true
x = ParHashSet(1, 2, 3)
diff --git a/test/files/jvm/serialization.scala b/test/files/jvm/serialization.scala
index 73bed2d46b..75daa8903d 100644
--- a/test/files/jvm/serialization.scala
+++ b/test/files/jvm/serialization.scala
@@ -286,7 +286,7 @@ object Test3_mutable {
import scala.collection.mutable.{
ArrayBuffer, ArrayBuilder, ArraySeq, ArrayStack, BitSet, DoubleLinkedList,
HashMap, HashSet, History, LinkedList, ListBuffer, Publisher, Queue,
- Stack, StringBuilder, WrappedArray, TreeSet}
+ Stack, StringBuilder, WrappedArray, TreeSet, Ctrie}
// in alphabetic order
try {
@@ -385,6 +385,11 @@ object Test3_mutable {
val ts1 = TreeSet[Int]() ++= Array(1, 2, 3)
val _ts1: TreeSet[Int] = read(write(ts1))
check(ts1, _ts1)
+
+ // Ctrie
+ val ct1 = Ctrie[Int, String]() ++= Array(1 -> "one", 2 -> "two", 3 -> "three")
+ val _ct1: Ctrie[Int, String] = read(write(ct1))
+ check(ct1, _ct1)
}
catch {
case e: Exception =>
@@ -608,6 +613,11 @@ object Test9_parallel {
val _mpm: mutable.ParHashMap[Int, Int] = read(write(mpm))
check(mpm, _mpm)
+ // mutable.ParCtrie
+ val mpc = mutable.ParCtrie(1 -> 2, 2 -> 4)
+ val _mpc: mutable.ParCtrie[Int, Int] = read(write(mpc))
+ check(mpc, _mpc)
+
// mutable.ParHashSet
val mps = mutable.ParHashSet(1, 2, 3)
val _mps: mutable.ParHashSet[Int] = read(write(mps))
diff --git a/test/files/jvm/typerep.scala b/test/files/jvm/typerep.scala
index 49a216c05c..3befc7ff3f 100644
--- a/test/files/jvm/typerep.scala
+++ b/test/files/jvm/typerep.scala
@@ -161,7 +161,7 @@ object TypeRep {
}).asInstanceOf[TypeRep[Option[A]]]
def getType[A](x: List[A])(implicit rep: TypeRep[A]): TypeRep[List[A]] = (x match {
- case h :: t => ListRep(getType(h))
+ case h :: t => ListRep(rep)
case Nil => NilRep
}).asInstanceOf[TypeRep[List[A]]]