Skip to content

Commit 440f51c

Browse files
committed
Fix compile tests using checkIterations
Port sbt/sbt@927910a needed because sbt 1.4 uses batch mode for scripted tests.
1 parent f53710f commit 440f51c

File tree

29 files changed

+239
-61
lines changed

29 files changed

+239
-61
lines changed
Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
1+
import sbt.internal.inc.Analysis
12
import complete.DefaultParsers._
23

3-
InputKey[Unit]("check-number-of-compiler-iterations") := {
4-
val args = spaceDelimited("<arg>").parsed
5-
val a = (compile in Compile).value.asInstanceOf[sbt.internal.inc.Analysis]
6-
assert(args.size == 1)
7-
val expectedIterationsNumber = args(0).toInt
8-
assert(a.compilations.allCompilations.size == expectedIterationsNumber, "a.compilations.allCompilations.size = %d (expected %d)".format(a.compilations.allCompilations.size, expectedIterationsNumber))
4+
// Reset compiler iterations, necessary because tests run in batch mode
5+
val recordPreviousIterations = taskKey[Unit]("Record previous iterations.")
6+
recordPreviousIterations := {
7+
val log = streams.value.log
8+
CompileState.previousIterations = {
9+
val previousAnalysis = (previousCompile in Compile).value.analysis.asScala
10+
previousAnalysis match {
11+
case None =>
12+
log.info("No previous analysis detected")
13+
0
14+
case Some(a: Analysis) => a.compilations.allCompilations.size
15+
}
16+
}
17+
}
18+
19+
val checkIterations = inputKey[Unit]("Verifies the accumulated number of iterations of incremental compilation.")
20+
21+
checkIterations := {
22+
val expected: Int = (Space ~> NatBasic).parsed
23+
val actual: Int = ((compile in Compile).value match { case a: Analysis => a.compilations.allCompilations.size }) - CompileState.previousIterations
24+
assert(expected == actual, s"Expected $expected compilations, got $actual")
925
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// This is necessary because tests are run in batch mode
2+
object CompileState {
3+
@volatile var previousIterations: Int = -1
4+
}

sbt-dotty/sbt-test/source-dependencies/abstract-type-override/test

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
> recordPreviousIterations
12
# Test for separate compilation and proper value of
23
# the OVERRIDE flag when abstract types, type alias
34
# and structural type are involved
@@ -11,4 +12,4 @@ $ copy-file changes/Bar1.scala src/main/scala/Bar.scala
1112
# second iteration
1213
#> compile
1314
# check if there are only two compile iterations performed
14-
> checkNumberOfCompilerIterations 2
15+
> checkIterations 2

sbt-dotty/sbt-test/source-dependencies/canon/build.sbt

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
1+
import sbt.internal.inc.Analysis
12
import complete.DefaultParsers._
23

3-
val checkIterations = inputKey[Unit]("Verifies the accumlated number of iterations of incremental compilation.")
4+
// Reset compiler iterations, necessary because tests run in batch mode
5+
val recordPreviousIterations = taskKey[Unit]("Record previous iterations.")
6+
recordPreviousIterations := {
7+
val log = streams.value.log
8+
CompileState.previousIterations = {
9+
val previousAnalysis = (previousCompile in Compile).value.analysis.asScala
10+
previousAnalysis match {
11+
case None =>
12+
log.info("No previous analysis detected")
13+
0
14+
case Some(a: Analysis) => a.compilations.allCompilations.size
15+
}
16+
}
17+
}
418

5-
checkIterations := {
6-
val analysis = (compile in Compile).value.asInstanceOf[sbt.internal.inc.Analysis]
19+
val checkIterations = inputKey[Unit]("Verifies the accumulated number of iterations of incremental compilation.")
720

21+
checkIterations := {
822
val expected: Int = (Space ~> NatBasic).parsed
9-
val actual: Int = analysis.compilations.allCompilations.size
23+
val actual: Int = ((compile in Compile).value match { case a: Analysis => a.compilations.allCompilations.size }) - CompileState.previousIterations
1024
assert(expected == actual, s"Expected $expected compilations, got $actual")
1125
}
12-
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// This is necessary because tests are run in batch mode
2+
object CompileState {
3+
@volatile var previousIterations: Int = -1
4+
}

sbt-dotty/sbt-test/source-dependencies/canon/test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
> recordPreviousIterations
12
# Tests that classpath entries that are different than their canonical representation are
23
# handled properly. In particular, a symlink from lib/a.jar to lib/../actual/a.jar.0 is
34
# available on the classpath and read by scalac. scalac 2.10.x does not interpret .jar.0

sbt-dotty/sbt-test/source-dependencies/constructors-unrelated/build.sbt

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
1+
import sbt.internal.inc.Analysis
12
import complete.DefaultParsers._
23

3-
val checkIterations = inputKey[Unit]("Verifies the accumlated number of iterations of incremental compilation.")
4+
// Reset compiler iterations, necessary because tests run in batch mode
5+
val recordPreviousIterations = taskKey[Unit]("Record previous iterations.")
6+
recordPreviousIterations := {
7+
val log = streams.value.log
8+
CompileState.previousIterations = {
9+
val previousAnalysis = (previousCompile in Compile).value.analysis.asScala
10+
previousAnalysis match {
11+
case None =>
12+
log.info("No previous analysis detected")
13+
0
14+
case Some(a: Analysis) => a.compilations.allCompilations.size
15+
}
16+
}
17+
}
418

5-
checkIterations := {
6-
val analysis = (compile in Compile).value.asInstanceOf[sbt.internal.inc.Analysis]
19+
val checkIterations = inputKey[Unit]("Verifies the accumulated number of iterations of incremental compilation.")
720

21+
checkIterations := {
822
val expected: Int = (Space ~> NatBasic).parsed
9-
val actual: Int = analysis.compilations.allCompilations.size
23+
val actual: Int = ((compile in Compile).value match { case a: Analysis => a.compilations.allCompilations.size }) - CompileState.previousIterations
1024
assert(expected == actual, s"Expected $expected compilations, got $actual")
1125
}
12-
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// This is necessary because tests are run in batch mode
2+
object CompileState {
3+
@volatile var previousIterations: Int = -1
4+
}

sbt-dotty/sbt-test/source-dependencies/constructors-unrelated/test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
> recordPreviousIterations
12
> compile
23
$ copy-file changes/A2.scala A.scala
34
# Second compilation round, there should be no third round (we don't need to recompile B.scala)

sbt-dotty/sbt-test/source-dependencies/inline-inherited/build.sbt

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
1+
import sbt.internal.inc.Analysis
12
import complete.DefaultParsers._
23

3-
val checkIterations = inputKey[Unit]("Verifies the accumlated number of iterations of incremental compilation.")
4+
// Reset compiler iterations, necessary because tests run in batch mode
5+
val recordPreviousIterations = taskKey[Unit]("Record previous iterations.")
6+
recordPreviousIterations := {
7+
val log = streams.value.log
8+
CompileState.previousIterations = {
9+
val previousAnalysis = (previousCompile in Compile).value.analysis.asScala
10+
previousAnalysis match {
11+
case None =>
12+
log.info("No previous analysis detected")
13+
0
14+
case Some(a: Analysis) => a.compilations.allCompilations.size
15+
}
16+
}
17+
}
418

5-
checkIterations := {
6-
val analysis = (compile in Compile).value.asInstanceOf[sbt.internal.inc.Analysis]
19+
val checkIterations = inputKey[Unit]("Verifies the accumulated number of iterations of incremental compilation.")
720

21+
checkIterations := {
822
val expected: Int = (Space ~> NatBasic).parsed
9-
val actual: Int = analysis.compilations.allCompilations.size
23+
val actual: Int = ((compile in Compile).value match { case a: Analysis => a.compilations.allCompilations.size }) - CompileState.previousIterations
1024
assert(expected == actual, s"Expected $expected compilations, got $actual")
1125
}
12-
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// This is necessary because tests are run in batch mode
2+
object CompileState {
3+
@volatile var previousIterations: Int = -1
4+
}

sbt-dotty/sbt-test/source-dependencies/inline-inherited/test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
> recordPreviousIterations
12
> compile
23
# Force recompilation of B, B.getInline hasn't changed so C shouldn't be recompiled.
34
$ copy-file changes/B1.scala B.scala

sbt-dotty/sbt-test/source-dependencies/inner-class/build.sbt

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
1+
import sbt.internal.inc.Analysis
12
import complete.DefaultParsers._
23

3-
val checkIterations = inputKey[Unit]("Verifies the accumlated number of iterations of incremental compilation.")
4+
// Reset compiler iterations, necessary because tests run in batch mode
5+
val recordPreviousIterations = taskKey[Unit]("Record previous iterations.")
6+
recordPreviousIterations := {
7+
val log = streams.value.log
8+
CompileState.previousIterations = {
9+
val previousAnalysis = (previousCompile in Compile).value.analysis.asScala
10+
previousAnalysis match {
11+
case None =>
12+
log.info("No previous analysis detected")
13+
0
14+
case Some(a: Analysis) => a.compilations.allCompilations.size
15+
}
16+
}
17+
}
418

5-
checkIterations := {
6-
val analysis = (compile in Compile).value.asInstanceOf[sbt.internal.inc.Analysis]
19+
val checkIterations = inputKey[Unit]("Verifies the accumulated number of iterations of incremental compilation.")
720

21+
checkIterations := {
822
val expected: Int = (Space ~> NatBasic).parsed
9-
val actual: Int = analysis.compilations.allCompilations.size
23+
val actual: Int = ((compile in Compile).value match { case a: Analysis => a.compilations.allCompilations.size }) - CompileState.previousIterations
1024
assert(expected == actual, s"Expected $expected compilations, got $actual")
1125
}
12-
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// This is necessary because tests are run in batch mode
2+
object CompileState {
3+
@volatile var previousIterations: Int = -1
4+
}

sbt-dotty/sbt-test/source-dependencies/inner-class/test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
> recordPreviousIterations
12
> run
23

34
# Recompile B (no meaningful change, this is just so that the dependencies on A.InnerClass are

sbt-dotty/sbt-test/source-dependencies/inner-object/build.sbt

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
1+
import sbt.internal.inc.Analysis
12
import complete.DefaultParsers._
23

3-
val checkIterations = inputKey[Unit]("Verifies the accumlated number of iterations of incremental compilation.")
4+
// Reset compiler iterations, necessary because tests run in batch mode
5+
val recordPreviousIterations = taskKey[Unit]("Record previous iterations.")
6+
recordPreviousIterations := {
7+
val log = streams.value.log
8+
CompileState.previousIterations = {
9+
val previousAnalysis = (previousCompile in Compile).value.analysis.asScala
10+
previousAnalysis match {
11+
case None =>
12+
log.info("No previous analysis detected")
13+
0
14+
case Some(a: Analysis) => a.compilations.allCompilations.size
15+
}
16+
}
17+
}
418

5-
checkIterations := {
6-
val analysis = (compile in Compile).value.asInstanceOf[sbt.internal.inc.Analysis]
19+
val checkIterations = inputKey[Unit]("Verifies the accumulated number of iterations of incremental compilation.")
720

21+
checkIterations := {
822
val expected: Int = (Space ~> NatBasic).parsed
9-
val actual: Int = analysis.compilations.allCompilations.size
23+
val actual: Int = ((compile in Compile).value match { case a: Analysis => a.compilations.allCompilations.size }) - CompileState.previousIterations
1024
assert(expected == actual, s"Expected $expected compilations, got $actual")
1125
}
12-
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// This is necessary because tests are run in batch mode
2+
object CompileState {
3+
@volatile var previousIterations: Int = -1
4+
}

sbt-dotty/sbt-test/source-dependencies/inner-object/test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
> recordPreviousIterations
12
> run
23

34
# Recompile B (no meaningful change, this is just so that the dependency on A.InnerObject are

sbt-dotty/sbt-test/source-dependencies/less-inter-inv-java/build.sbt

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
1+
import sbt.internal.inc.Analysis
12
import complete.DefaultParsers._
23

3-
val checkIterations = inputKey[Unit]("Verifies the accumlated number of iterations of incremental compilation.")
4+
// Reset compiler iterations, necessary because tests run in batch mode
5+
val recordPreviousIterations = taskKey[Unit]("Record previous iterations.")
6+
recordPreviousIterations := {
7+
val log = streams.value.log
8+
CompileState.previousIterations = {
9+
val previousAnalysis = (previousCompile in Compile).value.analysis.asScala
10+
previousAnalysis match {
11+
case None =>
12+
log.info("No previous analysis detected")
13+
0
14+
case Some(a: Analysis) => a.compilations.allCompilations.size
15+
}
16+
}
17+
}
418

5-
checkIterations := {
6-
val analysis = (compile in Compile).value.asInstanceOf[sbt.internal.inc.Analysis]
19+
val checkIterations = inputKey[Unit]("Verifies the accumulated number of iterations of incremental compilation.")
720

21+
checkIterations := {
822
val expected: Int = (Space ~> NatBasic).parsed
9-
val actual: Int = analysis.compilations.allCompilations.size
23+
val actual: Int = ((compile in Compile).value match { case a: Analysis => a.compilations.allCompilations.size }) - CompileState.previousIterations
1024
assert(expected == actual, s"Expected $expected compilations, got $actual")
1125
}
12-
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// This is necessary because tests are run in batch mode
2+
object CompileState {
3+
@volatile var previousIterations: Int = -1
4+
}

sbt-dotty/sbt-test/source-dependencies/less-inter-inv-java/test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
> recordPreviousIterations
12
# 1 iteration from initial full compile
23
> run
34
$ copy-file changes/A2.java A.java

sbt-dotty/sbt-test/source-dependencies/less-inter-inv/build.sbt

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
1+
import sbt.internal.inc.Analysis
12
import complete.DefaultParsers._
23

3-
val checkIterations = inputKey[Unit]("Verifies the accumlated number of iterations of incremental compilation.")
4+
// Reset compiler iterations, necessary because tests run in batch mode
5+
val recordPreviousIterations = taskKey[Unit]("Record previous iterations.")
6+
recordPreviousIterations := {
7+
val log = streams.value.log
8+
CompileState.previousIterations = {
9+
val previousAnalysis = (previousCompile in Compile).value.analysis.asScala
10+
previousAnalysis match {
11+
case None =>
12+
log.info("No previous analysis detected")
13+
0
14+
case Some(a: Analysis) => a.compilations.allCompilations.size
15+
}
16+
}
17+
}
418

5-
checkIterations := {
6-
val analysis = (compile in Compile).value.asInstanceOf[sbt.internal.inc.Analysis]
19+
val checkIterations = inputKey[Unit]("Verifies the accumulated number of iterations of incremental compilation.")
720

21+
checkIterations := {
822
val expected: Int = (Space ~> NatBasic).parsed
9-
val actual: Int = analysis.compilations.allCompilations.size
23+
val actual: Int = ((compile in Compile).value match { case a: Analysis => a.compilations.allCompilations.size }) - CompileState.previousIterations
1024
assert(expected == actual, s"Expected $expected compilations, got $actual")
1125
}
12-
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// This is necessary because tests are run in batch mode
2+
object CompileState {
3+
@volatile var previousIterations: Int = -1
4+
}

sbt-dotty/sbt-test/source-dependencies/less-inter-inv/test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
> recordPreviousIterations
12
# 1 iteration from initial full compile
23
> run
34
$ copy-file changes/A2.scala A.scala

sbt-dotty/sbt-test/source-dependencies/restore-classes/build.sbt

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
1+
import sbt.internal.inc.Analysis
12
import complete.DefaultParsers._
23

3-
crossTarget in Compile := target.value
4+
// Reset compiler iterations, necessary because tests run in batch mode
5+
val recordPreviousIterations = taskKey[Unit]("Record previous iterations.")
6+
recordPreviousIterations := {
7+
val log = streams.value.log
8+
CompileState.previousIterations = {
9+
val previousAnalysis = (previousCompile in Compile).value.analysis.asScala
10+
previousAnalysis match {
11+
case None =>
12+
log.info("No previous analysis detected")
13+
0
14+
case Some(a: Analysis) => a.compilations.allCompilations.size
15+
}
16+
}
17+
}
418

5-
val checkIterations = inputKey[Unit]("Verifies the accumlated number of iterations of incremental compilation.")
19+
val checkIterations = inputKey[Unit]("Verifies the accumulated number of iterations of incremental compilation.")
620

721
checkIterations := {
8-
val analysis = (compile in Compile).value.asInstanceOf[sbt.internal.inc.Analysis]
9-
1022
val expected: Int = (Space ~> NatBasic).parsed
11-
val actual: Int = analysis.compilations.allCompilations.size
23+
val actual: Int = ((compile in Compile).value match { case a: Analysis => a.compilations.allCompilations.size }) - CompileState.previousIterations
1224
assert(expected == actual, s"Expected $expected compilations, got $actual")
1325
}
14-
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// This is necessary because tests are run in batch mode
2+
object CompileState {
3+
@volatile var previousIterations: Int = -1
4+
}

sbt-dotty/sbt-test/source-dependencies/restore-classes/test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
> recordPreviousIterations
12
$ copy-file changes/A1.scala A.scala
23
$ copy-file changes/B.scala B.scala
34
# B depends on A

0 commit comments

Comments
 (0)