From 383fbca27ef4f4e0b5eae0e0e02029fe644248ac Mon Sep 17 00:00:00 2001 From: Araq Date: Fri, 17 Jan 2014 08:47:51 +0100 Subject: [PATCH] better tester --- compiler/semmacrosanity.nim | 4 +- lib/impure/db_sqlite.nim | 2 +- tests/{macro => macros}/tmacro1.nim | 0 tests/{macro => macros}/tmacro2.nim | 0 tests/{macro => macros}/tmacro3.nim | 0 tests/{macro => macros}/tmacro4.nim | 0 tests/{macro => macros}/tmacro5.nim | 0 tests/{macro => macros}/tmacroaspragma.nim | 0 tests/{macro => macros}/tmacrogenerics.nim | 0 tests/{macro => macros}/tmacros1.nim | 0 tests/{macro => macros}/tmacrostmt.nim | 0 tests/{macro => macros}/tmacrotypes.nim | 0 .../tnimrodnode_for_runtime.nim | 0 tests/{macro => macros}/tprintf.nim | 0 tests/{macro => macros}/tquotewords.nim | 0 tests/{macro => macros}/trecmacro.nim | 0 tests/{macro => macros}/tstringinterp.nim | 0 tests/{macro => macros}/tvtable.nim | 0 tests/testament/backend.nim | 6 +-- tests/testament/htmlgen.nim | 50 ++++++++++--------- tests/testament/tester.nim | 8 ++- 21 files changed, 39 insertions(+), 31 deletions(-) rename tests/{macro => macros}/tmacro1.nim (100%) rename tests/{macro => macros}/tmacro2.nim (100%) rename tests/{macro => macros}/tmacro3.nim (100%) rename tests/{macro => macros}/tmacro4.nim (100%) rename tests/{macro => macros}/tmacro5.nim (100%) rename tests/{macro => macros}/tmacroaspragma.nim (100%) rename tests/{macro => macros}/tmacrogenerics.nim (100%) rename tests/{macro => macros}/tmacros1.nim (100%) rename tests/{macro => macros}/tmacrostmt.nim (100%) rename tests/{macro => macros}/tmacrotypes.nim (100%) rename tests/{macro => macros}/tnimrodnode_for_runtime.nim (100%) rename tests/{macro => macros}/tprintf.nim (100%) rename tests/{macro => macros}/tquotewords.nim (100%) rename tests/{macro => macros}/trecmacro.nim (100%) rename tests/{macro => macros}/tstringinterp.nim (100%) rename tests/{macro => macros}/tvtable.nim (100%) diff --git a/compiler/semmacrosanity.nim b/compiler/semmacrosanity.nim index eff944baca..1bece95c20 100644 --- a/compiler/semmacrosanity.nim +++ b/compiler/semmacrosanity.nim @@ -43,12 +43,12 @@ proc annotateType*(n: PNode, t: PType) = n.typ = t for i in 0 .. = 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]) elif x.kind == tyProc and x.callConv == ccClosure: n.typ = t diff --git a/lib/impure/db_sqlite.nim b/lib/impure/db_sqlite.nim index c27efc3582..a3499a6df6 100644 --- a/lib/impure/db_sqlite.nim +++ b/lib/impure/db_sqlite.nim @@ -76,7 +76,7 @@ proc tryExec*(db: TDbConn, query: TSqlQuery, proc exec*(db: TDbConn, query: TSqlQuery, args: varargs[string, `$`]) {. tags: [FReadDB, FWriteDb].} = ## 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 = newSeq(result, L) diff --git a/tests/macro/tmacro1.nim b/tests/macros/tmacro1.nim similarity index 100% rename from tests/macro/tmacro1.nim rename to tests/macros/tmacro1.nim diff --git a/tests/macro/tmacro2.nim b/tests/macros/tmacro2.nim similarity index 100% rename from tests/macro/tmacro2.nim rename to tests/macros/tmacro2.nim diff --git a/tests/macro/tmacro3.nim b/tests/macros/tmacro3.nim similarity index 100% rename from tests/macro/tmacro3.nim rename to tests/macros/tmacro3.nim diff --git a/tests/macro/tmacro4.nim b/tests/macros/tmacro4.nim similarity index 100% rename from tests/macro/tmacro4.nim rename to tests/macros/tmacro4.nim diff --git a/tests/macro/tmacro5.nim b/tests/macros/tmacro5.nim similarity index 100% rename from tests/macro/tmacro5.nim rename to tests/macros/tmacro5.nim diff --git a/tests/macro/tmacroaspragma.nim b/tests/macros/tmacroaspragma.nim similarity index 100% rename from tests/macro/tmacroaspragma.nim rename to tests/macros/tmacroaspragma.nim diff --git a/tests/macro/tmacrogenerics.nim b/tests/macros/tmacrogenerics.nim similarity index 100% rename from tests/macro/tmacrogenerics.nim rename to tests/macros/tmacrogenerics.nim diff --git a/tests/macro/tmacros1.nim b/tests/macros/tmacros1.nim similarity index 100% rename from tests/macro/tmacros1.nim rename to tests/macros/tmacros1.nim diff --git a/tests/macro/tmacrostmt.nim b/tests/macros/tmacrostmt.nim similarity index 100% rename from tests/macro/tmacrostmt.nim rename to tests/macros/tmacrostmt.nim diff --git a/tests/macro/tmacrotypes.nim b/tests/macros/tmacrotypes.nim similarity index 100% rename from tests/macro/tmacrotypes.nim rename to tests/macros/tmacrotypes.nim diff --git a/tests/macro/tnimrodnode_for_runtime.nim b/tests/macros/tnimrodnode_for_runtime.nim similarity index 100% rename from tests/macro/tnimrodnode_for_runtime.nim rename to tests/macros/tnimrodnode_for_runtime.nim diff --git a/tests/macro/tprintf.nim b/tests/macros/tprintf.nim similarity index 100% rename from tests/macro/tprintf.nim rename to tests/macros/tprintf.nim diff --git a/tests/macro/tquotewords.nim b/tests/macros/tquotewords.nim similarity index 100% rename from tests/macro/tquotewords.nim rename to tests/macros/tquotewords.nim diff --git a/tests/macro/trecmacro.nim b/tests/macros/trecmacro.nim similarity index 100% rename from tests/macro/trecmacro.nim rename to tests/macros/trecmacro.nim diff --git a/tests/macro/tstringinterp.nim b/tests/macros/tstringinterp.nim similarity index 100% rename from tests/macro/tstringinterp.nim rename to tests/macros/tstringinterp.nim diff --git a/tests/macro/tvtable.nim b/tests/macros/tvtable.nim similarity index 100% rename from tests/macro/tvtable.nim rename to tests/macros/tvtable.nim diff --git a/tests/testament/backend.nim b/tests/testament/backend.nim index 87ac10b1fd..bc1f92eba7 100644 --- a/tests/testament/backend.nim +++ b/tests/testament/backend.nim @@ -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 diff --git a/tests/testament/htmlgen.nim b/tests/testament/htmlgen.nim index e42b880706..bc2d8bd37e 100644 --- a/tests/testament/htmlgen.nim +++ b/tests/testament/htmlgen.nim @@ -109,42 +109,46 @@ div.tabContent.hide { display: none; } proc td(s: string): string = result = "" & s.substr(0, 200).XMLEncode & "" -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, expected, given, result - from TestResult - where [commit] = ? and machine = ? - order by category""" + from TestResult + where [commit] = ? and machine = ? + order by category""" var db = open(connection="testament.db", user="testament", password="", database="testament") + # search for proper commit: + let lastCommit = db.getCommit(commit) + 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("

$#

" % machine.join(" ")) + 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.write("

$# $#

" % [branch, commit]) + # generate navigation: outfile.write("""") - for thisCommit in db.rows(sql"select id from [Commit] order by id desc"): - let lastCommit = thisCommit[0] - outfile.write("""
""" % lastCommit) + for currentMachine in db.rows(sql"select id from Machine order by id"): + let m = currentMachine[0] + outfile.write("""
""" % m) outfile.write(TableHeader) - for row in db.rows(sql(selRow), lastCommit, thisMachine): + for row in db.rows(sql(selRow), lastCommit, m): outfile.write("") for x in row: outfile.write(x.td) diff --git a/tests/testament/tester.nim b/tests/testament/tester.nim index 8abea82248..54a6de2d0b 100644 --- a/tests/testament/tester.nim +++ b/tests/testament/tester.nim @@ -22,7 +22,9 @@ const Command: all run all tests c|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 are passed to the compiler Options: @@ -254,7 +256,9 @@ proc main() = p.next processCategory(r, cat, p.cmdLineRest.string) of "html": - generateHtml(resultsFile) + var commit = 0 + discard parseInt(p.cmdLineRest.string, commit) + generateHtml(resultsFile, commit) else: quit usage