mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-30 09:54:49 +00:00
Improve unittest docs
This commit is contained in:
@@ -11,11 +11,21 @@
|
||||
##
|
||||
## This module implements boilerplate to make unit testing easy.
|
||||
##
|
||||
## The test status and name is printed after any output or traceback.
|
||||
##
|
||||
## Example:
|
||||
##
|
||||
## .. code:: nim
|
||||
##
|
||||
## 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":
|
||||
## # give up and stop if this fails
|
||||
## require(true)
|
||||
@@ -30,6 +40,13 @@
|
||||
## let v = @[1, 2, 3] # you can do initialization here
|
||||
## expect(IndexError):
|
||||
## 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
|
||||
macros
|
||||
@@ -226,10 +243,11 @@ template fail* =
|
||||
checkpoints = @[]
|
||||
|
||||
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
|
||||
## for reasons depending on outer environment,
|
||||
## or certain application logic conditions or configurations.
|
||||
## The test code is still executed.
|
||||
##
|
||||
## .. code-block:: nim
|
||||
##
|
||||
@@ -250,12 +268,12 @@ macro check*(conditions: untyped): untyped =
|
||||
##
|
||||
## import strutils
|
||||
##
|
||||
## check("AKB48".toLower() == "akb48")
|
||||
## check("AKB48".toLowerAscii() == "akb48")
|
||||
##
|
||||
## let teams = {'A', 'K', 'B', '4', '8'}
|
||||
##
|
||||
## check:
|
||||
## "AKB48".toLower() == "akb48"
|
||||
## "AKB48".toLowerAscii() == "akb48"
|
||||
## 'C' in teams
|
||||
let checked = callsite()[1]
|
||||
var
|
||||
|
||||
Reference in New Issue
Block a user