digitalmars.D - static unittest
- Andrei Alexandrescu (10/10) Apr 30 2014 Walter and I also discussed "static unittest" a while ago - yes, another...
- Meta (7/19) Apr 30 2014 There's also
- Atila Neves (9/33) Apr 30 2014 I've been doing this a lot lately. Since I wrote a unit test
- Atila Neves (5/40) Apr 30 2014 Having said that, I did think (and probably will) of writing a
- H. S. Teoh via Digitalmars-d (36/52) Apr 30 2014 Yeah I think 'static' is getting a little too overloaded in D. But in
- Andrei Alexandrescu (3/5) Apr 30 2014 static assert is for expressions, static unittest is for statements.
- Dicebot (5/12) Apr 30 2014 See linked thread, it was extensively discussed there. TL; DR:
- Vladimir Panteleev (5/15) Apr 30 2014 Isn't (__traits(compiles, ...) in a static assert redundant? All
- Andrei Alexandrescu (2/16) Apr 30 2014 Not if you want to compile statements. -- Andrei
- Dicebot (3/15) Apr 30 2014 http://forum.dlang.org/post/enlgrnfrfsfldaxiaoug@forum.dlang.org
- Kenji Hara via Digitalmars-d (4/14) Apr 30 2014 std.exception.assertCTFEable ?
- Jacob Carlborg (6/15) Apr 30 2014 It's already possible to do CTFE unit testing [1], if that was what
- Meta (7/19) Apr 30 2014 Also, while we're thinking about static unittest, what about
- Walter Bright (2/6) Apr 30 2014 Already have them - template constraints.
- Meta (3/12) Apr 30 2014 Your function needs to be a template for that. Also, object
- Walter Bright (3/13) Apr 30 2014 Easily handled with static asserts.
- Meta (28/47) May 01 2014 Just a thought, this might be a good idea for the problem of not
- Xavier Bigand (3/13) Apr 30 2014 Can be usefull on our project DQuick. Maybe my friend will be able to
Walter and I also discussed "static unittest" a while ago - yes, another use of static :o). A static unittest would be evaluated only during compilation, and would prove things that fall in the realm of static checking but are not verifiable with traditional typesystem approach. That won't enable things we can't do today (there's always assert(__traits(compiles, ...)) but it's instantly recognizable, very easy to use, and pushes semantic checking to a whole new level. Thoughts? Andrei
Apr 30 2014
On Wednesday, 30 April 2014 at 16:55:06 UTC, Andrei Alexandrescu wrote:Walter and I also discussed "static unittest" a while ago - yes, another use of static :o). A static unittest would be evaluated only during compilation, and would prove things that fall in the realm of static checking but are not verifiable with traditional typesystem approach. That won't enable things we can't do today (there's always assert(__traits(compiles, ...)) but it's instantly recognizable, very easy to use, and pushes semantic checking to a whole new level. Thoughts? AndreiThere's also unittest { static assert(...); }
Apr 30 2014
On Wednesday, 30 April 2014 at 16:57:13 UTC, Meta wrote:On Wednesday, 30 April 2014 at 16:55:06 UTC, Andrei Alexandrescu wrote:I've been doing this a lot lately. Since I wrote a unit test library I use that for all my unit tests, but the compilation ones are usually implementation details that don't need external tests. I started adding static asserts to the file that needed them but got lost in what was implementation and what was a test so I started wrapping all the static asserts in unittest blocks. Works for me. AtilaWalter and I also discussed "static unittest" a while ago - yes, another use of static :o). A static unittest would be evaluated only during compilation, and would prove things that fall in the realm of static checking but are not verifiable with traditional typesystem approach. That won't enable things we can't do today (there's always assert(__traits(compiles, ...)) but it's instantly recognizable, very easy to use, and pushes semantic checking to a whole new level. Thoughts? AndreiThere's also unittest { static assert(...); }
Apr 30 2014
On Wednesday, 30 April 2014 at 17:03:58 UTC, Atila Neves wrote:On Wednesday, 30 April 2014 at 16:57:13 UTC, Meta wrote:Having said that, I did think (and probably will) of writing a staticEquals for unit-threaded so at least I don't have to keep building up the string to print out for myself every time. AtilaOn Wednesday, 30 April 2014 at 16:55:06 UTC, Andrei Alexandrescu wrote:I've been doing this a lot lately. Since I wrote a unit test library I use that for all my unit tests, but the compilation ones are usually implementation details that don't need external tests. I started adding static asserts to the file that needed them but got lost in what was implementation and what was a test so I started wrapping all the static asserts in unittest blocks. Works for me. AtilaWalter and I also discussed "static unittest" a while ago - yes, another use of static :o). A static unittest would be evaluated only during compilation, and would prove things that fall in the realm of static checking but are not verifiable with traditional typesystem approach. That won't enable things we can't do today (there's always assert(__traits(compiles, ...)) but it's instantly recognizable, very easy to use, and pushes semantic checking to a whole new level. Thoughts? AndreiThere's also unittest { static assert(...); }
Apr 30 2014
On Wed, Apr 30, 2014 at 04:57:12PM +0000, Meta via Digitalmars-d wrote:On Wednesday, 30 April 2014 at 16:55:06 UTC, Andrei Alexandrescu wrote:Yeah I think 'static' is getting a little too overloaded in D. But in this case, I think it's excusable. :-PWalter and I also discussed "static unittest" a while ago - yes, another use of static :o).[...]A static unittest would be evaluated only during compilation, and would prove things that fall in the realm of static checking but are not verifiable with traditional typesystem approach. That won't enable things we can't do today (there's always assert(__traits(compiles, ...)) but it's instantly recognizable, very easy to use, and pushes semantic checking to a whole new level.There's also unittest { static assert(...); }Yeah, what does static unittest give us beyond static assert? (Other than nice syntax, that is.) Or are you suggesting that code inside a static unittest will be CTFE'd and elided from the emitted object code? That could be nice. Speaking of which, it would be nice if there was a way to elide CTFE-only functions from the object code, e.g.: real complicatedComputation(real arg) { ... return result; } enum x = complicatedComputation(5.0); Supposing that complicatedComputation() is never used except to assign a value to x, it would be nice to be able to omit it from the executable. Especially if it's a template function -- it will cut down on template bloat. Currently one way to hack this is: real complicatedComputation(real arg) { if (__ctfe) { ... return result; } else return real.nan; // UGLY } enum x = complicatedComputation(5.0); This minimizes the executable bloat (ld --gc-sections could help, but that is known to break in some circumstances), but it's ugly since the function still has to return *something*. T -- Many open minds should be closed for repairs. -- K5 user
Apr 30 2014
On 4/30/14, 10:11 AM, H. S. Teoh via Digitalmars-d wrote:Yeah, what does static unittest give us beyond static assert? (Other than nice syntax, that is.)static assert is for expressions, static unittest is for statements. Andrie
Apr 30 2014
On Wednesday, 30 April 2014 at 17:24:32 UTC, Andrei Alexandrescu wrote:On 4/30/14, 10:11 AM, H. S. Teoh via Digitalmars-d wrote:See linked thread, it was extensively discussed there. TL; DR: delegates + https://github.com/D-Programming-Language/phobos/blob/master/std/exception.d#L1401Yeah, what does static unittest give us beyond static assert? (Other than nice syntax, that is.)static assert is for expressions, static unittest is for statements. Andrie
Apr 30 2014
On Wednesday, 30 April 2014 at 16:55:06 UTC, Andrei Alexandrescu wrote:Walter and I also discussed "static unittest" a while ago - yes, another use of static :o). A static unittest would be evaluated only during compilation, and would prove things that fall in the realm of static checking but are not verifiable with traditional typesystem approach. That won't enable things we can't do today (there's always assert(__traits(compiles, ...)) but it's instantly recognizable, very easy to use, and pushes semantic checking to a whole new level.Isn't (__traits(compiles, ...) in a static assert redundant? All it does is replace one compilation error for another, additionally hiding its details.
Apr 30 2014
On 4/30/14, 10:00 AM, Vladimir Panteleev wrote:On Wednesday, 30 April 2014 at 16:55:06 UTC, Andrei Alexandrescu wrote:Not if you want to compile statements. -- AndreiWalter and I also discussed "static unittest" a while ago - yes, another use of static :o). A static unittest would be evaluated only during compilation, and would prove things that fall in the realm of static checking but are not verifiable with traditional typesystem approach. That won't enable things we can't do today (there's always assert(__traits(compiles, ...)) but it's instantly recognizable, very easy to use, and pushes semantic checking to a whole new level.Isn't (__traits(compiles, ...) in a static assert redundant? All it does is replace one compilation error for another, additionally hiding its details.
Apr 30 2014
On Wednesday, 30 April 2014 at 16:55:06 UTC, Andrei Alexandrescu wrote:Walter and I also discussed "static unittest" a while ago - yes, another use of static :o). A static unittest would be evaluated only during compilation, and would prove things that fall in the realm of static checking but are not verifiable with traditional typesystem approach. That won't enable things we can't do today (there's always assert(__traits(compiles, ...)) but it's instantly recognizable, very easy to use, and pushes semantic checking to a whole new level. Thoughts? Andreihttp://forum.dlang.org/post/enlgrnfrfsfldaxiaoug forum.dlang.org
Apr 30 2014
std.exception.assertCTFEable ? Kenji Hara 2014/05/01 1:56 "Andrei Alexandrescu via Digitalmars-d" < digitalmars-d puremagic.com>:Walter and I also discussed "static unittest" a while ago - yes, another use of static :o). A static unittest would be evaluated only during compilation, and would prove things that fall in the realm of static checking but are not verifiable with traditional typesystem approach. That won't enable things we can't do today (there's always assert(__traits(compiles, ...)) but it's instantly recognizable, very easy to use, and pushes semantic checking to a whole new level. Thoughts? Andrei
Apr 30 2014
On 2014-04-30 18:55, Andrei Alexandrescu wrote:Walter and I also discussed "static unittest" a while ago - yes, another use of static :o). A static unittest would be evaluated only during compilation, and would prove things that fall in the realm of static checking but are not verifiable with traditional typesystem approach. That won't enable things we can't do today (there's always assert(__traits(compiles, ...)) but it's instantly recognizable, very easy to use, and pushes semantic checking to a whole new level. Thoughts?It's already possible to do CTFE unit testing [1], if that was what you're thinking about. [1] http://forum.dlang.org/thread/ks1brj$1l6c$1 digitalmars.com -- /Jacob Carlborg
Apr 30 2014
On Wednesday, 30 April 2014 at 16:55:06 UTC, Andrei Alexandrescu wrote:Walter and I also discussed "static unittest" a while ago - yes, another use of static :o). A static unittest would be evaluated only during compilation, and would prove things that fall in the realm of static checking but are not verifiable with traditional typesystem approach. That won't enable things we can't do today (there's always assert(__traits(compiles, ...)) but it's instantly recognizable, very easy to use, and pushes semantic checking to a whole new level. Thoughts? AndreiAlso, while we're thinking about static unittest, what about contracts? I've seen Bearophile suggest it quite a few times, and I agree that it'd be very useful to have contracts that are able to check a subset of function contracts/object invariants at compile time.
Apr 30 2014
On 4/30/2014 1:38 PM, Meta wrote:Also, while we're thinking about static unittest, what about contracts? I've seen Bearophile suggest it quite a few times, and I agree that it'd be very useful to have contracts that are able to check a subset of function contracts/object invariants at compile time.Already have them - template constraints.
Apr 30 2014
On Wednesday, 30 April 2014 at 21:04:19 UTC, Walter Bright wrote:On 4/30/2014 1:38 PM, Meta wrote:Your function needs to be a template for that. Also, object invariants.Also, while we're thinking about static unittest, what about contracts? I've seen Bearophile suggest it quite a few times, and I agree that it'd be very useful to have contracts that are able to check a subset of function contracts/object invariants at compile time.Already have them - template constraints.
Apr 30 2014
On 4/30/2014 2:34 PM, Meta wrote:On Wednesday, 30 April 2014 at 21:04:19 UTC, Walter Bright wrote:Adding () turns a function into a function template. Also, static asserts.On 4/30/2014 1:38 PM, Meta wrote:Your function needs to be a template for that.Also, while we're thinking about static unittest, what about contracts? I've seen Bearophile suggest it quite a few times, and I agree that it'd be very useful to have contracts that are able to check a subset of function contracts/object invariants at compile time.Already have them - template constraints.Also, object invariants.Easily handled with static asserts.
Apr 30 2014
On Wednesday, 30 April 2014 at 22:14:44 UTC, Walter Bright wrote:On 4/30/2014 2:34 PM, Meta wrote:Just a thought, this might be a good idea for the problem of not knowing which condition fails when a template instantiation fails, i.e.: auto reduce(alias fun, Args...)(Args args) //We don't know which condition fails when this template fails to instantiate if (Args.length > 0 && Args.length <= 2 && isIterable!(Args[$ - 1])) { //... } Instead we could do: auto reduce(alias fun, Args...)(Args args) static in { assert(Args.length > 0); assert(Args.length <= 2); assert(isIterable!(Args[$ - 1])); } body { //... } And the error message which show you exactly which condition failed. You could also just use static asserts in the contract, but the topic of this thread is about `static unittest`, which is more or less redundant as well.On Wednesday, 30 April 2014 at 21:04:19 UTC, Walter Bright wrote:Adding () turns a function into a function template. Also, static asserts.On 4/30/2014 1:38 PM, Meta wrote:Your function needs to be a template for that.Also, while we're thinking about static unittest, what about contracts? I've seen Bearophile suggest it quite a few times, and I agree that it'd be very useful to have contracts that are able to check a subset of function contracts/object invariants at compile time.Already have them - template constraints.Also, object invariants.Easily handled with static asserts.
May 01 2014
Le 30/04/2014 18:55, Andrei Alexandrescu a écrit :Walter and I also discussed "static unittest" a while ago - yes, another use of static :o). A static unittest would be evaluated only during compilation, and would prove things that fall in the realm of static checking but are not verifiable with traditional typesystem approach. That won't enable things we can't do today (there's always assert(__traits(compiles, ...)) but it's instantly recognizable, very easy to use, and pushes semantic checking to a whole new level. Thoughts? AndreiCan be usefull on our project DQuick. Maybe my friend will be able to speek more on how much it's interesting.
Apr 30 2014