Skip to content

Commit 1db0434

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

File tree

8 files changed

+292
-231
lines changed

8 files changed

+292
-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: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,15 @@ abstract class PublishLocalTestDefinitions extends ScalaCliSuite with TestScalaV
4646
def inputs(
4747
message: String = "Hello",
4848
includePublishVersion: Boolean = true,
49-
excludeGeny: Boolean = false
50-
): TestInputs =
49+
excludeGeny: Boolean = false,
50+
testScope: Boolean = false
51+
): TestInputs = {
52+
val sourcesDirectory = if (testScope) os.rel / "src" / "test" else os.rel / "src"
5153
TestInputs(
52-
os.rel / "project.scala" -> projFile(message, excludeGeny),
53-
os.rel / "publish-conf.scala" -> publishConfFile(includePublishVersion)
54+
os.rel / sourcesDirectory / "project.scala" -> projFile(message, excludeGeny),
55+
os.rel / sourcesDirectory / "publish-conf.scala" -> publishConfFile(includePublishVersion)
5456
)
57+
}
5558
}
5659

5760
for (includePublishVersion <- Seq(true, false)) {
@@ -306,4 +309,24 @@ abstract class PublishLocalTestDefinitions extends ScalaCliSuite with TestScalaV
306309
expect(unexpectedFiles.isEmpty)
307310
}
308311
}
312+
313+
test("publish local with test scope") {
314+
val expectedMessage = "Hello"
315+
PublishTestInputs.inputs(message = expectedMessage, testScope = true).fromRoot { root =>
316+
os.proc(
317+
TestUtil.cli,
318+
"--power",
319+
"publish",
320+
"local",
321+
".",
322+
"--test",
323+
extraOptions
324+
)
325+
.call(cwd = root)
326+
val publishedDep =
327+
s"${PublishTestInputs.testOrg}:${PublishTestInputs.testName}_$testedPublishedScalaVersion:$testPublishVersion"
328+
val r = os.proc(TestUtil.cli, "run", "--dep", publishedDep).call(cwd = root)
329+
expect(r.out.trim() == expectedMessage)
330+
}
331+
}
309332
}

0 commit comments

Comments
 (0)