Skip to content

Commit 4de3b80

Browse files
committed
Support the --test flag with the publish & publish local sub-commands
1 parent 49c6696 commit 4de3b80

File tree

8 files changed

+291
-231
lines changed

8 files changed

+291
-231
lines changed

modules/cli/src/main/scala/scala/cli/commands/publish/Publish.scala

Lines changed: 106 additions & 109 deletions
Large diffs are not rendered by default.

modules/cli/src/main/scala/scala/cli/commands/publish/PublishLocal.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ object PublishLocal extends ScalaCommand[PublishLocalOptions] {
8686
isCi = options.publishParams.isCi,
8787
() => ConfigDb.empty, // shouldn't be used, no need of repo credentials here
8888
options.mainClass,
89-
dummy = options.sharedPublish.dummy
89+
dummy = options.sharedPublish.dummy,
90+
buildTests = options.sharedPublish.scope.test
9091
)
9192
}
9293
}

modules/cli/src/main/scala/scala/cli/commands/publish/SharedPublishOptions.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package scala.cli.commands.publish
33
import caseapp.*
44

55
import scala.build.compiler.{ScalaCompilerMaker, SimpleScalaCompilerMaker}
6-
import scala.cli.commands.shared.HelpGroup
6+
import scala.cli.commands.shared.{HelpGroup, ScopeOptions}
77
import scala.cli.commands.tags
88

99
// format: off
@@ -85,7 +85,10 @@ final case class SharedPublishOptions(
8585
@Group(HelpGroup.Publishing.toString)
8686
@HelpMessage("Proceed as if publishing, but do not upload / write artifacts to the remote repository")
8787
@Tag(tags.implementation)
88-
dummy: Boolean = false
88+
dummy: Boolean = false,
89+
90+
@Recurse
91+
scope: ScopeOptions = ScopeOptions()
8992
){
9093
// format: on
9194

modules/cli/src/main/scala/scala/cli/packaging/Library.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ object Library {
6565
} manifest.getMainAttributes.put(JarAttributes.Name.MAIN_CLASS, mainClass)
6666

6767
var zos: ZipOutputStream = null
68-
val contentDirs = builds.map(b => contentDirOverride.getOrElse(b.output))
68+
val contentDirs = builds.map(b => contentDirOverride.getOrElse(b.output)).distinct
6969

7070
try {
7171
zos = new JarOutputStream(outputStream, manifest)

modules/integration/src/test/scala/scala/cli/integration/PublishLocalTestDefinitions.scala

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ abstract class PublishLocalTestDefinitions extends ScalaCliSuite with TestScalaV
1717
private object PublishTestInputs {
1818
def testOrg: String = "test-local-org.sth"
1919
def testName: String = "my-proj"
20-
def projFile(message: String, exclude: Boolean = false): String =
20+
def projFile(message: String, exclude: Boolean = false, useTestScope: Boolean = false): String =
2121
s"""//> using scala $testedPublishedScalaVersion
22+
|${if (useTestScope) "//> using target.scope test" else ""}
2223
|//> using dep com.lihaoyi::os-lib:0.11.3${Some(",exclude=com.lihaoyi%%geny").filter(_ =>
2324
exclude
2425
).getOrElse("")}
@@ -46,11 +47,12 @@ abstract class PublishLocalTestDefinitions extends ScalaCliSuite with TestScalaV
4647
def inputs(
4748
message: String = "Hello",
4849
includePublishVersion: Boolean = true,
49-
excludeGeny: Boolean = false
50+
excludeGeny: Boolean = false,
51+
useTestScope: Boolean = false
5052
): TestInputs =
5153
TestInputs(
52-
os.rel / "project.scala" -> projFile(message, excludeGeny),
53-
os.rel / "publish-conf.scala" -> publishConfFile(includePublishVersion)
54+
os.rel / "src" / "project.scala" -> projFile(message, excludeGeny, useTestScope),
55+
os.rel / "src" / "publish-conf.scala" -> publishConfFile(includePublishVersion)
5456
)
5557
}
5658

@@ -306,4 +308,24 @@ abstract class PublishLocalTestDefinitions extends ScalaCliSuite with TestScalaV
306308
expect(unexpectedFiles.isEmpty)
307309
}
308310
}
311+
312+
test("publish local with test scope") {
313+
val expectedMessage = "Hello"
314+
PublishTestInputs.inputs(message = expectedMessage, useTestScope = true).fromRoot { root =>
315+
os.proc(
316+
TestUtil.cli,
317+
"--power",
318+
"publish",
319+
"local",
320+
".",
321+
"--test",
322+
extraOptions
323+
)
324+
.call(cwd = root)
325+
val publishedDep =
326+
s"${PublishTestInputs.testOrg}:${PublishTestInputs.testName}_$testedPublishedScalaVersion:$testPublishVersion"
327+
val r = os.proc(TestUtil.cli, "run", "--dep", publishedDep).call(cwd = root)
328+
expect(r.out.trim() == expectedMessage)
329+
}
330+
}
309331
}

0 commit comments

Comments
 (0)