Skip to content

Commit

Permalink
feature: remove the xml dependency from specs2-core
Browse files Browse the repository at this point in the history
  • Loading branch information
symbiont-eric-torreborre committed May 1, 2021
1 parent ebb5369 commit b283a6c
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 59 deletions.
35 changes: 28 additions & 7 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ lazy val specs2 = project.in(file(".")).
name := "specs2",
packagedArtifacts := Map.empty,
ThisBuild / githubWorkflowArtifactUpload := false,
Global / onChangedBuildSource := ReloadOnSourceChanges,
test := {}
).aggregate(
fpJVM, catsJVM, commonJVM, matcherJVM, coreJVM, matcherExtraJVM, scalazJVM, html,
analysisJVM, shapelessJVM, formJVM, markdownJVM, gwtJVM, junitJVM, scalacheckJVM, mockJVM,
analysisJVM, shapelessJVM, formJVM, markdownJVM, gwtJVM, junitJVM, scalacheckJVM, mockJVM, xmlJVM,
tests, fpJS, catsJS, commonJS, matcherJS, coreJS, matcherExtraJS, scalazJS, analysisJS,
shapelessJS, junitJS, scalacheckJS, mockJS
shapelessJS, junitJS, scalacheckJS, mockJS, xmlJS
)

val scala211 = "2.11.12"
Expand Down Expand Up @@ -119,7 +120,7 @@ lazy val common = crossProject(JSPlatform, JVMPlatform, NativePlatform).in(file(
libraryDependencies ++=
depends.paradise(scalaVersion.value) ++
Seq(depends.reflect(scalaOrganization.value, scalaVersion.value),
depends.scalaXML, depends.scalacheck.value % Test),
depends.scalacheck.value % Test),
commonSettings,
name := "specs2-common"
).
Expand Down Expand Up @@ -199,7 +200,7 @@ lazy val form = crossProject(JSPlatform, JVMPlatform, NativePlatform).
jvmSettings(depends.jvmTest, commonJvmSettings).
jsSettings(depends.jsTest, commonJsSettings).
nativeSettings(depends.nativeTest, commonNativeSettings).
dependsOn(core, markdown, matcherExtra, scalacheck % "test->test")
dependsOn(core, markdown, matcherExtra, scalacheck % "test->test", xml)

lazy val formJVM = form.jvm
lazy val formJS = form.js
Expand Down Expand Up @@ -235,12 +236,13 @@ lazy val html = project.in(file("html")).
commonSettings,
name := "specs2-html").
settings(depends.jvmTest, commonJvmSettings).
dependsOn(formJVM, mockJVM % Test, matcherExtraJVM % Test, scalacheckJVM % Test)
dependsOn(formJVM, mockJVM % Test, matcherExtraJVM % Test, scalacheckJVM % Test, xmlJVM)

lazy val junit = crossProject(JSPlatform, JVMPlatform, NativePlatform).in(file("junit")).
settings(
libraryDependencies ++= Seq(
depends.junit,
depends.scalaXml,
depends.mockito % Test),
commonSettings,
name := "specs2-junit").
Expand All @@ -256,7 +258,9 @@ lazy val markdown = crossProject(JSPlatform, JVMPlatform, NativePlatform).
crossType(CrossType.Pure).
in(file("markdown")).
settings(
libraryDependencies += depends.pegdown,
libraryDependencies ++= Seq(
depends.pegdown,
depends.scalaXml),
commonSettings,
name := "specs2-markdown").
jvmSettings(depends.jvmTest, commonJvmSettings).
Expand Down Expand Up @@ -290,7 +294,7 @@ lazy val matcherExtra = crossProject(JSPlatform, JVMPlatform, NativePlatform).in
jsSettings(depends.jsTest, commonJsSettings).
jvmSettings(depends.jvmTest, commonJvmSettings).
nativeSettings(depends.nativeTest, commonNativeSettings).
dependsOn(analysis, matcher, core % "test->test")
dependsOn(analysis, matcher, xml, core % "test->test")

lazy val matcherExtraJS = matcherExtra.js
lazy val matcherExtraJVM = matcherExtra.jvm
Expand Down Expand Up @@ -386,6 +390,22 @@ lazy val tests = Project(id = "tests", base = file("tests")).
scalazJVM,
catsJVM)

lazy val xml = crossProject(JSPlatform, JVMPlatform, NativePlatform).in(file("xml")).
settings(
libraryDependencies += depends.scalaXml,
commonSettings,
name := "xml"
).
jsSettings(depends.jsTest, commonJsSettings).
jvmSettings(depends.jvmTest, commonJvmSettings).
nativeSettings(commonNativeSettings, depends.nativeTest).
platformsSettings(JSPlatform, NativePlatform)(commonJsNativeSettings).
dependsOn(core)

