Summary: Make each unittest block a separate function that runs
                    independently of the others
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD

--- Comment #0 from Jonathan M Davis <> 2010-08-28 
17:14:31 PDT ---
At the moment, each module has a single unittest function made up of all of the
unittest blocks in the module. This causes 2 problems:

1. A failure in one unittest block results in none of the others getting run,
even though they are independent in the code.

2. Stack traces from unit tests are useless because you have no way of knowing
_which_ unittest block failed.

By making each unittest block its own function, they can be run independently.
It also will help with stack traces, because each one would have its own name -
even it differs only by a number (since presumably, that's how unittest blocks
at the same scope would be given names by the compiler). At least then you
could count the unittest blocks to find it. Right now, there's no way to know.

Now, if you add that with named unit tests, e.g.

unittest (mytest)

then you have a function name for the unit test and the stack trace is properly
specific (though presumably unnamed unit tests would still use a numbered
naming scheme of some kind).

I know that an enhancement request which includes named unit tests for D1 was
reported a while back ( bug 2749 ) - though it also includes stuff like nesting
unit tests (which I think is pointless) - and I know that it has been
previously discussed that unit test blocks should be independent, but I'm
unaware of a bug report on it.

So, here's an enhancement request to make unittest blocks independent, and as
part of that, I would _strongly_ encourage that named unit tests be added as
well. That way stack traces are clear and useful. Right now, if you want to do
that, you have to create a function that contains your unit test and have the
unittest block call it, which is certainly cumbersome, and the potential
benefits of named unit tests go far beyond stack traces, so we really should
have them at some point. Both would help a lot with unit tests.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to