Static unittests?
Artur Skawina
art.08.09 at gmail.com
Mon Aug 5 11:49:37 PDT 2013
On 08/05/13 20:27, monarch_dodra wrote:
> On Monday, 5 August 2013 at 18:15:22 UTC, Dicebot wrote:
>> On Monday, 5 August 2013 at 17:30:38 UTC, monarch_dodra wrote:
>>> static assert({int i; assert(i == 0;});
>>
>> enum i;
>> static assert(i == 0);
>>
>> I am really struggling to understand the use case.
>> D has a tool to force CTFE execution - `enum`. It has a tool for compile-time checks - `static assert`. Any possible compile-time test can be expressed via those. All assertCTFEable or similar tool adds is ability to save on some `static` markers.
>
> You are working around the argument. The point is that some calls simply can't be reduced to a single call. How would you deal with testing "parse" then?
>
> assertCTFEable!({ string s = "1234abc"; assert(parse! int(s) == 1234 && s == "abc"); });
>
> The point is that you can write "native" runtime code, and then only CTFE test it once. It brings more than just "saving" on markers.
>
> What about, for example:
>
> assertCTFEable!({
> int i = 5;
> string s;
> while (i--)
> s ~= 'a';
> assert(s == "aaaaa");
> });
>
> And still, all of these are just simple cases.
static assert({
int i = 5;
string s;
while (i--)
s ~= 'a';
return s == "aaaaa";
}());
etc
artur
More information about the Digitalmars-d
mailing list