From 6c08ba8290d8ddebbbf3b327401a6e3087c07188 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Tue, 2 Mar 2010 21:39:23 +0100 Subject: [PATCH] fixed colors module --- lib/pure/colors.nim | 16 +-- lib/pure/os.nim | 15 +++ tests/tester.nim | 261 ++++++++++++++++++++------------------------ 3 files changed, 142 insertions(+), 150 deletions(-) diff --git a/lib/pure/colors.nim b/lib/pure/colors.nim index 548f07381..c0f7ad043 100755 --- a/lib/pure/colors.nim +++ b/lib/pure/colors.nim @@ -9,6 +9,8 @@ ## This module implements graphical output for Nimrod; the current ## implementation uses Cairo under the surface. +import strutils + type TColor* = distinct int ## a color stored as RGB @@ -16,9 +18,9 @@ proc `==` *(a, b: TColor): bool {.borrow.} ## compares two colors. template extract(a: TColor, r, g, b: expr) = - var r = a shr 16 and 0xff - var g = a shr 8 and 0xff - var b = a and 0xff + var r = a.int shr 16 and 0xff + var g = a.int shr 8 and 0xff + var b = a.int and 0xff template rawRGB(r, g, b: expr): expr = TColor(r shl 16 or g shl 8 or b) @@ -64,9 +66,9 @@ template mix*(a, b: TColor, fn: expr): expr = y = if y < 0: 0 else: 255 y - bind extract(a, ar, ag, ab) - bind extract(b, br, bg, bb) - bind rawRGB(>yes" + else: result = "no" + +proc `$`(r: TResults): string = + result = "" & + "\n" + for test, expected, given, success in items(r.data): + result.add("\n" % [ + test, expected, given, success.colorBool]) + result.add("
TestExpectedGivenSuccess
$#$#$#$#
\n") + +proc cmpMsgs(r: var TResults, expected, given: TMsg, test: string) = + inc(r.total) + if strip(expected.msg) notin strip(given.msg): + r.data.add((test, expected.msg, given.msg, false)) + elif expected.file != given.file: + r.data.add((test, expected.file, given.file, false)) + elif expected.line != given.line: + r.data.add((test, $expected.line, $given.line, false)) + else: + r.data.add((test, expected.msg, given.msg, true)) + inc(r.passed) + +proc reject(r: var TResults, dir, options: string) = + ## handle all the tests that the compiler should reject + var specs = parseRejectData(dir) + + for test in os.walkFiles(dir / "t*.nim"): + var t = extractFilename(test) + var expected = findSpec(specs, t) + var given = callCompiler(test, options) + cmpMsgs(r, specs[expected], given, t) + +proc compile(r: var TResults, pattern, options: string) = + for test in os.walkFiles(pattern): + var t = extractFilename(test) + inc(r.total) + var given = callCompiler(test, options) + r.data.add((t, "", given.msg, not given.err)) + if not given.err: inc(r.passed) + +proc run(r: var TResults, dir, options: string) = + var specs = parseRunData(dir) + for test in os.walkFiles(dir / "t*.nim"): + var t = extractFilename(test) + inc(r.total) + var given = callCompiler(test, options) + if given.err: + r.data.add((t, "", given.msg, not given.err)) + else: + var exeFile = changeFileExt(test, ExeExt) + var expected = specs[findSpec(specs, t)] + if existsFile(exeFile): + var buf = myExec(exeFile) + var success = strip(buf) == strip(spec.outp) + if success: inc(r.passed) + r.data.add((t, spec.outp, buf, success)) + else: + r.data.add((t, spec.outp, "executable not found", false)) + +var options = "" +var rejectRes = initResults() +var compileRes = initResults() +var runRes = initResults() + for i in 1.. paramCount(): add(options, " ") add(options, paramStr(i)) -main(options) + +reject(rejectRes, "tests/reject", options) +compile(compileRes, "tests/accept/compile/t*.nim", options) +compile(compileRes, "examples/*.nim", options) +compile(compileRes, "examples/gtk/*.nim", options) +run(runRes, "tests/accept/run", options) +