From 00bd25d71080b9b774ecfa9be644d21790e2f0d5 Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Fri, 24 Jun 2022 09:52:47 +0200 Subject: [PATCH] Test case ensuring zinc is only re-compiling changed sources (#1907) Regression test, making sure Zinc incremental compilation only compile changed files. Related to * https://github.com/com-lihaoyi/mill/issues/1901 * https://github.com/com-lihaoyi/mill/pull/1904 Pull request: https://github.com/com-lihaoyi/mill/pull/1907 --- .../src/forked-server-tests.scala | 1 + integration/forked/src/forked-tests.scala | 1 + .../app/src/main/scala/App.scala | 20 +++++++++ .../src/main/scala/models/TestModel1.scala | 8 ++++ .../zinc-incremental-compilation/build.sc | 14 +++++++ .../src/ZincIncrementalCompilationTests.scala | 42 +++++++++++++++++++ integration/local/src/local/local-tests.scala | 11 ++--- 7 files changed, 92 insertions(+), 5 deletions(-) create mode 100644 integration/local/resources/zinc-incremental-compilation/app/src/main/scala/App.scala create mode 100644 integration/local/resources/zinc-incremental-compilation/app/src/main/scala/models/TestModel1.scala create mode 100644 integration/local/resources/zinc-incremental-compilation/build.sc create mode 100644 integration/local/src/ZincIncrementalCompilationTests.scala diff --git a/integration/forked-server/src/forked-server-tests.scala b/integration/forked-server/src/forked-server-tests.scala index ca1a73b5d37..6c066439483 100644 --- a/integration/forked-server/src/forked-server-tests.scala +++ b/integration/forked-server/src/forked-server-tests.scala @@ -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) diff --git a/integration/forked/src/forked-tests.scala b/integration/forked/src/forked-tests.scala index eb69ff3c562..e0873834a6d 100644 --- a/integration/forked/src/forked-tests.scala +++ b/integration/forked/src/forked-tests.scala @@ -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) diff --git a/integration/local/resources/zinc-incremental-compilation/app/src/main/scala/App.scala b/integration/local/resources/zinc-incremental-compilation/app/src/main/scala/App.scala new file mode 100644 index 00000000000..b618fd09cf7 --- /dev/null +++ b/integration/local/resources/zinc-incremental-compilation/app/src/main/scala/App.scala @@ -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) + } + +} diff --git a/integration/local/resources/zinc-incremental-compilation/app/src/main/scala/models/TestModel1.scala b/integration/local/resources/zinc-incremental-compilation/app/src/main/scala/models/TestModel1.scala new file mode 100644 index 00000000000..50c19f476c7 --- /dev/null +++ b/integration/local/resources/zinc-incremental-compilation/app/src/main/scala/models/TestModel1.scala @@ -0,0 +1,8 @@ +package models + +import java.time._ + +case class Foo( + id: Long = 0L, + gmtCreate: LocalDateTime +) diff --git a/integration/local/resources/zinc-incremental-compilation/build.sc b/integration/local/resources/zinc-incremental-compilation/build.sc new file mode 100644 index 00000000000..d5df512b77d --- /dev/null +++ b/integration/local/resources/zinc-incremental-compilation/build.sc @@ -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" + ) +} diff --git a/integration/local/src/ZincIncrementalCompilationTests.scala b/integration/local/src/ZincIncrementalCompilationTests.scala new file mode 100644 index 00000000000..d6f60571707 --- /dev/null +++ b/integration/local/src/ZincIncrementalCompilationTests.scala @@ -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) + } + } +} diff --git a/integration/local/src/local/local-tests.scala b/integration/local/src/local/local-tests.scala index 4e62cd74de0..e37519e5453 100644 --- a/integration/local/src/local/local-tests.scala +++ b/integration/local/src/local/local-tests.scala @@ -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)