diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2012-11-21 22:48:34 +0100 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2012-11-21 22:48:34 +0100 |
commit | 10aa18736a1d5161f9ad34ebcd9a6a756c904666 (patch) | |
tree | e9a23df0dd26e9b588d49be9772d901032629bf1 /src/test | |
parent | eeb0f5e676e8d9cc44ab886a6225da62dfb5d561 (diff) | |
download | scala-async-10aa18736a1d5161f9ad34ebcd9a6a756c904666.tar.gz scala-async-10aa18736a1d5161f9ad34ebcd9a6a756c904666.tar.bz2 scala-async-10aa18736a1d5161f9ad34ebcd9a6a756c904666.zip |
Only transform if/match-s that contain an await.
Accurate reporting of misplaced awaits.
Attempt to collect the minimal set of vars to lift.
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/scala/scala/async/TestUtils.scala | 4 | ||||
-rw-r--r-- | src/test/scala/scala/async/neg/AnfTransformNegSpec.scala | 4 | ||||
-rw-r--r-- | src/test/scala/scala/async/neg/NakedAwait.scala | 72 |
3 files changed, 76 insertions, 4 deletions
diff --git a/src/test/scala/scala/async/TestUtils.scala b/src/test/scala/scala/async/TestUtils.scala index bac22a3..0ae78b8 100644 --- a/src/test/scala/scala/async/TestUtils.scala +++ b/src/test/scala/scala/async/TestUtils.scala @@ -50,9 +50,9 @@ trait TestUtils { m.mkToolBox(options = compileOptions) } - def expectError(errorSnippet: String, compileOptions: String = "")(code: String) { + def expectError(errorSnippet: String, compileOptions: String = "", baseCompileOptions: String = "-cp target/scala-2.10/classes")(code: String) { intercept[ToolBoxError] { - eval(code, compileOptions) + eval(code, compileOptions + " " + baseCompileOptions) }.getMessage mustContain errorSnippet } } diff --git a/src/test/scala/scala/async/neg/AnfTransformNegSpec.scala b/src/test/scala/scala/async/neg/AnfTransformNegSpec.scala index 974a5f1..38790dd 100644 --- a/src/test/scala/scala/async/neg/AnfTransformNegSpec.scala +++ b/src/test/scala/scala/async/neg/AnfTransformNegSpec.scala @@ -13,7 +13,7 @@ class AnfTransformNegSpec { @Test def `inlining block produces duplicate definition`() { - expectError("x is already defined as value x", "-cp target/scala-2.10/classes -deprecation -Xfatal-warnings") { + expectError("x is already defined as value x", "-deprecation -Xfatal-warnings") { """ | import scala.concurrent.ExecutionContext.Implicits.global | import scala.concurrent.Future @@ -36,7 +36,7 @@ class AnfTransformNegSpec { @Test def `inlining block in tail position produces duplicate definition`() { - expectError("x is already defined as value x", "-cp target/scala-2.10/classes -deprecation -Xfatal-warnings") { + expectError("x is already defined as value x", "-deprecation -Xfatal-warnings") { """ | import scala.concurrent.ExecutionContext.Implicits.global | import scala.concurrent.Future diff --git a/src/test/scala/scala/async/neg/NakedAwait.scala b/src/test/scala/scala/async/neg/NakedAwait.scala index db67f18..66bc947 100644 --- a/src/test/scala/scala/async/neg/NakedAwait.scala +++ b/src/test/scala/scala/async/neg/NakedAwait.scala @@ -16,4 +16,76 @@ class NakedAwait { """.stripMargin } } + + + @Test + def `await not allowed in by-name argument`() { + expectError("await must not be used under a by-name argument.") { + """ + | import _root_.scala.async.AsyncId._ + | def foo(a: Int)(b: => Int) = 0 + | async { foo(0)(await(0)) } + """.stripMargin + } + } + + @Test + def `await not allowed in boolean short circuit argument 1`() { + expectError("await must not be used under a by-name argument.") { + """ + | import _root_.scala.async.AsyncId._ + | async { true && await(false) } + """.stripMargin + } + } + + @Test + def `await not allowed in boolean short circuit argument 2`() { + expectError("await must not be used under a by-name argument.") { + """ + | import _root_.scala.async.AsyncId._ + | async { true || await(false) } + """.stripMargin + } + } + + @Test + def nestedObject() { + expectError("await must not be used under a nested object.") { + """ + | import _root_.scala.async.AsyncId._ + | async { object Nested { await(false) } } + """.stripMargin + } + } + + @Test + def nestedTrait() { + expectError("await must not be used under a nested trait.") { + """ + | import _root_.scala.async.AsyncId._ + | async { trait Nested { await(false) } } + """.stripMargin + } + } + + @Test + def nestedClass() { + expectError("await must not be used under a nested class.") { + """ + | import _root_.scala.async.AsyncId._ + | async { class Nested { await(false) } } + """.stripMargin + } + } + + @Test + def nestedFunction() { + expectError("await must not be used under a nested anonymous function.") { + """ + | import _root_.scala.async.AsyncId._ + | async { () => { await(false) } } + """.stripMargin + } + } } |