better tester

This commit is contained in:
Araq 2014-01-17 08:47:51 +01:00
commit 383fbca27e
21 changed files with 39 additions and 31 deletions

View file

@ -43,12 +43,12 @@ proc annotateType*(n: PNode, t: PType) =
n.typ = t n.typ = t
for i in 0 .. <n.len: for i in 0 .. <n.len:
let field = x.n.ithField(i) let field = x.n.ithField(i)
if field.isNil: globalError n.info, "invalid " & $i & "th field" if field.isNil: globalError n.info, "invalid field at index " & $i
else: annotateType(n.sons[i], field.typ) else: annotateType(n.sons[i], field.typ)
elif x.kind == tyTuple: elif x.kind == tyTuple:
n.typ = t n.typ = t
for i in 0 .. <n.len: for i in 0 .. <n.len:
if i >= x.len: globalError n.info, "invalid " & $i & "th field" if i >= x.len: globalError n.info, "invalid field at index " & $i
else: annotateType(n.sons[i], x.sons[i]) else: annotateType(n.sons[i], x.sons[i])
elif x.kind == tyProc and x.callConv == ccClosure: elif x.kind == tyProc and x.callConv == ccClosure:
n.typ = t n.typ = t

View file

@ -76,7 +76,7 @@ proc tryExec*(db: TDbConn, query: TSqlQuery,
proc exec*(db: TDbConn, query: TSqlQuery, args: varargs[string, `$`]) {. proc exec*(db: TDbConn, query: TSqlQuery, args: varargs[string, `$`]) {.
tags: [FReadDB, FWriteDb].} = tags: [FReadDB, FWriteDb].} =
## executes the query and raises EDB if not successful. ## executes the query and raises EDB if not successful.
if not TryExec(db, query, args): dbError(db) if not tryExec(db, query, args): dbError(db)
proc newRow(L: int): TRow = proc newRow(L: int): TRow =
newSeq(result, L) newSeq(result, L)

View file

@ -49,10 +49,10 @@ proc createDb() =
# """, []) # """, [])
type type
MachineId* = distinct int64 MachineId = distinct int64
CommitId = distinct int64 CommitId = distinct int64
proc `$`*(id: MachineId): string {.borrow.} proc `$`(id: MachineId): string {.borrow.}
proc `$`(id: CommitId): string {.borrow.} proc `$`(id: CommitId): string {.borrow.}
var var
@ -61,7 +61,7 @@ var
proc `()`(cmd: string{lit}): string = cmd.execProcess.string.strip proc `()`(cmd: string{lit}): string = cmd.execProcess.string.strip
proc getMachine*: MachineId = proc getMachine: MachineId =
var name = "hostname"() var name = "hostname"()
if name.len == 0: if name.len == 0:
name = when defined(posix): getenv"HOSTNAME".string name = when defined(posix): getenv"HOSTNAME".string

View file

@ -109,42 +109,46 @@ div.tabContent.hide { display: none; }
proc td(s: string): string = proc td(s: string): string =
result = "<td>" & s.substr(0, 200).XMLEncode & "</td>" result = "<td>" & s.substr(0, 200).XMLEncode & "</td>"
proc generateHtml*(filename: string) = 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, const selRow = """select name, category, target, action,
expected, given, result expected, given, result
from TestResult from TestResult
where [commit] = ? and machine = ? where [commit] = ? and machine = ?
order by category""" order by category"""
var db = open(connection="testament.db", user="testament", password="", var db = open(connection="testament.db", user="testament", password="",
database="testament") database="testament")
# search for proper commit:
let lastCommit = db.getCommit(commit)
var outfile = open(filename, fmWrite) var outfile = open(filename, fmWrite)
outfile.write(HtmlBegin) outfile.write(HtmlBegin)
let thisMachine = backend.getMachine()
outfile.write()
let machine = db.getRow(sql"select name, os, cpu from machine where id = ?", let commit = db.getValue(sql"select hash from [Commit] where id = ?",
thisMachine) lastCommit)
outfile.write("<p><b>$#</b></p>" % machine.join(" ")) let branch = db.getValue(sql"select branch from [Commit] where id = ?",
lastCommit)
outfile.write("<p><b>$# $#</b></p>" % [branch, commit])
# generate navigation:
outfile.write("""<ul id="tabs">""") outfile.write("""<ul id="tabs">""")
for m in db.rows(sql"select id, name, os, cpu from Machine order by id"):
for thisCommit in db.rows(sql"select id from [Commit] order by id desc"): outfile.writeln """<li><a href="#$#">$#: $#, $#</a></li>""" % m
let lastCommit = thisCommit[0]
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.writeln """<li><a href="#$#">$#: $#</a></li>""" % [
lastCommit, branch, commit]
outfile.write("</ul>") outfile.write("</ul>")
for thisCommit in db.rows(sql"select id from [Commit] order by id desc"): for currentMachine in db.rows(sql"select id from Machine order by id"):
let lastCommit = thisCommit[0] let m = currentMachine[0]
outfile.write("""<div class="tabContent" id="$#">""" % lastCommit) outfile.write("""<div class="tabContent" id="$#">""" % m)
outfile.write(TableHeader) outfile.write(TableHeader)
for row in db.rows(sql(selRow), lastCommit, thisMachine): for row in db.rows(sql(selRow), lastCommit, m):
outfile.write("<tr>") outfile.write("<tr>")
for x in row: for x in row:
outfile.write(x.td) outfile.write(x.td)

View file

@ -22,7 +22,9 @@ const
Command: Command:
all run all tests all run all tests
c|category <category> run all the tests of a certain category c|category <category> run all the tests of a certain category
html generate $1 from the database html [commit] generate $1 from the database; uses the latest
commit or a specific one (use -1 for the commit
before latest etc)
Arguments: Arguments:
arguments are passed to the compiler arguments are passed to the compiler
Options: Options:
@ -254,7 +256,9 @@ proc main() =
p.next p.next
processCategory(r, cat, p.cmdLineRest.string) processCategory(r, cat, p.cmdLineRest.string)
of "html": of "html":
generateHtml(resultsFile) var commit = 0
discard parseInt(p.cmdLineRest.string, commit)
generateHtml(resultsFile, commit)
else: else:
quit usage quit usage