[Issue 11636] New: -unittest flag preserves assert() statements but still allows in/out contracts to be stripped
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Nov 28 14:51:19 PST 2013
https://d.puremagic.com/issues/show_bug.cgi?id=11636
Summary: -unittest flag preserves assert() statements but still
allows in/out contracts to be stripped
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: joseph.wakeling at webdrake.net
--- Comment #0 from Joseph Rushton Wakeling <joseph.wakeling at webdrake.net> 2013-11-28 14:51:13 PST ---
Created an attachment (id=1296)
Code to illustrate the bug: try running with -unittest, -release, and -unittest
-release flags
Adding the -unittest flag to a build means that any assert() statements in the
code will be preserved, even if the -release flag is also used.
However, -release will still strip out in/out contracts even if the -unittest
flag is used. This can lead to unittest failures when e.g. the unittest checks
that an in-contract is respected by looking for an AssertError.
The attached code illustrates this: if run with
rdmd -unittest contract.d
it runs without error, as the call to foo in main does not fail the in-contract
assert, and the unittest catches the AssertError.
Similarly, if run with
rdmd -release contract.d
it also runs without error, as the unittests are not called and the in-contract
is stripped out, meaning foo will run even with incorrect input.
However, when run with
rdmd -unittest -release contract.d
it will fail with an error:
core.exception.AssertError at contract.d(27): assertThrown failed: No
AssertError was thrown.
which triggers because, while asserts are still active, the in-contract has
still been stripped, and hence the assert it contains is not called, and an
AssertError is not thrown.
This inconsistency should surely be fixed -- if -unittest requires assert
statements to be present, it should require _all_ assert statements be present,
including those in in- and out-contracts.
--
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list