How do I write unit test for code that should fail to compile in Nim? -


i wrote of unit test of unittest module, i’m not sure how use code compiler should reject @ compile time. example, if want write following code , make sure compiler errors during compilation (the type , template in separate module), how write test case 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) 

you can similar compiles magic, provided system module.

here example compiler test suite:
https://github.com/nim-lang/nim/blob/devel/tests/metatype/tbindtypedesc.nim#l19

notice how @ top of file, define accept , reject simple static assertions using compiles magic , use them throughout file test valid , invalid overloaded calls.

personally, think failing @ compile-time better, can assign result of compiles run-time value or use in check statement. advantage of failures reported in standard way unittest library.


Comments

Popular posts from this blog

android - net_scheduler holding wakelock -

sql - MySQL : Getting Entries from a many-to-many table -

java - Retrieving data from database using jsp (Hibernate + Spring + Maven) -