diff options
author | Nikolay Tatarinov <5min4eq.unity@gmail.com> | 2018-03-06 10:22:01 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-06 10:22:01 +0300 |
commit | 8ac53668af0ff6ea699e5d99105bd74585057bf1 (patch) | |
tree | c582013b385f73565cd185012b5cafcee544c47c /scalalib/test/src | |
parent | d4a00892f9c9c43e3d0f6906482b27e04d79d8dc (diff) | |
download | mill-8ac53668af0ff6ea699e5d99105bd74585057bf1.tar.gz mill-8ac53668af0ff6ea699e5d99105bd74585057bf1.tar.bz2 mill-8ac53668af0ff6ea699e5d99105bd74585057bf1.zip |
fix optional xml tags in POM (#198)
Diffstat (limited to 'scalalib/test/src')
-rw-r--r-- | scalalib/test/src/mill/scalalib/publish/PomTests.scala | 199 |
1 files changed, 199 insertions, 0 deletions
diff --git a/scalalib/test/src/mill/scalalib/publish/PomTests.scala b/scalalib/test/src/mill/scalalib/publish/PomTests.scala new file mode 100644 index 00000000..31e87446 --- /dev/null +++ b/scalalib/test/src/mill/scalalib/publish/PomTests.scala @@ -0,0 +1,199 @@ +package mill.scalalib.publish + +import utest._ +import mill._ + +import scala.xml.{NodeSeq, XML} + +object PomTests extends TestSuite { + + def tests: Tests = Tests { + val artifactId = "mill-scalalib_2.12" + val artifact = + Artifact("com.lihaoyi", "mill-scalalib_2.12", "0.0.1") + val deps = Agg( + Dependency(Artifact("com.lihaoyi", "mill-main_2.12", "0.1.4"), + Scope.Compile), + Dependency(Artifact("org.scala-sbt", "test-interface", "1.0"), + Scope.Compile) + ) + val settings = PomSettings( + description = "mill-scalalib", + organization = "com.lihaoyi", + url = "https://github.com/lihaoyi/mill", + licenses = Seq(License.`MIT`), + versionControl = VersionControl.github("lihaoyi", "mill"), + developers = List( + Developer("lihaoyi", + "Li Haoyi", + "https://github.com/lihaoyi", + None, + None), + Developer("rockjam", + "Nikolai Tatarinov", + "https://github.com/rockjam", + Some("80pct done Inc."), + Some("https://80pctdone.com/")) + ) + ) + + 'fullPom - { + val fullPom = pomXml(artifact, deps, artifactId, settings) + + 'topLevel - { + assert( + singleText(fullPom \ "modelVersion") == "4.0.0", + singleText(fullPom \ "name") == artifactId, + singleText(fullPom \ "groupId") == artifact.group, + singleText(fullPom \ "artifactId") == artifact.id, + singleText(fullPom \ "packaging") == "jar", + singleText(fullPom \ "description") == settings.description, + singleText(fullPom \ "version") == artifact.version, + singleText(fullPom \ "url") == settings.url + ) + } + + 'licenses - { + val licenses = fullPom \ "licenses" \ "license" + + assert(licenses.size == 1) + + val license = licenses.head + val pomLicense = settings.licenses.head + assert( + singleText(license \ "name") == pomLicense.name, + singleText(license \ "url") == pomLicense.url, + singleText(license \ "distribution") == pomLicense.distribution + ) + } + + 'scm - { + val scm = (fullPom \ "scm").head + val pomScm = settings.versionControl + + assert( + optText(scm \ "connection") == pomScm.connection, + optText(scm \ "developerConnection") == pomScm.developerConnection, + optText(scm \ "tag").isEmpty, + optText(scm \ "url") == pomScm.browsableRepository + ) + } + + 'developers - { + val developers = fullPom \ "developers" \ "developer" + + assert(developers.size == 2) + + val pomDevelopers = settings.developers + + assert( + singleText(developers.head \ "id") == pomDevelopers.head.id, + singleText(developers.head \ "name") == pomDevelopers.head.name, + optText(developers.head \ "organization").isEmpty, + optText(developers.head \ "organizationUrl").isEmpty + ) + + assert( + singleText(developers.last \ "id") == pomDevelopers.last.id, + singleText(developers.last \ "name") == pomDevelopers.last.name, + optText(developers.last \ "organization") == pomDevelopers.last.organization, + optText(developers.last \ "organizationUrl") == pomDevelopers.last.organizationUrl + ) + } + + 'dependencies - { + val dependencies = fullPom \ "dependencies" \ "dependency" + + assert(dependencies.size == 2) + + val pomDeps = deps.indexed + + dependencies.zipWithIndex.foreach { + case (dep, index) => + assert( + singleText(dep \ "groupId") == pomDeps(index).artifact.group, + singleText(dep \ "artifactId") == pomDeps(index).artifact.id, + singleText(dep \ "version") == pomDeps(index).artifact.version, + optText(dep \ "scope").isEmpty + ) + } + } + } + + 'pomEmptyScm - { + val updatedSettings = settings.copy( + versionControl = VersionControl( + browsableRepository = Some("git://github.com/lihaoyi/mill.git"), + connection = None, + developerConnection = None, + tag = None + )) + val pomEmptyScm = pomXml(artifact, deps, artifactId, updatedSettings) + + 'scm - { + val scm = (pomEmptyScm \ "scm").head + val pomScm = updatedSettings.versionControl + + assert( + optText(scm \ "connection").isEmpty, + optText(scm \ "developerConnection").isEmpty, + optText(scm \ "tag").isEmpty, + optText(scm \ "url") == pomScm.browsableRepository + ) + } + } + + 'pomNoLicenses - { + val updatedSettings = settings.copy(licenses = Seq.empty) + val pomNoLicenses = pomXml(artifact, deps, artifactId, updatedSettings) + + 'licenses - { + assert( + (pomNoLicenses \ "licenses").nonEmpty, + (pomNoLicenses \ "licenses" \ "licenses").isEmpty + ) + } + } + + 'pomNoDeps - { + val pomNoDeps = pomXml(artifact, + dependencies = Agg.empty, + artifactId = artifactId, + pomSettings = settings) + + 'dependencies - { + assert( + (pomNoDeps \ "dependencies").nonEmpty, + (pomNoDeps \ "dependencies" \ "dependency").isEmpty + ) + } + } + + 'pomNoDevelopers - { + val updatedSettings = settings.copy(developers = Seq.empty) + val pomNoDevelopers = pomXml(artifact, deps, artifactId, updatedSettings) + + 'developers - { + assert( + (pomNoDevelopers \ "developers").nonEmpty, + (pomNoDevelopers \ "developers" \ "developer").isEmpty + ) + } + } + } + + def pomXml(artifact: Artifact, + dependencies: Agg[Dependency], + artifactId: String, + pomSettings: PomSettings) = + XML.loadString(Pom(artifact, dependencies, artifactId, pomSettings)) + + def singleText(seq: NodeSeq) = + seq + .map(_.text) + .headOption + .getOrElse(throw new RuntimeException("seq was empty")) + + def optText(seq: NodeSeq) = seq.map(_.text).headOption + +} |