Skip to content

Conversation

7sDream
Copy link
Contributor

@7sDream 7sDream commented May 23, 2018

code for test

import unittest

suite "throw exception":
  test "show exception type":
    raise newException(ValueError, "a value error")

before

[Suite] throw exception
test1.nim(5)             test1

    Unhandled exception: a value error
  [FAILED] show exception type

after

[Suite] throw exception
test1.nim(5)             test1

    Unhandled exception: a value error [ValueError]
  [FAILED] show exception type

Change the parameter name of template test to testDesc because we will e.name to get the type and testName is a property of TestResult type and used in this template too.

Test added, I create a new file instead of add it into tunittest.nim, because the exitcode need to be 1, don‘t want change exit code check for tests in tunittest.nim.

@cooldome
Copy link
Member

typedesc is a valid standard type so it is rather confusing, can we make it test_name instead

@data-man
Copy link
Contributor

Change the parameter name of template test to typeDesc

No, it's name of a test. Revert, please.

Otherwise, on this logic should be template suite*(suiteDesc, body) instead of template suite*(name, body) ?

The rest is fine, thanks!

@7sDream
Copy link
Contributor Author

7sDream commented May 24, 2018

@cooldome

test_name is same as testName so conflict with TestResult.testName.

@data-man

use name as parameter name will make e.name be expanded to e."show exception type" so:

in expression 'e."show exception type"': identifier expected, but found '"show exception type""'

How can we make a template parameter name not expanded temporarily in this line?

@7sDream
Copy link
Contributor Author

7sDream commented May 27, 2018

@cooldome @data-man

I added a help template to bypass the name conflicts, but it will lead to a useless template be exported, is this an acceptable way?

@7sDream
Copy link
Contributor Author

7sDream commented May 27, 2018

Oh, I noticed the bind stmt and then read the doc, now exceptionTypeName don't need to be exported.

But I wonder why the doc says:

But a bind is rarely useful because symbol binding from the definition scope is the default.

@data-man
Copy link
Contributor

LGTM.

@7sDream
Nice!
Please, add entry to the changelog (to the "Library changes" section).

@data-man data-man merged commit b6b6382 into nim-lang:devel May 28, 2018
@7sDream 7sDream deleted the unittest-raise-exception-output-add-type branch May 28, 2018 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants