-
-
Notifications
You must be signed in to change notification settings - Fork 420
scalapb-support-java-generation #5817
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,9 @@ import utest.{TestSuite, Tests, assert, *} | |
object TutorialTests extends TestSuite { | ||
val testScalaPbVersion = "0.11.7" | ||
|
||
trait TutorialBase extends TestRootModule | ||
trait TutorialBase extends TestRootModule { | ||
val core: TutorialModule | ||
} | ||
|
||
trait TutorialModule extends ScalaPBModule { | ||
def scalaVersion = sys.props.getOrElse("TEST_SCALA_2_12_VERSION", ???) | ||
|
@@ -70,19 +72,68 @@ object TutorialTests extends TestSuite { | |
lazy val millDiscover = Discover[this.type] | ||
} | ||
|
||
object TutorialWithJavaGen extends TutorialBase { | ||
object core extends TutorialModule { | ||
override def scalaPBGenerators = Seq(JavaGen) | ||
} | ||
|
||
lazy val millDiscover = Discover[this.type] | ||
} | ||
|
||
object TutorialWithScalaAndJavaGen extends TutorialBase { | ||
object core extends TutorialModule { | ||
override def scalaPBGenerators = Seq[Generator](ScalaGen, JavaGen) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like we need to explicitly define the type of the Seq here, otherwise upickle can't find the implicit reader. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does making |
||
} | ||
|
||
lazy val millDiscover = Discover[this.type] | ||
} | ||
|
||
val resourcePath: os.Path = os.Path(sys.env("MILL_TEST_RESOURCE_DIR")) | ||
|
||
def protobufOutPath(eval: UnitTester): os.Path = | ||
eval.outPath / "core/compileScalaPB.dest/com/example/tutorial" | ||
|
||
def compiledSourcefiles: Seq[os.RelPath] = Seq[os.RelPath]( | ||
def compiledScalaSourcefiles: Seq[os.RelPath] = Seq[os.RelPath]( | ||
os.rel / "AddressBook.scala", | ||
os.rel / "Person.scala", | ||
os.rel / "TutorialProto.scala", | ||
os.rel / "Include.scala", | ||
os.rel / "IncludeProto.scala" | ||
) | ||
|
||
def compiledJavaSourcefiles: Seq[os.RelPath] = Seq[os.RelPath]( | ||
os.rel / "AddressBookProtos.java", | ||
os.rel / "IncludeOuterClass.java" | ||
) | ||
|
||
// Helper function to test compilation with different generators | ||
def testCompilation( | ||
module: TutorialBase, | ||
expectedFiles: Seq[os.RelPath] | ||
): Unit = { | ||
UnitTester(module, resourcePath).scoped { eval => | ||
if (!mill.constants.Util.isWindows) { | ||
val Right(result) = eval.apply(module.core.compileScalaPB): @unchecked | ||
|
||
val outPath = protobufOutPath(eval) | ||
val outputFiles = os.walk(result.value.path).filter(os.isFile) | ||
val expectedSourcefiles = expectedFiles.map(outPath / _) | ||
|
||
assert( | ||
result.value.path == eval.outPath / "core/compileScalaPB.dest", | ||
outputFiles.nonEmpty, | ||
outputFiles.forall(expectedSourcefiles.contains), | ||
outputFiles.size == outputFiles.size, | ||
result.evalCount > 0 | ||
) | ||
|
||
// don't recompile if nothing changed | ||
val Right(result2) = eval.apply(module.core.compileScalaPB): @unchecked | ||
assert(result2.evalCount == 0) | ||
} | ||
} | ||
} | ||
|
||
def tests: Tests = Tests { | ||
test("scalapbVersion") { | ||
|
||
|
@@ -97,30 +148,9 @@ object TutorialTests extends TestSuite { | |
} | ||
|
||
test("compileScalaPB") { | ||
test("calledDirectly") - UnitTester(Tutorial, resourcePath).scoped { eval => | ||
if (!mill.constants.Util.isWindows) { | ||
val Right(result) = eval.apply(Tutorial.core.compileScalaPB): @unchecked | ||
|
||
val outPath = protobufOutPath(eval) | ||
|
||
val outputFiles = os.walk(result.value.path).filter(os.isFile) | ||
|
||
val expectedSourcefiles = compiledSourcefiles.map(outPath / _) | ||
|
||
assert( | ||
result.value.path == eval.outPath / "core/compileScalaPB.dest", | ||
outputFiles.nonEmpty, | ||
outputFiles.forall(expectedSourcefiles.contains), | ||
outputFiles.size == 5, | ||
result.evalCount > 0 | ||
) | ||
|
||
// don't recompile if nothing changed | ||
val Right(result2) = eval.apply(Tutorial.core.compileScalaPB): @unchecked | ||
|
||
assert(result2.evalCount == 0) | ||
} | ||
} | ||
test("scalaGen") - testCompilation(Tutorial, compiledScalaSourcefiles) | ||
test("javaGen") - testCompilation(TutorialWithJavaGen, compiledJavaSourcefiles) | ||
test("scalaAndJavaGen") - testCompilation(TutorialWithScalaAndJavaGen, compiledScalaSourcefiles ++ compiledJavaSourcefiles) | ||
|
||
test("calledWithSpecificFile") - UnitTester( | ||
TutorialWithSpecificSources, | ||
|
@@ -165,7 +195,7 @@ object TutorialTests extends TestSuite { | |
// | ||
// // val outputFiles = os.walk(outPath).filter(_.isFile) | ||
// | ||
// // val expectedSourcefiles = compiledSourcefiles.map(outPath / _) | ||
// // val expectedSourcefiles = compiledScalaSourcefiles.map(outPath / _) | ||
// | ||
// // assert( | ||
// // outputFiles.nonEmpty, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have some docs here which answers: What is a generator? Which can be choosen from? What is the default?