I wrote most of my unit test with a module unittest
, but Im not sure how to use it for code that the compiler should reject at compile time. For example, if I want to write the following code and make sure that there were always compilation errors during compilation (the type and template will be in a separate module), how can I write a test case for this?
import macros
type
T[n:static[int]] = object
template foo3(n: int): expr =
static:
if n > 3: error "n > 3"
type T3 = T[n]
T3
var
bar: foo3(4)
source
share