From 4a433615e71301c336481f28bf1379f2983fdaef Mon Sep 17 00:00:00 2001 From: Stefan Talpalaru Date: Sun, 18 Jun 2017 17:50:37 +0200 Subject: [PATCH 1/2] eliminate warnings with nim-0.17.0 --- .gitignore | 2 ++ src/einheit.nim | 54 ++++++++++++++++++++++++++++++------------- src/einheit/utils.nim | 6 ++--- 3 files changed, 43 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 7794435..7faae31 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ nimcache/ *.swp *.swo +/tests/test + diff --git a/src/einheit.nim b/src/einheit.nim index fdf52ea..a75b523 100644 --- a/src/einheit.nim +++ b/src/einheit.nim @@ -1,5 +1,5 @@ ## :Author: Joey Payne -## This module is an alternate implementation of +## This module is an alternate implementation of ## the unittest module in Nim. Inspired by the python ## unit test module. ## @@ -13,7 +13,8 @@ ## self.checkRaises(OSError, newException(OSError, "OS is exploding!")) ## import macros -import strutils +import unicode +import strutils except toLower import tables import typetraits when not defined(ECMAScript): @@ -115,15 +116,15 @@ type # -- Methods for the TestSuite base -- -method setup*(suite: TestSuite) = +method setup*(suite: TestSuite) {.base.} = ## Base method for setup code discard -method tearDown*(suite: TestSuite) = +method tearDown*(suite: TestSuite) {.base.} = ## Base method for tearDown code discard -method runTests*(suite: TestSuite) = +method runTests*(suite: TestSuite) {.base.} = ## Base method for running tests discard @@ -153,8 +154,8 @@ template returnException(name, testName, snip, vals, pos, posRel) = # ------------------------ Templates for checking ---------------------------- -template checkRaises*(self: TestSuite, error: Exception, - code: untyped): untyped {.immediate.}= +template checkRaises*(self: untyped, error: untyped, + code: untyped): untyped = ## Raises a TestAssertError when the exception "error" is ## not thrown in the code let @@ -184,7 +185,7 @@ template checkRaises*(self: TestSuite, error: Exception, returnException("checkRaises", testName, snip, vals, pos, posRel) -template recursive(node, action): expr {.dirty.} = +template recursive(node, action): untyped {.dirty.} = ## recursively iterate over AST nodes and perform an ## action on them proc helper(child: NimNode): NimNode {.gensym.} = @@ -244,7 +245,7 @@ macro getSyms(code:untyped): untyped = initTable[string, string]() result = getAst(emptyTable()) -template check*(self: TestSuite, code: untyped){.immediate.}= +template check*(self: untyped, code: untyped)= ## Assertions for tests if not code: # These need to be here to capture the actual info @@ -311,7 +312,7 @@ macro testSuite*(head: untyped, body: untyped): untyped = ## einheit.runTests() ## - + # object reference name inside methods. # ie: self, self let objReference = "self" @@ -430,10 +431,10 @@ macro testSuite*(head: untyped, body: untyped): untyped = template runTestsProc(self, typeName, baseMethod, typeMethod) = - method typeMethod(self: typeName) = + method typeMethod(self: typeName) {.base.} = when compiles(self.baseMethod()): self.baseMethod() - + method runTests(self: typeName) = self.typeMethod() @@ -446,6 +447,20 @@ macro testSuite*(head: untyped, body: untyped): untyped = foundSetup = false foundTeardown = false + # {.push warning[UseBase]: off.} + result.add( + newNimNode(nnkPragma).add( + ident("push"), + newNimNode(nnkExprColonExpr).add( + newNimNode(nnkBracketExpr).add( + ident("warning"), + ident("UseBase") + ), + ident("off") + ) + ) + ) + # Make forward declarations so that function order # does not matter, just like in real OOP! for node in body.children: @@ -473,10 +488,17 @@ macro testSuite*(head: untyped, body: untyped): untyped = else: discard + # {.pop.} + result.add( + newNimNode(nnkPragma).add( + ident("pop") + ) + ) + if not foundSetup: template setupProc(self, typeName, setupProc) = method setup(self: typeName) - method setupProc(self: typeName) + method setupProc(self: typeName) {.base.} template setupDecl(self, baseMethod) = method setup() = @@ -492,7 +514,7 @@ macro testSuite*(head: untyped, body: untyped): untyped = if not foundTeardown: template teardownProc(self, typeName, tdProc) = method tearDown(self: typeName) - method tdProc(self: typeName) + method tdProc(self: typeName) {.base.} template teardownDecl(self, baseMethod) = method tearDown() = @@ -694,7 +716,7 @@ macro testSuite*(head: untyped, body: untyped): untyped = # insert libs needed result.insert(0, getAst(importRequiredLibs())) - + result.add(runTests) template addTestSuite(typeName) = @@ -781,7 +803,7 @@ proc printSummary(totalTestsPassed: int, totalTests: int) = proc runTests*() = ## The method that runs the tests. Invoke - ## after setting up all of the tests and + ## after setting up all of the tests and ## usually inside a "when isMainModule" block var totalTests = 0 diff --git a/src/einheit/utils.nim b/src/einheit/utils.nim index cff5001..19bc95b 100644 --- a/src/einheit/utils.nim +++ b/src/einheit/utils.nim @@ -45,9 +45,9 @@ else: ws_xpixel: cushort ws_ypixel: cushort - let - IOC_OUT = 0x40000000 - IOCPARM_MASK = 0x1fff + # let + # IOC_OUT = 0x40000000 + # IOCPARM_MASK = 0x1fff var TIOCGWINSZ{.importc: "TIOCGWINSZ", header: "".}: uint From 9490e3cf3cd6a495e83d40f2fc487f340d31cad4 Mon Sep 17 00:00:00 2001 From: Stefan Talpalaru Date: Tue, 20 Jun 2017 22:38:22 +0200 Subject: [PATCH 2/2] remove commented out lines --- src/einheit/utils.nim | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/einheit/utils.nim b/src/einheit/utils.nim index 19bc95b..9040e41 100644 --- a/src/einheit/utils.nim +++ b/src/einheit/utils.nim @@ -45,10 +45,6 @@ else: ws_xpixel: cushort ws_ypixel: cushort - # let - # IOC_OUT = 0x40000000 - # IOCPARM_MASK = 0x1fff - var TIOCGWINSZ{.importc: "TIOCGWINSZ", header: "".}: uint