Permalink
Browse files

Added compliance test suite based on TipiTests submodule

  • Loading branch information...
1 parent f31a9f1 commit f180c511579fe4bbcc92aa0fe0ada716a5d13f3a @davegurnell committed Apr 10, 2012
View
@@ -1,3 +1,3 @@
-[submodule "src/test/resources/tipitests"]
- path = src/test/resources/tipitests
+[submodule "src/test/resources/compliance"]
+ path = src/test/resources/compliance
url = git@github.com:hiddenmemory/TipiTests
View
@@ -5,6 +5,28 @@ object Build extends Build {
lazy val scalatest = "org.scalatest" %% "scalatest" % "1.7.1"
lazy val slf4s = "com.weiglewilczek.slf4s" %% "slf4s" % "1.0.7"
+ val complianceFiles = SettingKey[Seq[(String, String)]]("compliance-files")
+ val complianceIndex = SettingKey[File]("compliance-index")
+ val writeComplianceIndex = TaskKey[Unit]("write-compliance-index")
+
+ def complianceFilesSetting =
+ (resourceDirectory in Test) apply { resourceDir =>
+ (for {
+ suiteDir <- IO.listFiles(resourceDir / "compliance").toList
+ inputFile <- IO.listFiles("*.input")(suiteDir).toList
+ inputFilename <- IO.relativize(resourceDir, inputFile)
+ outputFilename <- Some("[.]input".r.replaceAllIn(inputFilename, ".output")) if (resourceDir / outputFilename).exists
+ } yield (inputFilename, outputFilename)) : Seq[(String, String)]
+ }
+
+ def writeComplianceIndexTask =
+ (streams, complianceIndex, complianceFiles) map { (out, index, files) =>
+ IO.write(
+ index,
+ files map { case (a, b) => "/%s => /%s".format(a, b) } mkString "\n"
+ )
+ }
+
lazy val root = Project(
id = "root",
base = file("."),
@@ -27,7 +49,11 @@ object Build extends Build {
keyfile <- Option(System.getenv("DEFAULT_IVY_REPO_KEYFILE"))
} yield Resolver.sftp("Untyped", host, path)(Resolver.ivyStylePatterns).as(user, file(keyfile))
},
- publishMavenStyle := false
+ publishMavenStyle := false,
+ complianceIndex <<= (resourceDirectory in Test)(_ / "compliance.index"),
+ complianceFiles <<= complianceFilesSetting,
+ writeComplianceIndex <<= writeComplianceIndexTask,
+ test in Test <<= (test in Test).dependsOn(writeComplianceIndex)
)
)
}
File renamed without changes.
@@ -0,0 +1,6 @@
+/compliance/basic/Test01.input => /compliance/basic/Test01.output
+/compliance/basic/Test02.input => /compliance/basic/Test02.output
+/compliance/basic/Test03.input => /compliance/basic/Test03.output
+/compliance/basic/Test04.input => /compliance/basic/Test04.output
+/compliance/basic/Test05.input => /compliance/basic/Test05.output
+/compliance/basic/Test06.input => /compliance/basic/Test06.output
@@ -0,0 +1,30 @@
+package tipi.core
+
+import org.scalatest._
+
+class ComplianceSuite extends FunSuite {
+ val tipi = Tipi()
+
+ val indexPath = "/compliance.index"
+
+ def resourceSource(path: String) =
+ io.Source.fromURL(getClass.getResource(path))
+
+ lazy val tipiTests: List[(String, String)] = {
+ for {
+ line <- resourceSource(indexPath).getLines.toList
+ files <- line.split("=>").toList match {
+ case src :: des :: Nil => Some((src.trim, des.trim))
+ case _ => None
+ }
+ } yield files
+ }
+
+ for {
+ (src, des) <- tipiTests
+ } {
+ test(src + " => " + des) {
+ assert(tipi(resourceSource(src).mkString) === des)
+ }
+ }
+}

0 comments on commit f180c51

Please sign in to comment.