aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Christopher Vogt <oss.nsp@cvogt.org>2017-03-30 11:44:19 -0400
committerGitHub <noreply@github.com>2017-03-30 11:44:19 -0400
commit05d9dd8128b21eb64ffe6206af624237ac504b89 (patch)
tree0d0778cf588b8b5afbc4de6c6175800e246086e7
parent249b4a04bac50fcb9510e71ad142fcabf7b7f61d (diff)
parent3e37741a3d937a9d4c6ce85691226ef1197ebab6 (diff)
downloadcbt-05d9dd8128b21eb64ffe6206af624237ac504b89.tar.gz
cbt-05d9dd8128b21eb64ffe6206af624237ac504b89.tar.bz2
cbt-05d9dd8128b21eb64ffe6206af624237ac504b89.zip
Merge pull request #472 from cvogt/scalatest-for-2.12
Scalatest for 2.12
-rw-r--r--examples/scalatest-example/build/build.scala2
-rw-r--r--libraries/scalatest-runner/Runner.scala37
-rw-r--r--libraries/scalatest-runner/build/build.scala13
-rw-r--r--libraries/scalatest-runner/build/build/build.scala5
-rw-r--r--plugins/scalatest/ScalaTest.scala41
-rw-r--r--plugins/scalatest/build/build.scala2
-rw-r--r--stage2/BasicBuild.scala2
-rw-r--r--stage2/DirectoryDependency.scala8
-rw-r--r--stage2/libraries.scala11
9 files changed, 77 insertions, 44 deletions
diff --git a/examples/scalatest-example/build/build.scala b/examples/scalatest-example/build/build.scala
index 2c0ec21..8f8ed5f 100644
--- a/examples/scalatest-example/build/build.scala
+++ b/examples/scalatest-example/build/build.scala
@@ -8,7 +8,7 @@ java.lang.Exception: This should never happend. Could not find (org.scala-lang,s
*/
override def test: Dependency = {
new BasicBuild(context) with ScalaTest with SbtLayoutTest{
- override def dependencies = outer +: super.dependencies
+ override def dependencies = outer +: super.dependencies
}
}
}
diff --git a/libraries/scalatest-runner/Runner.scala b/libraries/scalatest-runner/Runner.scala
new file mode 100644
index 0000000..a9927bb
--- /dev/null
+++ b/libraries/scalatest-runner/Runner.scala
@@ -0,0 +1,37 @@
+package cbt.scalatest
+
+import org.scalatest._
+
+import java.io.File
+
+object Runner {
+ def run( classpath: Array[File], classLoader: ClassLoader ): Unit = {
+ val suiteNames = classpath.map( d => discoverSuites( d, classLoader ) ).flatten
+ runSuites( suiteNames.map( loadSuite( _, classLoader ) ) )
+ }
+
+ 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.toString ++ "/" ), classLoader, None )
+ .asInstanceOf[Set[String]]
+ .toVector
+ }
+ def loadSuite( name: String, classLoader: ClassLoader ) = {
+ classLoader.loadClass( name ).getConstructor().newInstance().asInstanceOf[Suite]
+ }
+}
diff --git a/libraries/scalatest-runner/build/build.scala b/libraries/scalatest-runner/build/build.scala
new file mode 100644
index 0000000..0c07c7c
--- /dev/null
+++ b/libraries/scalatest-runner/build/build.scala
@@ -0,0 +1,13 @@
+package cbt_libraries_build.scalatest_runner
+import cbt._
+import cbt_internal._
+
+class Build(val context: Context) extends Library{
+ override def inceptionYear = 2017
+ override def description = "run scalatest tests from given directory and classpath (compatible with 2.12 and 2.11)"
+
+ override def dependencies = super.dependencies ++
+ Resolver( mavenCentral ).bind(
+ ScalaDependency("org.scalatest","scalatest", if(scalaMajorVersion == "2.12") "3.0.1" else "2.2.6")
+ )
+}
diff --git a/libraries/scalatest-runner/build/build/build.scala b/libraries/scalatest-runner/build/build/build.scala
new file mode 100644
index 0000000..18003ee
--- /dev/null
+++ b/libraries/scalatest-runner/build/build/build.scala
@@ -0,0 +1,5 @@
+package cbt_build.scalatest_runner.build
+import cbt._
+class Build(val context: Context) extends BuildBuild with CbtInternal{
+ override def dependencies = super.dependencies :+ cbtInternal.library
+}
diff --git a/plugins/scalatest/ScalaTest.scala b/plugins/scalatest/ScalaTest.scala
index e2f44e3..87ab16d 100644
--- a/plugins/scalatest/ScalaTest.scala
+++ b/plugins/scalatest/ScalaTest.scala
@@ -1,42 +1,11 @@
package cbt
-import org.scalatest._
-
-
+import java.io.File
trait ScalaTest extends BaseBuild{
+ override def dependencies = super.dependencies :+ libraries.scalatestRunner
override def run: ExitCode = {
- import ScalaTestLib._
- val suiteNames = exportedClasspath.files.map( d => discoverSuites(d, classLoader) ).flatten
- runSuites( suiteNames.map( loadSuite( _, classLoader ) ) )
+ classLoader.loadClass( "cbt.scalatest.Runner" ).method(
+ "run", classOf[Array[File]], classOf[ClassLoader]
+ ).invoke( null, exportedClasspath.files.toArray, classLoader )
ExitCode.Success
}
- override def dependencies = super.dependencies ++ Resolver( mavenCentral ).bind( ScalaDependency("org.scalatest","scalatest","2.2.4") )
}
-
-object ScalaTestLib{
- import java.io.File
- 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]]
- .toVector
- }
- 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
index ce07b36..4e94cd7 100644
--- a/plugins/scalatest/build/build.scala
+++ b/plugins/scalatest/build/build.scala
@@ -4,7 +4,5 @@ class Build(val context: Context) extends BaseBuild{
override def dependencies = (
super.dependencies
:+ context.cbtDependency
- ) ++ Resolver( mavenCentral ).bind(
- ScalaDependency("org.scalatest","scalatest","2.2.4")
)
}
diff --git a/stage2/BasicBuild.scala b/stage2/BasicBuild.scala
index 067d1b7..2cf97e5 100644
--- a/stage2/BasicBuild.scala
+++ b/stage2/BasicBuild.scala
@@ -20,7 +20,7 @@ trait BaseBuild extends BuildInterface with DependencyImplementation with SbtDep
lazy val moduleKey: String = "BaseBuild("+target.string+")"
implicit def transientCache: java.util.Map[AnyRef,AnyRef] = context.transientCache
- implicit def libraries(implicit context: Context): libraries = new libraries(context)
+ implicit def libraries(implicit context: Context): libraries = new libraries(context, scalaVersion)
// library available to builds
implicit protected final val logger: Logger = context.logger
diff --git a/stage2/DirectoryDependency.scala b/stage2/DirectoryDependency.scala
index 6ebb988..f2b5557 100644
--- a/stage2/DirectoryDependency.scala
+++ b/stage2/DirectoryDependency.scala
@@ -57,7 +57,9 @@ object DirectoryDependency {
// the beginning. Instead CBT always needs to build the pure Java
// Launcher in the checkout with itself and then run it via reflection.
val ( checkoutDirectory, dependency ) =
- GitDependency.withCheckoutDirectory( base, hash, Some( "nailgun_launcher" ) )( context )
+ GitDependency.withCheckoutDirectory( base, hash, Some( "nailgun_launcher" ) )(
+ context.copy( scalaVersion = None )
+ )
dependency
.dependency
.asInstanceOf[BaseBuild] // should work because nailgun_launcher/ has no cbt build of it's own
@@ -71,7 +73,9 @@ object DirectoryDependency {
def loadCustomBuild: AnyRef = {
lib.logger.composition( "Loading build at " ++ buildDirectory.string )
- val buildBuild = apply( buildDirectory, None )( context ).dependency.asInstanceOf[BuildInterface]
+ val buildBuild = apply(
+ context.copy( workingDirectory = buildDirectory, scalaVersion = None ), None
+ ).dependency.asInstanceOf[BuildInterface]
import buildBuild._
val managedContext = context.copy( parentBuild = Some( buildBuild ) )
diff --git a/stage2/libraries.scala b/stage2/libraries.scala
index 3d2951c..f0e4ecc 100644
--- a/stage2/libraries.scala
+++ b/stage2/libraries.scala
@@ -1,6 +1,12 @@
package cbt
-class libraries( context: Context ) {
- private def dep( name: String ) = DirectoryDependency( context.cbtHome / "libraries" / name )( context )
+class libraries( context: Context, scalaVersion: String ) {
+ private def dep( name: String ) = DirectoryDependency(
+ context.copy(
+ scalaVersion = Some( scalaVersion ),
+ workingDirectory = context.cbtHome / "libraries" / name
+ ),
+ None
+ )
def captureArgs = dep( "capture_args" )
def eval = dep( "eval" )
def file = dep( "file" )
@@ -9,4 +15,5 @@ class libraries( context: Context ) {
def common_0 = dep( "common-0" )
def common_1 = dep( "common-1" )
def interfaces = dep( "interfaces" )
+ def scalatestRunner = dep( "scalatest-runner" )
}