migrate to scalatest 2.2.4

This commit is contained in:
Eugene Yokota 2015-09-04 17:40:48 -04:00
parent bc54e035ef
commit c20887853e
6 changed files with 120 additions and 106 deletions

View File

@ -33,9 +33,6 @@ def commonSettings: Seq[Setting[_]] = Seq(
publishArtifact in Test := true publishArtifact in Test := true
) )
def testedBaseSettings: Seq[Setting[_]] =
commonSettings ++ testDependencies
lazy val utilRoot: Project = (project in file(".")). lazy val utilRoot: Project = (project in file(".")).
// configs(Sxr.sxrConf). // configs(Sxr.sxrConf).
aggregate( aggregate(
@ -86,8 +83,9 @@ lazy val utilControl = (project in internalPath / "util-control").
) )
lazy val utilCollection = (project in internalPath / "util-collection"). lazy val utilCollection = (project in internalPath / "util-collection").
dependsOn(utilTesting % Test).
settings( settings(
testedBaseSettings, commonSettings,
Util.keywordsSettings, Util.keywordsSettings,
name := "Util Collection" name := "Util Collection"
) )
@ -95,16 +93,16 @@ lazy val utilCollection = (project in internalPath / "util-collection").
lazy val utilApplyMacro = (project in internalPath / "util-appmacro"). lazy val utilApplyMacro = (project in internalPath / "util-appmacro").
dependsOn(utilCollection). dependsOn(utilCollection).
settings( settings(
testedBaseSettings, commonSettings,
name := "Util Apply Macro", name := "Util Apply Macro",
libraryDependencies += scalaCompiler.value libraryDependencies += scalaCompiler.value
) )
// Command line-related utilities. // Command line-related utilities.
lazy val utilComplete = (project in internalPath / "util-complete"). lazy val utilComplete = (project in internalPath / "util-complete").
dependsOn(utilCollection, utilControl). dependsOn(utilCollection, utilControl, utilTesting % Test).
settings( settings(
testedBaseSettings, commonSettings,
name := "Util Completion", name := "Util Completion",
libraryDependencies ++= Seq(jline, sbtIO), libraryDependencies ++= Seq(jline, sbtIO),
crossScalaVersions := Seq(scala210, scala211) crossScalaVersions := Seq(scala210, scala211)
@ -112,9 +110,9 @@ lazy val utilComplete = (project in internalPath / "util-complete").
// logging // logging
lazy val utilLogging = (project in internalPath / "util-logging"). lazy val utilLogging = (project in internalPath / "util-logging").
dependsOn(utilInterface). dependsOn(utilInterface, utilTesting % Test).
settings( settings(
testedBaseSettings, commonSettings,
publishArtifact in (Test, packageBin) := true, publishArtifact in (Test, packageBin) := true,
name := "Util Logging", name := "Util Logging",
libraryDependencies += jline libraryDependencies += jline
@ -122,16 +120,17 @@ lazy val utilLogging = (project in internalPath / "util-logging").
// Relation // Relation
lazy val utilRelation = (project in internalPath / "util-relation"). lazy val utilRelation = (project in internalPath / "util-relation").
dependsOn(utilTesting % Test).
settings( settings(
testedBaseSettings, commonSettings,
name := "Util Relation" name := "Util Relation"
) )
// A logic with restricted negation as failure for a unique, stable model // A logic with restricted negation as failure for a unique, stable model
lazy val utilLogic = (project in internalPath / "util-logic"). lazy val utilLogic = (project in internalPath / "util-logic").
dependsOn(utilCollection, utilRelation). dependsOn(utilCollection, utilRelation, utilTesting % Test).
settings( settings(
testedBaseSettings, commonSettings,
name := "Util Logic" name := "Util Logic"
) )
@ -152,3 +151,11 @@ lazy val utilTracking = (project in internalPath / "util-tracking").
name := "Util Tracking", name := "Util Tracking",
libraryDependencies += sbtIO libraryDependencies += sbtIO
) )
// Internal utility for testing
lazy val utilTesting = (project in internalPath / "util-testing").
settings(
commonSettings,
name := "Util Testing",
libraryDependencies ++= Seq(scalaCheck, scalatest)
)

View File

@ -1,54 +1,60 @@
package sbt.util.internal package sbt.util.internal
package complete package complete
import org.specs2.mutable.Specification
import org.specs2.specification.Scope
import java.io.File import java.io.File
import sbt.io.IO._ import sbt.io.IO._
class FileExamplesTest extends Specification { class FileExamplesTest extends UnitSpec {
"listing all files in an absolute base directory" should { "listing all files in an absolute base directory" should
"produce the entire base directory's contents" in new directoryStructure { "produce the entire base directory's contents" in {
fileExamples().toList should containTheSameElementsAs(allRelativizedPaths) val _ = new DirectoryStructure {
fileExamples().toList should contain theSameElementsAs (allRelativizedPaths)
}
}
"listing files with a prefix that matches none" should
"produce an empty list" in {
val _ = new DirectoryStructure(withCompletionPrefix = "z") {
fileExamples().toList shouldBe empty
}
}
"listing single-character prefixed files" should
"produce matching paths only" in {
val _ = new DirectoryStructure(withCompletionPrefix = "f") {
fileExamples().toList should contain theSameElementsAs (prefixedPathsOnly)
}
}
"listing directory-prefixed files" should
"produce matching paths only" in {
val _ = new DirectoryStructure(withCompletionPrefix = "far") {
fileExamples().toList should contain theSameElementsAs (prefixedPathsOnly)
}
}
it should "produce sub-dir contents only when appending a file separator to the directory" in {
val _ = new DirectoryStructure(withCompletionPrefix = "far" + File.separator) {
fileExamples().toList should contain theSameElementsAs (prefixedPathsOnly)
} }
} }
"listing files with a prefix that matches none" should { "listing files with a sub-path prefix" should
"produce an empty list" in new directoryStructure(withCompletionPrefix = "z") { "produce matching paths only" in {
fileExamples().toList should beEmpty val _ = new DirectoryStructure(withCompletionPrefix = "far" + File.separator + "ba") {
} fileExamples().toList should contain theSameElementsAs (prefixedPathsOnly)
} }
"listing single-character prefixed files" should {
"produce matching paths only" in new directoryStructure(withCompletionPrefix = "f") {
fileExamples().toList should containTheSameElementsAs(prefixedPathsOnly)
}
}
"listing directory-prefixed files" should {
"produce matching paths only" in new directoryStructure(withCompletionPrefix = "far") {
fileExamples().toList should containTheSameElementsAs(prefixedPathsOnly)
} }
"produce sub-dir contents only when appending a file separator to the directory" in new directoryStructure(withCompletionPrefix = "far" + File.separator) { "completing a full path" should
fileExamples().toList should containTheSameElementsAs(prefixedPathsOnly) "produce a list with an empty string" in {
val _ = new DirectoryStructure(withCompletionPrefix = "bazaar") {
fileExamples().toList shouldEqual List("")
}
} }
}
"listing files with a sub-path prefix" should { class DirectoryStructure(withCompletionPrefix: String = "") extends DelayedInit {
"produce matching paths only" in new directoryStructure(withCompletionPrefix = "far" + File.separator + "ba") {
fileExamples().toList should containTheSameElementsAs(prefixedPathsOnly)
}
}
"completing a full path" should {
"produce a list with an empty string" in new directoryStructure(withCompletionPrefix = "bazaar") {
fileExamples().toList shouldEqual List("")
}
}
class directoryStructure(withCompletionPrefix: String = "") extends Scope with DelayedInit {
var fileExamples: FileExamples = _ var fileExamples: FileExamples = _
var baseDir: File = _ var baseDir: File = _
var childFiles: List[File] = _ var childFiles: List[File] = _

View File

@ -1,26 +1,23 @@
package sbt.util.internal package sbt.util.internal
package complete package complete
import org.specs2.mutable.Specification class FixedSetExamplesTest extends UnitSpec {
import org.specs2.specification.Scope
class FixedSetExamplesTest extends Specification { "adding a prefix" should "produce a smaller set of examples with the prefix removed" in {
val _ = new Examples {
"adding a prefix" should { fixedSetExamples.withAddedPrefix("f")() should contain theSameElementsAs (List("oo", "ool", "u"))
"produce a smaller set of examples with the prefix removed" in new examples { fixedSetExamples.withAddedPrefix("fo")() should contain theSameElementsAs (List("o", "ol"))
fixedSetExamples.withAddedPrefix("f")() must containTheSameElementsAs(List("oo", "ool", "u")) fixedSetExamples.withAddedPrefix("b")() should contain theSameElementsAs (List("ar"))
fixedSetExamples.withAddedPrefix("fo")() must containTheSameElementsAs(List("o", "ol"))
fixedSetExamples.withAddedPrefix("b")() must containTheSameElementsAs(List("ar"))
} }
} }
"without a prefix" should { "without a prefix" should "produce the original set" in {
"produce the original set" in new examples { val _ = new Examples {
fixedSetExamples() mustEqual exampleSet fixedSetExamples() shouldBe exampleSet
} }
} }
trait examples extends Scope { trait Examples {
val exampleSet = List("foo", "bar", "fool", "fu") val exampleSet = List("foo", "bar", "fool", "fu")
val fixedSetExamples = FixedSetExamples(exampleSet) val fixedSetExamples = FixedSetExamples(exampleSet)
} }

View File

@ -1,61 +1,64 @@
package sbt.util.internal package sbt.util.internal
package complete package complete
import org.specs2.mutable.Specification
import org.specs2.specification.Scope
import Completion._ import Completion._
class ParserWithExamplesTest extends Specification { class ParserWithExamplesTest extends UnitSpec {
"listing a limited number of completions" should { "listing a limited number of completions" should
"grab only the needed number of elements from the iterable source of examples" in new parserWithLazyExamples { "grab only the needed number of elements from the iterable source of examples" in {
parserWithExamples.completions(0) val _ = new ParserWithLazyExamples {
examples.size shouldEqual maxNumberOfExamples parserWithExamples.completions(0)
examples.size shouldEqual maxNumberOfExamples
}
} }
}
"listing only valid completions" should { "listing only valid completions" should
"use the delegate parser to remove invalid examples" in new parserWithValidExamples { "use the delegate parser to remove invalid examples" in {
val validCompletions = Completions(Set( val _ = new ParserWithValidExamples {
suggestion("blue"), val validCompletions = Completions(Set(
suggestion("red"))) suggestion("blue"),
parserWithExamples.completions(0) shouldEqual validCompletions suggestion("red")))
parserWithExamples.completions(0) shouldEqual validCompletions
}
} }
}
"listing valid completions in a derived parser" should { "listing valid completions in a derived parser" should
"produce only valid examples that start with the character of the derivation" in new parserWithValidExamples { "produce only valid examples that start with the character of the derivation" in {
val derivedCompletions = Completions(Set( val _ = new ParserWithValidExamples {
suggestion("lue"))) val derivedCompletions = Completions(Set(
parserWithExamples.derive('b').completions(0) shouldEqual derivedCompletions suggestion("lue")))
parserWithExamples.derive('b').completions(0) shouldEqual derivedCompletions
}
} }
}
"listing valid and invalid completions" should { "listing valid and invalid completions" should
"produce the entire source of examples" in new parserWithAllExamples { "produce the entire source of examples" in {
val completions = Completions(examples.map(suggestion(_)).toSet) val _ = new parserWithAllExamples {
parserWithExamples.completions(0) shouldEqual completions val completions = Completions(examples.map(suggestion(_)).toSet)
parserWithExamples.completions(0) shouldEqual completions
}
} }
}
"listing valid and invalid completions in a derived parser" should { "listing valid and invalid completions in a derived parser" should
"produce only examples that start with the character of the derivation" in new parserWithAllExamples { "produce only examples that start with the character of the derivation" in {
val derivedCompletions = Completions(Set( val _ = new parserWithAllExamples {
suggestion("lue"), val derivedCompletions = Completions(Set(
suggestion("lock"))) suggestion("lue"),
parserWithExamples.derive('b').completions(0) shouldEqual derivedCompletions suggestion("lock")))
parserWithExamples.derive('b').completions(0) shouldEqual derivedCompletions
}
} }
}
class parserWithLazyExamples extends parser(GrowableSourceOfExamples(), maxNumberOfExamples = 5, removeInvalidExamples = false) class ParserWithLazyExamples extends ParserExample(GrowableSourceOfExamples(), maxNumberOfExamples = 5, removeInvalidExamples = false)
class parserWithValidExamples extends parser(removeInvalidExamples = true) class ParserWithValidExamples extends ParserExample(removeInvalidExamples = true)
class parserWithAllExamples extends parser(removeInvalidExamples = false) class parserWithAllExamples extends ParserExample(removeInvalidExamples = false)
case class parser(examples: Iterable[String] = Set("blue", "yellow", "greeen", "block", "red"), case class ParserExample(examples: Iterable[String] = Set("blue", "yellow", "greeen", "block", "red"),
maxNumberOfExamples: Int = 25, maxNumberOfExamples: Int = 25,
removeInvalidExamples: Boolean) extends Scope { removeInvalidExamples: Boolean) {
import DefaultParsers._ import DefaultParsers._

View File

@ -0,0 +1,5 @@
package sbt.util.internal
import org.scalatest._
abstract class UnitSpec extends FlatSpec with Matchers

View File

@ -23,10 +23,6 @@ object Dependencies {
lazy val scalaXml = scala211Module("scala-xml", "1.0.1") lazy val scalaXml = scala211Module("scala-xml", "1.0.1")
lazy val scalaCheck = "org.scalacheck" %% "scalacheck" % "1.11.4" lazy val scalaCheck = "org.scalacheck" %% "scalacheck" % "1.12.4"
lazy val specs2 = "org.specs2" %% "specs2" % "2.3.11" lazy val scalatest = "org.scalatest" %% "scalatest" % "2.2.4"
lazy val testDependencies = libraryDependencies ++= Seq(
scalaCheck,
specs2
).map(_ % "test")
} }