summaryrefslogtreecommitdiff
path: root/contrib/scalapblib/test/src
diff options
context:
space:
mode:
authorDavid Gregory <DavidGregory084@users.noreply.github.com>2018-08-01 14:29:21 +0100
committerLi Haoyi <haoyi.sg@gmail.com>2018-08-01 21:29:21 +0800
commit20b13d595f13964d5f31d9aa741d4c28e3dadf48 (patch)
tree2a3c9f51bb955787e6c1047932cc97fd5a204dfc /contrib/scalapblib/test/src
parentf1982410df10466c9651c10c8402a1739fd2ccb8 (diff)
downloadmill-20b13d595f13964d5f31d9aa741d4c28e3dadf48.tar.gz
mill-20b13d595f13964d5f31d9aa741d4c28e3dadf48.tar.bz2
mill-20b13d595f13964d5f31d9aa741d4c28e3dadf48.zip
Add ScalaPB integration (#395)
* Add ScalaPB integration * Update ci scripts with new scalapblib module * Move ScalaPB integration to contrib module
Diffstat (limited to 'contrib/scalapblib/test/src')
-rw-r--r--contrib/scalapblib/test/src/mill/contrib/scalapblib/TutorialTests.scala114
1 files changed, 114 insertions, 0 deletions
diff --git a/contrib/scalapblib/test/src/mill/contrib/scalapblib/TutorialTests.scala b/contrib/scalapblib/test/src/mill/contrib/scalapblib/TutorialTests.scala
new file mode 100644
index 00000000..f88d3a5f
--- /dev/null
+++ b/contrib/scalapblib/test/src/mill/contrib/scalapblib/TutorialTests.scala
@@ -0,0 +1,114 @@
+package mill.contrib.scalapblib
+
+import ammonite.ops.{Path, cp, ls, mkdir, pwd, rm, _}
+import mill.eval.Result
+import mill.util.{TestEvaluator, TestUtil}
+import utest.framework.TestPath
+import utest.{TestSuite, Tests, assert, _}
+
+object TutorialTests extends TestSuite {
+
+ trait TutorialBase extends TestUtil.BaseModule {
+ override def millSourcePath: Path = TestUtil.getSrcPathBase() / millOuterCtx.enclosing.split('.')
+ }
+
+ trait TutorialModule extends ScalaPBModule {
+ def scalaVersion = "2.12.4"
+ def scalaPBVersion = "0.7.4"
+ def scalaPBFlatPackage = true
+ }
+
+ object Tutorial extends TutorialBase {
+
+ object core extends TutorialModule {
+ override def scalaPBVersion = "0.7.4"
+ }
+ }
+
+ val resourcePath: Path = pwd / 'contrib / 'scalapblib / 'test / 'protobuf / 'tutorial
+
+ def protobufOutPath[M <: TestUtil.BaseModule](eval: TestEvaluator[M]): Path =
+ eval.outPath / 'core / 'compileScalaPB / 'dest / 'com / 'example / 'tutorial
+
+ def workspaceTest[T, M <: TestUtil.BaseModule](m: M)
+ (t: TestEvaluator[M] => T)
+ (implicit tp: TestPath): T = {
+ val eval = new TestEvaluator(m)
+ rm(m.millSourcePath)
+ println(m.millSourcePath)
+ rm(eval.outPath)
+ println(eval.outPath)
+ mkdir(m.millSourcePath / 'core / 'protobuf)
+ cp(resourcePath, m.millSourcePath / 'core / 'protobuf / 'tutorial)
+ t(eval)
+ }
+
+ def compiledSourcefiles: Seq[RelPath] = Seq[RelPath](
+ "AddressBook.scala",
+ "Person.scala",
+ "TutorialProto.scala"
+ )
+
+ def tests: Tests = Tests {
+ 'scalapbVersion - {
+
+ 'fromBuild - workspaceTest(Tutorial) { eval =>
+ val Right((result, evalCount)) = eval.apply(Tutorial.core.scalaPBVersion)
+
+ assert(
+ result == "0.7.4",
+ evalCount > 0
+ )
+ }
+ }
+
+ 'compileScalaPB - {
+ 'calledDirectly - workspaceTest(Tutorial) { eval =>
+ val Right((result, evalCount)) = eval.apply(Tutorial.core.compileScalaPB)
+
+ val outPath = protobufOutPath(eval)
+
+ val outputFiles = ls.rec(result.path).filter(_.isFile)
+
+ val expectedSourcefiles = compiledSourcefiles.map(outPath / _)
+
+ assert(
+ result.path == eval.outPath / 'core / 'compileScalaPB / 'dest,
+ outputFiles.nonEmpty,
+ outputFiles.forall(expectedSourcefiles.contains),
+ outputFiles.size == 3,
+ evalCount > 0
+ )
+
+ // don't recompile if nothing changed
+ val Right((_, unchangedEvalCount)) = eval.apply(Tutorial.core.compileScalaPB)
+
+ assert(unchangedEvalCount == 0)
+ }
+
+ // This throws a NullPointerException in coursier somewhere
+ //
+ // 'triggeredByScalaCompile - workspaceTest(Tutorial) { eval =>
+ // val Right((_, evalCount)) = eval.apply(Tutorial.core.compile)
+
+ // val outPath = protobufOutPath(eval)
+
+ // val outputFiles = ls.rec(outPath).filter(_.isFile)
+
+ // val expectedSourcefiles = compiledSourcefiles.map(outPath / _)
+
+ // assert(
+ // outputFiles.nonEmpty,
+ // outputFiles.forall(expectedSourcefiles.contains),
+ // outputFiles.size == 3,
+ // evalCount > 0
+ // )
+
+ // // don't recompile if nothing changed
+ // val Right((_, unchangedEvalCount)) = eval.apply(Tutorial.core.compile)
+
+ // assert(unchangedEvalCount == 0)
+ // }
+ }
+ }
+}