diff --git a/build.sbt b/build.sbt index 9ac713786..cae1353d2 100644 --- a/build.sbt +++ b/build.sbt @@ -33,9 +33,6 @@ def commonSettings: Seq[Setting[_]] = Seq( publishArtifact in Test := true ) -def testedBaseSettings: Seq[Setting[_]] = - commonSettings ++ testDependencies - lazy val utilRoot: Project = (project in file(".")). // configs(Sxr.sxrConf). aggregate( @@ -86,8 +83,9 @@ lazy val utilControl = (project in internalPath / "util-control"). ) lazy val utilCollection = (project in internalPath / "util-collection"). + dependsOn(utilTesting % Test). settings( - testedBaseSettings, + commonSettings, Util.keywordsSettings, name := "Util Collection" ) @@ -95,16 +93,16 @@ lazy val utilCollection = (project in internalPath / "util-collection"). lazy val utilApplyMacro = (project in internalPath / "util-appmacro"). dependsOn(utilCollection). settings( - testedBaseSettings, + commonSettings, name := "Util Apply Macro", libraryDependencies += scalaCompiler.value ) // Command line-related utilities. lazy val utilComplete = (project in internalPath / "util-complete"). - dependsOn(utilCollection, utilControl). + dependsOn(utilCollection, utilControl, utilTesting % Test). settings( - testedBaseSettings, + commonSettings, name := "Util Completion", libraryDependencies ++= Seq(jline, sbtIO), crossScalaVersions := Seq(scala210, scala211) @@ -112,9 +110,9 @@ lazy val utilComplete = (project in internalPath / "util-complete"). // logging lazy val utilLogging = (project in internalPath / "util-logging"). - dependsOn(utilInterface). + dependsOn(utilInterface, utilTesting % Test). settings( - testedBaseSettings, + commonSettings, publishArtifact in (Test, packageBin) := true, name := "Util Logging", libraryDependencies += jline @@ -122,16 +120,17 @@ lazy val utilLogging = (project in internalPath / "util-logging"). // Relation lazy val utilRelation = (project in internalPath / "util-relation"). + dependsOn(utilTesting % Test). settings( - testedBaseSettings, + commonSettings, name := "Util Relation" ) // A logic with restricted negation as failure for a unique, stable model lazy val utilLogic = (project in internalPath / "util-logic"). - dependsOn(utilCollection, utilRelation). + dependsOn(utilCollection, utilRelation, utilTesting % Test). settings( - testedBaseSettings, + commonSettings, name := "Util Logic" ) @@ -152,3 +151,11 @@ lazy val utilTracking = (project in internalPath / "util-tracking"). name := "Util Tracking", libraryDependencies += sbtIO ) + +// Internal utility for testing +lazy val utilTesting = (project in internalPath / "util-testing"). + settings( + commonSettings, + name := "Util Testing", + libraryDependencies ++= Seq(scalaCheck, scalatest) + ) diff --git a/internal/util-complete/src/test/scala/sbt/complete/FileExamplesTest.scala b/internal/util-complete/src/test/scala/sbt/complete/FileExamplesTest.scala index a0db3d777..2f873cf6c 100644 --- a/internal/util-complete/src/test/scala/sbt/complete/FileExamplesTest.scala +++ b/internal/util-complete/src/test/scala/sbt/complete/FileExamplesTest.scala @@ -1,54 +1,60 @@ package sbt.util.internal package complete -import org.specs2.mutable.Specification -import org.specs2.specification.Scope import java.io.File import sbt.io.IO._ -class FileExamplesTest extends Specification { +class FileExamplesTest extends UnitSpec { - "listing all files in an absolute base directory" should { - "produce the entire base directory's contents" in new directoryStructure { - fileExamples().toList should containTheSameElementsAs(allRelativizedPaths) + "listing all files in an absolute base directory" should + "produce the entire base directory's contents" in { + 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 { - "produce an empty list" in new directoryStructure(withCompletionPrefix = "z") { - fileExamples().toList should beEmpty - } - } - - "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) + "listing files with a sub-path prefix" should + "produce matching paths only" in { + val _ = new DirectoryStructure(withCompletionPrefix = "far" + File.separator + "ba") { + fileExamples().toList should contain theSameElementsAs (prefixedPathsOnly) + } } - "produce sub-dir contents only when appending a file separator to the directory" in new directoryStructure(withCompletionPrefix = "far" + File.separator) { - fileExamples().toList should containTheSameElementsAs(prefixedPathsOnly) + "completing a full path" should + "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 { - "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 { + class DirectoryStructure(withCompletionPrefix: String = "") extends DelayedInit { var fileExamples: FileExamples = _ var baseDir: File = _ var childFiles: List[File] = _ diff --git a/internal/util-complete/src/test/scala/sbt/complete/FixedSetExamplesTest.scala b/internal/util-complete/src/test/scala/sbt/complete/FixedSetExamplesTest.scala index 4323b8e24..db1ebe67f 100644 --- a/internal/util-complete/src/test/scala/sbt/complete/FixedSetExamplesTest.scala +++ b/internal/util-complete/src/test/scala/sbt/complete/FixedSetExamplesTest.scala @@ -1,26 +1,23 @@ package sbt.util.internal package complete -import org.specs2.mutable.Specification -import org.specs2.specification.Scope +class FixedSetExamplesTest extends UnitSpec { -class FixedSetExamplesTest extends Specification { - - "adding a prefix" should { - "produce a smaller set of examples with the prefix removed" in new examples { - fixedSetExamples.withAddedPrefix("f")() must containTheSameElementsAs(List("oo", "ool", "u")) - fixedSetExamples.withAddedPrefix("fo")() must containTheSameElementsAs(List("o", "ol")) - fixedSetExamples.withAddedPrefix("b")() must containTheSameElementsAs(List("ar")) + "adding a prefix" should "produce a smaller set of examples with the prefix removed" in { + val _ = new Examples { + fixedSetExamples.withAddedPrefix("f")() should contain theSameElementsAs (List("oo", "ool", "u")) + fixedSetExamples.withAddedPrefix("fo")() should contain theSameElementsAs (List("o", "ol")) + fixedSetExamples.withAddedPrefix("b")() should contain theSameElementsAs (List("ar")) } } - "without a prefix" should { - "produce the original set" in new examples { - fixedSetExamples() mustEqual exampleSet + "without a prefix" should "produce the original set" in { + val _ = new Examples { + fixedSetExamples() shouldBe exampleSet } } - trait examples extends Scope { + trait Examples { val exampleSet = List("foo", "bar", "fool", "fu") val fixedSetExamples = FixedSetExamples(exampleSet) } diff --git a/internal/util-complete/src/test/scala/sbt/complete/ParserWithExamplesTest.scala b/internal/util-complete/src/test/scala/sbt/complete/ParserWithExamplesTest.scala index 854569e88..fc7c0ae90 100644 --- a/internal/util-complete/src/test/scala/sbt/complete/ParserWithExamplesTest.scala +++ b/internal/util-complete/src/test/scala/sbt/complete/ParserWithExamplesTest.scala @@ -1,61 +1,64 @@ package sbt.util.internal package complete -import org.specs2.mutable.Specification -import org.specs2.specification.Scope import Completion._ -class ParserWithExamplesTest extends Specification { +class ParserWithExamplesTest extends UnitSpec { - "listing a limited number of completions" should { - "grab only the needed number of elements from the iterable source of examples" in new parserWithLazyExamples { - parserWithExamples.completions(0) - examples.size shouldEqual maxNumberOfExamples + "listing a limited number of completions" should + "grab only the needed number of elements from the iterable source of examples" in { + val _ = new ParserWithLazyExamples { + parserWithExamples.completions(0) + examples.size shouldEqual maxNumberOfExamples + } } - } - "listing only valid completions" should { - "use the delegate parser to remove invalid examples" in new parserWithValidExamples { - val validCompletions = Completions(Set( - suggestion("blue"), - suggestion("red"))) - parserWithExamples.completions(0) shouldEqual validCompletions + "listing only valid completions" should + "use the delegate parser to remove invalid examples" in { + val _ = new ParserWithValidExamples { + val validCompletions = Completions(Set( + suggestion("blue"), + suggestion("red"))) + parserWithExamples.completions(0) shouldEqual validCompletions + } } - } - "listing valid completions in a derived parser" should { - "produce only valid examples that start with the character of the derivation" in new parserWithValidExamples { - val derivedCompletions = Completions(Set( - suggestion("lue"))) - parserWithExamples.derive('b').completions(0) shouldEqual derivedCompletions + "listing valid completions in a derived parser" should + "produce only valid examples that start with the character of the derivation" in { + val _ = new ParserWithValidExamples { + val derivedCompletions = Completions(Set( + suggestion("lue"))) + parserWithExamples.derive('b').completions(0) shouldEqual derivedCompletions + } } - } - "listing valid and invalid completions" should { - "produce the entire source of examples" in new parserWithAllExamples { - val completions = Completions(examples.map(suggestion(_)).toSet) - parserWithExamples.completions(0) shouldEqual completions + "listing valid and invalid completions" should + "produce the entire source of examples" in { + val _ = new parserWithAllExamples { + val completions = Completions(examples.map(suggestion(_)).toSet) + parserWithExamples.completions(0) shouldEqual completions + } } - } - "listing valid and invalid completions in a derived parser" should { - "produce only examples that start with the character of the derivation" in new parserWithAllExamples { - val derivedCompletions = Completions(Set( - suggestion("lue"), - suggestion("lock"))) - parserWithExamples.derive('b').completions(0) shouldEqual derivedCompletions + "listing valid and invalid completions in a derived parser" should + "produce only examples that start with the character of the derivation" in { + val _ = new parserWithAllExamples { + val derivedCompletions = Completions(Set( + suggestion("lue"), + 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, - removeInvalidExamples: Boolean) extends Scope { + removeInvalidExamples: Boolean) { import DefaultParsers._ diff --git a/internal/util-testing/src/main/scala/sbt/util/internal/UnitSpec.scala b/internal/util-testing/src/main/scala/sbt/util/internal/UnitSpec.scala new file mode 100644 index 000000000..83f17298e --- /dev/null +++ b/internal/util-testing/src/main/scala/sbt/util/internal/UnitSpec.scala @@ -0,0 +1,5 @@ +package sbt.util.internal + +import org.scalatest._ + +abstract class UnitSpec extends FlatSpec with Matchers diff --git a/project/Dependencies.scala b/project/Dependencies.scala index b0516b9cc..95b592d4d 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -23,10 +23,6 @@ object Dependencies { lazy val scalaXml = scala211Module("scala-xml", "1.0.1") - lazy val scalaCheck = "org.scalacheck" %% "scalacheck" % "1.11.4" - lazy val specs2 = "org.specs2" %% "specs2" % "2.3.11" - lazy val testDependencies = libraryDependencies ++= Seq( - scalaCheck, - specs2 - ).map(_ % "test") + lazy val scalaCheck = "org.scalacheck" %% "scalacheck" % "1.12.4" + lazy val scalatest = "org.scalatest" %% "scalatest" % "2.2.4" }