Skip to content

Commit ffbe5e0

Browse files
Abstract SBT-specific logic from community build tests
1 parent d024d29 commit ffbe5e0

File tree

1 file changed

+49
-44
lines changed

1 file changed

+49
-44
lines changed

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

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,29 @@ 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) = test(project) {
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+
("sbt", arguments)
40+
}
41+
1942
/** Build the given project with the published local compiler and sbt plugin.
2043
*
2144
* This test reads the compiler version from community-build/dotty-bootstrapped.version
@@ -26,7 +49,7 @@ class CommunityBuildTest {
2649
* @param updateCommand The sbt command used to update the project
2750
* @param extraSbtArgs Extra arguments to pass to sbt
2851
*/
29-
def test(project: String, testCommand: String, updateCommand: String, extraSbtArgs: Seq[String] = Nil): Unit = {
52+
def test(project: String)(commandAndArgs: => (String, Seq[String])): Unit = {
3053
def log(msg: String) = println(Console.GREEN + msg + Console.RESET)
3154

3255
log(s"Building $project with dotty-bootstrapped $compilerVersion...")
@@ -53,149 +76,131 @@ class CommunityBuildTest {
5376
exitCode
5477
}
5578

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: _*)
79+
val (command, arguments) = commandAndArgs
80+
val exitCode = exec(command, arguments: _*)
7681

7782
if (exitCode != 0) {
7883
fail(s"""
7984
|
80-
|sbt exited with an error code. To reproduce without JUnit, use:
85+
|$command exited with an error code. To reproduce without JUnit, use:
8186
|
8287
| sbt community-build/prepareCommunityBuild
8388
| cd community-build/community-projects/$project
84-
| sbt ${arguments.init.mkString(" ")} "${arguments.last}"
89+
| $command ${arguments.init.mkString(" ")} "${arguments.last}"
8590
|
86-
|For a faster feedback loop, one can try to extract a direct call to dotc
91+
|For a faster feedback loop on SBT projects, one can try to extract a direct call to dotc
8792
|using the sbt export command. For instance, for scalacheck, use
8893
| sbt export jvm/test:compileIncremental
8994
|
9095
|""".stripMargin)
9196
}
9297
}
9398

94-
@Test def intent = test(
99+
@Test def intent = testSbt(
95100
project = "intent",
96101
testCommand = "test",
97102
updateCommand = "update"
98103
)
99104

100-
@Test def algebra = test(
105+
@Test def algebra = testSbt(
101106
project = "algebra",
102107
testCommand = "coreJVM/compile",
103108
updateCommand = "coreJVM/update"
104109
)
105110

106-
@Test def scalacheck = test(
111+
@Test def scalacheck = testSbt(
107112
project = "scalacheck",
108113
testCommand = "jvm/test:compile",
109114
updateCommand = "jvm/test:update"
110115
)
111116

112-
@Test def scalatest = test(
117+
@Test def scalatest = testSbt(
113118
project = "scalatest",
114119
testCommand = ";scalacticDotty/clean;scalacticTestDotty/test;scalatestTestDotty/test",
115120
updateCommand = "scalatest/update"
116121
)
117122

118-
@Test def scalaXml = test(
123+
@Test def scalaXml = testSbt(
119124
project = "scala-xml",
120125
testCommand = "xml/test",
121126
updateCommand = "xml/update"
122127
)
123128

124-
@Test def scopt = test(
129+
@Test def scopt = testSbt(
125130
project = "scopt",
126131
testCommand = "scoptJVM/compile",
127132
updateCommand = "scoptJVM/update"
128133
)
129134

130-
@Test def scalap = test(
135+
@Test def scalap = testSbt(
131136
project = "scalap",
132137
testCommand = "scalap/compile",
133138
updateCommand = "scalap/update"
134139
)
135140

136-
@Test def squants = test(
141+
@Test def squants = testSbt(
137142
project = "squants",
138143
testCommand = "squantsJVM/compile",
139144
updateCommand = "squantsJVM/update"
140145
)
141146

142-
@Test def betterfiles = test(
147+
@Test def betterfiles = testSbt(
143148
project = "betterfiles",
144149
testCommand = "dotty-community-build/compile",
145150
updateCommand = "dotty-community-build/update"
146151
)
147152

148-
@Test def ScalaPB = test(
153+
@Test def ScalaPB = testSbt(
149154
project = "ScalaPB",
150155
testCommand = "dotty-community-build/compile",
151156
updateCommand = "dotty-community-build/update"
152157
)
153158

154-
@Test def minitest = test(
159+
@Test def minitest = testSbt(
155160
project = "minitest",
156161
testCommand = "dotty-community-build/compile",
157162
updateCommand = "dotty-community-build/update"
158163
)
159164

160-
@Test def fastparse = test(
165+
@Test def fastparse = testSbt(
161166
project = "fastparse",
162167
testCommand = "dotty-community-build/compile;dotty-community-build/test:compile",
163168
updateCommand = "dotty-community-build/update"
164169
)
165170

166171
// TODO: revert to sourcecodeJVM/test
167-
@Test def sourcecode = test(
172+
@Test def sourcecode = testSbt(
168173
project = "sourcecode",
169174
testCommand = "sourcecode/compile;sourcecode/test:compile",
170175
updateCommand = "sourcecode/update"
171176
)
172177

173-
@Test def stdLib213 = test(
178+
@Test def stdLib213 = testSbt(
174179
project = "stdLib213",
175180
testCommand = "library/compile",
176181
updateCommand = "library/update",
177182
extraSbtArgs = Seq("-Dscala.build.compileWithDotty=true")
178183
)
179184

180-
@Test def shapeless = test(
185+
@Test def shapeless = testSbt(
181186
project = "shapeless",
182187
testCommand = "test",
183188
updateCommand = "update"
184189
)
185190

186-
@Test def xmlInterpolator = test(
191+
@Test def xmlInterpolator = testSbt(
187192
project = "xml-interpolator",
188193
testCommand = "test",
189194
updateCommand = "update"
190195
)
191196

192-
@Test def semanticdb = test(
197+
@Test def semanticdb = testSbt(
193198
project = "semanticdb",
194199
testCommand = "test:compile",
195200
updateCommand = "update"
196201
)
197202

198-
@Test def effpi = test(
203+
@Test def effpi = testSbt(
199204
project = "effpi",
200205
// We set `useEffpiPlugin := false` because we don't want to run their
201206
// compiler plugin since it relies on external binaries (from the model
@@ -225,6 +230,6 @@ class UpdateCategory
225230

226231
@Category(Array(classOf[UpdateCategory]))
227232
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)
233+
override def testSbt(project: String, testCommand: String, updateCommand: String, extraSbtArgs: Seq[String]): Unit =
234+
super.testSbt(project, updateCommand, null, extraSbtArgs)
230235
}

0 commit comments

Comments
 (0)