#
#
# Nimrod Tester
# (c) Copyright 2014 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
#
## HTML generator for the tester.
import db_sqlite, cgi, backend, strutils
const
TableHeader = """
Test | Category | Target |
Action |
Expected |
Given |
Success |
"""
TableFooter = "
"
HtmlBegin = """
Test results
"""
HtmlEnd = ""
proc td(s: string): string =
result = "" & s.substr(0, 200).XMLEncode & " | "
proc getCommit(db: TDbConn, c: int): string =
var commit = c
for thisCommit in db.rows(sql"select id from [Commit] order by id desc"):
if commit == 0: result = thisCommit[0]
inc commit
if result.isNil:
quit "cannot determine commit " & $c
proc generateHtml*(filename: string, commit: int) =
const selRow = """select name, category, target, action,
expected, given, result
from TestResult
where [commit] = ? and machine = ?
order by category"""
var db = open(connection="testament.db", user="testament", password="",
database="testament")
# search for proper commit:
let lastCommit = db.getCommit(commit)
var outfile = open(filename, fmWrite)
outfile.write(HtmlBegin)
let commit = db.getValue(sql"select hash from [Commit] where id = ?",
lastCommit)
let branch = db.getValue(sql"select branch from [Commit] where id = ?",
lastCommit)
outfile.write("$# $#
" % [branch, commit])
# generate navigation:
outfile.write("""""")
for m in db.rows(sql"select id, name, os, cpu from Machine order by id"):
outfile.writeln """- $#: $#, $#
""" % m
outfile.write("
")
for currentMachine in db.rows(sql"select id from Machine order by id"):
let m = currentMachine[0]
outfile.write("""""" % m)
outfile.write(TableHeader)
for row in db.rows(sql(selRow), lastCommit, m):
outfile.write("
")
for x in row:
outfile.write(x.td)
outfile.write("
")
outfile.write(TableFooter)
outfile.write("")
outfile.write(HtmlEnd)
close(db)
close(outfile)
proc generateJson*(filename: string, commit: int) =
const selRow = """select count(*),
sum(result = 'reSuccess'),
sum(result = 'reIgnored')
from TestResult
where [commit] = ? and machine = ?
order by category"""
var db = open(connection="testament.db", user="testament", password="",
database="testament")
let lastCommit = db.getCommit(commit)
var outfile = open(filename, fmWrite)
let data = db.getRow(sql(selRow), lastCommit, $backend.getMachine(db))
outfile.writeln("""{"total": $#, "passed": $#, "skipped": $#}""" % data)
close(db)
close(outfile)