mirror of https://github.com/sbt/sbt.git
Reorganize existing tests
This commit is contained in:
parent
eb76b873f2
commit
c0ac7061db
22
build.sbt
22
build.sbt
|
|
@ -90,8 +90,8 @@ lazy val lmCore = (project in file("core"))
|
|||
gigahorseOkhttp,
|
||||
okhttpUrlconnection,
|
||||
sjsonnewScalaJson.value % Optional,
|
||||
scalaTest,
|
||||
scalaCheck
|
||||
scalaTest % Test,
|
||||
scalaCheck % Test
|
||||
),
|
||||
libraryDependencies ++= scalaXml.value,
|
||||
resourceGenerators in Compile += Def
|
||||
|
|
@ -119,13 +119,25 @@ lazy val lmCore = (project in file("core"))
|
|||
)
|
||||
.configure(addSbtIO, addSbtUtilLogging, addSbtUtilPosition, addSbtUtilCache)
|
||||
|
||||
lazy val lmIvy = (project in file("ivy"))
|
||||
.enablePlugins(ContrabandPlugin, JsonCodecPlugin)
|
||||
lazy val lmCommonTest = (project in file("common-test"))
|
||||
.dependsOn(lmCore)
|
||||
.settings(
|
||||
commonSettings,
|
||||
skip in publish := true,
|
||||
name := "common-test",
|
||||
libraryDependencies ++= Seq(scalaTest, scalaCheck),
|
||||
scalacOptions in (Compile, console) --=
|
||||
Vector("-Ywarn-unused-import", "-Ywarn-unused", "-Xlint"),
|
||||
mimaSettings,
|
||||
)
|
||||
|
||||
lazy val lmIvy = (project in file("ivy"))
|
||||
.enablePlugins(ContrabandPlugin, JsonCodecPlugin)
|
||||
.dependsOn(lmCore, lmCommonTest)
|
||||
.settings(
|
||||
commonSettings,
|
||||
name := "librarymanagement-ivy",
|
||||
libraryDependencies ++= Seq(ivy, scalaTest, scalaCheck),
|
||||
libraryDependencies ++= Seq(ivy, scalaTest % Test, scalaCheck % Test),
|
||||
managedSourceDirectories in Compile +=
|
||||
baseDirectory.value / "src" / "main" / "contraband-scala",
|
||||
sourceManaged in (Compile, generateContrabands) := baseDirectory.value / "src" / "main" / "contraband-scala",
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
package sbt.internal.librarymanagement
|
||||
|
||||
import sbt.librarymanagement._
|
||||
|
||||
abstract class AbstractEngineSpec extends UnitSpec {
|
||||
def cleanCache(): Unit
|
||||
|
||||
def module(moduleId: ModuleID,
|
||||
deps: Vector[ModuleID],
|
||||
scalaFullVersion: Option[String]): ModuleDescriptor
|
||||
|
||||
def updateEither(module: ModuleDescriptor): Either[UnresolvedWarning, UpdateReport]
|
||||
|
||||
def update(module: ModuleDescriptor) =
|
||||
updateEither(module) match {
|
||||
case Right(r) => r
|
||||
case Left(w) => throw w.resolveException
|
||||
}
|
||||
|
||||
def cleanCachedResolutionCache(module: ModuleDescriptor): Unit = ()
|
||||
}
|
||||
|
|
@ -3,27 +3,21 @@ package sbt.internal.librarymanagement
|
|||
import org.scalatest.LoneElement._
|
||||
import sbt.util.ShowLines
|
||||
import sbt.librarymanagement._
|
||||
import sbt.librarymanagement.ivy.UpdateOptions
|
||||
import sbt.librarymanagement.syntax._
|
||||
|
||||
class CachedResolutionSpec extends BaseIvySpecification {
|
||||
abstract class ResolutionSpec extends AbstractEngineSpec {
|
||||
import ShowLines._
|
||||
|
||||
override val resolvers = Vector(
|
||||
Resolver.mavenCentral,
|
||||
Resolver.sbtPluginRepo("releases")
|
||||
)
|
||||
|
||||
"Resolving the same module twice" should "work" in {
|
||||
cleanIvyCache()
|
||||
cleanCache()
|
||||
val m = module(
|
||||
ModuleID("com.example", "foo", "0.1.0").withConfigurations(Some("compile")),
|
||||
exampleModuleId("0.1.0"),
|
||||
Vector(commonsIo13),
|
||||
Some("2.10.2"),
|
||||
UpdateOptions().withCachedResolution(true)
|
||||
Some("2.10.2")
|
||||
)
|
||||
val report = ivyUpdate(m)
|
||||
val report = update(m)
|
||||
cleanCachedResolutionCache(m)
|
||||
val _ = ivyUpdate(m)
|
||||
val _ = update(m)
|
||||
// first resolution creates the minigraph
|
||||
println(report)
|
||||
// second resolution reads from the minigraph
|
||||
|
|
@ -34,17 +28,16 @@ class CachedResolutionSpec extends BaseIvySpecification {
|
|||
"Resolving the unsolvable module should" should "not work" in {
|
||||
// log.setLevel(Level.Debug)
|
||||
val m = module(
|
||||
ModuleID("com.example", "foo", "0.2.0").withConfigurations(Some("compile")),
|
||||
exampleModuleId("0.2.0"),
|
||||
Vector(mavenCayennePlugin302),
|
||||
Some("2.10.2"),
|
||||
UpdateOptions().withCachedResolution(true)
|
||||
Some("2.10.2")
|
||||
)
|
||||
ivyUpdateEither(m) match {
|
||||
updateEither(m) match {
|
||||
case Right(_) => sys.error("this should've failed")
|
||||
case Left(uw) =>
|
||||
println(uw.lines.mkString("\n"))
|
||||
}
|
||||
ivyUpdateEither(m) match {
|
||||
updateEither(m) match {
|
||||
case Right(_) => sys.error("this should've failed 2")
|
||||
case Left(uw) =>
|
||||
uw.lines should contain allOf ("\n\tNote: Unresolved dependencies path:",
|
||||
|
|
@ -61,18 +54,17 @@ class CachedResolutionSpec extends BaseIvySpecification {
|
|||
// #2046 says that netty:3.2.0.Final is incorrectly evicted by netty:3.2.1.Final
|
||||
"Resolving a module with a pseudo-conflict" should "work" in {
|
||||
// log.setLevel(Level.Debug)
|
||||
cleanIvyCache()
|
||||
cleanCache()
|
||||
val m = module(
|
||||
ModuleID("com.example", "foo", "0.3.0").withConfigurations(Some("compile")),
|
||||
exampleModuleId("0.3.0"),
|
||||
Vector(avro177, dataAvro1940, netty320),
|
||||
Some("2.10.2"),
|
||||
UpdateOptions().withCachedResolution(true)
|
||||
Some("2.10.2")
|
||||
)
|
||||
// first resolution creates the minigraph
|
||||
val _ = ivyUpdate(m)
|
||||
val _ = update(m)
|
||||
cleanCachedResolutionCache(m)
|
||||
// second resolution reads from the minigraph
|
||||
val report = ivyUpdate(m)
|
||||
val report = update(m)
|
||||
val modules: Seq[String] = report.configurations.head.modules map { _.toString }
|
||||
assert(modules exists { x: String =>
|
||||
x contains """org.jboss.netty:netty:3.2.0.Final"""
|
||||
|
|
@ -83,40 +75,37 @@ class CachedResolutionSpec extends BaseIvySpecification {
|
|||
}
|
||||
|
||||
"Resolving a module with sbt cross build" should "work" in {
|
||||
cleanIvyCache()
|
||||
cleanCache()
|
||||
val attributes013 = Map("e:sbtVersion" -> "0.13", "e:scalaVersion" -> "2.10")
|
||||
val attributes10 = Map("e:sbtVersion" -> "1.0", "e:scalaVersion" -> "2.12")
|
||||
val module013 = module(
|
||||
ModuleID("com.example", "foo", "0.4.0").withConfigurations(Some("compile")),
|
||||
exampleModuleId("0.4.0"),
|
||||
Vector(sbtRelease.withExtraAttributes(attributes013)),
|
||||
Some("2.10.6"),
|
||||
UpdateOptions().withCachedResolution(true)
|
||||
Some("2.10.6")
|
||||
)
|
||||
val module10 = module(
|
||||
ModuleID("com.example", "foo", "0.4.0").withConfigurations(Some("compile")),
|
||||
exampleModuleId("0.4.1"),
|
||||
Vector(sbtRelease.withExtraAttributes(attributes10)),
|
||||
Some("2.12.3"),
|
||||
UpdateOptions().withCachedResolution(true)
|
||||
Some("2.12.3")
|
||||
)
|
||||
ivyUpdate(module013).configurations.head.modules.map(_.toString).loneElement should include(
|
||||
update(module013).configurations.head.modules.map(_.toString).loneElement should include(
|
||||
"com.github.gseitz:sbt-release:1.0.6 (scalaVersion=2.10, sbtVersion=0.13)"
|
||||
)
|
||||
ivyUpdate(module10).configurations.head.modules.map(_.toString).loneElement should include(
|
||||
update(module10).configurations.head.modules.map(_.toString).loneElement should include(
|
||||
"com.github.gseitz:sbt-release:1.0.6 (scalaVersion=2.12, sbtVersion=1.0)"
|
||||
)
|
||||
}
|
||||
|
||||
def commonsIo13 = ModuleID("commons-io", "commons-io", "1.3").withConfigurations(Some("compile"))
|
||||
def exampleModuleId(v: String): ModuleID = ("com.example" % "foo" % v % Compile)
|
||||
|
||||
def commonsIo13 = ("commons-io" % "commons-io" % "1.3" % Compile)
|
||||
def mavenCayennePlugin302 =
|
||||
ModuleID("org.apache.cayenne.plugins", "maven-cayenne-plugin", "3.0.2").withConfigurations(
|
||||
Some("compile"))
|
||||
def avro177 = ModuleID("org.apache.avro", "avro", "1.7.7").withConfigurations(Some("compile"))
|
||||
("org.apache.cayenne.plugins" % "maven-cayenne-plugin" % "3.0.2" % Compile)
|
||||
def avro177 = ("org.apache.avro" % "avro" % "1.7.7" % Compile)
|
||||
def dataAvro1940 =
|
||||
ModuleID("com.linkedin.pegasus", "data-avro", "1.9.40").withConfigurations(Some("compile"))
|
||||
def netty320 =
|
||||
ModuleID("org.jboss.netty", "netty", "3.2.0.Final").withConfigurations(Some("compile"))
|
||||
def sbtRelease =
|
||||
ModuleID("com.github.gseitz", "sbt-release", "1.0.6").withConfigurations(Some("compile"))
|
||||
("com.linkedin.pegasus" % "data-avro" % "1.9.40" % Compile)
|
||||
def netty320 = ("org.jboss.netty" % "netty" % "3.2.0.Final" % Compile)
|
||||
def sbtRelease = ("com.github.gseitz" % "sbt-release" % "1.0.6" % Compile)
|
||||
|
||||
def defaultOptions = EvictionWarningOptions.default
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package sbt.internal.librarymanagement
|
||||
|
||||
import org.scalatest._
|
||||
|
||||
abstract class UnitSpec extends FlatSpec with Matchers
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package sbt.internal.librarymanagement
|
||||
|
||||
import sbt.librarymanagement._
|
||||
import sbt.librarymanagement.ivy._
|
||||
|
||||
trait BaseCachedResolutionSpec extends BaseIvySpecification {
|
||||
override def module(moduleId: ModuleID,
|
||||
deps: Vector[ModuleID],
|
||||
scalaFullVersion: Option[String]): ModuleDescriptor = {
|
||||
val uo: UpdateOptions = UpdateOptions()
|
||||
.withCachedResolution(true)
|
||||
module(moduleId, deps, scalaFullVersion, uo, true)
|
||||
}
|
||||
}
|
||||
|
|
@ -3,13 +3,13 @@ package sbt.internal.librarymanagement
|
|||
import sbt.io.IO
|
||||
import sbt.io.syntax._
|
||||
import java.io.File
|
||||
import cross.CrossVersionUtil
|
||||
import sbt.internal.util.ConsoleLogger
|
||||
import sbt.librarymanagement._
|
||||
import sbt.librarymanagement.ivy._
|
||||
import cross.CrossVersionUtil
|
||||
import Configurations._
|
||||
|
||||
trait BaseIvySpecification extends UnitSpec {
|
||||
trait BaseIvySpecification extends AbstractEngineSpec {
|
||||
def currentBase: File = new File(".")
|
||||
def currentTarget: File = currentBase / "target" / "ivyhome"
|
||||
def currentManaged: File = currentBase / "target" / "lib_managed"
|
||||
|
|
@ -22,6 +22,13 @@ trait BaseIvySpecification extends UnitSpec {
|
|||
IvyDependencyResolution(mkIvyConfiguration(uo))
|
||||
|
||||
def configurations = Vector(Compile, Test, Runtime)
|
||||
|
||||
def module(moduleId: ModuleID,
|
||||
deps: Vector[ModuleID],
|
||||
scalaFullVersion: Option[String]): ModuleDescriptor = {
|
||||
module(moduleId, deps, scalaFullVersion, UpdateOptions(), true)
|
||||
}
|
||||
|
||||
def module(moduleId: ModuleID,
|
||||
deps: Vector[ModuleID],
|
||||
scalaFullVersion: Option[String],
|
||||
|
|
@ -77,23 +84,28 @@ trait BaseIvySpecification extends UnitSpec {
|
|||
.withMetadataDirectory(metadataDirectory)
|
||||
}
|
||||
|
||||
def ivyUpdateEither(module: IvySbt#Module): Either[UnresolvedWarning, UpdateReport] = {
|
||||
// IO.delete(currentTarget)
|
||||
val config = makeUpdateConfiguration(false, Some(currentDependency))
|
||||
IvyActions.updateEither(module, config, UnresolvedWarningConfiguration(), log)
|
||||
def updateEither(module: ModuleDescriptor): Either[UnresolvedWarning, UpdateReport] =
|
||||
ivyUpdateEither(module)
|
||||
|
||||
def ivyUpdateEither(module: ModuleDescriptor): Either[UnresolvedWarning, UpdateReport] = {
|
||||
module match {
|
||||
case m: IvySbt#Module =>
|
||||
val config = makeUpdateConfiguration(false, Some(currentDependency))
|
||||
IvyActions.updateEither(m, config, UnresolvedWarningConfiguration(), log)
|
||||
}
|
||||
}
|
||||
|
||||
def cleanCache: Unit = cleanIvyCache()
|
||||
def cleanIvyCache(): Unit = IO.delete(currentTarget / "cache")
|
||||
|
||||
def cleanCachedResolutionCache(module: IvySbt#Module): Unit =
|
||||
IvyActions.cleanCachedResolutionCache(module, log)
|
||||
|
||||
def ivyUpdate(module: IvySbt#Module) =
|
||||
ivyUpdateEither(module) match {
|
||||
case Right(r) => r
|
||||
case Left(w) =>
|
||||
throw w.resolveException
|
||||
override def cleanCachedResolutionCache(module: ModuleDescriptor): Unit = {
|
||||
module match {
|
||||
case m: IvySbt#Module => IvyActions.cleanCachedResolutionCache(m, log)
|
||||
}
|
||||
}
|
||||
|
||||
def ivyUpdate(module: ModuleDescriptor): UpdateReport =
|
||||
update(module)
|
||||
|
||||
def mkPublishConfiguration(resolver: Resolver,
|
||||
artifacts: Map[Artifact, File]): PublishConfiguration = {
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package sbt.internal.librarymanagement
|
||||
|
||||
import sbt.librarymanagement._
|
||||
|
||||
class CachedResolutionSpec extends ResolutionSpec with BaseCachedResolutionSpec {
|
||||
override val resolvers = Vector(
|
||||
Resolver.mavenCentral,
|
||||
Resolver.sbtPluginRepo("releases")
|
||||
)
|
||||
}
|
||||
|
|
@ -1,13 +1,12 @@
|
|||
package sbt.librarymanagement
|
||||
package sbt.internal.librarymanagement
|
||||
|
||||
import java.net.URL
|
||||
import java.io.File
|
||||
|
||||
import sbt.internal._, librarymanagement._
|
||||
import sbt.librarymanagement._
|
||||
import sjsonnew.shaded.scalajson.ast.unsafe._
|
||||
import sjsonnew._, support.scalajson.unsafe._
|
||||
import org.scalatest.Assertion
|
||||
|
||||
import LibraryManagementCodec._
|
||||
|
||||
class DMSerializationSpec extends UnitSpec {
|
||||
|
|
@ -1,9 +1,8 @@
|
|||
package sbt.librarymanagement
|
||||
package sbt.internal.librarymanagement
|
||||
|
||||
import sbt.internal.librarymanagement.BaseIvySpecification
|
||||
import sbt.librarymanagement._
|
||||
import sbt.internal.librarymanagement.cross.CrossVersionUtil
|
||||
import sbt.librarymanagement.syntax._
|
||||
import org.scalatest.Assertions._
|
||||
|
||||
class EvictionWarningSpec extends BaseIvySpecification {
|
||||
// This is a specification to check the eviction warnings
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package sbt.librarymanagement
|
||||
package sbt.internal.librarymanagement
|
||||
|
||||
import sbt.librarymanagement._
|
||||
import sbt.librarymanagement.ivy.UpdateOptions
|
||||
import sbt.internal.librarymanagement._
|
||||
import sbt.librarymanagement.syntax._
|
||||
|
||||
class FrozenModeSpec extends BaseIvySpecification {
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
package sbt.librarymanagement
|
||||
package sbt.internal.librarymanagement
|
||||
|
||||
import org.scalatest.Assertion
|
||||
import sbt.internal.librarymanagement.BaseIvySpecification
|
||||
import sbt.librarymanagement._
|
||||
import sbt.librarymanagement.syntax._
|
||||
import org.scalatest.Assertion
|
||||
import DependencyBuilders.OrganizationArtifactName
|
||||
|
||||
class InclExclSpec extends BaseIvySpecification {
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package sbt.internal.librarymanagement
|
||||
|
||||
import sbt.librarymanagement._
|
||||
|
||||
class IvyResolutionSpec extends ResolutionSpec with BaseIvySpecification {
|
||||
override val resolvers = Vector(
|
||||
Resolver.mavenCentral,
|
||||
Resolver.sbtPluginRepo("releases")
|
||||
)
|
||||
}
|
||||
|
|
@ -66,8 +66,10 @@ class MakePomSpec extends UnitSpec {
|
|||
"foo+" should "convert to foo+" in beParsedAsError("foo+")
|
||||
|
||||
val mp = new MakePom(ConsoleLogger())
|
||||
def convertTo(s: String, expected: String): Unit =
|
||||
def convertTo(s: String, expected: String): Unit = {
|
||||
MakePom.makeDependencyVersion(s) shouldBe expected
|
||||
()
|
||||
}
|
||||
def beParsedAsError(s: String): Unit = {
|
||||
intercept[Throwable] {
|
||||
MakePom.makeDependencyVersion(s)
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
package sbt.librarymanagement
|
||||
package sbt.internal.librarymanagement
|
||||
|
||||
import java.io.File
|
||||
|
||||
import org.apache.ivy.util.Message
|
||||
import sbt.internal.librarymanagement.{ BaseIvySpecification, IvyActions }
|
||||
import sbt.librarymanagement._
|
||||
import sbt.librarymanagement.ivy._
|
||||
import sbt.io.IO
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
package sbt.librarymanagement
|
||||
package sbt.internal.librarymanagement
|
||||
|
||||
import sbt.librarymanagement.ivy.UpdateOptions
|
||||
import sbt.internal.librarymanagement.BaseIvySpecification
|
||||
import sbt.librarymanagement._
|
||||
import sbt.librarymanagement.syntax._
|
||||
import sbt.librarymanagement.ivy.UpdateOptions
|
||||
import Resolver._
|
||||
|
||||
class ModuleResolversTest extends BaseIvySpecification {
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
package sbt.librarymanagement
|
||||
package sbt.internal.librarymanagement
|
||||
|
||||
import sbt.librarymanagement._
|
||||
import sbt.librarymanagement.ivy.UpdateOptions
|
||||
import org.scalatest.Assertion
|
||||
import sbt.internal.librarymanagement._
|
||||
import sbt.io.IO
|
||||
|
||||
class OfflineModeSpec extends BaseIvySpecification {
|
||||
|
|
@ -1,12 +1,11 @@
|
|||
package sbt.librarymanagement
|
||||
package sbt.internal.librarymanagement
|
||||
|
||||
import org.apache.ivy.core.module.id.ModuleRevisionId
|
||||
import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor
|
||||
|
||||
import sbt.internal.librarymanagement.UnitSpec
|
||||
|
||||
import sbt.internal.librarymanagement.IvyScalaUtil.OverrideScalaMediator
|
||||
import ScalaArtifacts._
|
||||
import sbt.librarymanagement._
|
||||
import sbt.librarymanagement.ScalaArtifacts._
|
||||
|
||||
class ScalaOverrideTest extends UnitSpec {
|
||||
val OtherOrgID = "other.org"
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package sbt.librarymanagement.ivy
|
||||
package sbt.internal.librarymanagement
|
||||
|
||||
import sbt.internal.librarymanagement.UnitSpec
|
||||
import sbt.librarymanagement.ivy._
|
||||
|
||||
class UpdateOptionsSpec extends UnitSpec {
|
||||
|
||||
|
|
@ -45,8 +45,8 @@ object Dependencies {
|
|||
val scalaReflect = Def.setting { "org.scala-lang" % "scala-reflect" % scalaVersion.value }
|
||||
val scalaCompiler = Def.setting { "org.scala-lang" % "scala-compiler" % scalaVersion.value }
|
||||
val scalaXml = scala211Module("scala-xml", "1.0.5")
|
||||
val scalaTest = "org.scalatest" %% "scalatest" % "3.0.1" % Test
|
||||
val scalaCheck = "org.scalacheck" %% "scalacheck" % "1.13.4" % Test
|
||||
val scalaTest = "org.scalatest" %% "scalatest" % "3.0.1"
|
||||
val scalaCheck = "org.scalacheck" %% "scalacheck" % "1.13.4"
|
||||
val sjsonnew = Def.setting {
|
||||
"com.eed3si9n" %% "sjson-new-core" % contrabandSjsonNewVersion.value
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue