diff options
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/scala/scala/async/neg/LocalClasses0Spec.scala | 83 | ||||
-rw-r--r-- | src/test/scala/scala/async/run/local-classes0/LocalClasses0Spec.scala | 45 |
2 files changed, 83 insertions, 45 deletions
diff --git a/src/test/scala/scala/async/neg/LocalClasses0Spec.scala b/src/test/scala/scala/async/neg/LocalClasses0Spec.scala new file mode 100644 index 0000000..4bf3ce8 --- /dev/null +++ b/src/test/scala/scala/async/neg/LocalClasses0Spec.scala @@ -0,0 +1,83 @@ +package scala.async +package neg + +/** + * Copyright (C) 2012 Typesafe Inc. <http://www.typesafe.com> + */ + +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.Test + +@RunWith(classOf[JUnit4]) +class LocalClasses0Spec { + + @Test + def `An async block should reject local classes 1`() { + expectError("Local class Person illegal within `async` block", "-cp target/scala-2.10/classes -deprecation -Xfatal-warnings") { + """ + | import scala.async.Async._ + | async { + | case class Person(name: String) + | } + """.stripMargin + } + } + + @Test + def `An async block should reject local classes 2`() { + expectError("Local class Person illegal within `async` block", "-cp target/scala-2.10/classes -deprecation -Xfatal-warnings") { + """ + | import scala.concurrent.{Future, ExecutionContext} + | import ExecutionContext.Implicits.global + | import scala.async.Async._ + | async { + | case class Person(name: String) + | val fut = Future { 5 } + | val x = await(fut) + | x + | } + """.stripMargin + } + } + + @Test + def `An async block should reject local classes 3`() { + expectError("Local class Person illegal within `async` block", "-cp target/scala-2.10/classes -deprecation -Xfatal-warnings") { + """ + | import scala.concurrent.{Future, ExecutionContext} + | import ExecutionContext.Implicits.global + | import scala.async.Async._ + | async { + | val fut = Future { 5 } + | val x = await(fut) + | case class Person(name: String) + | x + | } + """.stripMargin + } + } + + @Test + def `An async block should reject a nested local class`() { + expectError("Local class Person illegal within `async` block", "-cp target/scala-2.10/classes -deprecation -Xfatal-warnings") { + """ + | import scala.concurrent.{Future, ExecutionContext} + | import ExecutionContext.Implicits.global + | import scala.async.Async._ + | async { + | val fut = Future { 5 } + | val x = 2 + 2 + | var y = 0 + | if (x > 0) { + | case class Person(name: String) + | y = await(fut) + | } else { + | y = x + | } + | y + | } + """.stripMargin + } + } +} diff --git a/src/test/scala/scala/async/run/local-classes0/LocalClasses0Spec.scala b/src/test/scala/scala/async/run/local-classes0/LocalClasses0Spec.scala deleted file mode 100644 index 6b8fc4b..0000000 --- a/src/test/scala/scala/async/run/local-classes0/LocalClasses0Spec.scala +++ /dev/null @@ -1,45 +0,0 @@ -package scala.async -package run -package await0 - -/** - * Copyright (C) 2012 Typesafe Inc. <http://www.typesafe.com> - */ - -import language.{reflectiveCalls, postfixOps} - -import scala.concurrent.{Future, ExecutionContext, future, Await} -import scala.concurrent.duration._ -import scala.async.Async.{async, await} -import org.junit.runner.RunWith -import org.junit.runners.JUnit4 -import org.junit.Test - -class LocalClasses0Class { - - import ExecutionContext.Implicits.global - - def base(x: Int): Future[Int] = future { - x + 2 - } - - def methodWithLocalClass(): Future[Int] = async { - case class Person(name: String) - val fut = base(10) - val x = await(fut) - x + 1 - } -} - -@RunWith(classOf[JUnit4]) -class LocalClasses0Spec { - - @Test - def `An async method should reject local classes without crashing`() { - val o = new LocalClasses0Class - val fut = o.methodWithLocalClass() - val res = Await.result(fut, 2 seconds) - res mustBe (13) - } -} - |