Skip to content

Commit e63d0c4

Browse files
committed
add integration tests
1 parent e8e8541 commit e63d0c4

10 files changed

+251
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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 = gCombinator.combine2(a, b, c)
18+
19+
def defaultValue: MyNumber = gDefaultValue.defaultValue
20+
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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 = gCombinator.combine2(a, b, c)
18+
19+
def defaultValue: MyString = gDefaultValue.defaultValue
20+
21+
}
Lines changed: 16 additions & 0 deletions
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+
}
Lines changed: 13 additions & 0 deletions
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+
}
Lines changed: 16 additions & 0 deletions
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+
}
Lines changed: 13 additions & 0 deletions
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+
}
Lines changed: 18 additions & 0 deletions
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+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package lib
2+
3+
trait Combinator[T] {
4+
def combine(a: T, b: T): T
5+
def combine2(a: T, b: T, c: T): T = combine(combine(a, b), c)
6+
}
Lines changed: 5 additions & 0 deletions
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+
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
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 should run
30+
modifyFile(
31+
workspacePath / "app" / "src" / "MyNumber.scala",
32+
_.replace(
33+
"def defaultValue: MyNumber = MyNumber(0)",
34+
"def defaultValue: MyNumber = MyNumber(1)"
35+
)
36+
)
37+
val thirdRun = eval("app.test.testQuick")
38+
val thirdRunOutLines = thirdRun.out.linesIterator.toSeq
39+
Seq(
40+
"app.MyNumberDefaultValueTests.simple"
41+
).foreach { expectedLines =>
42+
val exists = thirdRunOutLines.exists(_.contains(expectedLines))
43+
assert(exists)
44+
}
45+
46+
// Fourth run, MyNumberDefaultValueTests was failed, so it should run again
47+
val fourthRun = eval("app.test.testQuick")
48+
val fourthRunOutLines = fourthRun.out.linesIterator.toSeq
49+
Seq(
50+
"app.MyNumberDefaultValueTests.simple"
51+
).foreach { expectedLines =>
52+
val exists = fourthRunOutLines.exists(_.contains(expectedLines))
53+
assert(exists)
54+
}
55+
56+
// Fifth run, MyNumberDefaultValueTests was fixed, so it should run again
57+
modifyFile(
58+
workspacePath / "app" / "test" / "src" / "MyNumberDefaultValueTests.scala",
59+
_.replace("assert(result == MyNumber(0))", "assert(result == MyNumber(1))")
60+
)
61+
val fifthRun = eval("app.test.testQuick")
62+
val fifthRunOutLines = fifthRun.out.linesIterator.toSeq
63+
Seq(
64+
"app.MyNumberDefaultValueTests.simple"
65+
).foreach { expectedLines =>
66+
val exists = fifthRunOutLines.exists(_.contains(expectedLines))
67+
assert(exists)
68+
}
69+
70+
// Sixth run, nothing should run because we're not changing anything
71+
val sixthRun = eval("app.test.testQuick")
72+
assert(sixthRun.out.isEmpty)
73+
}
74+
test("update lib file") - integrationTest { tester =>
75+
import tester._
76+
77+
// First run, all tests should run
78+
val firstRun = eval("app.test.testQuick")
79+
val firstRunOutLines = firstRun.out.linesIterator.toSeq
80+
Seq(
81+
"app.MyNumberCombinatorTests.simple",
82+
"app.MyStringCombinatorTests.simple",
83+
"app.MyStringDefaultValueTests.simple",
84+
"app.MyNumberDefaultValueTests.simple"
85+
).foreach { expectedLines =>
86+
val exists = firstRunOutLines.exists(_.contains(expectedLines))
87+
assert(exists)
88+
}
89+
90+
// Second run, nothing should run because we're not changing anything
91+
val secondRun = eval("app.test.testQuick")
92+
assert(secondRun.out.isEmpty)
93+
94+
// Third run, Combinator.scala changed syntactically, should not run
95+
modifyFile(
96+
workspacePath / "lib" / "src" / "Combinator.scala",
97+
_.replace("def combine(a: T, b: T): T", "def combine(b: T, a: T): T")
98+
)
99+
val thirdRun = eval("app.test.testQuick")
100+
assert(thirdRun.out.isEmpty)
101+
102+
// Fourth run, Combinator.scala changed sematically, should run MyNumberCombinatorTests & MyStringCombinatorTests
103+
modifyFile(
104+
workspacePath / "lib" / "src" / "Combinator.scala",
105+
_.replace("def combine2(a: T, b: T, c: T): T = combine(combine(a, b), c)", "def combine2(a: T, b: T, c: T): T = combine(a, combine(b, c))")
106+
)
107+
val fourthRun = eval("app.test.testQuick")
108+
val fourthRunOutLines = fourthRun.out.linesIterator.toSeq
109+
Seq(
110+
"app.MyNumberCombinatorTests.simple",
111+
"app.MyStringCombinatorTests.simple"
112+
).foreach { expectedLines =>
113+
val exists = fourthRunOutLines.exists(_.contains(expectedLines))
114+
assert(exists)
115+
}
116+
117+
// Fifth run, nothing should run because we're not changing anything
118+
val fifthRun = eval("app.test.testQuick")
119+
assert(fifthRun.out.isEmpty)
120+
}
121+
}
122+
}

0 commit comments

Comments
 (0)