www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - specd - write more expressive unit tests

reply "jostly" <johan.f.ostling gmail.com> writes:
specd is a DSL library allowing you to write more expressive unit 
tests. It is inspired by projects like specs2 and ScalaTest from 
the Scala world.

Example:

     unittest {
         describe("a string")
             .should("have a length property", 
"foo".length.must.equal(3));
     }

Features:
* DSL for expressing unit tests as specifications
* Verify with "must" instead of assert
* Report successful / failed tests using green / red paradigm

Available as a dub dependency ("specd") or from 
https://github.com/jostly/specd

Comments and suggestions for improvement are welcome!

//Johan
Sep 02 2013
next sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2013-09-02 21:03, jostly wrote:
 specd is a DSL library allowing you to write more expressive unit tests.
 It is inspired by projects like specs2 and ScalaTest from the Scala world.

 Example:

      unittest {
          describe("a string")
              .should("have a length property", "foo".length.must.equal(3));
      }

 Features:
 * DSL for expressing unit tests as specifications
 * Verify with "must" instead of assert
 * Report successful / failed tests using green / red paradigm

 Available as a dub dependency ("specd") or from
 https://github.com/jostly/specd

 Comments and suggestions for improvement are welcome!
I've been working on something similar myself. https://github.com/jacob-carlborg/dspec I'm working on a new syntax using UDA's, shown here: https://github.com/jacob-carlborg/phobos/blob/serialization/std/serialization/tests/array.d -- /Jacob Carlborg
Sep 02 2013
parent reply "jostly" <johan.f.ostling gmail.com> writes:
On Tuesday, 3 September 2013 at 06:36:20 UTC, Jacob Carlborg 
wrote:
 On 2013-09-02 21:03, jostly wrote:
 specd is a DSL library allowing you to write more expressive 
 unit tests.
 It is inspired by projects like specs2 and ScalaTest from the 
 Scala world.

 Example:

     unittest {
         describe("a string")
             .should("have a length property", 
 "foo".length.must.equal(3));
     }

 Features:
 * DSL for expressing unit tests as specifications
 * Verify with "must" instead of assert
 * Report successful / failed tests using green / red paradigm

 Available as a dub dependency ("specd") or from
 https://github.com/jostly/specd

 Comments and suggestions for improvement are welcome!
I've been working on something similar myself. https://github.com/jacob-carlborg/dspec
Narrowly avoided nameclash there. :) Good to see others thinking along the same lines.
 I'm working on a new syntax using UDA's, shown here:

 https://github.com/jacob-carlborg/phobos/blob/serialization/std/serialization/tests/array.d
Looks interesting. I hadn't heard of the UDA's before, they seem quite powerful from a brief glance.
Sep 04 2013
parent Jacob Carlborg <doob me.com> writes:
On 2013-09-04 19:38, jostly wrote:

 Looks interesting. I hadn't heard of the UDA's before, they seem quite
 powerful from a brief glance.
Very simple but very powerful. It's basically way to tag symbols with values/types. -- /Jacob Carlborg
Sep 04 2013
prev sibling parent reply "linkrope" <linkrope github.com> writes:
It would be nice to have something like

     result.must.not.be!">"(42);

So, have a look at 'assertOp':
http://d.puremagic.com/issues/show_bug.cgi?id=4653

How can a user of your code add matchers, for example, to check 
for elements or attributes in XML? (Without having to change your 
code.) The hidden 'MatchStatement' makes the code easy to use but 
seems to make it hard to extend. You could add a second 
('matcher') parameter to 'must', but then you have to switch from 
'.' to '('...')':

     result.must(haveTag("root"));

By the way: Does the color output work on Windows?
Here is what I do to color the unit-test results:
https://github.com/linkrope/dunit/blob/master/dunit/color.d
Sep 04 2013
parent "jostly" <johan.f.ostling gmail.com> writes:
On Wednesday, 4 September 2013 at 11:06:45 UTC, linkrope wrote:
 It would be nice to have something like

     result.must.not.be!">"(42);

 So, have a look at 'assertOp':
 http://d.puremagic.com/issues/show_bug.cgi?id=4653

 How can a user of your code add matchers, for example, to check 
 for elements or attributes in XML? (Without having to change 
 your code.) The hidden 'MatchStatement' makes the code easy to 
 use but seems to make it hard to extend. You could add a second 
 ('matcher') parameter to 'must', but then you have to switch 
 from '.' to '('...')':

     result.must(haveTag("root"));

 By the way: Does the color output work on Windows?
 Here is what I do to color the unit-test results:
 https://github.com/linkrope/dunit/blob/master/dunit/color.d
Thanks for the feedback and the pointers - I think they're all good ideas. I'll look into making the necessary adjustments.
Sep 04 2013