lazy val xmlJS = xml.js
lazy val xmlJVM = xml.jvm
lazy val xmlNative = xml.native

lazy val specs2ShellPrompt = ThisBuild / shellPrompt := { state =>
val name = Project.extract(state).currentRef.project
(if (name == "specs2") "" else name) + "> "
Expand Down Expand Up @@ -500,6 +520,7 @@ lazy val publicationSettings = Seq(
publishMavenStyle := true,
Test / publishArtifact := false,
pomIncludeRepository := { x => false },
Global / pgpPassphrase := None,
pomExtra := (
<url>http://specs2.org/</url>
<licenses>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ class IterablexSpec extends Specification with IterableData with ScalaCheckResul
"if deeply nested lists have the same elements but in a different order" >> {
List(1, List(2, 3, List(4)), 5).sameElementsAs(List(5, List(List(4), 2, 3), 1))
}
"when comparing xml nodes in a different order" >> {
<a> <b/> <c/> </a>.child.sameElementsAs(<a> <c/> <b/> </a>.child)
}
"for 2 iterables created with same elements in a different order" >> {
implicit val iterables = arbitraryIterable
Prop.forAll { i1: Iterable[Any] =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import org.specs2.fp.syntax._
import execute.StandardResults
import text._
import Plural._
import control.Exceptions._
import time.SimpleTimer
import scala.xml._

/**
* The Stats class store results for the number of:
Expand Down Expand Up @@ -77,27 +75,6 @@ case class Stats(specs: Int = 0,
case DecoratedResult(_, r) => withResult(r)
}

/**
* @return the xml representation of the statistics. Omit the attributes with 0 as a value for conciseness
*/
def toXml: Elem = {
val stats = <stats>{trend.map(t => <trend>{t.toXml}</trend>).getOrElse(NodeSeq.Empty)}</stats>
val attributes = Map(
"specs" -> specs.toString,
"examples" -> examples.toString,
"successes" -> successes.toString,
"expectations" -> expectations.toString,
"failures" -> failures.toString,
"errors" -> errors.toString,
"pending" -> pending.toString,
"skipped" -> skipped.toString,
"time" -> timer.totalMillis.toString)
attributes.foldLeft(stats) { (res, cur) =>
if (cur._2 == "0") res
else res % new UnprefixedAttribute(cur._1, cur._2, Null)
}
}

override def toString =
"Stats("+
"specs = " + specs +", "+
Expand Down Expand Up @@ -231,24 +208,4 @@ case object Stats {
case DecoratedResult(_, r) => Stats(r)
}

def fromXml(stats: scala.xml.Node): Option[Stats] = {
if (stats.label != Stats.empty.toXml.label)
None
else {
val map = stats.attributes.asAttrMap
def asInt(key: String, defaultValue: Int = 0) = tryOrElse(Integer.parseInt(map(key)))(defaultValue)

Some(Stats(
asInt("specs" ),
asInt("examples" ),
asInt("successes" ),
asInt("expectations", 1),
asInt("failures" ),
asInt("errors" ),
asInt("pending" ),
asInt("skipped" ),
(stats \ "trend" \ "stats").headOption.flatMap(fromXml),
map.get("time").map(SimpleTimer.fromString).getOrElse(new SimpleTimer)))
}
}
}
41 changes: 41 additions & 0 deletions etorreborre.pub
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
-----BEGIN PGP PUBLIC KEY BLOCK-----

mQGNBGCBalABDADCpYxP2glZUYJKS/LKs5zqvOrCITt8cQ4u1KRaAZbyd6kP1Cfb
ZthNv9rjVK4txBNEcn6v145ATlyoEJn0M5pRmdr7zy4WhRw+qVWrYe/sMLF9uAlO
cNjFJi3+rMUZXdhgMxFEjELTdb/lKh8V4znbSHYMLZVOBRxv8mbCQaSFzOTh/jOA
pkgxmcgRi9C3FdsQMWoyNNM5PvxBBhpSG7y4kyjyHWCWS6/F3ve54jWK9C9XnSo8
CJ0QYT0zJQiP3zWB0zL6GzMcVpNASopwmERpeTE+Y4yOj3+MbbJiuOtHCBmY6i+3
LyKwfRZhSGW/PvhQfU6xC9zK08ShobIn1N5M2VQiJKxwyKekazKetMql9/FwqmXm
hqnOhFWGFseXn+X73K99h5p6eyLgZQL6K1wFwI+XJ/PLdDeosYUYhcveM1bGM3Uf
b1F5qfQjlBg0q/XOnBE8Q1Tn+OfbJnQaYyylKUfEdkgDEJqFQp9Z3Ae0JuMeX9+I
EYMifkq0y2wp7QEAEQEAAbQnRXJpYyBUb3JyZWJvcnJlIDxldG9ycmVib3JyZUB5
YWhvby5jb20+iQHUBBMBCAA+FiEEyhuaEezdPic91D5fxDnwNCA4SywFAmCBalAC
GwMFCQPCZwAFCwkIBwIGFQoJCAsCB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z
TYzmyP/jAwUhhqsAEQEAAYkBvAQYAQgAJhYhBMobmhHs3T4nPdQ+X8Q58DQgOEss
BQJggWpQAhsMBQkDwmcAAAoJEMQ58DQgOEssA9QL/RlE907tqoQb6faVUbIw8X3S
RbhD98YZruNLvUTaod7D7YKVvAOnnthy+SD1jgeaqMjbIOy/nB0xfmMIC1BNXqLP
i9RU01XQ5Nfdx1jiMp6TCOrmIR0OnO8BKQ3lFBg/TtH26yfqi70OMBYzNXNMqXC3
IIq/VD2DRRL1fPTph/nGFcfVOgMhy2XCq+Pb7WX/Gskeai9Ob2d8S1FEK3baYUWN
Bf6pIUlf4i0DGjJHOD9Na/iarFOVB8T9CFh/aYPAxLc5Lofce1lN61uins8aMQRv
Bbm1CJ0GGJ7CpdKeKxhi/YN+FLIvOOE4FC8eMvuSo+WtEB75VfCEh3Qfg8144rDD
r9ZtpKiixQJu217w7FiGMm0MqqsSRVOvXIPiN8Nz7Cr2M0T+n0feiRgbyDFsWlL1
QZ5e4M28NWOLOkmhmwhdQ9iqUMuTJNPb51JrgCI4dydkUcOIrBBpWP1nBSjZsibv
0g/2ums/UV+c7jEx8eh7UW7CF8jvOo/tsSnHlTxTDw==
=V4HB
-----END PGP PUBLIC KEY BLOCK-----
3 changes: 1 addition & 2 deletions project/depends.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ object depends {

def reflect(scalaOrganization: String, scalaVersion: String) = scalaOrganization % "scala-reflect" % scalaVersion


def scalaz(scalazVersion: String) =
Seq("org.scalaz" %% "scalaz-core",
"org.scalaz" %% "scalaz-effect").map(_ % scalazVersion)
Expand Down Expand Up @@ -45,7 +44,7 @@ object depends {
scalaParser.value
}

def scalaXML = "org.scala-lang.modules" %% "scala-xml" % "1.3.0"
def scalaXml = "org.scala-lang.modules" %% "scala-xml" % "1.3.0"

lazy val mockito = "org.mockito" % "mockito-core" % "3.9.0"
lazy val junit = "junit" % "junit" % "4.13.2"
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVer
addSbtPlugin("org.scala-native" % "sbt-scala-native" % scalaNativeVersion)
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.0.0")
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.0.0")
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.1.2")
addSbtPlugin("io.crashbox" % "sbt-gpg" % "0.2.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % "0.6.3")
addSbtPlugin("com.typesafe.sbt" % "sbt-site" % "1.4.1")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1")
Expand Down
3 changes: 2 additions & 1 deletion version.sbt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
ThisBuild / version := "4.10.6"
ThisBuild / version := "4.11.0"
ThisBuild / versionScheme := Some("semver-spec")
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package xml
import Nodex._
import scala.xml._
import scala.xml.NodeSeq._
import collection.Iterablex._

class NodexSpec extends Spec { def is = s2"""

Expand Down Expand Up @@ -43,5 +44,9 @@ class NodexSpec extends Spec { def is = s2"""
isEqualIgnoringSpaceOrdered returns true if 2 NodeSeqs are the same regardless of spaces and order
${ <a><b/><c/></a> isEqualIgnoringSpaceOrdered <a><b/><c/></a> }
${ !(<a><b/><c/></a> isEqualIgnoringSpaceOrdered <a><c/><b/></a>) }
"""
}

when comparing xml nodes in a different order
${ <a> <b/> <c/> </a>.child.sameElementsAs(<a> <c/> <b/> </a>.child) }

"""
}

0 comments on commit b283a6c

Please sign in to comment.