digitalmars.D.bugs - [Issue 11636] New: -unittest flag preserves assert() statements but still allows in/out contracts to be stripped
- d-bugmail puremagic.com (44/44) Nov 28 2013 https://d.puremagic.com/issues/show_bug.cgi?id=11636
- d-bugmail puremagic.com (15/18) Nov 28 2013 https://d.puremagic.com/issues/show_bug.cgi?id=11636
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 puremagic.com ReportedBy: joseph.wakeling 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 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: -------
Nov 28 2013
https://d.puremagic.com/issues/show_bug.cgi?id=11636 2013-11-28 15:02:56 PST ---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.Alternatively, if the point of view is that -unittest -release should effectively test code "as it is with the -release flag active" (i.e. so contracts _should_ be stripped), there needs to be some way of checking if -release has been used, and conditionally selecting different unittests accordingly, e.g.: version(release) assert(/* something appropriate to -release mode */); else assert(/* something else */); ... but code being tested "as it is with the -release flag active" doesn't seem to me to sit well with keeping in-body assert() statements active. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 28 2013