|
| 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 | + |
0 commit comments