Add scripted (functional test) for #2324.

Add a test that shows the scenario described in #2324 is handled correctly
now.
This commit is contained in:
Grzegorz Kossakowski 2015-12-23 14:17:47 +01:00
parent 95da6ec5a6
commit 3a6b6aadc0
5 changed files with 48 additions and 0 deletions

View File

@ -0,0 +1,25 @@
/* Performs checks related to compilations:
* a) checks in which compilation given set of files was recompiled
* b) checks overall number of compilations performed
*/
TaskKey[Unit]("check-compilations") := {
val analysis = (compile in Compile).value
val srcDir = (scalaSource in Compile).value
def relative(f: java.io.File): java.io.File = f.relativeTo(srcDir) getOrElse f
val allCompilations = analysis.compilations.allCompilations
val recompiledFiles: Seq[Set[java.io.File]] = allCompilations map { c =>
val recompiledFiles = analysis.apis.internal.collect {
case (file, api) if api.compilation.startTime == c.startTime => relative(file)
}
recompiledFiles.toSet
}
def recompiledFilesInIteration(iteration: Int, fileNames: Set[String]) = {
val files = fileNames.map(new java.io.File(_))
assert(recompiledFiles(iteration) == files, "%s != %s".format(recompiledFiles(iteration), files))
}
assert(allCompilations.size == 2)
// B.scala is just compiled at the beginning
recompiledFilesInIteration(0, Set("B.scala"))
// A.scala is changed and recompiled
recompiledFilesInIteration(1, Set("A.scala"))
}

View File

@ -0,0 +1,5 @@
object A {
private def foo: String = "1"
def bar: String = "29"
def xyz: Int = 101
}

View File

@ -0,0 +1,5 @@
object A {
private def foo: Int = 1
def bar: Int = 29
def xyz: Int = 101
}

View File

@ -0,0 +1,4 @@
class B {
private def foo: Int = 1
def baz(): Unit = println(foo, A.xyz)
}

View File

@ -0,0 +1,9 @@
# Test for https://github.com/sbt/sbt/issues/2324
# introduces first compile iteration
> compile
# change signature of a private `A.foo` method
$ copy-file changes/A1.scala src/main/scala/A.scala
# it should recompile just A.scala because changes to `A.foo` can't affect B
> compile
# check if there are only two compile iterations performed
> check-compilations