Merge pull request #1 from stefantalpalaru/warnings

eliminate warnings with nim-0.17.0
This commit is contained in:
Joey 2017-06-20 14:58:00 -06:00 • committed by GitHub
commit be17ec1963
3 changed files with 40 additions and 20 deletions

2
.gitignore vendored
View file

@ -1,3 +1,5 @@
nimcache/ nimcache/
*.swp *.swp
*.swo *.swo
/tests/test

View file

@ -1,5 +1,5 @@
## :Author: Joey Payne ## :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 ## the unittest module in Nim. Inspired by the python
## unit test module. ## unit test module.
## ##
@ -13,7 +13,8 @@
## self.checkRaises(OSError, newException(OSError, "OS is exploding!")) ## self.checkRaises(OSError, newException(OSError, "OS is exploding!"))
## ##
import macros import macros
import strutils import unicode
import strutils except toLower
import tables import tables
import typetraits import typetraits
when not defined(ECMAScript): when not defined(ECMAScript):
@ -115,15 +116,15 @@ type
# -- Methods for the TestSuite base -- # -- Methods for the TestSuite base --
method setup*(suite: TestSuite) = method setup*(suite: TestSuite) {.base.} =
## Base method for setup code ## Base method for setup code
discard discard
method tearDown*(suite: TestSuite) = method tearDown*(suite: TestSuite) {.base.} =
## Base method for tearDown code ## Base method for tearDown code
discard discard
method runTests*(suite: TestSuite) = method runTests*(suite: TestSuite) {.base.} =
## Base method for running tests ## Base method for running tests
discard discard
@ -153,8 +154,8 @@ template returnException(name, testName, snip, vals, pos, posRel) =
# ------------------------ Templates for checking ---------------------------- # ------------------------ Templates for checking ----------------------------
template checkRaises*(self: TestSuite, error: Exception, template checkRaises*(self: untyped, error: untyped,
code: untyped): untyped {.immediate.}= code: untyped): untyped =
## Raises a TestAssertError when the exception "error" is ## Raises a TestAssertError when the exception "error" is
## not thrown in the code ## not thrown in the code
let let
@ -184,7 +185,7 @@ template checkRaises*(self: TestSuite, error: Exception,
returnException("checkRaises", testName, snip, vals, pos, posRel) 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 ## recursively iterate over AST nodes and perform an
## action on them ## action on them
proc helper(child: NimNode): NimNode {.gensym.} = proc helper(child: NimNode): NimNode {.gensym.} =
@ -244,7 +245,7 @@ macro getSyms(code:untyped): untyped =
initTable[string, string]() initTable[string, string]()
result = getAst(emptyTable()) result = getAst(emptyTable())
template check*(self: TestSuite, code: untyped){.immediate.}= template check*(self: untyped, code: untyped)=
## Assertions for tests ## Assertions for tests
if not code: if not code:
# These need to be here to capture the actual info # These need to be here to capture the actual info
@ -311,7 +312,7 @@ macro testSuite*(head: untyped, body: untyped): untyped =
## einheit.runTests() ## einheit.runTests()
## ##
# object reference name inside methods. # object reference name inside methods.
# ie: self, self # ie: self, self
let objReference = "self" let objReference = "self"
@ -430,10 +431,10 @@ macro testSuite*(head: untyped, body: untyped): untyped =
template runTestsProc(self, typeName, baseMethod, typeMethod) = template runTestsProc(self, typeName, baseMethod, typeMethod) =
method typeMethod(self: typeName) = method typeMethod(self: typeName) {.base.} =
when compiles(self.baseMethod()): when compiles(self.baseMethod()):
self.baseMethod() self.baseMethod()
method runTests(self: typeName) = method runTests(self: typeName) =
self.typeMethod() self.typeMethod()
@ -446,6 +447,20 @@ macro testSuite*(head: untyped, body: untyped): untyped =
foundSetup = false foundSetup = false
foundTeardown = 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 # Make forward declarations so that function order
# does not matter, just like in real OOP! # does not matter, just like in real OOP!
for node in body.children: for node in body.children:
@ -473,10 +488,17 @@ macro testSuite*(head: untyped, body: untyped): untyped =
else: else:
discard discard
# {.pop.}
result.add(
newNimNode(nnkPragma).add(
ident("pop")
)
)
if not foundSetup: if not foundSetup:
template setupProc(self, typeName, setupProc) = template setupProc(self, typeName, setupProc) =
method setup(self: typeName) method setup(self: typeName)
method setupProc(self: typeName) method setupProc(self: typeName) {.base.}
template setupDecl(self, baseMethod) = template setupDecl(self, baseMethod) =
method setup() = method setup() =
@ -492,7 +514,7 @@ macro testSuite*(head: untyped, body: untyped): untyped =
if not foundTeardown: if not foundTeardown:
template teardownProc(self, typeName, tdProc) = template teardownProc(self, typeName, tdProc) =
method tearDown(self: typeName) method tearDown(self: typeName)
method tdProc(self: typeName) method tdProc(self: typeName) {.base.}
template teardownDecl(self, baseMethod) = template teardownDecl(self, baseMethod) =
method tearDown() = method tearDown() =
@ -694,7 +716,7 @@ macro testSuite*(head: untyped, body: untyped): untyped =
# insert libs needed # insert libs needed
result.insert(0, getAst(importRequiredLibs())) result.insert(0, getAst(importRequiredLibs()))
result.add(runTests) result.add(runTests)
template addTestSuite(typeName) = template addTestSuite(typeName) =
@ -781,7 +803,7 @@ proc printSummary(totalTestsPassed: int, totalTests: int) =
proc runTests*() = proc runTests*() =
## The method that runs the tests. Invoke ## 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 ## usually inside a "when isMainModule" block
var var
totalTests = 0 totalTests = 0

View file

@ -45,10 +45,6 @@ else:
ws_xpixel: cushort ws_xpixel: cushort
ws_ypixel: cushort ws_ypixel: cushort
let
IOC_OUT = 0x40000000
IOCPARM_MASK = 0x1fff
var var
TIOCGWINSZ{.importc: "TIOCGWINSZ", header: "<sys/ioctl.h>".}: uint TIOCGWINSZ{.importc: "TIOCGWINSZ", header: "<sys/ioctl.h>".}: uint