Skip to content

Commit

Permalink
Merge pull request #3502 from Gedochao/feature/run-main-from-test-scope
Browse files Browse the repository at this point in the history
Add support for running a main method from the test scope
  • Loading branch information
Gedochao authored Feb 21, 2025
2 parents 82fc505 + c9b42c2 commit c0a1ece
Show file tree
Hide file tree
Showing 26 changed files with 630 additions and 401 deletions.
11 changes: 8 additions & 3 deletions modules/build/src/main/scala/scala/build/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ trait Build {
def scope: Scope
def outputOpt: Option[os.Path]
def success: Boolean
def cancelled: Boolean
def diagnostics: Option[Seq[(Either[String, os.Path], bsp4j.Diagnostic)]]

def successfulOpt: Option[Build.Successful]
Expand All @@ -54,6 +55,7 @@ object Build {
logger: Logger
) extends Build {
def success: Boolean = true
def cancelled: Boolean = false
def successfulOpt: Some[this.type] = Some(this)
def outputOpt: Some[os.Path] = Some(output)
def dependencyClassPath: Seq[os.Path] = sources.resourceDirs ++ artifacts.classPath
Expand Down Expand Up @@ -215,9 +217,11 @@ object Build {
project: Project,
diagnostics: Option[Seq[(Either[String, os.Path], bsp4j.Diagnostic)]]
) extends Build {
def success: Boolean = false
def successfulOpt: None.type = None
def outputOpt: None.type = None
def success: Boolean = false

override def cancelled: Boolean = false
def successfulOpt: None.type = None
def outputOpt: None.type = None
}

final case class Cancelled(
Expand All @@ -227,6 +231,7 @@ object Build {
reason: String
) extends Build {
def success: Boolean = false
def cancelled: Boolean = true
def successfulOpt: None.type = None
def outputOpt: None.type = None
def diagnostics: None.type = None
Expand Down
15 changes: 14 additions & 1 deletion modules/build/src/test/scala/scala/build/tests/TestInputs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,27 @@ final case class TestInputs(
buildThreads: BuildThreads, // actually only used when bloopConfigOpt is non-empty
bloopConfigOpt: Option[BloopRifleConfig],
fromDirectory: Boolean = false
)(f: (os.Path, Inputs, Build) => T) =
)(f: (os.Path, Inputs, Build) => T): T =
withBuild(options, buildThreads, bloopConfigOpt, fromDirectory)((p, i, maybeBuild) =>
maybeBuild match {
case Left(e) => throw e
case Right(b) => f(p, i, b)
}
)

def withLoadedBuilds[T](
options: BuildOptions,
buildThreads: BuildThreads, // actually only used when bloopConfigOpt is non-empty
bloopConfigOpt: Option[BloopRifleConfig],
fromDirectory: Boolean = false
)(f: (os.Path, Inputs, Builds) => T) =
withBuilds(options, buildThreads, bloopConfigOpt, fromDirectory)((p, i, builds) =>
builds match {
case Left(e) => throw e
case Right(b) => f(p, i, b)
}
)

def withBuilds[T](
options: BuildOptions,
buildThreads: BuildThreads, // actually only used when bloopConfigOpt is non-empty
Expand Down
Loading

0 comments on commit c0a1ece

Please sign in to comment.