mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-20 18:06:53 +00:00
tester support html generation
This commit is contained in:
12
koch.nim
12
koch.nim
@@ -263,16 +263,8 @@ when defined(withUpdate):
|
||||
proc tests(args: string) =
|
||||
# we compile the tester with taintMode:on to have a basic
|
||||
# taint mode test :-)
|
||||
exec("nimrod cc --taintMode:on tests/tester")
|
||||
exec(getCurrentDir() / "tests/tester".exe & " reject")
|
||||
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")
|
||||
|
||||
exec("nimrod cc --taintMode:on tests/testament/tester")
|
||||
exec(getCurrentDir() / "tests/testament/tester".exe & " all")
|
||||
|
||||
proc temp(args: string) =
|
||||
var output = "compiler" / "nimrod".exe
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#
|
||||
#
|
||||
# The Nimrod Tester
|
||||
# (c) Copyright 2013 Andreas Rumpf
|
||||
# (c) Copyright 2014 Andreas Rumpf
|
||||
#
|
||||
# Look at license.txt for more info.
|
||||
# All rights reserved.
|
||||
@@ -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*: MachineId =
|
||||
var name = "hostname"()
|
||||
if name.len == 0:
|
||||
name = when defined(posix): getenv"HOSTNAME".string
|
||||
@@ -73,7 +73,7 @@ proc getMachine: MachineId =
|
||||
if id.len > 0:
|
||||
result = id.parseInt.MachineId
|
||||
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
|
||||
|
||||
proc getCommit: CommitId =
|
||||
|
||||
127
tests/testament/htmlgen.nim
Normal file
127
tests/testament/htmlgen.nim
Normal 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)
|
||||
@@ -10,8 +10,8 @@
|
||||
## This program verifies Nimrod against the testcases.
|
||||
|
||||
import
|
||||
parseutils, strutils, pegs, os, osproc, streams, parsecfg, browsers, json,
|
||||
marshal, cgi, backend, parseopt, specs #, caas
|
||||
parseutils, strutils, pegs, os, osproc, streams, parsecfg, json,
|
||||
marshal, backend, parseopt, specs, htmlgen, browsers
|
||||
|
||||
const
|
||||
resultsFile = "testresults.html"
|
||||
@@ -249,16 +249,18 @@ proc main() =
|
||||
processCategory(r, Category(dir), p.cmdLineRest.string)
|
||||
for a in AdditionalCategories:
|
||||
processCategory(r, Category(a), p.cmdLineRest.string)
|
||||
of "c", "category":
|
||||
of "c", "cat", "category":
|
||||
var cat = Category(p.key)
|
||||
p.next
|
||||
processCategory(r, cat, p.cmdLineRest.string)
|
||||
of "html":
|
||||
quit "too implement"
|
||||
generateHtml(resultsFile)
|
||||
else:
|
||||
quit usage
|
||||
|
||||
if optPrintResults: echo r, r.data
|
||||
if optPrintResults:
|
||||
if action == "html": openDefaultBrowser(resultsFile)
|
||||
else: echo r, r.data
|
||||
backend.close()
|
||||
|
||||
if paramCount() == 0:
|
||||
|
||||
Reference in New Issue
Block a user