forked from scalameta/munit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
384 lines (364 loc) · 11.7 KB
/
build.sbt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
import com.typesafe.tools.mima.core._
import sbtcrossproject.CrossPlugin.autoImport.crossProject
import sbtcrossproject.CrossPlugin.autoImport.CrossType
import scala.collection.mutable
def previousVersion = "0.7.0"
def scala213 = "2.13.11"
def scala212 = "2.12.18"
def scala211 = "2.11.12"
def scala3 = "3.1.2"
def junitVersion = "4.13.2"
def gcp = "com.google.cloud" % "google-cloud-storage" % "2.26.1"
inThisBuild(
List(
version ~= { old =>
if ("true" == System.getProperty("CI") && old.contains("+0-")) {
old.replaceAll("\\+0-.*", "")
} else {
old
}
},
organization := "org.scalameta",
homepage := Some(url("https://github.com/scalameta/munit")),
licenses := List(
"Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")
),
developers := List(
Developer(
"olafurpg",
"Ólafur Páll Geirsson",
"olafurpg@gmail.com",
url("https://geirsson.com")
)
),
scalaVersion := scala213,
useSuperShell := false
)
)
publish / skip := true
mimaPreviousArtifacts := Set.empty
crossScalaVersions := List()
addCommandAlias(
"scalafixAll",
s"; ++$scala212 ; scalafixEnable ; all scalafix test:scalafix"
)
addCommandAlias(
"scalafixCheckAll",
s"; ++$scala212 ; scalafixEnable ; scalafix --check ; test:scalafix --check"
)
val isPreScala213 = Set[Option[(Long, Long)]](Some((2, 11)), Some((2, 12)))
val scala2Versions = List(scala213, scala212, scala211)
val scala3Versions = List(scala3)
val allScalaVersions = scala2Versions ++ scala3Versions
def isNotScala211(v: Option[(Long, Long)]): Boolean = !v.contains((2, 11))
def isScala2(v: Option[(Long, Long)]): Boolean = v.exists(_._1 == 2)
val isScala3Setting = Def.setting {
isScala3(CrossVersion.partialVersion(scalaVersion.value))
}
def isScala3(v: Option[(Long, Long)]): Boolean = v.exists(_._1 == 3)
// NOTE(olafur): disable Scala.js and Native settings for IntelliJ.
lazy val skipIdeaSettings =
SettingKey[Boolean]("ide-skip-project").withRank(KeyRanks.Invisible) := true
lazy val mimaEnable: List[Def.Setting[_]] = List(
mimaBinaryIssueFilters ++= List(
ProblemFilters.exclude[DirectMissingMethodProblem](
"munit.MUnitRunner.descriptions"
),
ProblemFilters.exclude[DirectMissingMethodProblem](
"munit.MUnitRunner.testNames"
),
ProblemFilters.exclude[DirectMissingMethodProblem](
"munit.MUnitRunner.munitTests"
),
ProblemFilters.exclude[DirectMissingMethodProblem](
"munit.ValueTransforms.munitTimeout"
),
ProblemFilters.exclude[MissingTypesProblem]("munit.FailException"),
ProblemFilters.exclude[MissingTypesProblem]("munit.FailSuiteException"),
ProblemFilters.exclude[MissingTypesProblem](
"munit.TestValues$FlakyFailure"
),
ProblemFilters.exclude[DirectMissingMethodProblem](
"munit.internal.junitinterface.JUnitComputer.this"
),
// Known breaking changes for MUnit v1
ProblemFilters.exclude[DirectMissingMethodProblem](
"munit.Assertions.assertNotEquals"
),
ProblemFilters.exclude[DirectMissingMethodProblem](
"munit.Assertions.assertEquals"
),
ProblemFilters.exclude[IncompatibleMethTypeProblem](
"munit.Assertions.assertNotEquals"
),
ProblemFilters.exclude[IncompatibleMethTypeProblem](
"munit.Assertions.assertEquals"
),
ProblemFilters.exclude[IncompatibleMethTypeProblem](
"munit.FunSuite.assertNotEquals"
),
ProblemFilters.exclude[IncompatibleMethTypeProblem](
"munit.FunSuite.assertEquals"
),
ProblemFilters.exclude[IncompatibleMethTypeProblem](
"munit.FunSuite.munitTestTransform"
),
ProblemFilters.exclude[MissingClassProblem]("munit.GenericAfterEach"),
ProblemFilters.exclude[MissingClassProblem]("munit.GenericBeforeEach"),
ProblemFilters.exclude[MissingClassProblem]("munit.GenericTest"),
ProblemFilters.exclude[DirectMissingMethodProblem](
"munit.MUnitRunner.createTestDescription"
),
ProblemFilters.exclude[IncompatibleMethTypeProblem](
"munit.Suite.beforeEach"
),
ProblemFilters.exclude[IncompatibleMethTypeProblem](
"munit.Suite.afterEach"
),
ProblemFilters.exclude[MissingClassProblem]("munit.Suite$Fixture"),
ProblemFilters.exclude[IncompatibleMethTypeProblem](
"munit.TestTransforms#TestTransform.apply"
),
ProblemFilters.exclude[IncompatibleMethTypeProblem](
"munit.FunFixtures#FunFixture.this"
),
ProblemFilters.exclude[IncompatibleMethTypeProblem](
"munit.SuiteTransforms#SuiteTransform.this"
),
ProblemFilters.exclude[IncompatibleMethTypeProblem](
"munit.TestTransforms#TestTransform.this"
),
ProblemFilters.exclude[IncompatibleMethTypeProblem](
"munit.ValueTransforms#ValueTransform.this"
),
ProblemFilters.exclude[DirectMissingMethodProblem](
"munit.ScalaCheckSuite.unitToProp"
)
),
mimaPreviousArtifacts := {
if (crossPaths.value)
Set("org.scalameta" %% moduleName.value % previousVersion)
else Set("org.scalameta" % moduleName.value % previousVersion)
}
)
val sharedJVMSettings: List[Def.Setting[_]] = List(
crossScalaVersions := allScalaVersions
) ++ mimaEnable
val sharedJSSettings: List[Def.Setting[_]] = List(
skipIdeaSettings,
crossScalaVersions := allScalaVersions.filterNot(_.startsWith("0."))
)
val sharedJSConfigure: Project => Project =
_.disablePlugins(MimaPlugin)
val sharedNativeSettings: List[Def.Setting[_]] = List(
skipIdeaSettings,
crossScalaVersions := allScalaVersions.filterNot(_ == scala211)
)
val sharedNativeConfigure: Project => Project =
_.disablePlugins(ScalafixPlugin, MimaPlugin)
val sharedSettings = List(
scalacOptions ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 11)) =>
List(
"-Yrangepos",
"-Xexperimental",
"-Ywarn-unused-import",
"-target:jvm-1.8"
)
case Some((major, _)) if major != 2 =>
List(
"-language:implicitConversions"
)
case _ =>
List(
"-target:jvm-1.8",
"-Yrangepos",
// -Xlint is unusable because of
// https://github.com/scala/bug/issues/10448
"-Ywarn-unused:imports"
)
}
}
)
lazy val junit = project
.in(file("junit-interface"))
.settings(
mimaEnable,
moduleName := "junit-interface",
description := "A Java implementation of sbt's test interface for JUnit 4",
autoScalaLibrary := false,
crossPaths := false,
sbtPlugin := false,
crossScalaVersions := List(allScalaVersions.head),
libraryDependencies ++= List(
"junit" % "junit" % junitVersion,
"org.scala-sbt" % "test-interface" % "1.0"
),
Compile / javacOptions ++= List("-target", "1.8", "-source", "1.8"),
Compile / doc / javacOptions --= List("-target", "1.8")
)
lazy val munit = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.settings(
sharedSettings,
Compile / unmanagedSourceDirectories ++=
crossBuildingDirectories("munit", "main").value,
libraryDependencies ++= List(
"org.scala-lang" % "scala-reflect" % {
if (isScala3Setting.value) scala213
else scalaVersion.value
} % Provided
)
)
.nativeConfigure(sharedNativeConfigure)
.nativeSettings(
sharedNativeSettings,
libraryDependencies ++= List(
"org.scala-native" %%% "test-interface" % nativeVersion
)
)
.jsConfigure(sharedJSConfigure)
.jsSettings(
sharedJSSettings,
libraryDependencies ++= List(
("org.scala-js" %% "scalajs-test-interface" % scalaJSVersion)
.cross(CrossVersion.for3Use2_13),
("org.scala-js" %% "scalajs-junit-test-runtime" % scalaJSVersion)
.cross(CrossVersion.for3Use2_13)
)
)
.jvmSettings(
sharedJVMSettings,
libraryDependencies ++= List(
"junit" % "junit" % junitVersion
)
)
.jvmConfigure(_.dependsOn(junit))
lazy val munitJVM = munit.jvm
lazy val munitJS = munit.js
lazy val munitNative = munit.native
lazy val plugin = project
.in(file("munit-sbt"))
.enablePlugins(BuildInfoPlugin)
.settings(
sharedSettings,
moduleName := "sbt-munit",
sbtPlugin := true,
scalaVersion := scala212,
crossScalaVersions := List(scala212),
buildInfoPackage := "munit.sbtmunit",
buildInfoKeys := Seq[BuildInfoKey](
"munitVersion" -> version.value
),
crossScalaVersions := List(scala212),
libraryDependencies ++= List(
gcp
)
)
.disablePlugins(MimaPlugin)
lazy val munitScalacheck = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.in(file("munit-scalacheck"))
.dependsOn(munit)
.settings(
moduleName := "munit-scalacheck",
sharedSettings,
libraryDependencies += {
val partialVersion = CrossVersion.partialVersion(scalaVersion.value)
if (isNotScala211(partialVersion))
"org.scalacheck" %%% "scalacheck" % "1.17.0"
else
"org.scalacheck" %%% "scalacheck" % "1.15.2"
}
)
.jvmSettings(
sharedJVMSettings
)
.nativeConfigure(sharedNativeConfigure)
.nativeSettings(
sharedNativeSettings
)
.jsConfigure(sharedJSConfigure)
.jsSettings(sharedJSSettings)
lazy val munitScalacheckJVM = munitScalacheck.jvm
lazy val munitScalacheckJS = munitScalacheck.js
lazy val munitScalacheckNative = munitScalacheck.native
lazy val tests = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.dependsOn(munit, munitScalacheck)
.enablePlugins(BuildInfoPlugin)
.settings(
sharedSettings,
buildInfoPackage := "munit",
buildInfoKeys := Seq[BuildInfoKey](
"sourceDirectory" ->
((ThisBuild / baseDirectory).value / "tests" / "shared" / "src" / "main").getAbsolutePath.toString,
scalaVersion
),
Test / unmanagedSourceDirectories ++=
crossBuildingDirectories("tests", "test").value,
publish / skip := true
)
.nativeConfigure(sharedNativeConfigure)
.nativeSettings(sharedNativeSettings)
.jsConfigure(sharedJSConfigure)
.jsSettings(
sharedJSSettings,
jsEnv := {
val log = sLog.value
if (Option(System.getenv("GITHUB_JOB")).contains("jsdom")) {
log.info("Testing in JSDOMNodeJSEnv")
new org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv
} else {
log.info("Testing in NodeJSEnv")
new org.scalajs.jsenv.nodejs.NodeJSEnv
}
}
)
.jvmSettings(
sharedJVMSettings,
fork := true,
Test / parallelExecution := true,
Test / testOptions += Tests.Argument(TestFrameworks.MUnit, "+b")
)
.disablePlugins(MimaPlugin)
lazy val testsJVM = tests.jvm
lazy val testsJS = tests.js
lazy val testsNative = tests.native
lazy val docs = project
.in(file("munit-docs"))
.dependsOn(munitJVM, munitScalacheckJVM)
.enablePlugins(MdocPlugin, DocusaurusPlugin)
.disablePlugins(MimaPlugin)
.settings(
sharedSettings,
moduleName := "munit-docs",
crossScalaVersions := List(scala213, scala212),
test := {},
mdocOut :=
(ThisBuild / baseDirectory).value / "website" / "target" / "docs",
mdocExtraArguments := List("--no-link-hygiene"),
mdocVariables := Map(
"VERSION" -> version.value.replaceFirst("\\+.*", ""),
"STABLE_VERSION" -> "0.7.29"
),
fork := false
)
Global / excludeLintKeys ++= Set(
mimaPreviousArtifacts
)
def crossBuildingDirectories(name: String, config: String) =
Def.setting[Seq[File]] {
val root = (ThisBuild / baseDirectory).value / name
val base = root / "shared" / "src" / config
val result = mutable.ListBuffer.empty[File]
val partialVersion = CrossVersion.partialVersion(scalaVersion.value)
if (isPreScala213(partialVersion)) {
result += base / "scala-pre-2.13"
}
if (isNotScala211(partialVersion)) {
result += base / "scala-post-2.11"
}
if (isScala2(partialVersion)) {
result += base / "scala-2"
}
result.toList
}