scalatest 1.0 fails with sbt (0.5.5)

11 views
Skip to first unread message

peterh

unread,
Oct 12, 2009, 12:27:07 PM10/12/09
to scalatest-users
Hi Bill, Congrats to 1.0 !

I ran into one issue so far, it seems like something has changed
around Reporter which is causing issues with sbt.

[error] Could not run test
org.pinky.code.extension.JsonRepresentationTest:
java.lang.NoClassDefFoundError: org/scalatest/Reporter$class
java.lang.NoClassDefFoundError: org/scalatest/Reporter$class
at sbt.impl.ScalaTestRunner$ScalaTestReporter.<init>
(TestFrameworkImpl.scala:56)
at sbt.impl.ScalaTestRunner.runTest(TestFrameworkImpl.scala:46)
at sbt.BasicTestRunner.run(TestFramework.scala:38)
at sbt.TestFramework$$anonfun$7$$anonfun$apply$8.runTest$1
(TestFramework.scala:136)
at sbt.TestFramework$$anonfun$7$$anonfun$apply$8$$anonfun$apply
$9.apply(TestFramework.scala:147)
at sbt.TestFramework$$anonfun$7$$anonfun$apply$8$$anonfun$apply
$9.apply(TestFramework.scala:147)
at sbt.NamedTestTask.run(TestFramework.scala:57)
at sbt.ScalaProject$$anonfun$sbt$ScalaProject$$toTask$1.apply
(ScalaProject.scala:169)
at sbt.ScalaProject$$anonfun$sbt$ScalaProject$$toTask$1.apply
(ScalaProject.scala:169)
at sbt.TaskManager$Task.invoke(TaskManager.scala:62)
at sbt.impl.RunTask.doRun$1(RunTask.scala:75)
at sbt.impl.RunTask.runTask(RunTask.scala:83)

should I report this issue at sbt or is it something you can fix at
your side?

Thanks in advance,
Peter

Bill Venners

unread,
Oct 12, 2009, 12:55:26 PM10/12/09
to scalate...@googlegroups.com
Hi Peter,

That's probably a breakage, which is my fault but will need to be
fixed in sbt. Up until this release I had managed for the most part to
have a deprecation cycle for every incompatible change: i.e., I'd mark
things deprecated but they'd still work for two releases before I
removed them. But in 1.0, I did a major "Reporter refactor" that made
it really hard to do a deprecation cycle. The breakages should affect
mostly tools people (such as sbt, the IntelliJ IDEA plugin, etc.) more
than regular users, but if a regular user customized a Suite by
overriding any of the run methods, or did a custom reporter, things
like that, they'll have to make some minor changes to upgrade to 1.0.
I'll work with the sbt folks to get to the bottom of this problem.

Thanks.

Bill
--
Bill Venners
Artima, Inc.
http://www.artima.com

Josh Cough

unread,
Oct 12, 2009, 1:07:42 PM10/12/09
to scalate...@googlegroups.com
Bill, Mark, Peter, All,

I have code that fixes this (it works on my branch), it's just up to Mark to put it into sbt. Here is the link to the code: https://scalatest.dev.java.net/source/browse/scalatest/branches/josh-sbt-2/app/src/main/scala/org/scalatest/sbt/ScalaTestRunner.scala?rev=2017&view=markup

For anyone that wants to use sbt with scalatest at this very second, you can do this in two steps:

1) Put ScalaTestRunner in your own source code in the org.scalatest.sbt package.
2) Add this line to your sbt project file:
override def compileClasspath = super.compileClasspath +++ Path.fromFile(FileUtilities.sbtJar)

 However, last time I tried this was at least a week back. Hopefully it still works. Here is the code.

package org.scalatest.sbt

import _root_.sbt._

/**The test runner for ScalaTest suites. */
class ScalaTestRunner(val log: Logger, val listeners: Seq[TestReportListener],
val testLoader: ClassLoader) extends BasicTestRunner
{
import _root_.java.lang.reflect.Modifier

def runTest(testClassName: String): Result.Value = {
val testClass = Class.forName(testClassName, true, testLoader).asSubclass(classOf[Suite])

if( isAccessibleSuite(testClass)){
val test = testClass.newInstance
val reporter = new ScalaTestReporter
test.run(None, reporter, new Stopper {}, Filter(), Map.empty, None, new Tracker)
if (reporter.succeeded) Result.Passed else Result.Failed
} else{
Result.Passed
}
}

private val emptyClassArray = new Array[java.lang.Class[T] forSome { type T }](0)

private def isAccessibleSuite(clazz: java.lang.Class[_]): Boolean = {
try {
classOf[Suite].isAssignableFrom(clazz) &&
Modifier.isPublic(clazz.getModifiers) &&
!Modifier.isAbstract(clazz.getModifiers) &&
Modifier.isPublic(clazz.getConstructor(emptyClassArray: _*).getModifiers)
} catch {
case nsme: NoSuchMethodException => false
case se: SecurityException => false
}
}

/**An implementation of Reporter for ScalaTest. */
private class ScalaTestReporter extends org.scalatest.Reporter with NotNull
{
import org.scalatest.events._
var succeeded = true

def apply(event: Event) {
event match {
// why log.info sometimes and fire(MessageEvent...) other times?
case rc: RunCompleted => log.info("Run completed.")
case rs: RunStarting => fire(MessageEvent("Run starting"))
case rs: RunStopped => {succeeded = false; fire(ErrorEvent("Run stopped"))}
case ra: RunAborted => {succeeded = false; fire(ErrorEvent("Run aborted"))}

// this one seems to be working really well
case ts: TestStarting => fire(TypedEvent(ts.testName, "Test Starting", None)(None))
// not sure what to do here at all
case tp: TestPending =>
case tf: TestFailed => {succeeded = false; fire(TypedErrorEvent(tf.testName, "Test Failed", None, tf.throwable)(Some(Result.Failed)))}
// this one also seems to be working really well
case ts: TestSucceeded => fire(TypedEvent(ts.testName, "Test Succeeded", None)(Some(Result.Passed)))
// need to check if there is a reason why this test was ignored
case ti: TestIgnored => fire(IgnoredEvent(ti.testName, Some("test ignored")))

case sc: SuiteCompleted => fire(TypedEvent(sc.suiteName, "Suite Completed", None)(None))
// why not sure Some(Result.Failed) here?
// also, why not say succeeded = false?
// seems like i should do both if the suite is aborted.
case sa: SuiteAborted => fire(TypedErrorEvent(sa.suiteName, "Suite Aborted", Some(sa.message), sa.throwable)(None))
case ss: SuiteStarting => fire(TypedEvent(ss.suiteName, "Suite Starting", None)(None))

// not actually sure if this is what i should do here...info provided is really just...some random extra info provided by a test, like a log statement
case ip: InfoProvided => fire(MessageEvent(ip.message))
}
}
}
}

phausel

unread,
Oct 12, 2009, 1:27:27 PM10/12/09
to scalatest-users
excellent! thank you all! Peter


On Oct 12, 6:07 pm, Josh Cough <joshco...@gmail.com> wrote:
> Bill, Mark, Peter, All,
>
> I have code that fixes this (it works on my branch), it's just up to Mark to
> put it into sbt. Here is the link to the code:https://scalatest.dev.java.net/source/browse/scalatest/branches/josh-...

Dustin Whitney

unread,
Oct 21, 2009, 1:54:38 PM10/21/09
to scalatest-users
Josh's fix didn't work for me. Any other suggestions? I suppose I
could revert to scalatest 0.95 until sbt if fixed.

-Dustin
Reply all
Reply to author
Forward
0 new messages