Skip to content

Commit

Permalink
Test case ensuring zinc is only re-compiling changed sources (#1907)
Browse files Browse the repository at this point in the history
Regression test, making sure Zinc incremental compilation only compile changed files.

Related to

* #1901
* #1904

Pull request: #1907
  • Loading branch information
lefou authored Jun 24, 2022
1 parent 42d72a6 commit 00bd25d
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 5 deletions.
1 change: 1 addition & 0 deletions integration/forked-server/src/forked-server-tests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ object HygieneTests extends HygieneTests(fork = true, clientServer = true)
object LargeProjectTests extends LargeProjectTests(fork = true, clientServer = true)
object ScriptsInvalidationTests extends ScriptsInvalidationTests(fork = true, clientServer = true)
object ScriptsInvalidationForeignTests extends ScriptsInvalidationForeignTests(fork = true, clientServer = true)
object ZincIncrementalCompilationTests extends ZincIncrementalCompilationTests(fork = true, clientServer = true)
1 change: 1 addition & 0 deletions integration/forked/src/forked-tests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ object HygieneTests extends HygieneTests(fork = true, clientServer = false)
object LargeProjectTests extends LargeProjectTests(fork = true, clientServer = false)
object ScriptsInvalidationTests extends ScriptsInvalidationTests(fork = true, clientServer = false)
object ScriptsInvalidationForeignTests extends ScriptsInvalidationForeignTests(fork = true, clientServer = false)
object ZincIncrementalCompilationTests extends ZincIncrementalCompilationTests(fork = true, clientServer = false)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package app

import io.getquill._

object App {

val ctx = new SqlMirrorContext(PostgresDialect, SnakeCase)
import ctx._

case class Person(name: String, age: Int)

def test = {
val key = "foo"
val q = quote {
query[Person].filter(c => c.name like "% $1" + lift(key) + "%")
}
ctx.run(q)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package models

import java.time._

case class Foo(
id: Long = 0L,
gmtCreate: LocalDateTime
)
14 changes: 14 additions & 0 deletions integration/local/resources/zinc-incremental-compilation/build.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Issue https://github.com/com-lihaoyi/mill/issues/1901
import mill._
import mill.scalalib._

object app extends SbtModule {

def scalaVersion = "2.13.8"

def scalacOptions = Seq("-Vclasspath")

def ivyDeps = Agg(
ivy"io.getquill::quill-sql:3.18.0"
)
}
42 changes: 42 additions & 0 deletions integration/local/src/ZincIncrementalCompilationTests.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package mill.integration

import utest._

// Regress test for issue https://github.com/com-lihaoyi/mill/issues/1901
class ZincIncrementalCompilationTests(fork: Boolean, clientServer: Boolean)
extends IntegrationTestSuite("zinc-incremental-compilation", fork, clientServer) {
val tests = Tests {
initWorkspace()
"incremental compilation only compiles changed files" - {
val successful = eval("app.compile")
assert(successful)

val appSrc = wd / "app" / "src" / "main" / "scala" / "App.scala"
val classes = wd / "out" / "app" / "compile.dest" / "classes"
val app = classes / "app" / "App.class"
val model = classes / "models" / "Foo.class"
assert(Seq(classes, app, model, appSrc).forall(os.exists))

val appSrcInfo1 = os.stat(appSrc)
val appInfo1 = os.stat(app)
val modelInfo1 = os.stat(model)

println("** second run **")
os.write.append(appSrc, "\n ")

val succ2nd = eval("app.compile")
assert(succ2nd)

val appSrcInfo2 = os.stat(appSrc)
val appInfo2 = os.stat(app)
val modelInfo2 = os.stat(model)

// we changed it
assert(appSrcInfo1.mtime != appSrcInfo2.mtime)
// expected to be re-compiled
assert(appInfo1.ctime != appInfo2.ctime)
// expected to be NOT re-compiled
assert(modelInfo1.ctime == modelInfo2.ctime)
}
}
}
11 changes: 6 additions & 5 deletions integration/local/src/local/local-tests.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package mill.integration
package local

object DocAnnotationsTests extends DocAnnotationsTests(fork = false, false)
object HygieneTests extends HygieneTests(fork = false, false)
object LargeProjectTests extends LargeProjectTests(fork = false, false)
object ScriptsInvalidationTests extends ScriptsInvalidationTests(fork = false, false)
object ScriptsInvalidationForeignTests extends ScriptsInvalidationForeignTests(fork = false, false)
object DocAnnotationsTests extends DocAnnotationsTests(fork = false, clientServer = false)
object HygieneTests extends HygieneTests(fork = false, clientServer = false)
object LargeProjectTests extends LargeProjectTests(fork = false, clientServer = false)
object ScriptsInvalidationTests extends ScriptsInvalidationTests(fork = false, clientServer = false)
object ScriptsInvalidationForeignTests extends ScriptsInvalidationForeignTests(fork = false, clientServer = false)
object ZincIncrementalCompilationTests extends ZincIncrementalCompilationTests(fork = false, clientServer = false)

0 comments on commit 00bd25d

Please sign in to comment.