-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.sbt
203 lines (184 loc) · 5.74 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
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.15"
def scala212 = "2.12.20"
def scala3 = "3.3.4"
def junitVersion = "4.13.2"
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",
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)
val scala3Versions = List(scala3)
val allScalaVersions = scala2Versions ++ scala3Versions
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.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
)
val sharedNativeConfigure: Project => Project =
_.disablePlugins(ScalafixPlugin, MimaPlugin)
val sharedSettings = List(
scalacOptions ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
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 munitScalacheck = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.in(file("munit-scalacheck"))
.settings(
moduleName := "munit-scalacheck",
sharedSettings,
libraryDependencies ++= Seq(
"org.scalacheck" %%% "scalacheck" % "1.18.1",
"org.scalameta" %%% "munit-diff" % "1.0.2",
"org.scalameta" %%% "munit" % "1.0.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(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
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 (isScala2(partialVersion)) {
result += base / "scala-2"
}
result.toList
}