From 77f843629b4df341b23c81445517cf4885968d0b Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Tue, 28 Sep 2021 08:31:26 +0200 Subject: [PATCH] Added tests for IvyHook --- main/test/src/main/MillIvyHookTest.scala | 58 ++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 main/test/src/main/MillIvyHookTest.scala diff --git a/main/test/src/main/MillIvyHookTest.scala b/main/test/src/main/MillIvyHookTest.scala new file mode 100644 index 00000000000..db598b1b824 --- /dev/null +++ b/main/test/src/main/MillIvyHookTest.scala @@ -0,0 +1,58 @@ +package mill.main + +import java.io.File + +import scala.util.Try + +import ammonite.runtime.ImportHook.InterpreterInterface +import coursierapi.{Dependency => CDependency, Module => CModule, ScalaVersion => CScalaVersion} +import utest.{TestSuite, Tests, _} + +object MillIvyHookTest extends TestSuite { + val wd = os.pwd + def mapDep(d: CDependency): Seq[File] = + Seq( + (wd / d.getModule.getOrganization / d.getModule.getName / d.getVersion / s"${d.getModule.getName}-${d.getVersion}.jar").toIO + ) + override def tests: Tests = Tests { + val interp = new InterpreterInterface { + def loadIvy(coordinates: CDependency*): Either[String, Seq[File]] = + Right(coordinates.flatMap(mapDep)) + def watch(p: os.Path): Unit = ??? + def scalaVersion: String = "2.13.6" + } + test("simple") { + val deps = Seq( + ("a:b:c", CDependency.of("a", "b", "c"), wd / "a" / "b" / "c" / "b-c.jar"), + ( + "a::b:c", + CDependency.of(CModule.parse("a::b", CScalaVersion.of("2.13.6")), "c"), + wd / "a" / "b_2.13" / "c" / "b_2.13-c.jar" + ), + ( + "a::b::c", + CDependency.of( + CModule.parse( + s"a::b_mill${mill.BuildInfo.millBinPlatform}", + CScalaVersion.of("2.13.6") + ), + "c" + ), + wd / "a" / s"b_mill${mill.BuildInfo.millBinPlatform}_2.13" / "c" / s"b_mill${mill.BuildInfo.millBinPlatform}_2.13-c.jar" + ) + ) + val checks = deps.map { case (coord, dep, path) => + Try { + val expected: Either[String, (Seq[CDependency], Seq[File])] = + Right(Seq(dep), Seq(path.toIO)) + val resolved = MillIvyHook.resolve(interp, Seq(coord)) + assert( + // first check only adds context to the exception message + !coord.isEmpty && resolved == expected + ) + } + } + assert(checks.forall(_.isSuccess)) + } + } +}