diff options
Diffstat (limited to 'plugins/scalatest')
-rw-r--r-- | plugins/scalatest/ScalaTest.scala | 66 | ||||
-rw-r--r-- | plugins/scalatest/build/build.scala | 13 |
2 files changed, 79 insertions, 0 deletions
diff --git a/plugins/scalatest/ScalaTest.scala b/plugins/scalatest/ScalaTest.scala new file mode 100644 index 0000000..0959087 --- /dev/null +++ b/plugins/scalatest/ScalaTest.scala @@ -0,0 +1,66 @@ +import cbt._ +import java.net.URL +import java.io.File +import scala.collection.immutable.Seq +import org.scalatest._ +import org.scalatest + +/* FIXME: + - Separate out SbtLayout + - Allow depending on this via a git dependency. + Probably by adding support for subfolders to "GitDependency" +*/ + +trait SbtLayout extends BasicBuild{ + outer => + override def sources = Seq( projectDirectory ++ "/src/main/scala" ) + def testSources = projectDirectory ++ "/src/test/scala" + def testDependencies: Seq[Dependency] = Nil + lazy val testBuild = + new BasicBuild(context.copy(projectDirectory = testSources)) with ScalaTest{ + override def target = outer.target + override def compileTarget = outer.scalaTarget ++ "/test-classes" + override def dependencies = (outer +: testDependencies) ++ super.dependencies + } + override def test: Option[ExitCode] = + if(testSources.exists) Some( testBuild.run ) + else None +} + +trait ScalaTest extends BasicBuild{ + override def run: ExitCode = { + import ScalaTestLib._ + val _classLoader = classLoader(context.classLoaderCache) + val suiteNames = compile.map( d => discoverSuites(d, _classLoader) ).toVector.flatten + runSuites( suiteNames.map( loadSuite( _, _classLoader ) ) ) + ExitCode.Success + } +} + +object ScalaTestLib{ + def runSuites(suites: Seq[Suite]) = { + def color: Boolean = true + def durations: Boolean = true + def shortstacks: Boolean = true + def fullstacks: Boolean = true + def stats: Boolean = true + def testName: String = null + def configMap: ConfigMap = ConfigMap.empty + suites.foreach{ + _.execute(testName, configMap, color, durations, shortstacks, fullstacks, stats) + } + } + + def discoverSuites(discoveryPath: File, _classLoader: ClassLoader): Seq[String] = { + _classLoader + .loadClass("org.scalatest.tools.SuiteDiscoveryHelper") + .getMethod("discoverSuiteNames", classOf[List[_]], classOf[ClassLoader], classOf[Option[_]]) + .invoke(null, List(discoveryPath.string ++ "/"), _classLoader, None) + .asInstanceOf[Set[String]] + .to + } + def loadSuite(name: String, _classLoader: ClassLoader) = { + _classLoader.loadClass(name).getConstructor().newInstance().asInstanceOf[Suite] + } +} + diff --git a/plugins/scalatest/build/build.scala b/plugins/scalatest/build/build.scala new file mode 100644 index 0000000..d36d940 --- /dev/null +++ b/plugins/scalatest/build/build.scala @@ -0,0 +1,13 @@ +import cbt._ +import java.net.URL +import java.io.File +import scala.collection.immutable.Seq + +class Build(context: Context) extends BasicBuild(context){ + override def dependencies = super.dependencies ++ Seq( + MavenResolver(context.cbtHasChanged,context.paths.mavenCache,MavenResolver.central).resolve( + ScalaDependency("org.scalatest","scalatest","2.2.4") + ), + context.cbtDependency + ) +} |