Make use of used in unittest (#5410)
This commit is contained in:
parent
16aafddee5
commit
f250c30b9d
3 changed files with 45 additions and 14 deletions
|
|
@ -134,15 +134,15 @@ template suite*(name, body) {.dirty.} =
|
||||||
## [OK] (2 + -2) != 4
|
## [OK] (2 + -2) != 4
|
||||||
block:
|
block:
|
||||||
bind startSuite
|
bind startSuite
|
||||||
template setup(setupBody: untyped) {.dirty.} =
|
template setup(setupBody: untyped) {.dirty, used.} =
|
||||||
var testSetupIMPLFlag = true
|
var testSetupIMPLFlag {.used.} = true
|
||||||
template testSetupIMPL: untyped {.dirty.} = setupBody
|
template testSetupIMPL: untyped {.dirty.} = setupBody
|
||||||
|
|
||||||
template teardown(teardownBody: untyped) {.dirty.} =
|
template teardown(teardownBody: untyped) {.dirty, used.} =
|
||||||
var testTeardownIMPLFlag = true
|
var testTeardownIMPLFlag {.used.} = true
|
||||||
template testTeardownIMPL: untyped {.dirty.} = teardownBody
|
template testTeardownIMPL: untyped {.dirty.} = teardownBody
|
||||||
|
|
||||||
let testInSuiteImplFlag = true
|
let testInSuiteImplFlag {.used.} = true
|
||||||
startSuite name
|
startSuite name
|
||||||
body
|
body
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,35 @@
|
||||||
discard """
|
discard """
|
||||||
output: '''8'''
|
nimout: '''
|
||||||
|
compile start
|
||||||
|
tused.nim(15, 8) Hint: 'tused.echoSub(a: int, b: int)' is declared but not used [XDeclaredButNotUsed]
|
||||||
|
compile end'''
|
||||||
|
output: "8\n8"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
template implementArithOps(T) =
|
static:
|
||||||
|
echo "compile start"
|
||||||
|
|
||||||
|
template implementArithOpsOld(T) =
|
||||||
|
proc echoAdd(a, b: T) =
|
||||||
|
echo a + b
|
||||||
|
proc echoSub(a, b: T) =
|
||||||
|
echo a - b
|
||||||
|
|
||||||
|
template implementArithOpsNew(T) =
|
||||||
proc echoAdd(a, b: T) {.used.} =
|
proc echoAdd(a, b: T) {.used.} =
|
||||||
echo a + b
|
echo a + b
|
||||||
proc echoSub(a, b: T) {.used.} =
|
proc echoSub(a, b: T) {.used.} =
|
||||||
echo a - b
|
echo a - b
|
||||||
|
|
||||||
# no warning produced for the unused 'echoSub'
|
block:
|
||||||
implementArithOps(int)
|
# should produce warning for the unused 'echoSub'
|
||||||
echoAdd 3, 5
|
implementArithOpsOld(int)
|
||||||
|
echoAdd 3, 5
|
||||||
|
|
||||||
|
block:
|
||||||
|
# no warning produced for the unused 'echoSub'
|
||||||
|
implementArithOpsNew(int)
|
||||||
|
echoAdd 3, 5
|
||||||
|
|
||||||
|
static:
|
||||||
|
echo "compile end"
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,11 @@
|
||||||
|
discard """
|
||||||
|
nimout: "compile start\ncompile end"
|
||||||
|
"""
|
||||||
|
|
||||||
import unittest, sequtils
|
import unittest, sequtils
|
||||||
|
|
||||||
|
static:
|
||||||
|
echo "compile start"
|
||||||
|
|
||||||
proc doThings(spuds: var int): int =
|
proc doThings(spuds: var int): int =
|
||||||
spuds = 24
|
spuds = 24
|
||||||
|
|
@ -10,9 +16,9 @@ test "#964":
|
||||||
check spuds == 24
|
check spuds == 24
|
||||||
|
|
||||||
|
|
||||||
from strutils import toUpper
|
from strutils import toUpperAscii
|
||||||
test "#1384":
|
test "#1384":
|
||||||
check(@["hello", "world"].map(toUpper) == @["HELLO", "WORLD"])
|
check(@["hello", "world"].map(toUpperAscii) == @["HELLO", "WORLD"])
|
||||||
|
|
||||||
|
|
||||||
import options
|
import options
|
||||||
|
|
@ -57,7 +63,7 @@ suite "suite with only teardown":
|
||||||
|
|
||||||
suite "suite with only setup":
|
suite "suite with only setup":
|
||||||
setup:
|
setup:
|
||||||
var testVar = "from setup"
|
var testVar {.used.} = "from setup"
|
||||||
|
|
||||||
test "unittest with only setup 1":
|
test "unittest with only setup 1":
|
||||||
check testVar == "from setup"
|
check testVar == "from setup"
|
||||||
|
|
@ -89,3 +95,6 @@ suite "bug #4494":
|
||||||
var tags = @[1, 2, 3, 4, 5]
|
var tags = @[1, 2, 3, 4, 5]
|
||||||
check:
|
check:
|
||||||
allIt(0..3, tags[it] != tags[it + 1])
|
allIt(0..3, tags[it] != tags[it + 1])
|
||||||
|
|
||||||
|
static:
|
||||||
|
echo "compile end"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue