Compatibility test framework support and tests

This commit is contained in:
Mark Harrah 2010-01-25 22:52:50 -05:00
parent c8057f414b
commit 64fae31248
19 changed files with 192 additions and 5 deletions

View File

@ -211,7 +211,24 @@ trait BasicManagedProject extends ManagedProject with ReflectiveManagedProject w
/** The settings that represent inline declarations. The default settings combines the information
* from 'ivyXML', 'projectID', 'repositories', ivyConfigurations, defaultConfiguration,
* ivyScala, and 'libraryDependencies' and does not typically need to be be overridden. */
def inlineSettings = new InlineConfiguration(projectID, libraryDependencies, ivyXML, ivyConfigurations, defaultConfiguration, ivyScala, ivyValidate)
def inlineSettings = new InlineConfiguration(projectID, withCompat, ivyXML, ivyConfigurations, defaultConfiguration, ivyScala, ivyValidate)
/** Library dependencies with extra dependencies for compatibility*/
private def withCompat =
{
val deps = libraryDependencies
deps ++ compatExtra(deps)
}
/** Determines extra libraries needed for compatibility. Currently, this is the compatibility test framework. */
private def compatExtra(deps: Set[ModuleID]) = if(deps.exists(requiresCompat)) compatTestFramework else Nil
/** True if the given dependency requires the compatibility test framework. */
private def requiresCompat(m: ModuleID) =
(m.name == "scalacheck" && Set("1.5", "1.6").contains(m.revision)) ||
(m.name == "specs" && Set("1.6.0", "1.6.1").contains(m.revision)) ||
(m.name == "scalatest" && m.revision == "1.0")
/** Extra dependencies to add if a dependency on an older test framework (one released before the uniform test interface) is declared.
* This is the compatibility test framework by default.*/
def compatTestFramework = Set("org.scala-tools.sbt" %% "test-compat" % "0.4.0" % "test")
def defaultModuleSettings: ModuleSettings =
{
val in = inlineSettings

View File

@ -177,8 +177,8 @@ abstract class BasicScalaProject extends ScalaProject with BasicDependencyProjec
* run*/
def testFrameworks: Seq[TestFramework] =
{
import TestFrameworks.{JUnit, ScalaCheck, ScalaTest, Specs}
ScalaCheck :: Specs :: ScalaTest :: JUnit :: Nil
import TestFrameworks.{JUnit, ScalaCheck, ScalaTest, Specs, ScalaCheckCompat, ScalaTestCompat, SpecsCompat}
ScalaCheck :: Specs :: ScalaTest :: JUnit :: ScalaCheckCompat :: ScalaTestCompat :: SpecsCompat :: Nil
}
/** The list of listeners for testing. */
def testListeners: Seq[TestReportListener] = TestLogger(log) :: Nil

View File

@ -18,6 +18,10 @@ object TestFrameworks
val ScalaTest = new TestFramework("org.scalatest.tools.ScalaTestFramework")
val Specs = new TestFramework("org.specs.runner.SpecsFramework")
val JUnit = new TestFramework("com.novocode.junit.JUnitFramework")
// These are compatibility frameworks included in the 'test-compat' library
val ScalaCheckCompat = new TestFramework("sbt.impl.ScalaCheckFramework")
val ScalaTestCompat = new TestFramework("sbt.impl.ScalaTestFramework")
val SpecsCompat = new TestFramework("sbt.impl.SpecsFramework")
}
class TestFramework(val implClassName: String) extends NotNull

View File

@ -73,8 +73,7 @@ class TestLogger(val log: TLogger) extends TestsListener
def testEvent(event: TestEvent): Unit = event.detail.foreach(count)
def endGroup(name: String, t: Throwable)
{
// log.trace(t) : need to add a trace method to org.scalatools.testing.Logger
try { log.getClass.getMethod("trace", classOf[Throwable]).invoke(log, t) } catch { case e: Exception => () }
log.trace(t)
log.error("Could not run test " + name + ": " + t.toString)
}
def endGroup(name: String, result: Result.Value) {}

View File

@ -0,0 +1,2 @@
project.name=ScalaTest Compatibility Test
project.version=1.0

View File

@ -0,0 +1,6 @@
import sbt._
class CompatScalaTest(info: ProjectInfo) extends DefaultProject(info)
{
val specs = "org.scala-tools.testing" % "scalacheck" % "1.6" % "test"
}

View File

