Problem with assertThrown

kookman thekookman at gmail.com
Tue Sep 10 01:11:03 UTC 2024


On Tuesday, 10 September 2024 at 01:04:15 UTC, Jonathan M Davis 
wrote:
>
> When I run it locally, assertThrown passes as expected for test 
> case 5, and the same happens on run.dlang.io, so nothing in my 
> specific setup is making it pass when it normally wouldn't.
>
> So, unless you verified that your example failed (and since you 
> forgot to include that enum, I suspect you didn't), I would 
> guess that whatever your problem is went away when you reduced 
> the code to provide the example for your question.
>
> I would note however, that the message for the AssertError that 
> you provided
> did not come from assertThrown, since while assertThrown does 
> take the file
> and line number from the caller, its message starts with
> "assertThrown failed:", whereas your error message was the 
> generic message
> that you get from an assertion failure. So, whatever is going 
> wrong in your
> code, assertThrown is not determining that your code didn't 
> throw and then
> throwing an AssertError. It looks like an assertion on line 
> #283 of whatever
> code you actually ran (which is clearly longer than the example 
> you
> provided, since it's not that long) is failing.
>
> - Jonathan M Davis

Ah! *(forehead slap)* Thank you! It was actually an assert in the 
immediately following unittest block failing (which I hadn't 
added a message to). I should have tried my reduced version 
before posting.

Thanks,
Kookman


More information about the Digitalmars-d-learn mailing list