Skip to content

Commit 9610b60

Browse files
committed
add integration test
1 parent 690dacc commit 9610b60

11 files changed

+243
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package app
2+
3+
import lib.*
4+
5+
final case class MyNumber(val value: Int)
6+
7+
object MyNumber {
8+
9+
given gCombinator: Combinator[MyNumber] = new Combinator[MyNumber] {
10+
def combine(a: MyNumber, b: MyNumber): MyNumber = MyNumber(a.value + b.value)
11+
}
12+
13+
given gDefaultValue: DefaultValue[MyNumber] = new DefaultValue[MyNumber] {
14+
def defaultValue: MyNumber = MyNumber(0)
15+
}
16+
17+
def combine(a: MyNumber, b: MyNumber, c: MyNumber): MyNumber = {
18+
val temp = gCombinator.combine(a, b)
19+
gCombinator.combine(temp, c)
20+
}
21+
22+
def defaultValue: MyNumber = gDefaultValue.defaultValue
23+
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package app
2+
3+
import lib.*
4+
5+
final case class MyString(val value: String)
6+
7+
object MyString {
8+
9+
given gCombinator: Combinator[MyString] = new Combinator[MyString] {
10+
def combine(a: MyString, b: MyString): MyString = MyString(a.value + b.value)
11+
}
12+
13+
given gDefaultValue: DefaultValue[MyString] = new DefaultValue[MyString] {
14+
def defaultValue: MyString = MyString("")
15+
}
16+
17+
def combine(a: MyString, b: MyString, c: MyString): MyString = {
18+
val temp = gCombinator.combine(a, b)
19+
gCombinator.combine(temp, c)
20+
}
21+
22+
def defaultValue: MyString = gDefaultValue.defaultValue
23+
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package app
2+
3+
import utest.*
4+
import app.MyNumber
5+
6+
object MyNumberCombinatorTests extends TestSuite {
7+
def tests = Tests {
8+
test("simple") {
9+
val a = MyNumber(1)
10+
val b = MyNumber(2)
11+
val c = MyNumber(3)
12+
val result = MyNumber.combine(a, b, c)
13+
assert(result == MyNumber(6))
14+
}
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package app
2+
3+
import utest.*
4+
import app.MyNumber
5+
6+
object MyNumberDefaultValueTests extends TestSuite {
7+
def tests = Tests {
8+
test("simple") {
9+
val result = MyNumber.defaultValue
10+
assert(result == MyNumber(0))
11+
}
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package app
2+
3+
import utest.*
4+
import app.MyString
5+
6+
object MyStringCombinatorTests extends TestSuite {
7+
def tests = Tests {
8+
test("simple") {
9+
val a = MyString("a")
10+
val b = MyString("b")
11+
val c = MyString("c")
12+
val result = MyString.combine(a, b, c)
13+
assert(result == MyString("abc"))
14+
}
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package app
2+
3+
import utest.*
4+
import app.MyString
5+
6+
object MyStringDefaultValueTests extends TestSuite {
7+
def tests = Tests {
8+
test("simple") {
9+
val result = MyString.defaultValue
10+
assert(result == MyString(""))
11+
}
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package build
2+
3+
import mill._, scalalib._
4+
5+
object lib extends ScalaModule {
6+
def scalaVersion = "3.3.1"
7+
}
8+
9+
object app extends ScalaModule {
10+
def scalaVersion = "3.3.1"
11+
def moduleDeps = Seq(lib)
12+
13+
object test extends ScalaTests {
14+
def ivyDeps = Seq(ivy"com.lihaoyi::utest:0.8.5")
15+
def testFramework = "utest.runner.Framework"
16+
def moduleDeps = Seq(app)
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package lib
2+
3+
trait Combinator[T] {
4+
def combine(a: T, b: T): T
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package lib
2+
3+
trait DefaultValue[T] {
4+
def defaultValue: T
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package mill.integration
2+
3+
import mill.testkit.UtestIntegrationTestSuite
4+
5+
import utest._
6+
7+
object TestQuickTests extends UtestIntegrationTestSuite {
8+
val tests: Tests = Tests {
9+
test("update app file") - integrationTest { tester =>
10+
import tester._
11+
12+
// First run, all tests should run
13+
val firstRun = eval("app.test.testQuick")
14+
val firstRunOutLines = firstRun.out.linesIterator.toSeq
15+
Seq(
16+
"app.MyNumberCombinatorTests.simple",
17+
"app.MyStringCombinatorTests.simple",
18+
"app.MyStringDefaultValueTests.simple",
19+
"app.MyNumberDefaultValueTests.simple",
20+
).foreach { expectedLines =>
21+
val exists = firstRunOutLines.exists(_.contains(expectedLines))
22+
assert(exists)
23+
}
24+
25+
// Second run, nothing should run because we're not changing anything
26+
val secondRun = eval("app.test.testQuick")
27+
assert(secondRun.out.isEmpty)
28+
29+
// Third run, MyNumber.scala changed, so MyNumberDefaultValueTests & MyNumberCombinatorTests should run
30+
modifyFile(workspacePath / "app" / "src" / "MyNumber.scala", _.replace("def defaultValue: MyNumber = MyNumber(0)", "def defaultValue: MyNumber = MyNumber(1)"))
31+
val thirdRun = eval("app.test.testQuick")
32+
val thirdRunOutLines = thirdRun.out.linesIterator.toSeq
33+
Seq(
34+
"app.MyNumberCombinatorTests.simple",
35+
"app.MyNumberDefaultValueTests.simple",
36+
).foreach { expectedLines =>
37+
val exists = thirdRunOutLines.exists(_.contains(expectedLines))
38+
assert(exists)
39+
}
40+
41+
// Fourth run, MyNumberDefaultValueTests was failed, so it should run again
42+
val fourthRun = eval("app.test.testQuick")
43+
val fourthRunOutLines = fourthRun.out.linesIterator.toSeq
44+
Seq(
45+
"app.MyNumberDefaultValueTests.simple",
46+
).foreach { expectedLines =>
47+
val exists = fourthRunOutLines.exists(_.contains(expectedLines))
48+
assert(exists)
49+
}
50+
51+
// Fifth run, MyNumberDefaultValueTests was fixed, so it should run again
52+
modifyFile(workspacePath / "app" / "test" / "src" / "MyNumberDefaultValueTests.scala", _.replace("assert(result == MyNumber(0))", "assert(result == MyNumber(1))"))
53+
val fifthRun = eval("app.test.testQuick")
54+
val fifthRunOutLines = fifthRun.out.linesIterator.toSeq
55+
Seq(
56+
"app.MyNumberDefaultValueTests.simple",
57+
).foreach { expectedLines =>
58+
val exists = fifthRunOutLines.exists(_.contains(expectedLines))
59+
assert(exists)
60+
}
61+
62+
// Sixth run, nothing should run because we're not changing anything
63+
val sixthRun = eval("app.test.testQuick")
64+
assert(sixthRun.out.isEmpty)
65+
}
66+
test("update lib file") - integrationTest { tester =>
67+
import tester._
68+
69+
// First run, all tests should run
70+
val firstRun = eval("app.test.testQuick")
71+
val firstRunOutLines = firstRun.out.linesIterator.toSeq
72+
Seq(
73+
"app.MyNumberCombinatorTests.simple",
74+
"app.MyStringCombinatorTests.simple",
75+
"app.MyStringDefaultValueTests.simple",
76+
"app.MyNumberDefaultValueTests.simple",
77+
).foreach { expectedLines =>
78+
val exists = firstRunOutLines.exists(_.contains(expectedLines))
79+
assert(exists)
80+
}
81+
82+
// Second run, nothing should run because we're not changing anything
83+
val secondRun = eval("app.test.testQuick")
84+
assert(secondRun.out.isEmpty)
85+
86+
// Third run, Combinator.scala changed, so MyNumberCombinatorTests & MyStringCombinatorTests should run
87+
modifyFile(workspacePath / "lib" / "src" / "Combinator.scala", _.replace("def combine(a: T, b: T): T", "def combine(b: T, a: T): T"))
88+
val thirdRun = eval("app.test.testQuick")
89+
val thirdRunOutLines = thirdRun.out.linesIterator.toSeq
90+
Seq(
91+
"app.MyNumberCombinatorTests.simple",
92+
"app.MyStringCombinatorTests.simple",
93+
).foreach { expectedLines =>
94+
val exists = thirdRunOutLines.exists(_.contains(expectedLines))
95+
assert(exists)
96+
}
97+
98+
// Fourth run, nothing should run because we're not changing anything
99+
val fourthRun = eval("app.test.testQuick")
100+
assert(fourthRun.out.isEmpty)
101+
}
102+
}
103+
}
104+

scalalib/src/mill/scalalib/JavaModule.scala

+5-4
Original file line numberDiff line numberDiff line change
@@ -233,20 +233,21 @@ trait JavaModule
233233
testUseArgsFile(),
234234
forkArgs(),
235235
Seq.empty,
236-
zincWorker().scalalibClasspath(),
236+
jvmWorker().scalalibClasspath(),
237237
resources(),
238238
testFramework(),
239239
runClasspath(),
240240
testClasspaths,
241241
args.toSeq,
242242
testClasses,
243-
zincWorker().testrunnerEntrypointClasspath(),
243+
jvmWorker().testrunnerEntrypointClasspath(),
244244
forkEnv(),
245245
testSandboxWorkingDir(),
246246
forkWorkingDir(),
247247
quickTestReportXml,
248-
zincWorker().javaHome().map(_.path),
249-
testParallelism()
248+
jvmWorker().javaHome().map(_.path),
249+
testParallelism(),
250+
testLogLevel()
250251
)
251252

252253
val results = testModuleUtil.runTests()

0 commit comments

Comments
 (0)