@@ -11,7 +11,9 @@ import utest.{TestSuite, Tests, assert, *}
1111object TutorialTests extends TestSuite {
1212 val testScalaPbVersion = " 0.11.7"
1313
14- trait TutorialBase extends TestRootModule
14+ trait TutorialBase extends TestRootModule {
15+ val core : TutorialModule
16+ }
1517
1618 trait TutorialModule extends ScalaPBModule {
1719 def scalaVersion = sys.props.getOrElse(" TEST_SCALA_2_12_VERSION" , ??? )
@@ -70,19 +72,70 @@ object TutorialTests extends TestSuite {
7072 lazy val millDiscover = Discover [this .type ]
7173 }
7274
75+ object TutorialWithJavaGen extends TutorialBase {
76+ object core extends TutorialModule {
77+ override def scalaPBGenerators = Seq (JavaGen )
78+ }
79+
80+ lazy val millDiscover = Discover [this .type ]
81+ }
82+
83+ object TutorialWithScalaAndJavaGen extends TutorialBase {
84+ object core extends TutorialModule {
85+ override def scalaPBGenerators = Task {
86+ Seq [Generator ](ScalaGen , JavaGen )
87+ }
88+ }
89+
90+ lazy val millDiscover = Discover [this .type ]
91+ }
92+
7393 val resourcePath : os.Path = os.Path (sys.env(" MILL_TEST_RESOURCE_DIR" ))
7494
7595 def protobufOutPath (eval : UnitTester ): os.Path =
7696 eval.outPath / " core/compileScalaPB.dest/com/example/tutorial"
7797
78- def compiledSourcefiles : Seq [os.RelPath ] = Seq [os.RelPath ](
98+ def compiledScalaSourcefiles : Seq [os.RelPath ] = Seq [os.RelPath ](
7999 os.rel / " AddressBook.scala" ,
80100 os.rel / " Person.scala" ,
81101 os.rel / " TutorialProto.scala" ,
82102 os.rel / " Include.scala" ,
83103 os.rel / " IncludeProto.scala"
84104 )
85105
106+ def compiledJavaSourcefiles : Seq [os.RelPath ] = Seq [os.RelPath ](
107+ os.rel / " AddressBookProtos.java" ,
108+ os.rel / " IncludeOuterClass.java"
109+ )
110+
111+ // Helper function to test compilation with different generators
112+ def testCompilation (
113+ module : TutorialBase ,
114+ expectedFiles : Seq [os.RelPath ]
115+ ): Unit = {
116+ UnitTester (module, resourcePath).scoped { eval =>
117+ if (! mill.constants.Util .isWindows) {
118+ val Right (result) = eval.apply(module.core.compileScalaPB): @ unchecked
119+
120+ val outPath = protobufOutPath(eval)
121+ val outputFiles = os.walk(result.value.path).filter(os.isFile)
122+ val expectedSourcefiles = expectedFiles.map(outPath / _)
123+
124+ assert(
125+ result.value.path == eval.outPath / " core/compileScalaPB.dest" ,
126+ outputFiles.nonEmpty,
127+ outputFiles.forall(expectedSourcefiles.contains),
128+ outputFiles.size == outputFiles.size,
129+ result.evalCount > 0
130+ )
131+
132+ // don't recompile if nothing changed
133+ val Right (result2) = eval.apply(module.core.compileScalaPB): @ unchecked
134+ assert(result2.evalCount == 0 )
135+ }
136+ }
137+ }
138+
86139 def tests : Tests = Tests {
87140 test(" scalapbVersion" ) {
88141
@@ -97,30 +150,9 @@ object TutorialTests extends TestSuite {
97150 }
98151
99152 test(" compileScalaPB" ) {
100- test(" calledDirectly" ) - UnitTester (Tutorial , resourcePath).scoped { eval =>
101- if (! mill.constants.Util .isWindows) {
102- val Right (result) = eval.apply(Tutorial .core.compileScalaPB): @ unchecked
103-
104- val outPath = protobufOutPath(eval)
105-
106- val outputFiles = os.walk(result.value.path).filter(os.isFile)
107-
108- val expectedSourcefiles = compiledSourcefiles.map(outPath / _)
109-
110- assert(
111- result.value.path == eval.outPath / " core/compileScalaPB.dest" ,
112- outputFiles.nonEmpty,
113- outputFiles.forall(expectedSourcefiles.contains),
114- outputFiles.size == 5 ,
115- result.evalCount > 0
116- )
117-
118- // don't recompile if nothing changed
119- val Right (result2) = eval.apply(Tutorial .core.compileScalaPB): @ unchecked
120-
121- assert(result2.evalCount == 0 )
122- }
123- }
153+ test(" scalaGen" ) - testCompilation(Tutorial , compiledScalaSourcefiles)
154+ test(" javaGen" ) - testCompilation(TutorialWithJavaGen , compiledJavaSourcefiles)
155+ test(" scalaAndJavaGen" ) - testCompilation(TutorialWithScalaAndJavaGen , compiledScalaSourcefiles ++ compiledJavaSourcefiles)
124156
125157 test(" calledWithSpecificFile" ) - UnitTester (
126158 TutorialWithSpecificSources ,
@@ -165,7 +197,7 @@ object TutorialTests extends TestSuite {
165197//
166198// // val outputFiles = os.walk(outPath).filter(_.isFile)
167199//
168- // // val expectedSourcefiles = compiledSourcefiles .map(outPath / _)
200+ // // val expectedSourcefiles = compiledScalaSourcefiles .map(outPath / _)
169201//
170202// // assert(
171203// // outputFiles.nonEmpty,
0 commit comments