Skip to content

Commit 103f372

Browse files
committed
Fix race condition in tests and make some tests actually run
1 parent 119d733 commit 103f372

File tree

1 file changed

+37
-28
lines changed

1 file changed

+37
-28
lines changed

src/test/scala/scala/async/run/late/LateExpansion.scala

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ class LateExpansion {
247247
@Test def testGenericTypeBoundaryIssue(): Unit = {
248248
val result = run(
249249
"""
250+
250251
import scala.async.run.late.{autoawait,lateasync}
251252
trait InstrumentOfValue
252253
trait Security[T <: InstrumentOfValue] extends InstrumentOfValue
@@ -263,6 +264,7 @@ class LateExpansion {
263264
}
264265
}
265266
}
267+
object Test { @lateasync def test: Unit = TestGenericTypeBoundIssue.doStuff(new Bound) }
266268
""".stripMargin)
267269
}
268270

@@ -281,6 +283,7 @@ class LateExpansion {
281283
42 // type mismatch; found : AnyVal required: Int
282284
}
283285
}
286+
object Test { @lateasync def test: Unit = new TestReturnExprIssue("").doStuff }
284287
""".stripMargin)
285288
}
286289

@@ -386,39 +389,45 @@ class LateExpansion {
386389
}
387390
""")
388391
}
392+
private def createTempDir(): File = {
393+
val f = File.createTempFile("output", "")
394+
f.delete()
395+
f.mkdirs()
396+
f
397+
}
389398
def run(code: String): Any = {
390-
val reporter = new StoreReporter
391-
val settings = new Settings(println(_))
392399
// settings.processArgumentString("-Xprint:patmat,postpatmat,jvm -Ybackend:GenASM -nowarn")
393-
settings.outdir.value = sys.props("java.io.tmpdir")
394-
settings.embeddedDefaults(getClass.getClassLoader)
395-
val isInSBT = !settings.classpath.isSetByUser
396-
if (isInSBT) settings.usejavacp.value = true
397-
val global = new Global(settings, reporter) {
398-
self =>
399-
400-
object late extends {
401-
val global: self.type = self
402-
} with LatePlugin
403-
404-
override protected def loadPlugins(): List[Plugin] = late :: Nil
405-
}
406-
import global._
400+
val out = createTempDir()
401+
try {
402+
val reporter = new StoreReporter
403+
val settings = new Settings(println(_))
404+
settings.outdir.value = out.getAbsolutePath
405+
settings.embeddedDefaults(getClass.getClassLoader)
406+
val isInSBT = !settings.classpath.isSetByUser
407+
if (isInSBT) settings.usejavacp.value = true
408+
val global = new Global(settings, reporter) {
409+
self =>
410+
411+
object late extends {
412+
val global: self.type = self
413+
} with LatePlugin
414+
415+
override protected def loadPlugins(): List[Plugin] = late :: Nil
416+
}
417+
import global._
407418

408-
val run = new Run
409-
val source = newSourceFile(code)
410-
// TreeInterrogation.withDebug {
419+
val run = new Run
420+
val source = newSourceFile(code)
421+
// TreeInterrogation.withDebug {
411422
run.compileSources(source :: Nil)
412-
// }
413-
Assert.assertTrue(reporter.infos.mkString("\n"), !reporter.hasErrors)
414-
val loader = new URLClassLoader(Seq(new File(settings.outdir.value).toURI.toURL), global.getClass.getClassLoader)
415-
val cls = try {
416-
loader.loadClass("Test")
417-
} catch {
418-
case ex: ClassNotFoundException =>
419-
throw new ClassNotFoundException(new File(settings.outdir.value).list().mkString(", "), ex)
423+
// }
424+
Assert.assertTrue(reporter.infos.mkString("\n"), !reporter.hasErrors)
425+
val loader = new URLClassLoader(Seq(new File(settings.outdir.value).toURI.toURL), global.getClass.getClassLoader)
426+
val cls = loader.loadClass("Test")
427+
cls.getMethod("test").invoke(null)
428+
} finally {
429+
scala.reflect.io.Path.apply(out).deleteRecursively()
420430
}
421-
cls.getMethod("test").invoke(null)
422431
}
423432
}
424433

0 commit comments

Comments
 (0)