Skip to content

Commit c0a1ece

Browse files
authored
Merge pull request VirtusLab#3502 from Gedochao/feature/run-main-from-test-scope
Add support for running a main method from the test scope
2 parents 82fc505 + c9b42c2 commit c0a1ece

File tree

26 files changed

+630
-401
lines changed

26 files changed

+630
-401
lines changed

modules/build/src/main/scala/scala/build/Build.scala

+8-3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ trait Build {
3232
def scope: Scope
3333
def outputOpt: Option[os.Path]
3434
def success: Boolean
35+
def cancelled: Boolean
3536
def diagnostics: Option[Seq[(Either[String, os.Path], bsp4j.Diagnostic)]]
3637

3738
def successfulOpt: Option[Build.Successful]
@@ -54,6 +55,7 @@ object Build {
5455
logger: Logger
5556
) extends Build {
5657
def success: Boolean = true
58+
def cancelled: Boolean = false
5759
def successfulOpt: Some[this.type] = Some(this)
5860
def outputOpt: Some[os.Path] = Some(output)
5961
def dependencyClassPath: Seq[os.Path] = sources.resourceDirs ++ artifacts.classPath
@@ -215,9 +217,11 @@ object Build {
215217
project: Project,
216218
diagnostics: Option[Seq[(Either[String, os.Path], bsp4j.Diagnostic)]]
217219
) extends Build {
218-
def success: Boolean = false
219-
def successfulOpt: None.type = None
220-
def outputOpt: None.type = None
220+
def success: Boolean = false
221+
222+
override def cancelled: Boolean = false
223+
def successfulOpt: None.type = None
224+
def outputOpt: None.type = None
221225
}
222226

223227
final case class Cancelled(
@@ -227,6 +231,7 @@ object Build {
227231
reason: String
228232
) extends Build {
229233
def success: Boolean = false
234+
def cancelled: Boolean = true
230235
def successfulOpt: None.type = None
231236
def outputOpt: None.type = None
232237
def diagnostics: None.type = None

modules/build/src/test/scala/scala/build/tests/TestInputs.scala

+14-1
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,27 @@ final case class TestInputs(
6666
buildThreads: BuildThreads, // actually only used when bloopConfigOpt is non-empty
6767
bloopConfigOpt: Option[BloopRifleConfig],
6868
fromDirectory: Boolean = false
69-
)(f: (os.Path, Inputs, Build) => T) =
69+
)(f: (os.Path, Inputs, Build) => T): T =
7070
withBuild(options, buildThreads, bloopConfigOpt, fromDirectory)((p, i, maybeBuild) =>
7171
maybeBuild match {
7272
case Left(e) => throw e
7373
case Right(b) => f(p, i, b)
7474
}
7575
)
7676

77+
def withLoadedBuilds[T](
78+
options: BuildOptions,
79+
buildThreads: BuildThreads, // actually only used when bloopConfigOpt is non-empty
80+
bloopConfigOpt: Option[BloopRifleConfig],
81+
fromDirectory: Boolean = false
82+
)(f: (os.Path, Inputs, Builds) => T) =
83+
withBuilds(options, buildThreads, bloopConfigOpt, fromDirectory)((p, i, builds) =>
84+
builds match {
85+
case Left(e) => throw e
86+
case Right(b) => f(p, i, b)
87+
}
88+
)
89+
7790
def withBuilds[T](
7891
options: BuildOptions,
7992
buildThreads: BuildThreads, // actually only used when bloopConfigOpt is non-empty

0 commit comments

Comments
 (0)