diff --git a/src/main/scala/uk/org/floop/sparqlTestRunner/Run.scala b/src/main/scala/uk/org/floop/sparqlTestRunner/Run.scala index 301791a..9bcddec 100644 --- a/src/main/scala/uk/org/floop/sparqlTestRunner/Run.scala +++ b/src/main/scala/uk/org/floop/sparqlTestRunner/Run.scala @@ -8,12 +8,12 @@ import org.apache.jena.rdf.model.{Model, ModelFactory} import org.apache.jena.riot.RDFDataMgr -import scala.collection.JavaConversions._ import scala.io.Source -import scala.xml.{NodeSeq, XML} +import scala.xml.{NodeSeq, PrettyPrinter} case class Config(dir: File = new File("tests/sparql"), report: File = new File("reports/TESTS-sparql-test-runner.xml"), + ignoreFail: Boolean = false, data: Seq[File] = Seq()) object Run extends App { @@ -26,6 +26,9 @@ opt[File]('r', "report") optional() valueName "" action { (x, c) => c.copy(report = x) } text "file to output XML test report, defaults to reports/TESTS-sparql-test-runner.xml" + opt[Unit]('i', "ignorefail") optional() action { (_, c) => + c.copy(ignoreFail = true) + } text "exit with success even if there are reported failures" arg[File]("...") unbounded() required() action { (x, c) => c.copy(data = c.data :+ x) } text "data to run the queries against" } @@ -43,8 +46,11 @@ for (dir <- Option(config.report.getParentFile)) { dir.mkdirs } - XML.save(config.report.toString, {results}, "UTF-8", true) - System.exit(error match { + val pp = new PrettyPrinter(80, 2) + val pw = new PrintWriter(config.report) + pw.write(pp.format({results})) + pw.close + System.exit((error && !config.ignoreFail) match { case true => 1 case false => 0 }) @@ -107,18 +113,19 @@ if (nonEmptyResults) { errors += 1 System.err.println(s"Testcase $comment\nExpected empty result set, got:\n${actualResults}") - + } } } } else if (query.isAskType) { - var result = exec.execAsk() + val result = exec.execAsk() val timeTaken = (System.currentTimeMillis() - timeTestStart).toFloat / 1000 testCases = testCases ++ { if (!result) { errors += 1 System.err.println(s"Testcase $comment\nExpected ASK query to return TRUE") + }} } else { skipped += 1 @@ -134,7 +141,7 @@ } val testSuiteTime = (System.currentTimeMillis() - timeSuiteStart - subSuiteTimes).toFloat / 1000 val suiteName = { - val relativeName = root.relativize(dir.toPath).toString + val relativeName = root.getParent.relativize(dir.toPath).toString if (relativeName.length == 0) { "root" } else {