mirror of https://github.com/sbt/sbt.git
Fix more tests using compiler iterations
This commit is contained in:
parent
6191f35f1c
commit
0ebf2d14a3
|
|
@ -1,12 +1,26 @@
|
|||
import sbt.internal.inc.Analysis
|
||||
import complete.DefaultParsers._
|
||||
|
||||
// checks number of compilation iterations performed since last `clean` run
|
||||
InputKey[Unit]("check-number-of-compiler-iterations") := {
|
||||
val args = Def.spaceDelimited().parsed
|
||||
val a = (compile in Compile).value.asInstanceOf[Analysis]
|
||||
assert(args.size == 1)
|
||||
val expectedIterationsNumber = args(0).toInt
|
||||
val allCompilationsSize = a.compilations.allCompilations.size
|
||||
assert(allCompilationsSize == expectedIterationsNumber,
|
||||
"allCompilationsSize == %d (expected %d)".format(allCompilationsSize, expectedIterationsNumber))
|
||||
// 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 }) - 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 @@
|
|||
# do not introduce unnecessary compile iterations
|
||||
|
||||
# introduces first compile iteration
|
||||
> recordPreviousIterations
|
||||
> compile
|
||||
# this change is local to a method and does not change the api so introduces
|
||||
# only one additional compile iteration
|
||||
|
|
@ -9,4 +10,4 @@ $ copy-file changes/Foo1.scala src/main/scala/Foo.scala
|
|||
# second iteration
|
||||
> compile
|
||||
# check if there are only two compile iterations being performed
|
||||
> checkNumberOfCompilerIterations 2
|
||||
> checkIterations 2
|
||||
|
|
|
|||
|
|
@ -1,15 +1,28 @@
|
|||
import sbt.internal.inc.Analysis
|
||||
import complete.DefaultParsers._
|
||||
|
||||
logLevel := Level.Debug
|
||||
|
||||
// dumps analysis into target/analysis-dump.txt file
|
||||
InputKey[Unit]("check-number-of-compiler-iterations") := {
|
||||
val args = Def.spaceDelimited().parsed
|
||||
val a = (compile in Compile).value.asInstanceOf[Analysis]
|
||||
assert(args.size == 1)
|
||||
val expectedIterationsNumber = args(0).toInt
|
||||
assert(
|
||||
a.compilations.allCompilations.size == expectedIterationsNumber,
|
||||
"a.compilations.allCompilations.size = %d (expected %d)".format(
|
||||
a.compilations.allCompilations.size, expectedIterationsNumber))
|
||||
// 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 }) - 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 @@
|
|||
# do not introduce unnecessary compile iterations
|
||||
|
||||
# introduces first compile iteration
|
||||
> recordPreviousIterations
|
||||
> compile
|
||||
# this change is local to a method and does not change the api so introduces
|
||||
# only one additional compile iteration
|
||||
|
|
@ -9,4 +10,4 @@ $ copy-file changes/B1.scala src/main/scala/B.scala
|
|||
# second iteration
|
||||
> compile
|
||||
# check if there are only two compile iterations being performed
|
||||
> checkNumberOfCompilerIterations 2
|
||||
> checkIterations 2
|
||||
|
|
|
|||
|
|
@ -1,11 +1,26 @@
|
|||
import sbt.internal.inc.Analysis
|
||||
import complete.DefaultParsers._
|
||||
|
||||
InputKey[Unit]("check-number-of-compiler-iterations") := {
|
||||
val args = Def.spaceDelimited().parsed
|
||||
val a = (compile in Compile).value.asInstanceOf[Analysis]
|
||||
assert(args.size == 1)
|
||||
val expectedIterationsNumber = args(0).toInt
|
||||
assert(a.compilations.allCompilations.size == expectedIterationsNumber,
|
||||
"a.compilations.allCompilations.size = %d (expected %d)".format(
|
||||
a.compilations.allCompilations.size, expectedIterationsNumber))
|
||||
// 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 }) - 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
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
# https://github.com/sbt/sbt/issues/610
|
||||
|
||||
# introduces first compile iteration
|
||||
> recordPreviousIterations
|
||||
> compile
|
||||
# this change is local to method and does not change api so introduces
|
||||
# only one additional compile iteration
|
||||
|
|
@ -11,4 +12,4 @@ $ copy-file changes/Impl1.scala src/main/scala/Impl.scala
|
|||
# second iteration
|
||||
> compile
|
||||
# check if there are only two compile iterations performed
|
||||
> checkNumberOfCompilerIterations 2
|
||||
> checkIterations 2
|
||||
|
|
|
|||
Loading…
Reference in New Issue