[BUG] failed unittest in renamed module prints stack trace
Adam D. Ruppe
destructionator at gmail.com
Fri May 23 10:56:29 UTC 2025
On Friday, 23 May 2025 at 06:42:02 UTC, kdevel wrote:
> is stored under the name `foo_bar.d` one gets what is expected:
That's interesting, I didn't realize it ever did that.... but
> However, if the module name differs from the filename [1] an
> additional core dump is generated:
Yeah, this annoyed me in opend recently too and I pushed a fix
for it just earlier this week:
https://github.com/opendlang/opend/commit/da79e82c6507b81798c2de73c7d8ff47397e8914#diff-9a6dcca83f85a8a48ac3437327e62f02d6e9c1394e6cfc0f43c9cf4304ac98a2R126-R245
See where that `isModTest` function is called for this specific
thing (I also wanted to generally compress things that are
irrelevant to the end user in that whole commit so there's a
couple other things too).
The opend output for your same program:
```
core.exception.AssertError at foo_bar.d(4): 1 != 2
----------------
??:? _d_unittest_msg [0x43f630]
./foo_bar.d:4 foo_bara.__unittest_L3_C1() [0x437760]
1/1 modules FAILED unittests
```
So yes, there's a stacktrace, but it stops at the module unittest
- same as it stops at main() for normal program run exceptions -
which makes it look a lot less spammy.
I'm scheduled to release a blog post on Monday detailing the
other enhancements in this release so i'll save the rest for then.
But I didn't realize the module name mattered.... and yeah that
behavior is present in opend too (no surprise really, opend
druntime differs from upstream mostly in the added Emscripten and
Freestanding support, and the merger of dmd and ldc codebases,
the actual function contents mostly are the same).
And here it is:
src/core/runtime.d line 618 in opend master:
```
if ( typeid(e) == typeid(AssertError) )
{
// Crude heuristic to figure whether the
assertion originates in
// the unittested module. TODO: improve.
auto moduleName = m.name;
if (moduleName.length && e.file.length >
moduleName.length
&& e.file[0 .. moduleName.length] ==
moduleName)
{
```
Eh, I like the opend result better, it applies to all exceptions,
tempting to just delete this hack entirely instead of trying to
fix it more.
More information about the Digitalmars-d
mailing list