Skip to content

Commit aa5ba25

Browse files
committed
reorganizing tests and adding some more
1 parent 8114ab7 commit aa5ba25

File tree

6 files changed

+92
-73
lines changed

6 files changed

+92
-73
lines changed

libs/groovylib/src/mill/groovylib/GroovyModule.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import mill.javalib.api.internal.{JavaCompilerOptions, JvmWorkerApi, ZincCompile
1717
trait GroovyModule extends JavaModule with GroovyModuleApi { outer =>
1818

1919
/**
20-
* The Groovy version to be used (for API and Language level settings).
20+
* The Groovy version to be used.
2121
*/
2222
def groovyVersion: T[String]
2323

@@ -55,7 +55,7 @@ trait GroovyModule extends JavaModule with GroovyModuleApi { outer =>
5555

5656
/**
5757
* The dependencies of this module.
58-
* Defaults to add the groovy-stdlib dependency matching the [[groovyVersion]].
58+
* Defaults to add the groovy dependency matching the [[groovyVersion]].
5959
*/
6060
override def mandatoryMvnDeps: T[Seq[Dep]] = Task {
6161
super.mandatoryMvnDeps() ++ Seq(
@@ -168,7 +168,7 @@ trait GroovyModule extends JavaModule with GroovyModuleApi { outer =>
168168
_.compile(groovySourceFiles, compileCp, classes)
169169
}
170170

171-
val analysisFile = dest / "groovy.analysis.dummy" // FIXME
171+
val analysisFile = dest / "groovy.analysis.dummy" // needed for mills CompilationResult
172172
os.write(target = analysisFile, data = "", createFolders = true)
173173

174174
workerResult match {
@@ -196,7 +196,7 @@ trait GroovyModule extends JavaModule with GroovyModuleApi { outer =>
196196

197197
/**
198198
* Aggregation of all the options passed to the Groovy compiler.
199-
* In most cases, instead of overriding this Target you want to override `groovycOptions` instead.
199+
* In most cases, instead of overriding this target you want to override `groovycOptions` instead.
200200
*/
201201
def allGroovycOptions: T[Seq[String]] = Task {
202202
groovycOptions()

libs/groovylib/test/resources/hello-groovy/main/spock/src/SpockTest.groovy

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ class SpockTest extends Specification {
1010
getHelloString() == "Hello, world!"
1111
}
1212

13-
def "test fails"() {
14-
expect:
15-
getHelloString() == "Wrong"
16-
}
17-
1813
def "sayHello to '#name' equals '#expected'"() {
1914
expect:
2015
sayHello(name) == expected

libs/groovylib/test/resources/hello-groovy/main/src/Hello.groovy

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,5 @@ class Hello {
1212

1313
static void main(String[] args) {
1414
println(getHelloString())
15-
}
16-
15+
}
1716
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package hellostatic
2+
3+
import groovy.transform.CompileStatic
4+
5+
@CompileStatic
6+
class HelloStatic {
7+
8+
static void main(String[] args) {
9+
def x = new Some("Hello World")
10+
x.doStuff()
11+
}
12+
}
13+
14+
@CompileStatic
15+
class Some {
16+
17+
private String toPrint;
18+
19+
Some(String toPrint){
20+
this.toPrint = toPrint
21+
}
22+
23+
void doStuff(){
24+
println(toPrint)
25+
}
26+
}

libs/groovylib/test/resources/hello-groovy/main/test/src/HelloTest.groovy

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,4 @@ class HelloTest {
99
void testSuccess() {
1010
assertEquals("Hello, world!", Hello.getHelloString())
1111
}
12-
13-
@Test
14-
void testFailure() {
15-
assertEquals("world!", Hello.getHelloString())
16-
}
1712
}

libs/groovylib/test/src/mill/groovylib/HelloGroovyTests.scala

Lines changed: 61 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,27 @@ import utest.*
99

1010
object HelloGroovyTests extends TestSuite {
1111

12-
val junit5Version = sys.props.getOrElse("TEST_JUNIT5_VERSION", "5.13.1")
12+
val groovy4Version = "4.0.28"
13+
val junit5Version = sys.props.getOrElse("TEST_JUNIT5_VERSION", "5.13.4")
1314

1415
object HelloGroovy extends TestRootModule {
1516

1617
lazy val millDiscover = Discover[this.type]
1718

18-
object maven extends JavaModule with MavenModule {
19+
// needed for a special test where only the tests are written in Groovy while appcode remains Java
20+
object `mixed-compile` extends JavaModule with MavenModule {
1921

20-
object `maven-test-only` extends TestGroovyMavenModule with TestModule.Junit5 {
22+
object `test` extends TestGroovyMavenModule with TestModule.Junit5 {
2123

22-
override def groovyVersion = "4.0.28"
23-
override def testModuleName: String = "test"
24+
override def moduleDeps: Seq[JavaModule] = Seq(
25+
HelloGroovy.`mixed-compile`, // TODO improve: TestOnly does not inherit outer deps
26+
)
2427

28+
override def groovyVersion = groovy4Version
2529
override def depManagement = Seq(
26-
mvn"org.junit.jupiter:junit-jupiter-engine:5.13.4"
30+
mvn"org.junit.jupiter:junit-jupiter-engine:$junit5Version"
2731
)
28-
29-
override def jupiterVersion = "5.13.4"
32+
override def jupiterVersion = junit5Version
3033
override def junitPlatformVersion = "1.13.4"
3134
}
3235

@@ -46,18 +49,16 @@ object HelloGroovyTests extends TestSuite {
4649
override def junitPlatformVersion = "1.13.4"
4750
}
4851

49-
object script extends GroovyTests with TestModule.Junit5 {
50-
override def depManagement = Seq(
51-
mvn"org.junit.jupiter:junit-jupiter-engine:5.13.4"
52-
)
53-
54-
override def jupiterVersion = "5.13.4"
55-
override def junitPlatformVersion = "1.13.4"
56-
52+
object script extends GroovyModule {
5753
override def groovyVersion = "4.0.28"
5854
override def mainClass = Some("HelloScript")
5955
}
6056

57+
object staticcompile extends GroovyModule {
58+
override def groovyVersion = "4.0.28"
59+
override def mainClass = Some("hellostatic.HelloStatic")
60+
}
61+
6162
object spock extends GroovyTests with TestModule.Junit5 {
6263
override def junitPlatformVersion = "1.13.4"
6364
def spockVersion: T[String] = "2.3-groovy-4.0"
@@ -75,7 +76,7 @@ object HelloGroovyTests extends TestSuite {
7576
}
7677
}
7778
object main extends Test {
78-
override def groovyVersion: T[String] = "4.0.28"
79+
override def groovyVersion: T[String] = groovy4Version
7980
}
8081
}
8182

@@ -89,15 +90,15 @@ object HelloGroovyTests extends TestSuite {
8990
def tests: Tests = Tests {
9091

9192
def m = HelloGroovy.main
92-
def mavenTestOnly = HelloGroovy.maven.`maven-test-only`
93+
def mixed = HelloGroovy.`mixed-compile`
9394

9495
test("running a Groovy script") {
9596
testEval().scoped { eval =>
9697
val Right(_) = eval.apply(m.script.run()): @unchecked
9798
}
9899
}
99100

100-
test("compile Groovy module") {
101+
test("compile & run Groovy module") {
101102
testEval().scoped { eval =>
102103
val Right(compiler) = eval.apply(m.groovyCompilerMvnDeps): @unchecked
103104

@@ -112,70 +113,73 @@ object HelloGroovyTests extends TestSuite {
112113
assert(
113114
os.walk(result.value.classes.path).exists(_.last == "Hello.class")
114115
)
115-
}
116116

117-
test("run Groovy module") {
118-
testEval().scoped { eval =>
119-
val Right(_) = eval.apply(m.run()): @unchecked
120-
}
117+
val Right(_) = eval.apply(m.run()): @unchecked
121118
}
122119
}
123120

124-
test("compile Groovy JUnit5 test") {
121+
test("compile & run Groovy JUnit5 test") {
125122
testEval().scoped { eval =>
126123

127124
val Right(result) = eval.apply(m.test.compile): @unchecked
128125

129126
assert(
130127
os.walk(result.value.classes.path).exists(_.last == "HelloTest.class")
131128
)
132-
}
133-
}
134129

135-
test("run JUnit5 test") {
136-
testEval().scoped { eval =>
137130
val Right(discovered) = eval.apply(m.test.discoveredTestClasses): @unchecked
138131
assert(discovered.value == Seq("hello.tests.HelloTest"))
139-
}
140-
testEval().scoped { eval =>
141-
val Left(ExecResult.Failure(_)) = eval.apply(m.test.testForked()): @unchecked
142-
}
143-
}
144-
145-
test("compile and run test-only Maven JUnit5 test") {
146-
testEval().scoped { eval =>
147132

148-
val Right(resultCompile) = eval.apply(mavenTestOnly.compile): @unchecked
149-
assert(
150-
os.walk(resultCompile.value.classes.path).exists(_.last == "HelloMavenTestOnly.class")
151-
)
152-
153-
val Right(discovered) = eval.apply(mavenTestOnly.discoveredTestClasses): @unchecked
154-
assert(discovered.value == Seq("hello.maven.tests.HelloMavenTestOnly"))
155-
156-
val Right(_) = eval.apply(mavenTestOnly.testForked()): @unchecked
133+
val Right(_) = eval.apply(m.test.testForked()): @unchecked
157134
}
158135
}
159136

160-
test("compile Spock test") {
137+
// test("compiling & running a statically compiled Groovy") {
138+
// testEval().scoped { eval =>
139+
// val Right(_) = eval.apply(m.staticcompile.showMvnDepsTree()): @unchecked
140+
// val Right(result) = eval.apply(m.staticcompile.compile): @unchecked
141+
// assert(
142+
// os.walk(result.value.classes.path).exists(_.last == "HelloStatic.class")
143+
// )
144+
// val Right(_) = eval.apply(m.staticcompile.run()): @unchecked
145+
// }
146+
// }
147+
148+
test("compile & run test-only Maven JUnit5 test") {
161149
testEval().scoped { eval =>
162150

163-
val Right(result1) = eval.apply(m.spock.compile): @unchecked
151+
val Right(resultCompile) = eval.apply(mixed.compile): @unchecked
164152
assert(
165-
os.walk(result1.value.classes.path).exists(_.last == "SpockTest.class")
153+
os.walk(resultCompile.value.classes.path).exists(_.last == "Greeter.class")
166154
)
167-
}
168-
}
169-
170-
test("run Spock test") {
171-
testEval().scoped { eval =>
172155

173-
val Right(discovered) = eval.apply(m.spock.discoveredTestClasses): @unchecked
174-
assert(discovered.value == Seq("hello.spock.SpockTest"))
156+
val Right(_) = eval.apply(mixed.test.compile): @unchecked
157+
val Right(discovered) = eval.apply(mixed.test.discoveredTestClasses): @unchecked
158+
assert(discovered.value == Seq("tests.GreeterTests"))
175159

176-
val Left(ExecResult.Failure(_)) = eval.apply(m.spock.testForked()): @unchecked
160+
val Right(_) = eval.apply(mixed.test.testForked()): @unchecked
177161
}
178162
}
179163

164+
// test("compile Spock test") {
165+
// testEval().scoped { eval =>
166+
//
167+
// val Right(result1) = eval.apply(m.spock.compile): @unchecked
168+
// assert(
169+
// os.walk(result1.value.classes.path).exists(_.last == "SpockTest.class")
170+
// )
171+
// }
172+
// }
173+
174+
// test("run Spock test") {
175+
// testEval().scoped { eval =>
176+
//
177+
// val Right(discovered) = eval.apply(m.spock.discoveredTestClasses): @unchecked
178+
// assert(discovered.value == Seq("hello.spock.SpockTest"))
179+
//
180+
// val Right(_) = eval.apply(m.spock.testForked()): @unchecked
181+
// }
182+
// }
183+
180184
}
181185
}

0 commit comments

Comments
 (0)