Skip to content

Commit 0d8b672

Browse files
committed
Add option to run single tests from community build
1 parent fb6d511 commit 0d8b672

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

community-build/src/scala/dotty/communitybuild/Main.scala

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,34 @@ object Main:
1919
e.printStackTrace()
2020
Nil
2121

22+
def withProjects[T](names: Seq[String], opName: String)(op: CommunityProject => Unit): Unit =
23+
val missing = names.filterNot(projectMap.contains)
24+
if missing.nonEmpty then
25+
println(s"Missing projects: ${missing.mkString(", ")}. All projects: ${allProjects.mkString(", ")}")
26+
sys.exit(1)
27+
28+
val failed = names.flatMap( o =>
29+
try
30+
op(projectMap(o))
31+
None
32+
catch case e: Throwable =>
33+
e.printStackTrace()
34+
Some(o)
35+
)
36+
37+
if failed.nonEmpty then
38+
println(s"$opName failed for ${failed.mkString(", ")}")
39+
sys.exit(1)
40+
2241
/** Allows running various commands on community build projects. */
2342
def main(args: Array[String]): Unit =
2443
args.toList match
25-
case "publish" :: name :: Nil =>
44+
case "publish" :: names =>
45+
withProjects(names, "Publishing")(_.publish())
46+
47+
case "build" :: names =>
48+
withProjects(names, "Build")(_.build())
49+
2650
case "doc" :: "all" :: destStr :: Nil =>
2751
val dest = Paths.get(destStr)
2852
Seq("rm", "-rf", destStr).!
@@ -82,7 +106,7 @@ object Main:
82106

83107
case args =>
84108
println("USAGE: <COMMAND> <PROJECT NAME>")
85-
println("COMMAND is one of: publish doc")
109+
println("COMMAND is one of: publish doc run")
86110
println("Available projects are:")
87111
allProjects.foreach { k =>
88112
println(s"\t${k.project}")

community-build/src/scala/dotty/communitybuild/projects.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ sealed trait CommunityProject:
8484
if exitCode != 0 then
8585
throw RuntimeException(s"Doc command exited with code $exitCode for project $project. Project details:\n$this")
8686

87+
final def build(): Int = exec(projectDir, binaryName, buildCommands: _*)
88+
89+
final def buildCommands = runCommandsArgs :+ testCommand
90+
8791
end CommunityProject
8892

8993
final case class MillCommunityProject(

community-build/test/scala/dotty/communitybuild/CommunityBuildTest.scala

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ abstract class CommunityBuildTest:
2222
*/
2323
extension (self: CommunityProject) def run()(using suite: CommunityBuildTest) =
2424
self.dependencies.foreach(_.publish())
25-
suite.test(self.project, self.binaryName, self.runCommandsArgs :+ self.testCommand)
25+
suite.test(self)
2626

2727
/** Build the given project with the published local compiler and sbt plugin.
2828
*
@@ -34,10 +34,14 @@ abstract class CommunityBuildTest:
3434
* a build tool like SBT or Mill
3535
* @param arguments Arguments to pass to the testing program
3636
*/
37-
def test(project: String, command: String, arguments: Seq[String]): Unit = {
37+
def test(projectDef: CommunityProject): Unit = {
38+
val project = projectDef.project
39+
val command = projectDef.binaryName
40+
val arguments = projectDef.buildCommands
41+
3842
@annotation.tailrec
39-
def execTimes(task: => Int, timesToRerun: Int): Boolean =
40-
val exitCode = task
43+
def execTimes(task: () => Int, timesToRerun: Int): Boolean =
44+
val exitCode = task()
4145
if exitCode == 0
4246
then true
4347
else if timesToRerun == 0
@@ -60,7 +64,7 @@ abstract class CommunityBuildTest:
6064
|""".stripMargin)
6165
}
6266

63-
val testsCompletedSuccessfully = execTimes(exec(projectDir, command, arguments: _*), 3)
67+
val testsCompletedSuccessfully = execTimes(projectDef.build, 3)
6468

6569
if (!testsCompletedSuccessfully) {
6670
fail(s"""

0 commit comments

Comments
 (0)