I'm currently trying to test that my macro throws an exception if you give it a malformed file I've gone down the route of using testament for this as its the only way I can see this working as I'm expecting my test to not compile! however when I run my testament test it returns a reFilesDiffer
discard """
errormsg: "unhandled exception: missing `sheets` attribute [CastleDbError]"
line: 6
"""
import castledb
generateCastleDbModel("""{}""", exportTypes = false) #this is a macro from the castledb module that throws a CastleDbError
the output of testament was as followed
$ testament r tests/tcastledb_macro_errors.nim
FAIL: tests/tcastledb_macro_errors.nim C
Test "tests\tcastledb_macro_errors.nim" in category "tests"
Failure: reFilesDiffer
Expected:
tests\tcastledb_macro_errors.nim
Gotten:
castledb.nim
FAILURE! total: 1 passed: 0 skipped: 0 failed: 1
I think I am getting this error as its the castledb module that throws the exception instead of the exception being thrown in the test file. Is there anyway around this? I've tried using include instead of import
testing that a macro throws an exception
After digging through the testament code I've found an undocumented part of testament that solves this. The final output is the following
discard """
errormsg: "missing `sheets` attribute"
file: "castledb.nim"
"""
import castledb
generateCastleDbModel("test.json", """{}""", exportTypes = false) #this is a macro from the castledb module that throws a CastleDbError