mirror of https://github.com/sbt/sbt.git
Fix compile tests using `checkIterations`
Those tests using `checkIterations` were not working because an invariant was working: the first iterations number is 0. As we reuse sbt for running several tests, this is no longer true, so this commit makes sure that they are updated with the pertinent infrastructure to compute the performed iterations from the latest known number of iterations.
This commit is contained in:
parent
c94a445737
commit
927910aa72
|
|
@ -1,10 +1,26 @@
|
|||
import sbt.internal.inc.Analysis
|
||||
import complete.DefaultParsers._
|
||||
|
||||
// Reset compiler iterations, necessary because tests run in batch mode
|
||||
val recordPreviousIterations = taskKey[Unit]("Record previous iterations.")
|
||||
recordPreviousIterations := {
|
||||
CompileState.previousIterations = {
|
||||
val previousAnalysis = (previousCompile in Compile).value.analysis
|
||||
if (previousAnalysis.isEmpty) {
|
||||
streams.value.log.info("No previous analysis detected")
|
||||
0
|
||||
} else {
|
||||
previousAnalysis.get match {
|
||||
case a: Analysis => a.compilations.allCompilations.size
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val checkIterations = inputKey[Unit]("Verifies the accumulated number of iterations of incremental compilation.")
|
||||
|
||||
checkIterations := {
|
||||
val expected: Int = (Space ~> NatBasic).parsed
|
||||
val actual: Int = (compile in Compile).value match { case a: Analysis => a.compilations.allCompilations.size }
|
||||
val actual: Int = ((compile in Compile).value match { case a: Analysis => a.compilations.allCompilations.size }) - CompileState.previousIterations
|
||||
assert(expected == actual, s"Expected $expected compilations, got $actual")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
// This is necessary because tests are run in batch mode
|
||||
object CompileState {
|
||||
@volatile var previousIterations: Int = -1
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@
|
|||
# This also verifies that compilation does not get repeatedly triggered by a mismatch in
|
||||
# paths.
|
||||
|
||||
> recordPreviousIterations
|
||||
> compile
|
||||
> compile
|
||||
> checkIterations 1
|
||||
> checkIterations 1
|
||||
|
|
|
|||
|
|
@ -1,10 +1,26 @@
|
|||
import sbt.internal.inc.Analysis
|
||||
import complete.DefaultParsers._
|
||||
|
||||
// Reset compiler iterations, necessary because tests run in batch mode
|
||||
val recordPreviousIterations = taskKey[Unit]("Record previous iterations.")
|
||||
recordPreviousIterations := {
|
||||
CompileState.previousIterations = {
|
||||
val previousAnalysis = (previousCompile in Compile).value.analysis
|
||||
if (previousAnalysis.isEmpty) {
|
||||
streams.value.log.info("No previous analysis detected")
|
||||
0
|
||||
} else {
|
||||
previousAnalysis.get match {
|
||||
case a: Analysis => a.compilations.allCompilations.size
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val checkIterations = inputKey[Unit]("Verifies the accumulated number of iterations of incremental compilation.")
|
||||
|
||||
checkIterations := {
|
||||
val expected: Int = (Space ~> NatBasic).parsed
|
||||
val actual: Int = (compile in Compile).value match { case a: Analysis => a.compilations.allCompilations.size }
|
||||
assert(expected == actual, s"Expected $expected compilations, got $actual")
|
||||
}
|
||||
val expected: Int = (Space ~> NatBasic).parsed
|
||||
val actual: Int = ((compile in Compile).value match { case a: Analysis => a.compilations.allCompilations.size }) - CompileState.previousIterations
|
||||
assert(expected == actual, s"Expected $expected compilations, got $actual")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
// This is necessary because tests are run in batch mode
|
||||
object CompileState {
|
||||
@volatile var previousIterations: Int = -1
|
||||
}
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
# initial compilation
|
||||
> recordPreviousIterations
|
||||
> checkIterations 1
|
||||
|
||||
# no further compilation should be necessary, since nothing changed
|
||||
# previously, a dependency on a jar in <java.home>lib/ext/ would
|
||||
# always force recompilation
|
||||
> checkIterations 1
|
||||
> checkIterations 1
|
||||
|
|
|
|||
|
|
@ -1,10 +1,26 @@
|
|||
import sbt.internal.inc.Analysis
|
||||
import complete.DefaultParsers._
|
||||
|
||||
// Reset compiler iterations, necessary because tests run in batch mode
|
||||
val recordPreviousIterations = taskKey[Unit]("Record previous iterations.")
|
||||
recordPreviousIterations := {
|
||||
CompileState.previousIterations = {
|
||||
val previousAnalysis = (previousCompile in Compile).value.analysis
|
||||
if (previousAnalysis.isEmpty) {
|
||||
streams.value.log.info("No previous analysis detected")
|
||||
0
|
||||
} else {
|
||||
previousAnalysis.get match {
|
||||
case a: Analysis => a.compilations.allCompilations.size
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val checkIterations = inputKey[Unit]("Verifies the accumulated number of iterations of incremental compilation.")
|
||||
|
||||
checkIterations := {
|
||||
val expected: Int = (Space ~> NatBasic).parsed
|
||||
val actual: Int = (compile in Compile).value match { case a: Analysis => a.compilations.allCompilations.size }
|
||||
val actual: Int = ((compile in Compile).value match { case a: Analysis => a.compilations.allCompilations.size }) - CompileState.previousIterations
|
||||
assert(expected == actual, s"Expected $expected compilations, got $actual")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
// This is necessary because tests are run in batch mode
|
||||
object CompileState {
|
||||
@volatile var previousIterations: Int = -1
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
# 1 iteration from initial full compile
|
||||
> recordPreviousIterations
|
||||
> run
|
||||
$ copy-file changes/A2.java A.java
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,26 @@
|
|||
import sbt.internal.inc.Analysis
|
||||
import complete.DefaultParsers._
|
||||
|
||||
// Reset compiler iterations, necessary because tests run in batch mode
|
||||
val recordPreviousIterations = taskKey[Unit]("Record previous iterations.")
|
||||
recordPreviousIterations := {
|
||||
CompileState.previousIterations = {
|
||||
val previousAnalysis = (previousCompile in Compile).value.analysis
|
||||
if (previousAnalysis.isEmpty) {
|
||||
streams.value.log.info("No previous analysis detected")
|
||||
0
|
||||
} else {
|
||||
previousAnalysis.get match {
|
||||
case a: Analysis => a.compilations.allCompilations.size
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val checkIterations = inputKey[Unit]("Verifies the accumulated number of iterations of incremental compilation.")
|
||||
|
||||
checkIterations := {
|
||||
val expected: Int = (Space ~> NatBasic).parsed
|
||||
val actual: Int = (compile in Compile).value match { case a: Analysis => a.compilations.allCompilations.size }
|
||||
val actual: Int = ((compile in Compile).value match { case a: Analysis => a.compilations.allCompilations.size }) - CompileState.previousIterations
|
||||
assert(expected == actual, s"Expected $expected compilations, got $actual")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
// This is necessary because tests are run in batch mode
|
||||
object CompileState {
|
||||
@volatile var previousIterations: Int = -1
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
# 1 iteration from initial full compile
|
||||
> recordPreviousIterations
|
||||
> run
|
||||
$ copy-file changes/A2.scala A.scala
|
||||
|
||||
|
|
|
|||
|
|
@ -3,10 +3,26 @@ import complete.DefaultParsers._
|
|||
|
||||
crossTarget in Compile := target.value
|
||||
|
||||
// Reset compiler iterations, necessary because tests run in batch mode
|
||||
val recordPreviousIterations = taskKey[Unit]("Record previous iterations.")
|
||||
recordPreviousIterations := {
|
||||
CompileState.previousIterations = {
|
||||
val previousAnalysis = (previousCompile in Compile).value.analysis
|
||||
if (previousAnalysis.isEmpty) {
|
||||
streams.value.log.info("No previous analysis detected")
|
||||
0
|
||||
} else {
|
||||
previousAnalysis.get match {
|
||||
case a: Analysis => a.compilations.allCompilations.size
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val checkIterations = inputKey[Unit]("Verifies the accumulated number of iterations of incremental compilation.")
|
||||
|
||||
checkIterations := {
|
||||
val expected: Int = (Space ~> NatBasic).parsed
|
||||
val actual: Int = (compile in Compile).value match { case a: Analysis => a.compilations.allCompilations.size }
|
||||
val actual: Int = ((compile in Compile).value match { case a: Analysis => a.compilations.allCompilations.size }) - CompileState.previousIterations
|
||||
assert(expected == actual, s"Expected $expected compilations, got $actual")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
// This is necessary because tests are run in batch mode
|
||||
object CompileState {
|
||||
@volatile var previousIterations: Int = -1
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ $ copy-file changes/A1.scala A.scala
|
|||
$ copy-file changes/B.scala B.scala
|
||||
# B depends on A
|
||||
# 1 iteration
|
||||
> recordPreviousIterations
|
||||
> compile
|
||||
|
||||
$ copy-file changes/A2.scala A.scala
|
||||
|
|
|
|||
Loading…
Reference in New Issue