remove deprecated stuff in unittest module (#17156)
* remove unnecessary when statement * remove outdated codes * remove deprecated stuff in testament * fix
This commit is contained in:
parent
d35f366d6f
commit
99633d7682
2 changed files with 48 additions and 43 deletions
|
|
@ -108,16 +108,15 @@
|
||||||
import std/private/since
|
import std/private/since
|
||||||
import std/exitprocs
|
import std/exitprocs
|
||||||
|
|
||||||
import
|
import std/[macros, strutils, streams, times, sets, sequtils]
|
||||||
macros, strutils, streams, times, sets, sequtils
|
|
||||||
|
|
||||||
when declared(stdout):
|
when declared(stdout):
|
||||||
import os
|
import std/os
|
||||||
|
|
||||||
const useTerminal = not defined(js)
|
const useTerminal = not defined(js)
|
||||||
|
|
||||||
when useTerminal:
|
when useTerminal:
|
||||||
import terminal
|
import std/terminal
|
||||||
|
|
||||||
type
|
type
|
||||||
TestStatus* = enum ## The status of a test when it is done.
|
TestStatus* = enum ## The status of a test when it is done.
|
||||||
|
|
@ -637,19 +636,17 @@ macro check*(conditions: untyped): untyped =
|
||||||
## Verify if a statement or a list of statements is true.
|
## Verify if a statement or a list of statements is true.
|
||||||
## A helpful error message and set checkpoints are printed out on
|
## A helpful error message and set checkpoints are printed out on
|
||||||
## failure (if ``outputLevel`` is not ``PRINT_NONE``).
|
## failure (if ``outputLevel`` is not ``PRINT_NONE``).
|
||||||
## Example:
|
runnableExamples:
|
||||||
##
|
import std/strutils
|
||||||
## .. code-block:: nim
|
|
||||||
##
|
check("AKB48".toLowerAscii() == "akb48")
|
||||||
## import strutils
|
|
||||||
##
|
let teams = {'A', 'K', 'B', '4', '8'}
|
||||||
## check("AKB48".toLowerAscii() == "akb48")
|
|
||||||
##
|
check:
|
||||||
## let teams = {'A', 'K', 'B', '4', '8'}
|
"AKB48".toLowerAscii() == "akb48"
|
||||||
##
|
'C' notin teams
|
||||||
## check:
|
|
||||||
## "AKB48".toLowerAscii() == "akb48"
|
|
||||||
## 'C' in teams
|
|
||||||
let checked = callsite()[1]
|
let checked = callsite()[1]
|
||||||
|
|
||||||
template asgn(a: untyped, value: typed) =
|
template asgn(a: untyped, value: typed) =
|
||||||
|
|
@ -741,22 +738,19 @@ macro expect*(exceptions: varargs[typed], body: untyped): untyped =
|
||||||
## Test if `body` raises an exception found in the passed `exceptions`.
|
## Test if `body` raises an exception found in the passed `exceptions`.
|
||||||
## The test passes if the raised exception is part of the acceptable
|
## The test passes if the raised exception is part of the acceptable
|
||||||
## exceptions. Otherwise, it fails.
|
## exceptions. Otherwise, it fails.
|
||||||
## Example:
|
runnableExamples:
|
||||||
##
|
import std/[math, random, strutils]
|
||||||
## .. code-block:: nim
|
proc defectiveRobot() =
|
||||||
##
|
randomize()
|
||||||
## import math, random
|
case rand(1..4)
|
||||||
## proc defectiveRobot() =
|
of 1: raise newException(OSError, "CANNOT COMPUTE!")
|
||||||
## randomize()
|
of 2: discard parseInt("Hello World!")
|
||||||
## case rand(1..4)
|
of 3: raise newException(IOError, "I can't do that Dave.")
|
||||||
## of 1: raise newException(OSError, "CANNOT COMPUTE!")
|
else: assert 2 + 2 == 5
|
||||||
## of 2: discard parseInt("Hello World!")
|
|
||||||
## of 3: raise newException(IOError, "I can't do that Dave.")
|
expect IOError, OSError, ValueError, AssertionDefect:
|
||||||
## else: assert 2 + 2 == 5
|
defectiveRobot()
|
||||||
##
|
|
||||||
## expect IOError, OSError, ValueError, AssertionDefect:
|
|
||||||
## defectiveRobot()
|
|
||||||
let exp = callsite()
|
|
||||||
template expectBody(errorTypes, lineInfoLit, body): NimNode {.dirty.} =
|
template expectBody(errorTypes, lineInfoLit, body): NimNode {.dirty.} =
|
||||||
try:
|
try:
|
||||||
body
|
body
|
||||||
|
|
@ -768,13 +762,11 @@ macro expect*(exceptions: varargs[typed], body: untyped): untyped =
|
||||||
checkpoint(lineInfoLit & ": Expect Failed, unexpected exception was thrown.")
|
checkpoint(lineInfoLit & ": Expect Failed, unexpected exception was thrown.")
|
||||||
fail()
|
fail()
|
||||||
|
|
||||||
var body = exp[exp.len - 1]
|
|
||||||
|
|
||||||
var errorTypes = newNimNode(nnkBracket)
|
var errorTypes = newNimNode(nnkBracket)
|
||||||
for i in countup(1, exp.len - 2):
|
for exp in exceptions:
|
||||||
errorTypes.add(exp[i])
|
errorTypes.add(exp)
|
||||||
|
|
||||||
result = getAst(expectBody(errorTypes, exp.lineInfo, body))
|
result = getAst(expectBody(errorTypes, errorTypes.lineInfo, body))
|
||||||
|
|
||||||
proc disableParamFiltering* =
|
proc disableParamFiltering* =
|
||||||
## disables filtering tests with the command line params
|
## disables filtering tests with the command line params
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ discard """
|
||||||
targets: "c js"
|
targets: "c js"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import unittest, sequtils
|
import std/[unittest, sequtils]
|
||||||
|
|
||||||
proc doThings(spuds: var int): int =
|
proc doThings(spuds: var int): int =
|
||||||
spuds = 24
|
spuds = 24
|
||||||
|
|
@ -33,12 +33,12 @@ test "#964":
|
||||||
check spuds == 24
|
check spuds == 24
|
||||||
|
|
||||||
|
|
||||||
from strutils import toUpperAscii
|
from std/strutils import toUpperAscii
|
||||||
test "#1384":
|
test "#1384":
|
||||||
check(@["hello", "world"].map(toUpperAscii) == @["HELLO", "WORLD"])
|
check(@["hello", "world"].map(toUpperAscii) == @["HELLO", "WORLD"])
|
||||||
|
|
||||||
|
|
||||||
import options
|
import std/options
|
||||||
test "unittest typedescs":
|
test "unittest typedescs":
|
||||||
check(none(int) == none(int))
|
check(none(int) == none(int))
|
||||||
check(none(int) != some(1))
|
check(none(int) != some(1))
|
||||||
|
|
@ -49,8 +49,8 @@ test "unittest multiple requires":
|
||||||
require(true)
|
require(true)
|
||||||
|
|
||||||
|
|
||||||
import random
|
import std/random
|
||||||
from strutils import parseInt
|
from std/strutils import parseInt
|
||||||
proc defectiveRobot() =
|
proc defectiveRobot() =
|
||||||
case rand(1..4)
|
case rand(1..4)
|
||||||
of 1: raise newException(OSError, "CANNOT COMPUTE!")
|
of 1: raise newException(OSError, "CANNOT COMPUTE!")
|
||||||
|
|
@ -177,3 +177,16 @@ suite "test name filtering":
|
||||||
check false == matchFilter("suite1", "foo", "*ite2::")
|
check false == matchFilter("suite1", "foo", "*ite2::")
|
||||||
check matchFilter("suite1", "q**we::foo", "q**we::foo")
|
check matchFilter("suite1", "q**we::foo", "q**we::foo")
|
||||||
check matchFilter("suite1", "a::b*c::d*e", "a::b*c::d*e")
|
check matchFilter("suite1", "a::b*c::d*e", "a::b*c::d*e")
|
||||||
|
|
||||||
|
|
||||||
|
block:
|
||||||
|
type MyFoo = object
|
||||||
|
var obj = MyFoo()
|
||||||
|
let check = 1
|
||||||
|
check(obj == obj)
|
||||||
|
|
||||||
|
block:
|
||||||
|
let check = 123
|
||||||
|
var a = 1
|
||||||
|
var b = 1
|
||||||
|
check(a == b)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue