-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
re #47: Added tests using the scripted-plugin
- Loading branch information
Heiko Seeberger
committed
Oct 24, 2011
1 parent
781fbfa
commit 618e14a
Showing
7 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import java.io.{ File, FileInputStream } | ||
import sbt._ | ||
import sbt.Keys._ | ||
import scala.xml.{ Elem, XML } | ||
|
||
object Build extends Build { | ||
|
||
lazy val UserHome = System.getProperty("user.home") | ||
|
||
// Dependencies | ||
lazy val specs2 = "org.specs2" %% "specs2" % "1.6.1" | ||
lazy val specs2Test = "org.specs2" %% "specs2" % "1.6.1" % "test" | ||
lazy val slf4s = "com.weiglewilczek.slf4s" %% "slf4s" % "1.0.7" | ||
|
||
// Settings | ||
val commonSettings = Defaults.defaultSettings ++ Seq( | ||
organization := "localhost", | ||
scalaVersion := "2.9.1", | ||
libraryDependencies ++= Seq(specs2Test), | ||
shellPrompt := { "sbt (%s)> " format projectId(_) }) | ||
|
||
// Projects | ||
lazy val root: Project = Project("root", | ||
file("."), | ||
settings = commonSettings ++ Seq( | ||
verifyProjectFiles := verifyProjectFilesAction, | ||
verifyClasspathFiles := verifyClasspathFilesAction), | ||
aggregate = Seq(sub1)) | ||
lazy val sub1: Project = Project("sub1", | ||
file("sub1"), | ||
settings = commonSettings, | ||
dependencies = Seq(root), | ||
aggregate = Seq(sub11, sub12)) | ||
lazy val sub11: Project = Project("sub11", | ||
file("sub1/sub11"), | ||
settings = commonSettings :+ (libraryDependencies += slf4s), | ||
dependencies = Seq(sub1)) | ||
lazy val sub11Test = sub11 % "test->test" | ||
lazy val sub12: Project = Project("sub12", | ||
file("sub1/sub12"), | ||
settings = commonSettings :+ (libraryDependencies += specs2), | ||
dependencies = Seq(sub1, sub11, sub11Test)) | ||
|
||
// Helpers | ||
def projectId(state: State) = extracted(state).currentProject.id | ||
def extracted(state: State) = Project extract state | ||
|
||
lazy val verifyProjectFiles = TaskKey[Unit]("verify-project-files") | ||
|
||
lazy val verifyClasspathFiles = TaskKey[Unit]("verify-classpath-files") | ||
|
||
def verifyProjectFilesAction: Unit = { | ||
val projectXml = XML.load(new FileInputStream(new File(root.base, ".project"))) | ||
val name = (projectXml \ "name" map { _.text }).mkString | ||
assert(name == "root", "Expected name to be 'root', but was '%s'!" format name) | ||
} | ||
|
||
def verifyClasspathFilesAction: Unit = { | ||
def classpathXml(project: Project): Elem = | ||
XML.load(new FileInputStream(new File(project.base, ".classpath"))) | ||
def assertContains(classpath: Elem, xml: Elem): Unit = | ||
assert((classpath \ "classpathentry") contains xml, "Missing %s!" format xml) | ||
def verifyCommonEntries(classpath: Elem) = { | ||
assertContains(classpath, | ||
<classpathentry output=".target/scala-2.9.1/classes" path="src/main/scala" kind="src"/>) | ||
assertContains(classpath, | ||
<classpathentry path={ UserHome + "/.ivy2/cache/org.specs2/specs2_2.9.1/jars/specs2_2.9.1-1.6.1.jar" } kind="lib"/>) | ||
assertContains(classpath, | ||
<classpathentry path={ UserHome + "/.ivy2/cache/org.specs2/specs2-scalaz-core_2.9.1/jars/specs2-scalaz-core_2.9.1-6.0.1.jar" } kind="lib"/>) | ||
assertContains(classpath, | ||
<classpathentry path="org.scala-ide.sdt.launching.SCALA_CONTAINER" kind="con"/>) | ||
assertContains(classpath, | ||
<classpathentry path="org.eclipse.jdt.launching.JRE_CONTAINER" kind="con"/>) | ||
assertContains(classpath, | ||
<classpathentry path=".target/scala-2.9.1/classes" kind="output"/>) | ||
} | ||
// root | ||
verifyCommonEntries(classpathXml(root)) | ||
// sub1 | ||
verifyCommonEntries(classpathXml(sub1)) | ||
assertContains(classpathXml(sub1), | ||
<classpathentry exported="true" path="/root" kind="src" combineaccessrules="false"/>) | ||
// sub11 | ||
verifyCommonEntries(classpathXml(sub11)) | ||
assertContains(classpathXml(sub11), | ||
<classpathentry path={ UserHome + "/.ivy2/cache/org.slf4j/slf4j-api/jars/slf4j-api-1.6.1.jar" } kind="lib"/>) | ||
assertContains(classpathXml(sub11), | ||
<classpathentry exported="true" path="/sub1" kind="src" combineaccessrules="false"/>) | ||
// sub12 | ||
verifyCommonEntries(classpathXml(sub12)) | ||
assertContains(classpathXml(sub12), | ||
<classpathentry path={ UserHome + "/.ivy2/cache/org.slf4j/slf4j-api/jars/slf4j-api-1.6.1.jar" } kind="lib"/>) | ||
assertContains(classpathXml(sub12), | ||
<classpathentry exported="true" path="/sub1" kind="src" combineaccessrules="false"/>) | ||
assertContains(classpathXml(sub12), | ||
<classpathentry exported="true" path="/sub11" kind="src" combineaccessrules="false"/>) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
//resolvers += Classpaths.typesafeResolver | ||
|
||
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse" % "1.5.0-SNAPSHOT") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
object Root { | ||
val root = "root" | ||
} |
3 changes: 3 additions & 0 deletions
3
src/sbt-test/sbteclipse/default/sub1/src/main/scala/Sub1.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
object Sub1 { | ||
val sub1 = Root.root + " > sub1" | ||
} |
5 changes: 5 additions & 0 deletions
5
src/sbt-test/sbteclipse/default/sub1/sub11/src/main/scala/Sub11.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import com.weiglewilczek.slf4s.Logging | ||
|
||
object Sub11 extends Logging { | ||
val sub11 = Root.root + ": " + Sub1.sub1 + " > sub11" | ||
} |
3 changes: 3 additions & 0 deletions
3
src/sbt-test/sbteclipse/default/sub1/sub12/src/main/scala/Sub12.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
object Sub12 { | ||
val sub12 = Root.root + ": " + Sub1.sub1 + " > sub12 -> " + Sub11.sub11 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# eclipse without options | ||
$ exec find . -name .classpath -delete | ||
$ exec find . -name .project -delete | ||
> eclipse | ||
$ exists .classpath | ||
$ exists .project | ||
$ exists sub1/.classpath | ||
$ exists sub1/.project | ||
$ exists sub1/sub11/.classpath | ||
$ exists sub1/sub11/.project | ||
$ exists sub1/sub12/.classpath | ||
$ exists sub1/sub12/.project | ||
> verify-project-files | ||
> verify-classpath-files | ||
|
||
# eclipse create-src | ||
$ delete src/main/java | ||
$ delete src/main/resources | ||
$ delete src/main/scala | ||
> eclipse create-src | ||
$ exists src/main/java | ||
$ exists src/main/resources | ||
$ exists src/main/scala | ||
|
||
# eclipse skip-parents | ||
$ exec find . -name .classpath -delete | ||
$ exec find . -name .project -delete | ||
> eclipse skip-parents | ||
$ absent .classpath | ||
$ absent .project | ||
$ absent sub1/.classpath | ||
$ absent sub1/.project | ||
$ exists sub1/sub11/.classpath | ||
$ exists sub1/sub11/.project | ||
$ exists sub1/sub12/.classpath | ||
$ exists sub1/sub12/.project | ||
|
||
# eclipse skip-root | ||
$ exec find . -name .classpath -delete | ||
$ exec find . -name .project -delete | ||
> eclipse skip-root | ||
$ absent .classpath | ||
$ absent .project | ||
$ exists sub1/.classpath | ||
$ exists sub1/.project | ||
$ exists sub1/sub11/.classpath | ||
$ exists sub1/sub11/.project | ||
$ exists sub1/sub12/.classpath | ||
$ exists sub1/sub12/.project |