Skip to content

Commit 947e823

Browse files
committed
test: select the right line number for the location spec
depending on the scala version
1 parent 5e675ce commit 947e823

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

build.sbt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,16 @@ lazy val common = crossProject(platforms: _*)
105105
lazy val core = crossProject(platforms: _*)
106106
.withoutSuffixFor(jvm)
107107
.in(file("core"))
108+
.enablePlugins(BuildInfoPlugin)
108109
.settings(
109110
name := "specs2-core",
110111
commonSettings,
111112
depends.junitTest,
112113
// until 5.0.0-RC-23 is published
113114
// mimaPreviousArtifacts := Set.empty,
114-
mimaFailOnNoPrevious := false
115+
mimaFailOnNoPrevious := false,
116+
buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion),
117+
buildInfoPackage := "org.specs2"
115118
)
116119
.jvmSettings(commonJvmSettings)
117120
.jsSettings(commonJsSettings)

core/jvm/src/test/scala/org/specs2/io/LocationSpec.scala

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class LocationSpec extends org.specs2.mutable.Spec with TypedEqual:
1515
given spec: LocationUnitSpecification = new LocationUnitSpecification(ee)
1616

1717
"for the first piece of text, with 'should'" >> {
18-
textAt(index = 0) === 16
18+
textAt(index = 0) === lineNumber(16, 13)
1919
}
2020
"for the first example, with 'in'" >> {
2121
exampleAt(index = 0) === 14
@@ -24,13 +24,13 @@ class LocationSpec extends org.specs2.mutable.Spec with TypedEqual:
2424
exampleAt(index = 1) === 15
2525
}
2626
"for the second piece of text, with '>>'" >> {
27-
textAt(index = 1) === 23
27+
textAt(index = 1) === lineNumber(23, 18)
2828
}
2929
"for the 3rd example, with '>>'" >> {
30-
exampleAt(index = 2) === 20
30+
exampleAt(index = 2) === lineNumber(20, 19)
3131
}
3232
"for the 4th example, with '>>'" >> {
33-
exampleAt(index = 3) === 22
33+
exampleAt(index = 3) === lineNumber(22, 21)
3434
}
3535
}
3636

@@ -60,6 +60,10 @@ class LocationSpec extends org.specs2.mutable.Spec with TypedEqual:
6060
}
6161
}
6262

63+
def lineNumber(on322: Int, onLater: Int): Int =
64+
val scalaVersion = org.specs2.BuildInfo.scalaVersion
65+
if scalaVersion == "3.2.2" then on322 else onLater
66+
6367
def textAt(index: Int)(using spec: WithFragments) = fragmentLine(isText, index)
6468
def exampleAt(index: Int)(using spec: WithFragments) = fragmentLine(isExample, index)
6569
def brAt(index: Int)(using spec: WithFragments) = fragmentLine(isFormatting, index)

0 commit comments

Comments
 (0)