Extensions Wiki » Extensions » Syntax Test Report

Syntax Test Report

Last modified by Vincent Massol on 2012/05/18 14:11
cogDisplays the results of the Compatibility Test Suite for all Syntaxes
TypeSnippet
Developed by

Vincent Massol

LicenseGNU Lesser General Public License 2.1

Table of contents

Description

The Rendering module has a Compatibility Test Suite (CTS) which defines Rendering tests and those tests are executed for each supported Syntax.

This snippet provides an overview of the test results. You can also see it live on the Rendering Wiki.

Code

{{ctsdata}}
{{groovy}}
def url = "http://ci.xwiki.org/job/xwiki-rendering/lastSuccessfulBuild/testReport/api/xml?xpath=//suite/case/className%5Btext()%20=%20'org.xwiki.rendering.test.cts.RenderingTest'%5D/..&wrapper=root".toURL().text
def root = new XmlSlurper().parseText(url)
root."case".each() { it ->
  def testAsString = it.name.text().replaceAll("\\\\/", "/").replaceAll("\\\\u002C", ",")
  if (it.skipped == "false") {
    testAsString = "${testAsString} - Passed"
  }
  println testAsString
}
{{/groovy}}
{{/ctsdata}}

{{groovy}}
import org.apache.commons.configuration.PropertiesConfiguration
import org.xwiki.rendering.internal.macro.ctsreport.State

def colors = [PASSED:"039915", FAILING:"F50A21", MISSING:"F59B0A", NOT_APPLICABLE:"C2C0C0"]

def descriptions
try {
  def config = new PropertiesConfiguration("https://raw.github.com/xwiki/xwiki-rendering/master/xwiki-rendering-test/src/main/resources/cts/config.properties".toURL())
   descriptions = config.getProperties("testDescriptions", new Properties())
} catch (e) {
  descriptions = new Properties()
}

println "{{box cssClass='floatinginfobox'}}"
println "**Legend**"
println "|(% style='background-color: #${colors.get("PASSED")}' %)|Passed test"
println "|(% style='background-color: #${colors.get("FAILING")}' %)|Failing test"
println "|(% style='background-color: #${colors.get("MISSING")}' %)|Missing test (needs to be written, could pass or fail)"
println "|(% style='background-color: #${colors.get("NOT_APPLICABLE")}' %)|Not supported"
if (!descriptions.isEmpty()) {
  println ""
  println "**Test Descriptions**"
  ctsTestNames.each() { name ->
    println "|${name}|${descriptions.get(name)}"
  }
}
println "{{/box}}"
println ""

def syntaxModules = ["xwiki/2.0":"xwiki20", "xwiki/2.1":"xwiki21", "xwiki/1.0":"xwiki10"]

def buffer = []
def completeness = [:]

ctsTests = ctsTests.sort()
ctsTests.each() { syntax, inOutTests ->
  def nbTests = [FAILING:0, NOT_APPLICABLE:0, PASSED:0, MISSING:0 ]
  def nbTotal = 0
  def nbPassed = 0

  // Find the syntax module name
  def syntaxResourceName = syntax.replace("/", "").replace(".", "")
  def syntaxModuleName = syntaxModules.get(syntax)
  if (!syntaxModuleName) {
    syntaxModuleName = syntax.find(/\w+/)
  }
  def syntaxLocation = "https://raw.github.com/xwiki/xwiki-rendering/master/xwiki-rendering-syntaxes/xwiki-rendering-syntax-${syntaxModuleName}/src/test/resources/${syntaxResourceName}"

  buffer.add("{{id name='${syntax}'/}}")
  buffer.add("= Syntax: ${syntax} =")

  def syntaxBuffer = []

  def inTests = inOutTests.getLeft()
  if (inTests.isEmpty()) {
    syntaxBuffer.add("There is no Parser for this syntax.")
  } else {
    syntaxBuffer.add("Parser Tests:")
    syntaxBuffer.add("|=Input|=Expected Output|=Result")
    inTests.each() { test ->

      int nb = nbTests.get(test.state.toString())
      nbTests.put(test.state.toString(), ++nb)
      nbTotal++
      if (test.state == State.PASSED) { nbPassed++ }

      def syntaxExtension = test.syntaxExtension ?: ""
      def ctsExtension = test.ctsExtension ?: ""

      // Compute link to sources
      def ctsCell = "[[${test.prefix}${syntaxExtension}>>https://raw.github.com/xwiki/xwiki-rendering/master/xwiki-rendering-test/src/main/resources/cts/${test.prefix}${ctsExtension}]]"
      def syntaxCell = "[[${test.prefix}${syntaxExtension}>>${syntaxLocation}/${test.prefix}${test.syntaxExtension}]]"

      syntaxBuffer.add("|${syntaxCell}|${ctsCell}|(% style='background-color: #${colors.get(test.state.name())}' %)")
    }
  }  
  syntaxBuffer += ""

  def outTests = inOutTests.getRight()
  if (outTests.isEmpty()) {
    syntaxBuffer.add("There is no Renderer for this syntax.")
  } else {
    syntaxBuffer.add("Renderer Tests:")
    syntaxBuffer.add("|=Input|=Expected Output|=Result")
    outTests.each() { test ->

      int nb = nbTests.get(test.state.toString())
      nbTests.put(test.state.toString(), ++nb)
      nbTotal++
      if (test.state == State.PASSED) { nbPassed++ }

      def syntaxExtension = test.syntaxExtension ?: ""
      def ctsExtension = test.ctsExtension ?: ""

      // Compute link to sources
      def ctsCell = "[[${test.prefix}${syntaxExtension}>>https://raw.github.com/xwiki/xwiki-rendering/master/xwiki-rendering-test/src/main/resources/cts/${test.prefix}${ctsExtension}]]"
      def syntaxCell = "[[${test.prefix}${syntaxExtension}>>${syntaxLocation}/${test.prefix}${test.syntaxExtension}]]"

      syntaxBuffer.add("|${ctsCell}|${syntaxCell}|(% style='background-color: #${colors.get(test.state.name())}' %)")
    }
  }

  def chartBuffer = []
  def colorsAsString = colors.values().join(',')
  chartBuffer.add("{{chart type='pie' source='inline' params='range:B2-B${nbTests.size() + 1};series:columns;colors:${colorsAsString}' title='Summary for ${syntax}'}}")
  chartBuffer.add("|  |Value")
  nbTests.each() { state, nb ->
    chartBuffer.add("|${state}|${nb}")
  }
  chartBuffer.add("{{/chart}}")

  syntaxBuffer.addAll(0, chartBuffer)
  buffer.addAll(syntaxBuffer)

  completeness.put(syntax, 100*(nbPassed/nbTotal))
}

// Add Summary Table

println "Test Reports for the following syntaxes:"
println ""
println "|=Syntax|=% Completeness"
//println "{{toc/}}"
//println ""
ctsTests.keySet().each() { syntax ->
  println "|[[${syntax}>>||anchor='${syntax}']]|((({{html}}<div style='width:200px; border:1px solid grey; padding:3px;'><div style='width:${completeness.get(syntax)}%;  background:green;'>${completeness.get(syntax)}%</div></div>{{/html}})))"
}
println ""

buffer.each() { println it }
{{/groovy}}

Result

syntaxreport.png

Created by Vincent Massol on 2012/05/12 12:23

Download XWiki