@@ -11,7 +11,9 @@ import utest.{TestSuite, Tests, assert, *}
11
11
object TutorialTests extends TestSuite {
12
12
val testScalaPbVersion = " 0.11.7"
13
13
14
- trait TutorialBase extends TestRootModule
14
+ trait TutorialBase extends TestRootModule {
15
+ val core : TutorialModule
16
+ }
15
17
16
18
trait TutorialModule extends ScalaPBModule {
17
19
def scalaVersion = sys.props.getOrElse(" TEST_SCALA_2_12_VERSION" , ??? )
@@ -70,19 +72,68 @@ object TutorialTests extends TestSuite {
70
72
lazy val millDiscover = Discover [this .type ]
71
73
}
72
74
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 = Seq [Generator ](ScalaGen , JavaGen )
86
+ }
87
+
88
+ lazy val millDiscover = Discover [this .type ]
89
+ }
90
+
73
91
val resourcePath : os.Path = os.Path (sys.env(" MILL_TEST_RESOURCE_DIR" ))
74
92
75
93
def protobufOutPath (eval : UnitTester ): os.Path =
76
94
eval.outPath / " core/compileScalaPB.dest/com/example/tutorial"
77
95
78
- def compiledSourcefiles : Seq [os.RelPath ] = Seq [os.RelPath ](
96
+ def compiledScalaSourcefiles : Seq [os.RelPath ] = Seq [os.RelPath ](
79
97
os.rel / " AddressBook.scala" ,
80
98
os.rel / " Person.scala" ,
81
99
os.rel / " TutorialProto.scala" ,
82
100
os.rel / " Include.scala" ,
83
101
os.rel / " IncludeProto.scala"
84
102
)
85
103
104
+ def compiledJavaSourcefiles : Seq [os.RelPath ] = Seq [os.RelPath ](
105
+ os.rel / " AddressBookProtos.java" ,
106
+ os.rel / " IncludeOuterClass.java"
107
+ )
108
+
109
+ // Helper function to test compilation with different generators
110
+ def testCompilation (
111
+ module : TutorialBase ,
112
+ expectedFiles : Seq [os.RelPath ]
113
+ ): Unit = {
114
+ UnitTester (module, resourcePath).scoped { eval =>
115
+ if (! mill.constants.Util .isWindows) {
116
+ val Right (result) = eval.apply(module.core.compileScalaPB): @ unchecked
117
+
118
+ val outPath = protobufOutPath(eval)
119
+ val outputFiles = os.walk(result.value.path).filter(os.isFile)
120
+ val expectedSourcefiles = expectedFiles.map(outPath / _)
121
+
122
+ assert(
123
+ result.value.path == eval.outPath / " core/compileScalaPB.dest" ,
124
+ outputFiles.nonEmpty,
125
+ outputFiles.forall(expectedSourcefiles.contains),
126
+ outputFiles.size == outputFiles.size,
127
+ result.evalCount > 0
128
+ )
129
+
130
+ // don't recompile if nothing changed
131
+ val Right (result2) = eval.apply(module.core.compileScalaPB): @ unchecked
132
+ assert(result2.evalCount == 0 )
133
+ }
134
+ }
135
+ }
136
+
86
137
def tests : Tests = Tests {
87
138
test(" scalapbVersion" ) {
88
139
@@ -97,30 +148,9 @@ object TutorialTests extends TestSuite {
97
148
}
98
149
99
150
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
- }
151
+ test(" scalaGen" ) - testCompilation(Tutorial , compiledScalaSourcefiles)
152
+ test(" javaGen" ) - testCompilation(TutorialWithJavaGen , compiledJavaSourcefiles)
153
+ test(" scalaAndJavaGen" ) - testCompilation(TutorialWithScalaAndJavaGen , compiledScalaSourcefiles ++ compiledJavaSourcefiles)
124
154
125
155
test(" calledWithSpecificFile" ) - UnitTester (
126
156
TutorialWithSpecificSources ,
@@ -165,7 +195,7 @@ object TutorialTests extends TestSuite {
165
195
//
166
196
// // val outputFiles = os.walk(outPath).filter(_.isFile)
167
197
//
168
- // // val expectedSourcefiles = compiledSourcefiles .map(outPath / _)
198
+ // // val expectedSourcefiles = compiledScalaSourcefiles .map(outPath / _)
169
199
//
170
200
// // assert(
171
201
// // outputFiles.nonEmpty,
0 commit comments