Skip to content

Commit 21051f6

Browse files
Abstract SBT-specific logic from community build tests
1 parent af4aa19 commit 21051f6

File tree

1 file changed

+51
-44
lines changed

1 file changed

+51
-44
lines changed

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

Lines changed: 51 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,32 @@ class CommunityBuildTest {
1616
new String(Files.readAllBytes(file), UTF_8)
1717
}
1818

19+
def testSbt(project: String, testCommand: String, updateCommand: String, extraSbtArgs: Seq[String] = Nil) = {
20+
// Workaround for https://github.com/sbt/sbt/issues/4395
21+
new File(sys.props("user.home") + "/.sbt/1.0/plugins").mkdirs()
22+
val pluginFilePath = communitybuildDir.resolve("sbt-dotty-sbt").toAbsolutePath().toString()
23+
24+
// Run the sbt command with the compiler version and sbt plugin set in the build
25+
val arguments = {
26+
val sbtProps = Option(System.getProperty("sbt.ivy.home")) match {
27+
case Some(ivyHome) =>
28+
Seq(s"-Dsbt.ivy.home=$ivyHome")
29+
case _ =>
30+
Seq()
31+
}
32+
extraSbtArgs ++ sbtProps ++ Seq(
33+
"-sbt-version", "1.2.7",
34+
s"--addPluginSbtFile=$pluginFilePath",
35+
s";clean ;set updateOptions in Global ~= (_.withLatestSnapshots(false)) ;++$compilerVersion! $testCommand"
36+
)
37+
}
38+
39+
test(project, "sbt", arguments)
40+
}
41+
42+
def testMill(project: String, testCommand: String, extraMillArgs: Seq[String] = Nil) =
43+
test(project, "./mill", extraMillArgs :+ testCommand)
44+
1945
/** Build the given project with the published local compiler and sbt plugin.
2046
*
2147
* This test reads the compiler version from community-build/dotty-bootstrapped.version
@@ -26,7 +52,7 @@ class CommunityBuildTest {
2652
* @param updateCommand The sbt command used to update the project
2753
* @param extraSbtArgs Extra arguments to pass to sbt
2854
*/
29-
def test(project: String, testCommand: String, updateCommand: String, extraSbtArgs: Seq[String] = Nil): Unit = {
55+
def test(project: String, command: String, arguments: Seq[String]): Unit = {
3056
def log(msg: String) = println(Console.GREEN + msg + Console.RESET)
3157

3258
log(s"Building $project with dotty-bootstrapped $compilerVersion...")
@@ -53,149 +79,130 @@ class CommunityBuildTest {
5379
exitCode
5480
}
5581

56-
// Workaround for https://github.com/sbt/sbt/issues/4395
57-
new File(sys.props("user.home") + "/.sbt/1.0/plugins").mkdirs()
58-
val pluginFilePath = communitybuildDir.resolve("sbt-dotty-sbt").toAbsolutePath().toString()
59-
60-
// Run the sbt command with the compiler version and sbt plugin set in the build
61-
val arguments = {
62-
val sbtProps = Option(System.getProperty("sbt.ivy.home")) match {
63-
case Some(ivyHome) =>
64-
Seq(s"-Dsbt.ivy.home=$ivyHome")
65-
case _ =>
66-
Seq()
67-
}
68-
extraSbtArgs ++ sbtProps ++ Seq(
69-
"-sbt-version", "1.2.7",
70-
s"--addPluginSbtFile=$pluginFilePath",
71-
s";clean ;set updateOptions in Global ~= (_.withLatestSnapshots(false)) ;++$compilerVersion! $testCommand"
72-
)
73-
}
74-
75-
val exitCode = exec("sbt", arguments: _*)
82+
val exitCode = exec(command, arguments: _*)
7683

7784
if (exitCode != 0) {
7885
fail(s"""
7986
|
80-
|sbt exited with an error code. To reproduce without JUnit, use:
87+
|$command exited with an error code. To reproduce without JUnit, use:
8188
|
8289
| sbt community-build/prepareCommunityBuild
8390
| cd community-build/community-projects/$project
84-
| sbt ${arguments.init.mkString(" ")} "${arguments.last}"
91+
| $command ${arguments.init.mkString(" ")} "${arguments.last}"
8592
|
86-
|For a faster feedback loop, one can try to extract a direct call to dotc
93+
|For a faster feedback loop on SBT projects, one can try to extract a direct call to dotc
8794
|using the sbt export command. For instance, for scalacheck, use
8895
| sbt export jvm/test:compileIncremental
8996
|
9097
|""".stripMargin)
9198
}
9299
}
93100

94-
@Test def intent = test(
101+
@Test def intent = testSbt(
95102
project = "intent",
96103
testCommand = "test",
97104
updateCommand = "update"
98105
)
99106

100-
@Test def algebra = test(
107+
@Test def algebra = testSbt(
101108
project = "algebra",
102109
testCommand = "coreJVM/compile",
103110
updateCommand = "coreJVM/update"
104111
)
105112

106-
@Test def scalacheck = test(
113+
@Test def scalacheck = testSbt(
107114
project = "scalacheck",
108115
testCommand = "jvm/test:compile",
109116
updateCommand = "jvm/test:update"
110117
)
111118

112-
@Test def scalatest = test(
119+
@Test def scalatest = testSbt(
113120
project = "scalatest",
114121
testCommand = ";scalacticDotty/clean;scalacticTestDotty/test;scalatestTestDotty/test",
115122
updateCommand = "scalatest/update"
116123
)
117124

118-
@Test def scalaXml = test(
125+
@Test def scalaXml = testSbt(
119126
project = "scala-xml",
120127
testCommand = "xml/test",
121128
updateCommand = "xml/update"
122129
)
123130

124-
@Test def scopt = test(
131+
@Test def scopt = testSbt(
125132
project = "scopt",
126133
testCommand = "scoptJVM/compile",
127134
updateCommand = "scoptJVM/update"
128135
)
129136

130-
@Test def scalap = test(
137+
@Test def scalap = testSbt(
131138
project = "scalap",
132139
testCommand = "scalap/compile",
133140
updateCommand = "scalap/update"
134141
)
135142

136-
@Test def squants = test(
143+
@Test def squants = testSbt(
137144
project = "squants",
138145
testCommand = "squantsJVM/compile",
139146
updateCommand = "squantsJVM/update"
140147
)
141148

142-
@Test def betterfiles = test(
149+
@Test def betterfiles = testSbt(
143150
project = "betterfiles",
144151
testCommand = "dotty-community-build/compile",
145152
updateCommand = "dotty-community-build/update"
146153
)
147154

148-
@Test def ScalaPB = test(
155+
@Test def ScalaPB = testSbt(
149156
project = "ScalaPB",
150157
testCommand = "dotty-community-build/compile",
151158
updateCommand = "dotty-community-build/update"
152159
)
153160

154-
@Test def minitest = test(
161+
@Test def minitest = testSbt(
155162
project = "minitest",
156163
testCommand = "dotty-community-build/compile",
157164
updateCommand = "dotty-community-build/update"
158165
)
159166

160-
@Test def fastparse = test(
167+
@Test def fastparse = testSbt(
161168
project = "fastparse",
162169
testCommand = "dotty-community-build/compile;dotty-community-build/test:compile",
163170
updateCommand = "dotty-community-build/update"
164171
)
165172

166173
// TODO: revert to sourcecodeJVM/test
167-
@Test def sourcecode = test(
174+
@Test def sourcecode = testSbt(
168175
project = "sourcecode",
169176
testCommand = "sourcecode/compile;sourcecode/test:compile",
170177
updateCommand = "sourcecode/update"
171178
)
172179

173-
@Test def stdLib213 = test(
180+
@Test def stdLib213 = testSbt(
174181
project = "stdLib213",
175182
testCommand = "library/compile",
176183
updateCommand = "library/update",
177184
extraSbtArgs = Seq("-Dscala.build.compileWithDotty=true")
178185
)
179186

180-
@Test def shapeless = test(
187+
@Test def shapeless = testSbt(
181188
project = "shapeless",
182189
testCommand = "test",
183190
updateCommand = "update"
184191
)
185192

186-
@Test def xmlInterpolator = test(
193+
@Test def xmlInterpolator = testSbt(
187194
project = "xml-interpolator",
188195
testCommand = "test",
189196
updateCommand = "update"
190197
)
191198

192-
@Test def semanticdb = test(
199+
@Test def semanticdb = testSbt(
193200
project = "semanticdb",
194201
testCommand = "test:compile",
195202
updateCommand = "update"
196203
)
197204

198-
@Test def effpi = test(
205+
@Test def effpi = testSbt(
199206
project = "effpi",
200207
// We set `useEffpiPlugin := false` because we don't want to run their
201208
// compiler plugin since it relies on external binaries (from the model
@@ -225,6 +232,6 @@ class UpdateCategory
225232

226233
@Category(Array(classOf[UpdateCategory]))
227234
class CommunityBuildUpdate extends CommunityBuildTest {
228-
override def test(project: String, testCommand: String, updateCommand: String, extraSbtArgs: Seq[String]): Unit =
229-
super.test(project, updateCommand, null, extraSbtArgs)
235+
override def testSbt(project: String, testCommand: String, updateCommand: String, extraSbtArgs: Seq[String]): Unit =
236+
super.testSbt(project, updateCommand, null, extraSbtArgs)
230237
}

0 commit comments

Comments
 (0)