Skip to content

Commit

Permalink
add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
jilen committed Dec 1, 2023
1 parent dd0344b commit 8302c3d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion scalalib/src/mill/scalalib/CoursierModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import mill.api.PathRef
import scala.annotation.nowarn
import scala.concurrent.Await
import scala.concurrent.duration.Duration
import scala.concurrent.ExecutionContext.Implicits.global

/**
* This module provides the capability to resolve (transitive) dependencies from (remote) repositories.
Expand Down Expand Up @@ -63,6 +62,7 @@ trait CoursierModule extends mill.Module {
* The repositories used to resolved dependencies with [[resolveDeps()]].
*/
def repositoriesTask: Task[Seq[Repository]] = T.task {
import scala.concurrent.ExecutionContext.Implicits.global
val repos = Await.result(
Resolve().finalRepositories.future(),
Duration.Inf
Expand Down
2 changes: 2 additions & 0 deletions scalalib/test/resources/coursier/mirror.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
central.from=https://repo1.maven.org/maven2
central.to=https://repo.maven.apache.org/maven2/
42 changes: 42 additions & 0 deletions scalalib/test/src/mill/scalalib/CoursierMirrorTests.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package mill.scalalib

import mill.util.{TestEvaluator, TestUtil}
import mill.eval.{Evaluator}
import utest._
import utest.framework.TestPath

object CoursierMirrorTests extends TestSuite {

val resourcePath = os.pwd / "scalalib" / "test" / "resources" / "coursier"

object CoursierTest extends TestUtil.BaseModule {
object core extends ScalaModule {
def scalaVersion = "2.13.12"
}
}

def workspaceTest[T](
m: TestUtil.BaseModule,
resourcePath: os.Path = resourcePath,
env: Map[String, String] = Evaluator.defaultEnv,
debug: Boolean = false
)(t: TestEvaluator => T)(implicit tp: TestPath): T = {
val eval = new TestEvaluator(m, env = env, debugEnabled = debug)
os.remove.all(m.millSourcePath)
os.remove.all(eval.outPath)
os.makeDir.all(m.millSourcePath / os.up)
os.copy(resourcePath, m.millSourcePath)
t(eval)
}

def tests: Tests = Tests {
sys.props("coursier.mirrors") = (resourcePath / "mirror.properties").toString
"readMirror" - workspaceTest(CoursierTest) { eval =>
val Right((result, evalCount)) = eval.apply(CoursierTest.core.repositoriesTask)
val centralReplaced = result.exists { repo =>
repo.repr.contains("https://repo.maven.apache.org/maven2")
}
assert(centralReplaced)
}
}
}

0 comments on commit 8302c3d

Please sign in to comment.