Permalink
Browse files

Migrated xmlTest to Specs

  • Loading branch information...
1 parent 30350ab commit 79732dd779fa3d4b2f573ac41761d9fe5cf7a939 @eltimn eltimn committed Sep 15, 2010
@@ -3,8 +3,8 @@ import sbt._
class LiftProject(info: ProjectInfo) extends DefaultWebProject(info) {
val liftVersion = "2.1-RC1"
- val scalatoolsSnapshot =
- "Scala Tools Snapshot" at "http://scala-tools.org/repo-snapshots/"
+ // uncomment the following if you want to use the snapshot repo
+ //val scalatoolsSnapshot = ScalaToolsSnapshots
// If you're using JRebel for Lift development, uncomment
// this line
@@ -0,0 +1,64 @@
+package code
+
+import java.io.File
+
+import scala.xml.XML
+
+import org.specs.Specification
+import org.specs.runner.JUnit4
+
+import net.liftweb.common.Full
+import net.liftweb.util.PCDataXmlParser
+
+class XmlSourceSpecsTest extends JUnit4(XmlSourceSpecs)
+
+object XmlSourceSpecs extends Specification {
+
+ "XML Sources" should {
+ "be well-formed" in {
+ /**
+ * Tests to make sure the project's XML files are well-formed.
+ *
+ * Finds every *.html and *.xml file in src/main/webapp (and its
+ * subdirectories) and tests to make sure they are well-formed.
+ */
+ var failed: List[File] = Nil
+
+ def handledXml(file: String) =
+ file.endsWith(".xml")
+
+ def handledXHtml(file: String) =
+ file.endsWith(".html") || file.endsWith(".htm") || file.endsWith(".xhtml")
+
+ def wellFormed(file: File) {
+ if (file.isDirectory)
+ for (f <- file.listFiles) wellFormed(f)
+
+ if (file.isFile && handledXml(file.getName)) {
+ try {
+ XML.loadFile(file)
+ } catch {
+ case e: _root_.org.xml.sax.SAXParseException => failed = file :: failed
+ }
+ }
+ if (file.isFile && handledXHtml(file.getName)) {
+ PCDataXmlParser(new java.io.FileInputStream(file.getAbsolutePath)) match {
+ case Full(_) => // file is ok
+ case _ => failed = file :: failed
+ }
+ }
+ }
+
+ wellFormed(new File("src/main/webapp"))
+
+ val numFails = failed.size
+ if (numFails > 0) {
+ val fileStr = if (numFails == 1) "file" else "files"
+ val msg = "Malformed XML in " + numFails + " " + fileStr + ": " + failed.mkString(", ")
+ fail(msg)
+ }
+
+ numFails must_== 0
+ }
+ }
+}
@@ -2,7 +2,7 @@ package code {
package snippet {
import org.specs._
-import org.specs.runner.JUnit3
+import org.specs.runner.JUnit4
import org.specs.runner.ConsoleRunner
import net.liftweb._
import http._
@@ -14,7 +14,7 @@ import Helpers._
import lib._
-class HelloWorldTestSpecsAsTest extends JUnit3(HelloWorldTestSpecs)
+class HelloWorldTestSpecsAsTest extends JUnit4(HelloWorldTestSpecs)
object HelloWorldTestSpecsRunner extends ConsoleRunner(HelloWorldTestSpecs)
object HelloWorldTestSpecs extends Specification {

0 comments on commit 79732dd

Please sign in to comment.