digitalmars.D.announce - unit-threaded v0.6.5 - Type-parametrized tests
- Atila Neves (22/22) Mar 09 2016 The forum must be sick of hearing from me... :P For those not in
- Jacob Carlborg (4/23) Mar 10 2016 Do you have a slightly more extended example that shows how this is used...
- Atila Neves (13/52) Mar 10 2016 No, sorry. I haven't needed it yet. Something like this?
- Jacob Carlborg (9/20) Mar 11 2016 I'm trying to think how this would be useful. Would you want to test
- Atila Neves (7/28) Mar 11 2016 There's this: https://github.com/mcandre/dashcheck
- Robert burner Schadek (2/3) Mar 11 2016 Yes, https://github.com/D-Programming-Language/phobos/pull/2995
- Iakh (2/7) Mar 10 2016 It is not clear that this UDA is about unittesting
- Atila Neves (3/11) Mar 10 2016 Even when attached to a test function?
- Meta (2/3) Mar 10 2016 I'm always excited for a new release of unit-threaded
- Atila Neves (3/6) Mar 10 2016 Thanks for the kind words!
The forum must be sick of hearing from me... :P For those not in the know, unit-threaded is an advanced unit testing library for D: http://code.dlang.org/packages/unit-threaded The v0.6.3 release had tests parametrized by value; this v0.6.5 release brings with it the possibility of parametrizing tests by type, like so: Types!(int, byte) void testInit(T)() { assert(T.init == 0); } This will run the testInit code twice, once for each type, and report them as separate tests: tests.pass.attributes.testInit.int: tests.pass.attributes.testInit.byte: I've literally only written that silly testInit example yet. But imagine how easy it'd be to test, say, different input ranges. I'm thinking of ways of getting the parametrized tests to work with the built-in unittest blocks. I assume it'll be hacky. Right now it's the only thing that requires non-standard test functions and I'm trying to augment the existing unit testing features of D instead of replacing them. Atila
Mar 09 2016
On 2016-03-09 19:01, Atila Neves wrote:The forum must be sick of hearing from me... :P For those not in the know, unit-threaded is an advanced unit testing library for D: http://code.dlang.org/packages/unit-threaded The v0.6.3 release had tests parametrized by value; this v0.6.5 release brings with it the possibility of parametrizing tests by type, like so: Types!(int, byte) void testInit(T)() { assert(T.init == 0); } This will run the testInit code twice, once for each type, and report them as separate tests: tests.pass.attributes.testInit.int: tests.pass.attributes.testInit.byte: I've literally only written that silly testInit example yet. But imagine how easy it'd be to test, say, different input ranges. I'm thinking of ways of getting the parametrized tests to work with the built-in unittest blocks. I assume it'll be hacky. Right now it's the only thing that requires non-standard test functions and I'm trying to augment the existing unit testing features of D instead of replacing them.Do you have a slightly more extended example that shows how this is used? -- /Jacob Carlborg
Mar 10 2016
On Thursday, 10 March 2016 at 08:09:40 UTC, Jacob Carlborg wrote:On 2016-03-09 19:01, Atila Neves wrote:No, sorry. I haven't needed it yet. Something like this? Types!(int, string) void testArray(T)() { import std.container; auto arr = Array!T(); arr.empty.shouldBeTrue; arr.insertBack(T.init); arr.empty.shouldBeFalse; auto l = arr.length; l.shouldEqual(1); } AtilaThe forum must be sick of hearing from me... :P For those not in the know, unit-threaded is an advanced unit testing library for D: http://code.dlang.org/packages/unit-threaded The v0.6.3 release had tests parametrized by value; this v0.6.5 release brings with it the possibility of parametrizing tests by type, like so: Types!(int, byte) void testInit(T)() { assert(T.init == 0); } This will run the testInit code twice, once for each type, and report them as separate tests: tests.pass.attributes.testInit.int: tests.pass.attributes.testInit.byte: I've literally only written that silly testInit example yet. But imagine how easy it'd be to test, say, different input ranges. I'm thinking of ways of getting the parametrized tests to work with the built-in unittest blocks. I assume it'll be hacky. Right now it's the only thing that requires non-standard test functions and I'm trying to augment the existing unit testing features of D instead of replacing them.Do you have a slightly more extended example that shows how this is used?
Mar 10 2016
On 2016-03-10 12:05, Atila Neves wrote:No, sorry. I haven't needed it yet. Something like this?Yes.Types!(int, string) void testArray(T)() { import std.container; auto arr = Array!T(); arr.empty.shouldBeTrue; arr.insertBack(T.init); arr.empty.shouldBeFalse; auto l = arr.length; l.shouldEqual(1); }I'm trying to think how this would be useful. Would you want to test with different values than T.init? Or is there some library that can generate random values based on a type? What about user defined types? T.init my not be useful at all. I don't want to sound negative but I'm trying to see the use cases. -- /Jacob Carlborg
Mar 11 2016
On Friday, 11 March 2016 at 08:06:19 UTC, Jacob Carlborg wrote:On 2016-03-10 12:05, Atila Neves wrote:There's this: https://github.com/mcandre/dashcheck Didn't Robert have a QuickCheck-alike as well? Like I said, I'm not sure of the use cases, but I thought I'd enable it and it was fun to do. I know I've written template unit tests in C++ in the past, but I can't remember why. AtilaNo, sorry. I haven't needed it yet. Something like this?Yes.Types!(int, string) void testArray(T)() { import std.container; auto arr = Array!T(); arr.empty.shouldBeTrue; arr.insertBack(T.init); arr.empty.shouldBeFalse; auto l = arr.length; l.shouldEqual(1); }I'm trying to think how this would be useful. Would you want to test with different values than T.init? Or is there some library that can generate random values based on a type? What about user defined types? T.init my not be useful at all. I don't want to sound negative but I'm trying to see the use cases.
Mar 11 2016
On Friday, 11 March 2016 at 14:26:34 UTC, Atila Neves wrote:Didn't Robert have a QuickCheck-alike as well?Yes, https://github.com/D-Programming-Language/phobos/pull/2995
Mar 11 2016
On Wednesday, 9 March 2016 at 18:01:49 UTC, Atila Neves wrote:Types!(int, byte) void testInit(T)() { assert(T.init == 0); } AtilaIt is not clear that this UDA is about unittesting
Mar 10 2016
On Thursday, 10 March 2016 at 09:33:39 UTC, Iakh wrote:On Wednesday, 9 March 2016 at 18:01:49 UTC, Atila Neves wrote:Even when attached to a test function? AtilaTypes!(int, byte) void testInit(T)() { assert(T.init == 0); } AtilaIt is not clear that this UDA is about unittesting
Mar 10 2016
On Wednesday, 9 March 2016 at 18:01:49 UTC, Atila Neves wrote:The forum must be sick of hearing from me... :PI'm always excited for a new release of unit-threaded
Mar 10 2016
On Thursday, 10 March 2016 at 16:06:38 UTC, Meta wrote:On Wednesday, 9 March 2016 at 18:01:49 UTC, Atila Neves wrote:Thanks for the kind words! AtilaThe forum must be sick of hearing from me... :PI'm always excited for a new release of unit-threaded
Mar 10 2016