Jump to page: 1 2
Thread overview
[Issue 5587] New: Use __LINE__ to pick number in unittest block names
Feb 15, 2011
Jonathan M Davis
Apr 28, 2011
Don
Apr 28, 2011
Walter Bright
Apr 29, 2011
Walter Bright
Apr 29, 2011
Walter Bright
Apr 29, 2011
kennytm@gmail.com
Jul 18, 2011
kennytm@gmail.com
Jul 18, 2011
kennytm@gmail.com
Sep 06, 2012
Walter Bright
Sep 06, 2012
Jonathan M Davis
February 15, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5587

           Summary: Use __LINE__ to pick number in unittest block names
           Product: D
           Version: unspecified
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: jmdavisProg@gmx.com


--- Comment #0 from Jonathan M Davis <jmdavisProg@gmx.com> 2011-02-15 01:00:14 PST ---
At the moment, we can't name unit tests. Ideally we could, but for now, we can't. And this is a big problem in that any exceptions that are thrown from a function called directly or indirectly by a unittest block ends up with a fairly useless stack trace because the function generated from the unittest block is something like _unittest1298, which gives absolutely no clue as to which unittest block it's for. I have no idea how that number is generated, but as far as I can tell, it's useless. Don suggested that we use __LINE__ to generate that number so that it actually _is_ meaningful. So, I'm opening this enhancement request for that to be done. I still think that we should have named unittest blocks at some point (e.g. unittest(testName) {}), but using __LINE__ in the name would be a big help.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 28, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5587


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug@yahoo.com.au
            Version|unspecified                 |D1 & D2
           Severity|normal                      |enhancement


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 28, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5587


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com


--- Comment #1 from Walter Bright <bugzilla@digitalmars.com> 2011-04-28 13:44:27 PDT ---
It's a good idea. Actually, file and line.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 29, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5587



--- Comment #2 from Walter Bright <bugzilla@digitalmars.com> 2011-04-28 17:07:25 PDT ---
Um, have to be careful about two unittests on the same line!

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 29, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5587


Andrei Alexandrescu <andrei@metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrei@metalanguage.com


--- Comment #3 from Andrei Alexandrescu <andrei@metalanguage.com> 2011-04-28 17:29:21 PDT ---
(In reply to comment #2)
> Um, have to be careful about two unittests on the same line!

__COLUMN__ ftw!

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 29, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5587


Steven Schveighoffer <schveiguy@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy@yahoo.com


--- Comment #4 from Steven Schveighoffer <schveiguy@yahoo.com> 2011-04-29 04:48:50 PDT ---
I think this request is a very good idea.

(In reply to comment #2)
> Um, have to be careful about two unittests on the same line!

Why?  Either combine the functions into one, or disallow that possibility (shouldn't be too disruptive I would think).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 29, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5587



--- Comment #5 from Walter Bright <bugzilla@digitalmars.com> 2011-04-29 12:40:25 PDT ---
(In reply to comment #4)
> > Um, have to be careful about two unittests on the same line!
> Why?  Either combine the functions into one,

Which introduces a complex special case.

> or disallow that possibility
> (shouldn't be too disruptive I would think).

D has no similar dependencies on line endings, this would be a bizarre exception.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 29, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5587


kennytm@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kennytm@gmail.com


--- Comment #6 from kennytm@gmail.com 2011-04-29 12:55:00 PDT ---
(In reply to comment #1)
> It's a good idea. Actually, file and line.

"File" is not needed because the module's name is already part of the mangled name of the unittest.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 29, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5587



--- Comment #7 from Steven Schveighoffer <schveiguy@yahoo.com> 2011-04-29 12:59:43 PDT ---
(In reply to comment #5)
> > Why?  Either combine the functions into one,
> 
> Which introduces a complex special case.

Actually, you are right, this solution requires complex rewriting of the code. Probably not worth the effort.

> > or disallow that possibility
> > (shouldn't be too disruptive I would think).
> 
> D has no similar dependencies on line endings, this would be a bizarre exception.

It's not that bizarre.  It doesn't even have to go into the grammar.  All that happens is you have the auto-namer name the two unit tests the same, and let the semantic pass reject it (duplicate function definition).  This can easily be explained to the user in the docs.

Besides, who puts two function blocks on the same line anyways?  I've seen people write one or two statement functions on the same line, but never more than one of those on the same line (except in obfuscation contests, but who writes unit tests for those?)

My prediction is that if you did this you will never ever hear a complaint about it :)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 29, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5587



--- Comment #8 from Andrei Alexandrescu <andrei@metalanguage.com> 2011-04-29 13:07:43 PDT ---
(In reply to comment #5)
> (In reply to comment #4)
> > > Um, have to be careful about two unittests on the same line!
> > Why?  Either combine the functions into one,
> 
> Which introduces a complex special case.
> 
> > or disallow that possibility
> > (shouldn't be too disruptive I would think).
> 
> D has no similar dependencies on line endings, this would be a bizarre exception.

Yah. Probably a simple practical solution is to define a name for the unittest depending on __FILE__ and __LINE__  for single unittests, and to add a count only for several unittests on the same line. This makes the common case simple and the exceedingly rare exception handled with panache. For example:

unittest { a(); }
unittest { b(); } unittest { c(); }

The first unittest is "unittest at foo/bar/baz.d:238", the second unittest is "unittest #1 at foo/bar/baz.d:239", and the third is "unittest #2 at foo/bar/baz.d:239". That takes care of everything.

BTW Walter I appreciate you giving a look to this. It's a simple addition that would drastically improve the conviviality of unittests.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
« First   ‹ Prev
1 2