Merge pull request #4938 from FedericoCeratto/unittest

Improve unittest docs
This commit is contained in:
Andreas Rumpf 2016-10-24 17:03:11 +02:00 • committed by GitHub
commit 353ce7315a

View file

@ -11,11 +11,21 @@
## ##
## This module implements boilerplate to make unit testing easy. ## This module implements boilerplate to make unit testing easy.
## ##
## The test status and name is printed after any output or traceback.
##
## Example: ## Example:
## ##
## .. code:: nim ## .. code:: nim
## ##
## suite "description for this stuff": ## suite "description for this stuff":
## echo "suite setup: run once before the tests"
##
## setup:
## echo "run before each test"
##
## teardown:
## echo "run after each test":
##
## test "essential truths": ## test "essential truths":
## # give up and stop if this fails ## # give up and stop if this fails
## require(true) ## require(true)
@ -30,6 +40,13 @@
## let v = @[1, 2, 3] # you can do initialization here ## let v = @[1, 2, 3] # you can do initialization here
## expect(IndexError): ## expect(IndexError):
## discard v[4] ## discard v[4]
##
## echo "suite teardown: run once after the tests"
##
##
## Tests can be nested, however failure of a nested test will not mark the
## parent test as failed. Setup and teardown are inherited. Setup can be
## overridden locally.
import import
macros macros
@ -226,10 +243,11 @@ template fail* =
checkpoints = @[] checkpoints = @[]
template skip* = template skip* =
## Makes test to be skipped. Should be used directly ## Mark the test as skipped. Should be used directly
## in case when it is not possible to perform test ## in case when it is not possible to perform test
## for reasons depending on outer environment, ## for reasons depending on outer environment,
## or certain application logic conditions or configurations. ## or certain application logic conditions or configurations.
## The test code is still executed.
## ##
## .. code-block:: nim ## .. code-block:: nim
## ##
@ -250,12 +268,12 @@ macro check*(conditions: untyped): untyped =
## ##
## import strutils ## import strutils
## ##
## check("AKB48".toLower() == "akb48") ## check("AKB48".toLowerAscii() == "akb48")
## ##
## let teams = {'A', 'K', 'B', '4', '8'} ## let teams = {'A', 'K', 'B', '4', '8'}
## ##
## check: ## check:
## "AKB48".toLower() == "akb48" ## "AKB48".toLowerAscii() == "akb48"
## 'C' in teams ## 'C' in teams
let checked = callsite()[1] let checked = callsite()[1]
var var