aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2017-10-13 09:16:02 +1000
committerJason Zaugg <jzaugg@gmail.com>2017-10-13 09:16:02 +1000
commit103f3727cd6ab9f8edcc280b5a1ea096de9f48ba (patch)
tree6cdc9d4a1830a05ebd339d9eb4ad490a41670395
parent119d73381cb033f1a27a25d7d8730a58be9c7066 (diff)
downloadscala-async-103f3727cd6ab9f8edcc280b5a1ea096de9f48ba.tar.gz
scala-async-103f3727cd6ab9f8edcc280b5a1ea096de9f48ba.tar.bz2
scala-async-103f3727cd6ab9f8edcc280b5a1ea096de9f48ba.zip
Fix race condition in tests and make some tests actually run
-rw-r--r--src/test/scala/scala/async/run/late/LateExpansion.scala65
1 files changed, 37 insertions, 28 deletions
diff --git a/src/test/scala/scala/async/run/late/LateExpansion.scala b/src/test/scala/scala/async/run/late/LateExpansion.scala
index 8ac8aec..e012df8 100644
--- a/src/test/scala/scala/async/run/late/LateExpansion.scala
+++ b/src/test/scala/scala/async/run/late/LateExpansion.scala
@@ -247,6 +247,7 @@ class LateExpansion {
@Test def testGenericTypeBoundaryIssue(): Unit = {
val result = run(
"""
+
import scala.async.run.late.{autoawait,lateasync}
trait InstrumentOfValue
trait Security[T <: InstrumentOfValue] extends InstrumentOfValue
@@ -263,6 +264,7 @@ class LateExpansion {
}
}
}
+ object Test { @lateasync def test: Unit = TestGenericTypeBoundIssue.doStuff(new Bound) }
""".stripMargin)
}
@@ -281,6 +283,7 @@ class LateExpansion {
42 // type mismatch; found : AnyVal required: Int
}
}
+ object Test { @lateasync def test: Unit = new TestReturnExprIssue("").doStuff }
""".stripMargin)
}
@@ -386,39 +389,45 @@ class LateExpansion {
}
""")
}
+ private def createTempDir(): File = {
+ val f = File.createTempFile("output", "")
+ f.delete()
+ f.mkdirs()
+ f
+ }
def run(code: String): Any = {
- val reporter = new StoreReporter
- val settings = new Settings(println(_))
// settings.processArgumentString("-Xprint:patmat,postpatmat,jvm -Ybackend:GenASM -nowarn")
- settings.outdir.value = sys.props("java.io.tmpdir")
- settings.embeddedDefaults(getClass.getClassLoader)
- val isInSBT = !settings.classpath.isSetByUser
- if (isInSBT) settings.usejavacp.value = true
- val global = new Global(settings, reporter) {
- self =>
-
- object late extends {
- val global: self.type = self
- } with LatePlugin
-
- override protected def loadPlugins(): List[Plugin] = late :: Nil
- }
- import global._
+ val out = createTempDir()
+ try {
+ val reporter = new StoreReporter
+ val settings = new Settings(println(_))
+ settings.outdir.value = out.getAbsolutePath
+ settings.embeddedDefaults(getClass.getClassLoader)
+ val isInSBT = !settings.classpath.isSetByUser
+ if (isInSBT) settings.usejavacp.value = true
+ val global = new Global(settings, reporter) {
+ self =>
+
+ object late extends {
+ val global: self.type = self
+ } with LatePlugin
+
+ override protected def loadPlugins(): List[Plugin] = late :: Nil
+ }
+ import global._
- val run = new Run
- val source = newSourceFile(code)
-// TreeInterrogation.withDebug {
+ val run = new Run
+ val source = newSourceFile(code)
+ // TreeInterrogation.withDebug {
run.compileSources(source :: Nil)
-// }
- Assert.assertTrue(reporter.infos.mkString("\n"), !reporter.hasErrors)
- val loader = new URLClassLoader(Seq(new File(settings.outdir.value).toURI.toURL), global.getClass.getClassLoader)
- val cls = try {
- loader.loadClass("Test")
- } catch {
- case ex: ClassNotFoundException =>
- throw new ClassNotFoundException(new File(settings.outdir.value).list().mkString(", "), ex)
+ // }
+ Assert.assertTrue(reporter.infos.mkString("\n"), !reporter.hasErrors)
+ val loader = new URLClassLoader(Seq(new File(settings.outdir.value).toURI.toURL), global.getClass.getClassLoader)
+ val cls = loader.loadClass("Test")
+ cls.getMethod("test").invoke(null)
+ } finally {
+ scala.reflect.io.Path.apply(out).deleteRecursively()
}
- cls.getMethod("test").invoke(null)
}
}