From f3117d350ea245769d60a80b2d12b062cff4b8ff Mon Sep 17 00:00:00 2001 From: Miran Date: Fri, 7 Feb 2020 22:04:08 +0100 Subject: [PATCH] fix #6736: templates in unittest now show actual value (#13354) --- lib/pure/unittest.nim | 2 +- tests/stdlib/tunittesttemplate.nim | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 tests/stdlib/tunittesttemplate.nim diff --git a/lib/pure/unittest.nim b/lib/pure/unittest.nim index c50ef0b1b5..ee2c5fe228 100644 --- a/lib/pure/unittest.nim +++ b/lib/pure/unittest.nim @@ -631,7 +631,7 @@ macro check*(conditions: untyped): untyped = var counter = 0 - if exp[0].kind == nnkIdent and + if exp[0].kind in {nnkIdent, nnkOpenSymChoice, nnkClosedSymChoice, nnkSym} and $exp[0] in ["not", "in", "notin", "==", "<=", ">=", "<", ">", "!=", "is", "isnot"]: diff --git a/tests/stdlib/tunittesttemplate.nim b/tests/stdlib/tunittesttemplate.nim new file mode 100644 index 0000000000..5ac323a369 --- /dev/null +++ b/tests/stdlib/tunittesttemplate.nim @@ -0,0 +1,25 @@ +discard """ + exitcode: 1 + outputsub: ''' + tunittesttemplate.nim(20, 12): Check failed: a.b == + 2 + a.b was 0 + [FAILED] 1 +''' +""" + +# bug #6736 + +import unittest + +type + A = object + b: int + +template t: untyped = + check(a.b == 2) + +suite "1": + test "1": + var a = A(b: 0) + t()