@ -0,0 +1,20 @@
import org.scalacheck._
object Failure extends Properties("String") {
property("startsWith") = Prop.forAll((a: String, b: String) => (a+b).startsWith(a))
property("endsWith") = Prop.forAll((a: String, b: String) => (a+b).endsWith(b))
// Is this really always true?
property("concat") = Prop.forAll((a: String, b: String) =>
(a+b).length > a.length && (a+b).length > b.length
)
property("substring") = Prop.forAll((a: String, b: String) =>
(a+b).substring(a.length) == b
)
property("substring") = Prop.forAll((a: String, b: String, c: String) =>
(a+b+c).substring(a.length, a.length+b.length) == b
)
}

View File

@ -0,0 +1,15 @@
import org.scalacheck._
object Success extends Properties("String") {
property("startsWith") = Prop.forAll((a: String, b: String) => (a+b).startsWith(a))
property("endsWith") = Prop.forAll((a: String, b: String) => (a+b).endsWith(b))
property("substring") = Prop.forAll((a: String, b: String) =>
(a+b).substring(a.length) == b
)
property("substring") = Prop.forAll((a: String, b: String, c: String) =>
(a+b+c).substring(a.length, a.length+b.length) == b
)
}

View File

@ -0,0 +1,28 @@
> ++2.7.2
> update
> test-only Success
-> test-only Failure
> ++2.7.3
> update
> test-only Success
-> test-only Failure
> ++2.7.4
> update
> test-only Success
-> test-only Failure
> ++2.7.5
> update
> test-only Success
-> test-only Failure
> ++2.7.6
> update
> test-only Success
-> test-only Failure
> ++2.7.7
> update
> test-only Success
-> test-only Failure

View File

@ -0,0 +1,2 @@
project.name=ScalaTest Compatibility Test
project.version=1.0

View File

@ -0,0 +1,6 @@
import sbt._
class CompatScalaTest(info: ProjectInfo) extends DefaultProject(info)
{
val specs = "org.scalatest" % "scalatest" % "1.0" % "test"
}

View File

@ -0,0 +1,21 @@
/** The ScalaTest example on the home page, but failing.. */
import org.scalatest.FlatSpec
import org.scalatest.matchers.ShouldMatchers
import scala.collection.mutable.Stack
class Failure extends FlatSpec with ShouldMatchers {
"A Stack" should "pop values in last-in-first-out order" in {
val stack = new Stack[Int]
stack.push(1)
stack.push(2)
stack.pop() should equal (2)
stack.pop() should equal (19) // should fail
}
it should "throw NoSuchElementException if an empty stack is popped" in {
val emptyStack = new Stack[String]
evaluating { emptyStack.pop() } should produce [NoSuchElementException]
}
}

View File

@ -0,0 +1,21 @@
/** The ScalaTest example on the home page. */
import org.scalatest.FlatSpec
import org.scalatest.matchers.ShouldMatchers
import scala.collection.mutable.Stack
class StackSpecSuccess extends FlatSpec with ShouldMatchers {
"A Stack" should "pop values in last-in-first-out order" in {
val stack = new Stack[Int]
stack.push(1)
stack.push(2)
stack.pop() should equal (2)
stack.pop() should equal (1)
}
it should "throw NoSuchElementException if an empty stack is popped" in {
val emptyStack = new Stack[String]
evaluating { emptyStack.pop() } should produce [NoSuchElementException]
}
}

View File

@ -0,0 +1,9 @@
> ++2.7.5
> update
> test-only Success
-> test-only Failure
> ++2.7.7
> update
> test-only Success
-> test-only Failure

View File

@ -0,0 +1,2 @@
project.name=Specs Compatibility Test
project.version=1.0

View File

@ -0,0 +1,6 @@
import sbt._
class CompatSpecsTest(info: ProjectInfo) extends DefaultProject(info)
{
val specs = "org.scala-tools.testing" % "specs" % "1.6.0" % "test"
}

View File

@ -0,0 +1,10 @@
import org.specs._
object Failure extends Specification {
"'hello world' has 11 characters" in {
"hello world".size must be equalTo(12)
}
"'hello world' matches 'h.* w.*'" in {
"hello world" must be matching("h.* w.*")
}
}

View File

@ -0,0 +1,10 @@
import org.specs._
object Success extends Specification {
"'hello world' has 11 characters" in {
"hello world".size must be equalTo(11)
}
"'hello world' matches 'h.* w.*'" in {
"hello world" must be matching("h.* w.*")
}
}

View File

@ -0,0 +1,9 @@
> ++2.7.5
> update
> test-only Success
-> test-only Failure
> ++2.7.7
> update
> test-only Success
-> test-only Failure