From fb98e832439819b11649a878320d30938fc30abb Mon Sep 17 00:00:00 2001 From: vsalvis Date: Mon, 20 Apr 2015 11:18:32 +0200 Subject: Robuster FileLock test to prevent exception if fork in Test is ever disabled --- test/test/CompilerTest.scala | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'test/test/CompilerTest.scala') diff --git a/test/test/CompilerTest.scala b/test/test/CompilerTest.scala index 1dd65b6e0..f404c79ba 100644 --- a/test/test/CompilerTest.scala +++ b/test/test/CompilerTest.scala @@ -42,11 +42,17 @@ abstract class CompilerTest extends DottyTest { val generatePartestFiles = { val partestLockFile = "." + JFile.separator + "tests" + JFile.separator + "partest.lock" - val partestLock = new RandomAccessFile(partestLockFile, "rw").getChannel.tryLock - if (partestLock != null) { // file not locked by sbt -> don't generate partest - partestLock.release - false - } else true + try { + val partestLock = new RandomAccessFile(partestLockFile, "rw").getChannel.tryLock + if (partestLock != null) { // file not locked by sbt -> don't generate partest + partestLock.release + false + } else true + } catch { + // if sbt doesn't fork in Test, the tryLock request will throw instead of + // returning null, because locks are per JVM, not per thread + case ex: java.nio.channels.OverlappingFileLockException => true + } } // Delete generated files from previous run -- cgit v1.2.3