digitalmars.D - unittest
- Sean Kelly (21/21) Dec 01 2007 Given the dual use of "invariant" in D 2.0, I was thinking it might be
- BCS (3/29) Dec 02 2007 an interesting idea, I can't say I'm totally for it, but I'd like to see...
- Sean Kelly (7/35) Dec 02 2007 Right now, Tango uses "version(UnitTest)" for this purpose but it would
Given the dual use of "invariant" in D 2.0, I was thinking it might be useful to do the something similar with "unittest". Make it equivalent to "version(unittest)" and be enabled when -unittest was specified during compilation. This seems a rather natural extension of the keyword and the semantics would be nearly identical to how "invariant" works right now: unittest int x; // single declaration enabled on -unittest unittest int fn() {} // function compiled on -unittest unittest // everything in the block compiled on -unittest { import std.stdio; int y; void f2() {} } unittest() // unit test function, similar to invariant() { writefln( "hello" ); } As an added bonus, this would regain consistency with the invariant function, which has been bugging me since its adoption for use with const. Sean
Dec 01 2007
Reply to Sean,Given the dual use of "invariant" in D 2.0, I was thinking it might be useful to do the something similar with "unittest". Make it equivalent to "version(unittest)" and be enabled when -unittest was specified during compilation. This seems a rather natural extension of the keyword and the semantics would be nearly identical to how "invariant" works right now: unittest int x; // single declaration enabled on -unittest unittest int fn() {} // function compiled on -unittest unittest // everything in the block compiled on -unittest { import std.stdio; int y; void f2() {} } unittest() // unit test function, similar to invariant() { writefln( "hello" ); } As an added bonus, this would regain consistency with the invariant function, which has been bugging me since its adoption for use with const. Seanan interesting idea, I can't say I'm totally for it, but I'd like to see it considered.
Dec 02 2007
BCS wrote:Reply to Sean,Right now, Tango uses "version(UnitTest)" for this purpose but it would be nice to have some actual language support for this. Though I'll admit my real motivation is to try and regain some consistency with "invariant" and "unittest" in D 2.0. It doesn't seem likely that the words used for const features will change, so... SeanGiven the dual use of "invariant" in D 2.0, I was thinking it might be useful to do the something similar with "unittest". Make it equivalent to "version(unittest)" and be enabled when -unittest was specified during compilation. This seems a rather natural extension of the keyword and the semantics would be nearly identical to how "invariant" works right now: unittest int x; // single declaration enabled on -unittest unittest int fn() {} // function compiled on -unittest unittest // everything in the block compiled on -unittest { import std.stdio; int y; void f2() {} } unittest() // unit test function, similar to invariant() { writefln( "hello" ); } As an added bonus, this would regain consistency with the invariant function, which has been bugging me since its adoption for use with const.an interesting idea, I can't say I'm totally for it, but I'd like to see it considered.
Dec 02 2007