tester support html generation

This commit is contained in:
Araq 2014-01-14 01:12:56 +01:00
commit c648a5774a
8 changed files with 141 additions and 20 deletions

View file

@ -263,16 +263,8 @@ when defined(withUpdate):
proc tests(args: string) = proc tests(args: string) =
# we compile the tester with taintMode:on to have a basic # we compile the tester with taintMode:on to have a basic
# taint mode test :-) # taint mode test :-)
exec("nimrod cc --taintMode:on tests/tester") exec("nimrod cc --taintMode:on tests/testament/tester")
exec(getCurrentDir() / "tests/tester".exe & " reject") exec(getCurrentDir() / "tests/testament/tester".exe & " all")
exec(getCurrentDir() / "tests/tester".exe & " compile")
exec(getCurrentDir() / "tests/tester".exe & " run")
exec(getCurrentDir() / "tests/tester".exe & " merge")
when false:
# activate real soon:
exec("nimrod cc --taintMode:on tests/testament/tester")
exec(getCurrentDir() / "tests/testament/tester".exe & " all")
proc temp(args: string) = proc temp(args: string) =
var output = "compiler" / "nimrod".exe var output = "compiler" / "nimrod".exe

View file

@ -1,7 +1,7 @@
# #
# #
# The Nimrod Tester # The Nimrod Tester
# (c) Copyright 2013 Andreas Rumpf # (c) Copyright 2014 Andreas Rumpf
# #
# Look at license.txt for more info. # Look at license.txt for more info.
# All rights reserved. # All rights reserved.
@ -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
@ -73,7 +73,7 @@ proc getMachine: MachineId =
if id.len > 0: if id.len > 0:
result = id.parseInt.MachineId result = id.parseInt.MachineId
else: else:
result = db.insertId(sql"insert into Machine(name, os, cpu) values (?,?,?)", result = db.insertId(sql"insert into Machine(name, os, cpu) values (?,?,?)",
name, system.hostOS, system.hostCPU).MachineId name, system.hostOS, system.hostCPU).MachineId
proc getCommit: CommitId = proc getCommit: CommitId =

127
tests/testament/htmlgen.nim Normal file
View file

@ -0,0 +1,127 @@
#
#
# 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 = """<table border="1">
<tr><td>Test</td><td>Category</td><td>Target</td>
<td>Action</td>
<td>Expected</td>
<td>Given</td>
<td>Success</td></tr>"""
TableFooter = "</table>"
HtmlBegin = """<html>
<head>
<title>Test results</title>
<style type="text/css">
<!--""" & slurp("css/boilerplate.css") & "\n" &
slurp("css/style.css") &
"""
ul#tabs { list-style-type: none; margin: 30px 0 0 0; padding: 0 0 0.3em 0; }
ul#tabs li { display: inline; }
ul#tabs li a { color: #42454a; background-color: #dedbde;
border: 1px solid #c9c3ba; border-bottom: none;
padding: 0.3em; text-decoration: none; }
ul#tabs li a:hover { background-color: #f1f0ee; }
ul#tabs li a.selected { color: #000; background-color: #f1f0ee;
font-weight: bold; padding: 0.7em 0.3em 0.38em 0.3em; }
div.tabContent { border: 1px solid #c9c3ba;
padding: 0.5em; background-color: #f1f0ee; }
div.tabContent.hide { display: none; }
-->
</style>
<script>
var tabLinks = new Array();
var contentDivs = new Array();
function init() {
// Grab the tab links and content divs from the page
var tabListItems = document.getElementById('tabs').childNodes;
for ( var i = 0; i < tabListItems.length; i++ ) {
if ( tabListItems[i].nodeName == "LI" ) {
var tabLink = getFirstChildWithTagName( tabListItems[i], 'A' );
var id = getHash( tabLink.getAttribute('href') );
tabLinks[id] = tabLink;
contentDivs[id] = document.getElementById( id );
}
}
// Assign onclick events to the tab links, and
// highlight the first tab
var i = 0;
for ( var id in tabLinks ) {
tabLinks[id].onclick = showTab;
tabLinks[id].onfocus = function() { this.blur() };
if ( i == 0 ) tabLinks[id].className = 'selected';
i++;
}
// Hide all content divs except the first
var i = 0;
for ( var id in contentDivs ) {
if ( i != 0 ) contentDivs[id].className = 'tabContent hide';
i++;
}
}
</script>
</head>
<body onload="init()">"""
HtmlEnd = "</body></html>"
proc td(s: string): string =
result = "<td>" & s.substr(0, 200).XMLEncode & "</td>"
proc generateHtml*(filename: string) =
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")
var outfile = open(filename, fmWrite)
outfile.write(HtmlBegin)
let thisMachine = backend.getMachine()
outfile.write()
let machine = db.getRow(sql"select name, os, cpu from machine where id = ?",
thisMachine)
outfile.write("<p><b>$#</b></p>" % machine.join(" "))
outfile.write("""<ul id="tabs">""")
for lastCommit in db.getRow(sql"select id from [Commit] order by id desc"):
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>")
for lastCommit in db.getRow(sql"select id from [Commit] order by id desc"):
outfile.write("""<div class="tabContent" id="$#">""" % lastCommit)
outfile.write(TableHeader)
for row in db.rows(sql(selRow), lastCommit, thisMachine):
outfile.write("<tr>")
for x in row:
outfile.write(x.td)
outfile.write("</tr>")
outfile.write(TableFooter)
outfile.write("</div>")
outfile.write(HtmlEnd)
close(db)
close(outfile)

View file

@ -10,8 +10,8 @@
## This program verifies Nimrod against the testcases. ## This program verifies Nimrod against the testcases.
import import
parseutils, strutils, pegs, os, osproc, streams, parsecfg, browsers, json, parseutils, strutils, pegs, os, osproc, streams, parsecfg, json,
marshal, cgi, backend, parseopt, specs #, caas marshal, backend, parseopt, specs, htmlgen, browsers
const const
resultsFile = "testresults.html" resultsFile = "testresults.html"
@ -249,16 +249,18 @@ proc main() =
processCategory(r, Category(dir), p.cmdLineRest.string) processCategory(r, Category(dir), p.cmdLineRest.string)
for a in AdditionalCategories: for a in AdditionalCategories:
processCategory(r, Category(a), p.cmdLineRest.string) processCategory(r, Category(a), p.cmdLineRest.string)
of "c", "category": of "c", "cat", "category":
var cat = Category(p.key) var cat = Category(p.key)
p.next p.next
processCategory(r, cat, p.cmdLineRest.string) processCategory(r, cat, p.cmdLineRest.string)
of "html": of "html":
quit "too implement" generateHtml(resultsFile)
else: else:
quit usage quit usage
if optPrintResults: echo r, r.data if optPrintResults:
if action == "html": openDefaultBrowser(resultsFile)
else: echo r, r.data
backend.close() backend.close()
if paramCount() == 0: if paramCount() == 0: