Skip to content

Commit 0d4c5f7

Browse files
authored
Add dependency and dependencies alias for using directive (#1903)
1 parent 7b9abfd commit 0d4c5f7

File tree

2 files changed

+44
-36
lines changed

2 files changed

+44
-36
lines changed

modules/build/src/test/scala/scala/build/tests/SourcesTests.scala

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -33,42 +33,48 @@ class SourcesTests extends munit.FunSuite {
3333
() => sys.error("shouldn't be used")
3434
)
3535

36-
test("dependencies in .scala - using") {
37-
val testInputs = TestInputs(
38-
os.rel / "something.scala" ->
39-
"""//> using deps "org1:name1:1.1", "org2::name2:2.2"
40-
|//> using dep "org3:::name3:3.3"
41-
|import scala.collection.mutable
42-
|
43-
|object Something {
44-
| def a = 1
45-
|}
46-
|""".stripMargin
47-
)
48-
val expectedDeps = Seq(
49-
dep"org3:::name3:3.3",
50-
dep"org1:name1:1.1",
51-
dep"org2::name2:2.2"
52-
)
53-
testInputs.withInputs { (_, inputs) =>
54-
val (crossSources, _) =
55-
CrossSources.forInputs(
56-
inputs,
57-
preprocessors,
58-
TestLogger(),
59-
suppressDirectivesInMultipleFilesWarning = None
60-
).orThrow
61-
val scopedSources = crossSources.scopedSources(BuildOptions()).orThrow
62-
val sources = scopedSources.sources(Scope.Main, crossSources.sharedOptions(BuildOptions()))
36+
for (
37+
(singularAlias, pluralAlias) <-
38+
List(("lib", "libs"), ("dep", "deps"), ("dependency", "dependencies"))
39+
)
40+
test(s"dependencies in .scala - using aliases: $pluralAlias and $singularAlias") {
41+
val testInputs = TestInputs(
42+
os.rel / "something.scala" ->
43+
s"""//> using $pluralAlias "org1:name1:1.1", "org2::name2:2.2"
44+
|//> using $singularAlias "org3:::name3:3.3"
45+
|import scala.collection.mutable
46+
|
47+
|object Something {
48+
| def a = 1
49+
|}
50+
|""".stripMargin
51+
)
52+
val expectedDeps = Seq(
53+
dep"org1:name1:1.1",
54+
dep"org2::name2:2.2",
55+
dep"org3:::name3:3.3"
56+
)
57+
testInputs.withInputs { (_, inputs) =>
58+
val (crossSources, _) =
59+
CrossSources.forInputs(
60+
inputs,
61+
preprocessors,
62+
TestLogger(),
63+
suppressDirectivesInMultipleFilesWarning = None
64+
).orThrow
65+
val scopedSources = crossSources.scopedSources(BuildOptions()).orThrow
66+
val sources = scopedSources.sources(Scope.Main, crossSources.sharedOptions(BuildOptions()))
67+
68+
val obtainedDeps = sources.buildOptions.classPathOptions.extraDependencies.toSeq.toSeq.map(
69+
_.value
70+
)
6371

64-
expect(sources.buildOptions.classPathOptions.extraDependencies.toSeq.toSeq.map(
65-
_.value
66-
) == expectedDeps)
67-
expect(sources.paths.length == 1)
68-
expect(sources.paths.map(_._2) == Seq(os.rel / "something.scala"))
69-
expect(sources.inMemory.isEmpty)
72+
expect(obtainedDeps.sortBy(_.version) == expectedDeps.sortBy(_.version))
73+
expect(sources.paths.length == 1)
74+
expect(sources.paths.map(_._2) == Seq(os.rel / "something.scala"))
75+
expect(sources.inMemory.isEmpty)
76+
}
7077
}
71-
}
7278

7379
test("dependencies in .scala - using witin tests") {
7480
val testInputs = TestInputs(

modules/directives/src/main/scala/scala/build/preprocessing/directives/Dependency.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ import scala.cli.commands.SpecificationLevel
2525
final case class Dependency(
2626
@DirectiveName("lib")
2727
@DirectiveName("libs")
28+
@DirectiveName("dep")
2829
@DirectiveName("deps")
29-
dep: List[Positioned[String]] = Nil
30+
@DirectiveName("dependencies")
31+
dependency: List[Positioned[String]] = Nil
3032
) extends HasBuildOptions {
3133
def buildOptions: Either[BuildException, BuildOptions] = either {
32-
val maybeDependencies = dep
34+
val maybeDependencies = dependency
3335
.map { posStr =>
3436
posStr
3537
.map { str =>

0 commit comments

Comments
 (0)