Skip to content

Commit

Permalink
Support the --test flag with the publish & publish local sub-comm…
Browse files Browse the repository at this point in the history
…ands
  • Loading branch information
Gedochao committed Mar 4, 2025
1 parent 49c6696 commit 4de3b80
Show file tree
Hide file tree
Showing 8 changed files with 291 additions and 231 deletions.
215 changes: 106 additions & 109 deletions modules/cli/src/main/scala/scala/cli/commands/publish/Publish.scala

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ object PublishLocal extends ScalaCommand[PublishLocalOptions] {
isCi = options.publishParams.isCi,
() => ConfigDb.empty, // shouldn't be used, no need of repo credentials here
options.mainClass,
dummy = options.sharedPublish.dummy
dummy = options.sharedPublish.dummy,
buildTests = options.sharedPublish.scope.test
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package scala.cli.commands.publish
import caseapp.*

import scala.build.compiler.{ScalaCompilerMaker, SimpleScalaCompilerMaker}
import scala.cli.commands.shared.HelpGroup
import scala.cli.commands.shared.{HelpGroup, ScopeOptions}
import scala.cli.commands.tags

// format: off
Expand Down Expand Up @@ -85,7 +85,10 @@ final case class SharedPublishOptions(
@Group(HelpGroup.Publishing.toString)
@HelpMessage("Proceed as if publishing, but do not upload / write artifacts to the remote repository")
@Tag(tags.implementation)
dummy: Boolean = false
dummy: Boolean = false,

@Recurse
scope: ScopeOptions = ScopeOptions()
){
// format: on

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ object Library {
} manifest.getMainAttributes.put(JarAttributes.Name.MAIN_CLASS, mainClass)

var zos: ZipOutputStream = null
val contentDirs = builds.map(b => contentDirOverride.getOrElse(b.output))
val contentDirs = builds.map(b => contentDirOverride.getOrElse(b.output)).distinct

try {
zos = new JarOutputStream(outputStream, manifest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ abstract class PublishLocalTestDefinitions extends ScalaCliSuite with TestScalaV
private object PublishTestInputs {
def testOrg: String = "test-local-org.sth"
def testName: String = "my-proj"
def projFile(message: String, exclude: Boolean = false): String =
def projFile(message: String, exclude: Boolean = false, useTestScope: Boolean = false): String =
s"""//> using scala $testedPublishedScalaVersion
|${if (useTestScope) "//> using target.scope test" else ""}
|//> using dep com.lihaoyi::os-lib:0.11.3${Some(",exclude=com.lihaoyi%%geny").filter(_ =>
exclude
).getOrElse("")}
Expand Down Expand Up @@ -46,11 +47,12 @@ abstract class PublishLocalTestDefinitions extends ScalaCliSuite with TestScalaV
def inputs(
message: String = "Hello",
includePublishVersion: Boolean = true,
excludeGeny: Boolean = false
excludeGeny: Boolean = false,
useTestScope: Boolean = false
): TestInputs =
TestInputs(
os.rel / "project.scala" -> projFile(message, excludeGeny),
os.rel / "publish-conf.scala" -> publishConfFile(includePublishVersion)
os.rel / "src" / "project.scala" -> projFile(message, excludeGeny, useTestScope),
os.rel / "src" / "publish-conf.scala" -> publishConfFile(includePublishVersion)
)
}

Expand Down Expand Up @@ -306,4 +308,24 @@ abstract class PublishLocalTestDefinitions extends ScalaCliSuite with TestScalaV
expect(unexpectedFiles.isEmpty)
}
}

test("publish local with test scope") {
val expectedMessage = "Hello"
PublishTestInputs.inputs(message = expectedMessage, useTestScope = true).fromRoot { root =>
os.proc(
TestUtil.cli,
"--power",
"publish",
"local",
".",
"--test",
extraOptions
)
.call(cwd = root)
val publishedDep =
s"${PublishTestInputs.testOrg}:${PublishTestInputs.testName}_$testedPublishedScalaVersion:$testPublishVersion"
val r = os.proc(TestUtil.cli, "run", "--dep", publishedDep).call(cwd = root)
expect(r.out.trim() == expectedMessage)
}
}
}
Loading

0 comments on commit 4de3b80

Please sign in to comment.