diff options
author | David Gregory <DavidGregory084@users.noreply.github.com> | 2018-08-01 14:29:21 +0100 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2018-08-01 21:29:21 +0800 |
commit | 20b13d595f13964d5f31d9aa741d4c28e3dadf48 (patch) | |
tree | 2a3c9f51bb955787e6c1047932cc97fd5a204dfc /contrib/scalapblib/test | |
parent | f1982410df10466c9651c10c8402a1739fd2ccb8 (diff) | |
download | mill-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')
-rw-r--r-- | contrib/scalapblib/test/protobuf/tutorial/Tutorial.proto | 29 | ||||
-rw-r--r-- | contrib/scalapblib/test/src/mill/contrib/scalapblib/TutorialTests.scala | 114 |
2 files changed, 143 insertions, 0 deletions
diff --git a/contrib/scalapblib/test/protobuf/tutorial/Tutorial.proto b/contrib/scalapblib/test/protobuf/tutorial/Tutorial.proto new file mode 100644 index 00000000..d66911b8 --- /dev/null +++ b/contrib/scalapblib/test/protobuf/tutorial/Tutorial.proto @@ -0,0 +1,29 @@ +syntax = "proto2"; + +package tutorial; + +option java_package = "com.example.tutorial"; +option java_outer_classname = "AddressBookProtos"; + +message Person { + required string name = 1; + required int32 id = 2; + optional string email = 3; + + enum PhoneType { + MOBILE = 0; + HOME = 1; + WORK = 2; + } + + message PhoneNumber { + required string number = 1; + optional PhoneType type = 2 [default = HOME]; + } + + repeated PhoneNumber phones = 4; +} + +message AddressBook { + repeated Person people = 1; +} 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) + // } + } + } +} |