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
|
package mill.scalalib.publish
import utest._
import mill._
import scala.xml.{Node, NodeSeq, XML}
object IvyTests extends TestSuite {
def tests: Tests = Tests {
val artifactId = "mill-scalalib_2.12"
val artifact =
Artifact("com.lihaoyi", "mill-scalalib_2.12", "0.0.1")
val deps = Agg(
Dependency(Artifact("com.lihaoyi", "mill-main_2.12", "0.1.4"),
Scope.Compile),
Dependency(Artifact("org.scala-sbt", "test-interface", "1.0"),
Scope.Compile),
Dependency(Artifact("com.lihaoyi", "pprint_2.12", "0.5.3"),
Scope.Compile, exclusions = List("com.lihaoyi" -> "fansi_2.12", "*" -> "sourcecode_2.12"))
)
'fullIvy - {
val fullIvy = XML.loadString(Ivy(artifact, deps))
'topLevel - {
val info = singleNode(fullIvy \ "info")
assert(
singleAttr(info, "organisation") == artifact.group
, singleAttr(info, "module") == artifact.id
, singleAttr(info, "revision") == artifact.version
)
}
'dependencies - {
val dependencies = fullIvy \ "dependencies" \ "dependency"
val ivyDeps = deps.indexed
assert(dependencies.size == ivyDeps.size)
dependencies.zipWithIndex.foreach { case (dep, index) =>
assert(
singleAttr(dep, "org") == ivyDeps(index).artifact.group
, singleAttr(dep, "name") == ivyDeps(index).artifact.id
, singleAttr(dep, "rev") == ivyDeps(index).artifact.version
, (dep \ "exclude").zipWithIndex forall { case (exclude, j) =>
singleAttr(exclude, "org") == ivyDeps(index).exclusions(j)._1 &&
singleAttr(exclude, "name") == ivyDeps(index).exclusions(j)._2
}
)
}
}
}
}
def singleNode(seq: NodeSeq): Node =
seq.headOption.getOrElse(throw new RuntimeException("empty seq"))
def singleAttr(node: Node, attr: String): String =
node.attribute(attr).flatMap(_.headOption.map(_.text)).getOrElse(throw new RuntimeException(s"empty attr $attr"))
}
|