Skip to content

Commit be2eaf0

Browse files
committed
Better documentation for partest dottyJar option
1 parent 45633c1 commit be2eaf0

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

project/Build.scala

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,30 @@ object DottyBuild extends Build {
6464
// enable verbose exception messages for JUnit
6565
testOptions in Test += Tests.Argument(TestFrameworks.JUnit, "-a", "-v", "--run-listener=test.ContextEscapeDetector"),
6666
testOptions in Test += Tests.Cleanup({ () => if (partestLock != null) partestLock.release }),
67-
// when this file is locked, running test generates the files for partest
68-
// otherwise it just executes the tests directly
67+
// When this file is locked, running test generates the files for partest.
68+
// Otherwise it just executes the tests directly. So running two separate
69+
// sbt instances might result in unexpected behavior if one does partest
70+
// and the other test, since the second still sees the locked file and thus
71+
// generates partest files instead of running JUnit tests, but doesn't
72+
// partest them.
6973
lockPartestFile := {
7074
val partestLockFile = "." + File.separator + "tests" + File.separator + "partest.lock"
7175
try {
7276
partestLock = new RandomAccessFile(partestLockFile, "rw").getChannel.tryLock
77+
if (partestLock == null)
78+
throw new RuntimeException("ERROR: sbt partest: file is locked already. Bad things happen when trying to mix test/partest in two concurrent sbt instances.")
7379
} catch {
74-
case ex: java.nio.channels.OverlappingFileLockException => // locked already
80+
case ex: java.nio.channels.OverlappingFileLockException => // locked already, Tests.Cleanup didn't run
81+
if (partestLock != null)
82+
partestLock.release
83+
throw new RuntimeException("ERROR: sbt partest: file was still locked, please try again or restart sbt.")
7584
}
7685
},
7786
runPartestRunner <<= Def.taskDyn {
7887
val jars = Seq((packageBin in Compile).value.getAbsolutePath) ++
7988
getJarPaths(partestDeps.value, ivyPaths.value.ivyHome)
8089
val dottyJars = "-dottyJars " + jars.length + " " + jars.mkString(" ")
90+
// Provide the jars required on the classpath of run tests
8191
runTask(Test, "dotty.partest.DPConsoleRunner", dottyJars)
8292
},
8393

test/dotty/partest/DPConsoleRunner.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ import java.net.URLClassLoader
1414

1515
/** Runs dotty partest from the Console, discovering test sources in
1616
* DPConfig.testRoot that have been generated automatically by
17-
* DPPrepJUnitRunner. Use `sbt partest` to run.
17+
* DPPrepJUnitRunner. Use `sbt partest` to run. If additional jars are
18+
* required by some run tests, add them to partestDeps in the sbt Build.scala.
1819
*/
1920
object DPConsoleRunner {
2021
def main(args: Array[String]): Unit = {
2122
// unfortunately sbt runTask passes args as single string
23+
// extra jars for run tests are passed with -dottyJars <count> <jar1> <jar2> ...
2224
val jarFinder = """-dottyJars (\d*) (.*)""".r
2325
val (jarList, otherArgs) = args.toList.partition(jarFinder.findFirstIn(_).isDefined)
2426
val extraJars = jarList match {

test/test/CompilerTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import org.junit.Test
3131
* - run: compilation succeeds, partest: test run generates the output in
3232
* <test>.check. Run tests always need to be:
3333
* object Test { def main(args: Array[String]): Unit = ... }
34-
*
34+
* Classpath jars can be added to partestDeps in the sbt Build.scala.
3535
*/
3636
abstract class CompilerTest extends DottyTest {
3737

0 commit comments

Comments
 (0)