My late christmas present for you: context-aware assertion error messages
rjframe
dlang at ryanjframe.com
Tue Jan 15 12:14:33 UTC 2019
On Tue, 15 Jan 2019 10:23:32 +0000, Seb wrote:
> On Tuesday, 15 January 2019 at 08:43:06 UTC, Kagamin wrote:
>> On Saturday, 12 January 2019 at 15:34:02 UTC, Seb wrote:
>>> void main()
>>> {
>>> int a = 1, b = 2;
>>> assert(a == b); // ERROR: 1 != 2
>>> }
>>
>> But 1!=2 is true :)
>> Maybe do it the C way "assertion 1 == 2 failed"? Also there's in
>> operator.
>
> Hmm you have a point there. How do other people feel about this?
>
> My main motivation was to be able to see the actual values (instead of
> just an AssertError), so I would be more than happy to change the format
> of the message.
I think I'd agree with Kagamin - after the first time you'd know it, but D
already has a big list of "after the first time" features; If we see
D-learners posting, confused about it, then it should probably be
adjusted; otherwise, maybe it's not a major concern.
I just skimmed some of my tests and the current message works, but may
take some getting used to because of the reversal of the conditional. Ex:
assert(opts.imports[0] == "std.stdio");
// becomes "ERROR: std.file != std.stdio"... well, yeah.
// "ERROR: assertion std.file == std.stdio failed" is an easier read
// (at least for me)
--Ryan
More information about the Digitalmars-d
mailing list