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

Support the --test flag with the publish & publish local sub-commands #3538

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
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
Loading