Skip to content

Loading…

Bug 5587: Give unit test name by __LINE__. #264

Merged
merged 2 commits into from

4 participants

@kennytm

http://d.puremagic.com/issues/show_bug.cgi?id=5587

This commit appends 'Lxx' to the unittest's mangled name. The user can get the line number from the traceback:

5   x       0x000091c5 onAssertErrorMsg + 73
6   x       0x00009206 onUnittestErrorMsg + 26
7   x       0x00013199 _d_unittestm + 45
8   x       0x000019d7 void x.__unittest_fail(int) + 27
9   x       0x00001a0a void x.__unittestL13_1() + 46
                                        ^^^ line 13
kennytm added some commits
@kennytm kennytm Bug 5587: Give unit test name by __LINE__.
This commit appends 'Lxx' to the unittest's mangled name. The user can get the line number from the traceback:

5   x       0x000091c5 onAssertErrorMsg + 73
6   x       0x00009206 onUnittestErrorMsg + 26
7   x       0x00013199 _d_unittestm + 45
8   x       0x000019d7 void x.__unittest_fail(int) + 27
9   x       0x00001a0a void x.__unittestL13_1() + 46
                                        ^^^ line 13
8f478ac
@kennytm kennytm Fix build failure: snprintf doesn't exist on Windows. af9cd30
@alexrp
D Programming Language member

This really needs to be merged. It would make debugging so much easier.

@nazriel

Ping on this.

@WalterBright WalterBright merged commit d3669f7 into D-Programming-Language:master
@WalterBright WalterBright added a commit that referenced this pull request
@WalterBright WalterBright merge D2 pull #264 9850e67
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 3, 2012
  1. @kennytm

    Bug 5587: Give unit test name by __LINE__.

    kennytm committed
    This commit appends 'Lxx' to the unittest's mangled name. The user can get the line number from the traceback:
    
    5   x       0x000091c5 onAssertErrorMsg + 73
    6   x       0x00009206 onUnittestErrorMsg + 26
    7   x       0x00013199 _d_unittestm + 45
    8   x       0x000019d7 void x.__unittest_fail(int) + 27
    9   x       0x00001a0a void x.__unittestL13_1() + 46
                                            ^^^ line 13
  2. @kennytm
Showing with 11 additions and 3 deletions.
  1. +11 −3 src/func.c
View
14 src/func.c
@@ -3812,13 +3812,21 @@ void InvariantDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
* instances per module.
*/
-static Identifier *unitTestId()
+#if __DMC__ || _MSC_VER
+#define snprintf _snprintf
+#endif
+static Identifier *unitTestId(Loc loc)
{
- return Lexer::uniqueId("__unittest");
+ char name[24];
+ snprintf(name, 24, "__unittestL%u_", loc.linnum);
+ return Lexer::uniqueId(name);
}
+#if __DMC__ || _MSC_VER
+#undef snprintf
+#endif
UnitTestDeclaration::UnitTestDeclaration(Loc loc, Loc endloc)
- : FuncDeclaration(loc, endloc, unitTestId(), STCundefined, NULL)
+ : FuncDeclaration(loc, endloc, unitTestId(loc), STCundefined, NULL)
{
}
Something went wrong with that request. Please try again.