Boost logo

Boost :

Subject: Re: [boost] [test] Interest in 'hamcrest'-style checks?
From: Richard (legalize+jeeves_at_[hidden])
Date: 2013-12-29 03:04:44


[Please do not mail me a copy of your followup]

boost_at_[hidden] spake the secret code
<A266F076-5C34-4A6C-8686-B8CE83318ECA_at_[hidden]> thusly:

>I recently read "Modern C++ Programming with Test-Driven Development",
>and I really enjoyed this book and highly recommend it.

I didn't know about this book until you posted this thread. I bought
it and read it and loved it!

>One of the
>styles I saw for the first time was "hamcrest"-style assertions.
>("Hamcrest" is an anagram of "matchers"; also see
>http://en.wikipedia.org/wiki/Hamcrest.)

This is something that I don't think really buys us much in C++. The
reason I say this is because in C++ we can take a macro argument and
turn it into a string in order to produce a diagnostic message for the
assert -- which Boost.Test does already.

In Java, you have no preprocessor and no way to do this, so Hamcrest
style matchers are the way that they get the extra detail into the
assertion messages.

Combine this ability of the preprocessor to take arbitrary program
source text and turn it into a string and introduce a set of useful
predicates for things like checking if a string starts with a prefix
and you find the need for Hamcrest style matchers pretty much
disappears.

Without the ability to turn source text into a string, the case for
Hamcrest style matchers would increase dramatically. One area where I
see Hamcrest style matchers being useful is in configuring mock
objects. Having used jMock for Java and Turtle for Boost.Test/C++ I
think both of them read fairly similar.

-- 
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
     The Computer Graphics Museum <http://computergraphicsmuseum.org>
         The Terminals Wiki <http://terminals.classiccmp.org>
  Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk