From 64fae312486dc2fec4ec27fd94673b5cee4b9146 Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Mon, 25 Jan 2010 22:52:50 -0500 Subject: [PATCH] Compatibility test framework support and tests --- src/main/scala/sbt/BasicProjectTypes.scala | 19 ++++++++++++- src/main/scala/sbt/DefaultProject.scala | 4 +-- src/main/scala/sbt/TestFramework.scala | 4 +++ src/main/scala/sbt/TestReportListener.scala | 3 +- .../project/build.properties | 2 ++ .../project/build/CompatScalaCheck.scala | 6 ++++ .../src/test/scala/Failure.scala | 20 +++++++++++++ .../src/test/scala/Success.scala | 15 ++++++++++ src/sbt-test/tests/scalacheck-compat/test | 28 +++++++++++++++++++ .../scalatest-compat/project/build.properties | 2 ++ .../project/build/CompatScalaTest.scala | 6 ++++ .../src/test/scala/Failure.scala | 21 ++++++++++++++ .../src/test/scala/Success.scala | 21 ++++++++++++++ src/sbt-test/tests/scalatest-compat/test | 9 ++++++ .../specs-compat/project/build.properties | 2 ++ .../project/build/CompatSpecsTest.scala | 6 ++++ .../specs-compat/src/test/scala/Fail.scala | 10 +++++++ .../specs-compat/src/test/scala/Success.scala | 10 +++++++ src/sbt-test/tests/specs-compat/test | 9 ++++++ 19 files changed, 192 insertions(+), 5 deletions(-) create mode 100644 src/sbt-test/tests/scalacheck-compat/project/build.properties create mode 100644 src/sbt-test/tests/scalacheck-compat/project/build/CompatScalaCheck.scala create mode 100644 src/sbt-test/tests/scalacheck-compat/src/test/scala/Failure.scala create mode 100644 src/sbt-test/tests/scalacheck-compat/src/test/scala/Success.scala create mode 100644 src/sbt-test/tests/scalacheck-compat/test create mode 100644 src/sbt-test/tests/scalatest-compat/project/build.properties create mode 100644 src/sbt-test/tests/scalatest-compat/project/build/CompatScalaTest.scala create mode 100644 src/sbt-test/tests/scalatest-compat/src/test/scala/Failure.scala create mode 100644 src/sbt-test/tests/scalatest-compat/src/test/scala/Success.scala create mode 100644 src/sbt-test/tests/scalatest-compat/test create mode 100644 src/sbt-test/tests/specs-compat/project/build.properties create mode 100644 src/sbt-test/tests/specs-compat/project/build/CompatSpecsTest.scala create mode 100644 src/sbt-test/tests/specs-compat/src/test/scala/Fail.scala create mode 100644 src/sbt-test/tests/specs-compat/src/test/scala/Success.scala create mode 100644 src/sbt-test/tests/specs-compat/test diff --git a/src/main/scala/sbt/BasicProjectTypes.scala b/src/main/scala/sbt/BasicProjectTypes.scala index 581317951..f6d835aeb 100644 --- a/src/main/scala/sbt/BasicProjectTypes.scala +++ b/src/main/scala/sbt/BasicProjectTypes.scala @@ -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 diff --git a/src/main/scala/sbt/DefaultProject.scala b/src/main/scala/sbt/DefaultProject.scala index c7a1c91c0..ab854c1dc 100644 --- a/src/main/scala/sbt/DefaultProject.scala +++ b/src/main/scala/sbt/DefaultProject.scala @@ -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 diff --git a/src/main/scala/sbt/TestFramework.scala b/src/main/scala/sbt/TestFramework.scala index ea7303b8e..14e432979 100644 --- a/src/main/scala/sbt/TestFramework.scala +++ b/src/main/scala/sbt/TestFramework.scala @@ -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 diff --git a/src/main/scala/sbt/TestReportListener.scala b/src/main/scala/sbt/TestReportListener.scala index 938b008f9..bab4a0cda 100644 --- a/src/main/scala/sbt/TestReportListener.scala +++ b/src/main/scala/sbt/TestReportListener.scala @@ -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) {} diff --git a/src/sbt-test/tests/scalacheck-compat/project/build.properties b/src/sbt-test/tests/scalacheck-compat/project/build.properties new file mode 100644 index 000000000..6165fa252 --- /dev/null +++ b/src/sbt-test/tests/scalacheck-compat/project/build.properties @@ -0,0 +1,2 @@ +project.name=ScalaTest Compatibility Test +project.version=1.0 \ No newline at end of file diff --git a/src/sbt-test/tests/scalacheck-compat/project/build/CompatScalaCheck.scala b/src/sbt-test/tests/scalacheck-compat/project/build/CompatScalaCheck.scala new file mode 100644 index 000000000..650e9bff2 --- /dev/null +++ b/src/sbt-test/tests/scalacheck-compat/project/build/CompatScalaCheck.scala @@ -0,0 +1,6 @@ +import sbt._ + +class CompatScalaTest(info: ProjectInfo) extends DefaultProject(info) +{ + val specs = "org.scala-tools.testing" % "scalacheck" % "1.6" % "test" +} \ No newline at end of file diff --git a/src/sbt-test/tests/scalacheck-compat/src/test/scala/Failure.scala b/src/sbt-test/tests/scalacheck-compat/src/test/scala/Failure.scala new file mode 100644 index 000000000..4b33d47e3 --- /dev/null +++ b/src/sbt-test/tests/scalacheck-compat/src/test/scala/Failure.scala @@ -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 + ) +} \ No newline at end of file diff --git a/src/sbt-test/tests/scalacheck-compat/src/test/scala/Success.scala b/src/sbt-test/tests/scalacheck-compat/src/test/scala/Success.scala new file mode 100644 index 000000000..270132dea --- /dev/null +++ b/src/sbt-test/tests/scalacheck-compat/src/test/scala/Success.scala @@ -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 + ) +} \ No newline at end of file diff --git a/src/sbt-test/tests/scalacheck-compat/test b/src/sbt-test/tests/scalacheck-compat/test new file mode 100644 index 000000000..8476eb245 --- /dev/null +++ b/src/sbt-test/tests/scalacheck-compat/test @@ -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 \ No newline at end of file diff --git a/src/sbt-test/tests/scalatest-compat/project/build.properties b/src/sbt-test/tests/scalatest-compat/project/build.properties new file mode 100644 index 000000000..6165fa252 --- /dev/null +++ b/src/sbt-test/tests/scalatest-compat/project/build.properties @@ -0,0 +1,2 @@ +project.name=ScalaTest Compatibility Test +project.version=1.0 \ No newline at end of file diff --git a/src/sbt-test/tests/scalatest-compat/project/build/CompatScalaTest.scala b/src/sbt-test/tests/scalatest-compat/project/build/CompatScalaTest.scala new file mode 100644 index 000000000..f064eab3e --- /dev/null +++ b/src/sbt-test/tests/scalatest-compat/project/build/CompatScalaTest.scala @@ -0,0 +1,6 @@ +import sbt._ + +class CompatScalaTest(info: ProjectInfo) extends DefaultProject(info) +{ + val specs = "org.scalatest" % "scalatest" % "1.0" % "test" +} \ No newline at end of file diff --git a/src/sbt-test/tests/scalatest-compat/src/test/scala/Failure.scala b/src/sbt-test/tests/scalatest-compat/src/test/scala/Failure.scala new file mode 100644 index 000000000..ce1de3b0f --- /dev/null +++ b/src/sbt-test/tests/scalatest-compat/src/test/scala/Failure.scala @@ -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] + } +} diff --git a/src/sbt-test/tests/scalatest-compat/src/test/scala/Success.scala b/src/sbt-test/tests/scalatest-compat/src/test/scala/Success.scala new file mode 100644 index 000000000..3f39a585b --- /dev/null +++ b/src/sbt-test/tests/scalatest-compat/src/test/scala/Success.scala @@ -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] + } +} diff --git a/src/sbt-test/tests/scalatest-compat/test b/src/sbt-test/tests/scalatest-compat/test new file mode 100644 index 000000000..943bb2d7d --- /dev/null +++ b/src/sbt-test/tests/scalatest-compat/test @@ -0,0 +1,9 @@ +> ++2.7.5 +> update +> test-only Success +-> test-only Failure + +> ++2.7.7 +> update +> test-only Success +-> test-only Failure \ No newline at end of file diff --git a/src/sbt-test/tests/specs-compat/project/build.properties b/src/sbt-test/tests/specs-compat/project/build.properties new file mode 100644 index 000000000..658e0505b --- /dev/null +++ b/src/sbt-test/tests/specs-compat/project/build.properties @@ -0,0 +1,2 @@ +project.name=Specs Compatibility Test +project.version=1.0 \ No newline at end of file diff --git a/src/sbt-test/tests/specs-compat/project/build/CompatSpecsTest.scala b/src/sbt-test/tests/specs-compat/project/build/CompatSpecsTest.scala new file mode 100644 index 000000000..eee281dd8 --- /dev/null +++ b/src/sbt-test/tests/specs-compat/project/build/CompatSpecsTest.scala @@ -0,0 +1,6 @@ +import sbt._ + +class CompatSpecsTest(info: ProjectInfo) extends DefaultProject(info) +{ + val specs = "org.scala-tools.testing" % "specs" % "1.6.0" % "test" +} \ No newline at end of file diff --git a/src/sbt-test/tests/specs-compat/src/test/scala/Fail.scala b/src/sbt-test/tests/specs-compat/src/test/scala/Fail.scala new file mode 100644 index 000000000..b71e69285 --- /dev/null +++ b/src/sbt-test/tests/specs-compat/src/test/scala/Fail.scala @@ -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.*") + } +} \ No newline at end of file diff --git a/src/sbt-test/tests/specs-compat/src/test/scala/Success.scala b/src/sbt-test/tests/specs-compat/src/test/scala/Success.scala new file mode 100644 index 000000000..6c3406584 --- /dev/null +++ b/src/sbt-test/tests/specs-compat/src/test/scala/Success.scala @@ -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.*") + } +} \ No newline at end of file diff --git a/src/sbt-test/tests/specs-compat/test b/src/sbt-test/tests/specs-compat/test new file mode 100644 index 000000000..943bb2d7d --- /dev/null +++ b/src/sbt-test/tests/specs-compat/test @@ -0,0 +1,9 @@ +> ++2.7.5 +> update +> test-only Success +-> test-only Failure + +> ++2.7.7 +> update +> test-only Success +-> test-only Failure \ No newline at end of file