summaryrefslogtreecommitdiff
path: root/scalalib/test/src/ResolveDepsTests.scala
diff options
context:
space:
mode:
Diffstat (limited to 'scalalib/test/src/ResolveDepsTests.scala')
-rw-r--r--scalalib/test/src/ResolveDepsTests.scala77
1 files changed, 77 insertions, 0 deletions
diff --git a/scalalib/test/src/ResolveDepsTests.scala b/scalalib/test/src/ResolveDepsTests.scala
new file mode 100644
index 00000000..78361625
--- /dev/null
+++ b/scalalib/test/src/ResolveDepsTests.scala
@@ -0,0 +1,77 @@
+package mill.scalalib
+
+import coursier.Cache
+import coursier.maven.MavenRepository
+import mill.api.Result.{Failure, Success}
+import mill.eval.{PathRef, Result}
+import mill.util.Loose.Agg
+import utest._
+
+object ResolveDepsTests extends TestSuite {
+ val repos = Seq(Cache.ivy2Local, MavenRepository("https://repo1.maven.org/maven2"))
+
+ def evalDeps(deps: Agg[Dep]): Result[Agg[PathRef]] = Lib.resolveDependencies(
+ repos,
+ Lib.depToDependency(_, "2.12.4", ""),
+ deps
+ )
+
+ val tests = Tests {
+ 'resolveValidDeps - {
+ val deps = Agg(ivy"com.lihaoyi::pprint:0.5.3")
+ val Success(paths) = evalDeps(deps)
+ assert(paths.nonEmpty)
+ }
+
+ 'resolveValidDepsWithClassifier - {
+ val deps = Agg(ivy"org.lwjgl:lwjgl:3.1.1;classifier=natives-macos")
+ val Success(paths) = evalDeps(deps)
+ assert(paths.nonEmpty)
+ assert(paths.items.next.path.toString.contains("natives-macos"))
+ }
+
+ 'resolveTransitiveRuntimeDeps - {
+ val deps = Agg(ivy"org.mockito:mockito-core:2.7.22")
+ val Success(paths) = evalDeps(deps)
+ assert(paths.nonEmpty)
+ assert(paths.exists(_.path.toString.contains("objenesis")))
+ assert(paths.exists(_.path.toString.contains("byte-buddy")))
+ }
+
+ 'excludeTransitiveDeps - {
+ val deps = Agg(ivy"com.lihaoyi::pprint:0.5.3".exclude("com.lihaoyi" -> "fansi_2.12"))
+ val Success(paths) = evalDeps(deps)
+ assert(!paths.exists(_.path.toString.contains("fansi_2.12")))
+ }
+
+ 'excludeTransitiveDepsByOrg - {
+ val deps = Agg(ivy"com.lihaoyi::pprint:0.5.3".excludeOrg("com.lihaoyi"))
+ val Success(paths) = evalDeps(deps)
+ assert(!paths.exists(path => path.path.toString.contains("com/lihaoyi") && !path.path.toString.contains("pprint_2.12")))
+ }
+
+ 'excludeTransitiveDepsByName - {
+ val deps = Agg(ivy"com.lihaoyi::pprint:0.5.3".excludeName("fansi_2.12"))
+ val Success(paths) = evalDeps(deps)
+ assert(!paths.exists(_.path.toString.contains("fansi_2.12")))
+ }
+
+ 'errOnInvalidOrgDeps - {
+ val deps = Agg(ivy"xxx.yyy.invalid::pprint:0.5.3")
+ val Failure(errMsg, _) = evalDeps(deps)
+ assert(errMsg.contains("xxx.yyy.invalid"))
+ }
+
+ 'errOnInvalidVersionDeps - {
+ val deps = Agg(ivy"com.lihaoyi::pprint:invalid.version.num")
+ val Failure(errMsg, _) = evalDeps(deps)
+ assert(errMsg.contains("invalid.version.num"))
+ }
+
+ 'errOnPartialSuccess - {
+ val deps = Agg(ivy"com.lihaoyi::pprint:0.5.3", ivy"fake::fake:fake")
+ val Failure(errMsg, _) = evalDeps(deps)
+ assert(errMsg.contains("fake"))
+ }
+ }
+}