new tester produces json output

This commit is contained in:
Araq 2014-02-02 00:41:04 +01:00
commit d29aa4c5ac
7 changed files with 30 additions and 721 deletions

View file

@ -49,10 +49,10 @@ proc createDb() =
# """, [])
type
MachineId = distinct int64
MachineId* = distinct int64
CommitId = distinct int64
proc `$`(id: MachineId): string {.borrow.}
proc `$`*(id: MachineId): string {.borrow.}
proc `$`(id: CommitId): string {.borrow.}
var
@ -61,7 +61,7 @@ var
proc `()`(cmd: string{lit}): string = cmd.execProcess.string.strip
proc getMachine: MachineId =
proc getMachine*(db: TDbConn): MachineId =
var name = "hostname"()
if name.len == 0:
name = when defined(posix): getenv"HOSTNAME".string
@ -76,7 +76,7 @@ proc getMachine: MachineId =
result = db.insertId(sql"insert into Machine(name, os, cpu) values (?,?,?)",
name, system.hostOS, system.hostCPU).MachineId
proc getCommit: CommitId =
proc getCommit(db: TDbConn): CommitId =
const commLen = "commit ".len
let hash = "git log -n 1"()[commLen..commLen+10]
let branch = "git symbolic-ref --short HEAD"()
@ -115,7 +115,7 @@ proc open*() =
db = open(connection="testament.db", user="testament", password="",
database="testament")
createDb()
thisMachine = getMachine()
thisCommit = getCommit()
thisMachine = getMachine(db)
thisCommit = getCommit(db)
proc close*() = close(db)

View file

@ -159,3 +159,22 @@ proc generateHtml*(filename: string, commit: int) =
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)

View file

@ -208,20 +208,6 @@ proc makeTest(test, options: string, cat: Category, action = actionCompile,
include categories
proc toJson(res: TResults): PJsonNode =
result = newJObject()
result["total"] = newJInt(res.total)
result["passed"] = newJInt(res.passed)
result["skipped"] = newJInt(res.skipped)
proc outputJson(reject, compile, run: TResults) =
var doc = newJObject()
doc["reject"] = toJson(reject)
doc["compile"] = toJson(compile)
doc["run"] = toJson(run)
var s = pretty(doc)
writeFile(jsonFile, s)
# proc runCaasTests(r: var TResults) =
# for test, output, status, mode in caasTestsRunner():
# r.addResult(test, "", output & "-> " & $mode,
@ -259,6 +245,7 @@ proc main() =
var commit = 0
discard parseInt(p.cmdLineRest.string, commit)
generateHtml(resultsFile, commit)
generateJson(jsonFile, commit)
else:
quit usage