Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
compile-time test support
This change brings 3 new items to `unittest2`:

* `-d:unittest2Static` compile-time flag that enables `test` to run both
at compile time and runtime
* `staticTest` that only run at compilet ime no matter the flag
* `runtimeTest` that only run at run time no matter the flag
  • Loading branch information
arnetheduck committed Nov 10, 2023
commit 29079eafcb8083ae4a3a9f23cfec8f14aff8f58f
71 changes: 34 additions & 37 deletions tests/tunittest.nim
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,10 @@ test "unittest typedescs":
check(none(int) == none(int))
check(none(int) != some(1))


test "unittest multiple requires":
require(true)
require(true)


import random
proc defectiveRobot() =
randomize()
Expand All @@ -55,7 +53,7 @@ proc defectiveRobot() =
of 2: discard parseInt("Hello World!")
of 3: raise newException(IOError, "I can't do that Dave.")
else: assert 2 + 2 == 5
test "unittest expect":
runtimeTest "unittest expect":
expect IOError, OSError, ValueError, AssertionDefect:
defectiveRobot()
expect CatchableError:
Expand All @@ -67,50 +65,50 @@ test "unittest expect":
expect Defect, CatchableError:
if true: raise Defect.newException("Okay")

var
a = 1
b = -1
c = 1
var
a = 1
b = -1
c = 1

#unittests are sequential right now
suite "suite with only teardown":
teardown:
b = 2
#unittests are sequential right now
suite "suite with only teardown":
teardown:
b = 2

test "unittest with only teardown 1":
check a == c
runtimeTest "unittest with only teardown 1":
check a == c

test "unittest with only teardown 2":
check b > a
runtimeTest "unittest with only teardown 2":
check b > a

suite "suite with only setup":
setup:
var testVar {.used.} = "from setup"
suite "suite with only setup":
setup:
var testVar {.used.} = "from setup"

test "unittest with only setup 1":
check testVar == "from setup"
check b > a
b = -1
runtimeTest "unittest with only setup 1":
check testVar == "from setup"
check b > a
b = -1

test "unittest with only setup 2":
check b < a
runtimeTest "unittest with only setup 2":
check b < a

suite "suite with none":
test "unittest with none":
check b < a
suite "suite with none":
runtimeTest "unittest with none":
check b < a

suite "suite with both":
setup:
a = -2
suite "suite with both":
setup:
a = -2

teardown:
c = 2
teardown:
c = 2

test "unittest with both 1":
check b > a
runtimeTest "unittest with both 1":
check b > a

test "unittest with both 2":
check c == 2
runtimeTest "unittest with both 2":
check c == 2

suite "bug #4494":
test "Uniqueness check":
Expand Down Expand Up @@ -187,4 +185,3 @@ when defined(testing):

# Also supposed to work outside tests:
check 1 == 1

Loading