summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/lookups/tredef.nim (renamed from tests/lookup/tredef.nim)0
-rw-r--r--tests/testament/backend.nim10
-rw-r--r--tests/testament/caasdriver.nim (renamed from tests/caasdriver.nim)0
-rw-r--r--tests/testament/css/boilerplate.css (renamed from tests/css/boilerplate.css)0
-rw-r--r--tests/testament/css/style.css (renamed from tests/css/style.css)0
-rw-r--r--tests/testament/htmlgen.nim127
-rw-r--r--tests/testament/tester.nim12
7 files changed, 139 insertions, 10 deletions
diff --git a/tests/lookup/tredef.nim b/tests/lookups/tredef.nim
index 02d1f7776..02d1f7776 100644
--- a/tests/lookup/tredef.nim
+++ b/tests/lookups/tredef.nim
diff --git a/tests/testament/backend.nim b/tests/testament/backend.nim
index 65d040b24..500535d9b 100644
--- a/tests/testament/backend.nim
+++ b/tests/testament/backend.nim
@@ -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 =
diff --git a/tests/caasdriver.nim b/tests/testament/caasdriver.nim
index 28f0bae9b..28f0bae9b 100644
--- a/tests/caasdriver.nim
+++ b/tests/testament/caasdriver.nim
diff --git a/tests/css/boilerplate.css b/tests/testament/css/boilerplate.css
index b209b5aa1..b209b5aa1 100644
--- a/tests/css/boilerplate.css
+++ b/tests/testament/css/boilerplate.css
diff --git a/tests/css/style.css b/tests/testament/css/style.css
index 43a8add68..43a8add68 100644
--- a/tests/css/style.css
+++ b/tests/testament/css/style.css
diff --git a/tests/testament/htmlgen.nim b/tests/testament/htmlgen.nim
new file mode 100644
index 000000000..6e3865bab
--- /dev/null
+++ b/tests/testament/htmlgen.nim
@@ -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)
diff --git a/tests/testament/tester.nim b/tests/testament/tester.nim
index 2c9a32e5e..61d0072e3 100644
--- a/tests/testament/tester.nim
+++ b/tests/testament/tester.nim
@@ -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: