-
Notifications
You must be signed in to change notification settings - Fork 119
/
DependencyUpdateTests.scala
92 lines (84 loc) · 2.97 KB
/
DependencyUpdateTests.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package scala.cli.integration
import com.eed3si9n.expecty.Expecty.expect
import coursier.core.Version
class DependencyUpdateTests extends ScalaCliSuite {
test("dependency update test") {
val fileName = "Hello.scala"
val message = "Hello World"
val fileContent =
s"""|//> using dep "com.lihaoyi::os-lib:0.7.8"
|//> using dep "com.lihaoyi::utest:0.7.10"
|
|object Hello extends App {
| println("$message")
|}""".stripMargin
val inputs = TestInputs(os.rel / fileName -> fileContent)
inputs.fromRoot { root =>
// update dependencies
val p = os.proc(TestUtil.cli, "--power", "dependency-update", "--all", fileName)
.call(
cwd = root,
stdin = os.Inherit,
mergeErrIntoOut = true
)
expect(p.out.trim().contains("Updated dependency"))
expect( // check if dependency update command modify file
os.read(root / fileName) != fileContent)
// after updating dependencies app should run
val out = os.proc(TestUtil.cli, fileName).call(cwd = root).out.trim()
expect(out == message)
}
}
test("update toolkit dependence") {
val toolkitVersion = "0.1.3"
val testInputs = TestInputs(
os.rel / "Foo.scala" ->
s"""//> using toolkit "$toolkitVersion"
|
|object Hello extends App {
| println("Hello")
|}
|""".stripMargin
)
testInputs.fromRoot { root =>
// update toolkit
os.proc(TestUtil.cli, "--power", "dependency-update", "--all", ".")
.call(cwd = root)
val toolkitDirective = "//> using toolkit \"(.*)\"".r
val updatedToolkitVersionOpt = {
val regexMatch = toolkitDirective.findFirstMatchIn(os.read(root / "Foo.scala"))
regexMatch.map(_.group(1))
}
expect(updatedToolkitVersionOpt.nonEmpty)
val updatedToolkitVersion = updatedToolkitVersionOpt.get
expect(Version(updatedToolkitVersion) > Version(toolkitVersion))
}
}
test("update typelevel toolkit dependency") {
val toolkitVersion = "0.0.1"
val testInputs = TestInputs(
os.rel / "Foo.scala" ->
s"""//> using toolkit "typelevel:$toolkitVersion"
|
|import cats.effect.*
|
|object Hello extends IOApp.Simple {
| def run = IO.println("Hello")
|}
|""".stripMargin
)
testInputs.fromRoot { root =>
// update toolkit
os.proc(TestUtil.cli, "--power", "dependency-update", "--all", ".")
.call(cwd = root)
val toolkitDirective = "//> using toolkit \"typelevel:(.*)\"".r
val updatedToolkitVersionOpt = {
val regexMatch = toolkitDirective.findFirstMatchIn(os.read(root / "Foo.scala"))
regexMatch.map(_.group(1))
}
expect(updatedToolkitVersionOpt.nonEmpty)
val updatedToolkitVersion = updatedToolkitVersionOpt.get
expect(Version(updatedToolkitVersion) > Version(toolkitVersion))
}
}
}