Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixup classpath directive: now also works with predef #143

Merged
merged 7 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/src/main/scala/replpp/util/ClasspathHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ object ClasspathHelper {
if (verboseEnabled(config)) fromDependencies.foreach(println)
}

val additionalEntries = config.classpathConfig.additionalClasspathEntries ++ UsingDirectives.findClasspathEntries(scriptLines)
val allLines = allPredefLines(config) ++ scriptLines
val additionalEntries = config.classpathConfig.additionalClasspathEntries ++ UsingDirectives.findClasspathEntries(allLines)
additionalEntries.map(Paths.get(_)).foreach(entries.addOne)

entries.result().sorted
Expand Down
44 changes: 24 additions & 20 deletions core/src/test/scala/replpp/util/ClasspathHelperTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,30 @@ class ClasspathHelperTests extends AnyWordSpec with Matchers {
}

"resolves dependencies" when {
"declared in config" in {
val config = Config(classpathConfig = Config.ForClasspath(dependencies = Seq(
"org.scala-lang:scala-library:2.13.10",
"org.scala-lang::scala3-library:3.3.0",
)))
val deps = ClasspathHelper.dependencyArtifacts(config, scriptLines = Seq.empty)
deps.size shouldBe 2

assert(deps.find(_.endsWith("scala3-library_3-3.3.0.jar")).isDefined)
assert(deps.find(_.endsWith("scala-library-2.13.10.jar")).isDefined)
}

"declared in scriptFile" in {
val deps = ClasspathHelper.dependencyArtifacts(Config(), scriptLines = Seq("//> using dep com.michaelpollmeier::colordiff:0.36"))
deps.size shouldBe 4

assert(deps.find(_.endsWith("colordiff_3-0.36.jar")).isDefined)
assert(deps.find(_.endsWith("scala3-library_3-3.3.0.jar")).isDefined)
assert(deps.find(_.endsWith("diffutils-1.3.0.jar")).isDefined)
assert(deps.find(_.endsWith("scala-library-2.13.10.jar")).isDefined)
if (scala.util.Properties.isWin) {
info("test for dependency resolution disabled on windows - in general it works, but it's flaky :(")
} else {
"declared in config" in {
val config = Config(classpathConfig = Config.ForClasspath(dependencies = Seq(
"org.scala-lang:scala-library:2.13.10",
"org.scala-lang::scala3-library:3.3.0",
)))
val deps = ClasspathHelper.dependencyArtifacts(config, scriptLines = Seq.empty)
deps.size shouldBe 2

assert(deps.find(_.endsWith("scala3-library_3-3.3.0.jar")).isDefined)
assert(deps.find(_.endsWith("scala-library-2.13.10.jar")).isDefined)
}

"declared in scriptFile" in {
val deps = ClasspathHelper.dependencyArtifacts(Config(), scriptLines = Seq("//> using dep com.michaelpollmeier::colordiff:0.36"))
deps.size shouldBe 4

assert(deps.find(_.endsWith("colordiff_3-0.36.jar")).isDefined)
assert(deps.find(_.endsWith("scala3-library_3-3.3.0.jar")).isDefined)
assert(deps.find(_.endsWith("diffutils-1.3.0.jar")).isDefined)
assert(deps.find(_.endsWith("scala-library-2.13.10.jar")).isDefined)
}
}
}

Expand Down
Loading