How do C programmers do unit testing?

This may seem like a silly question, but how do C programmers (assume
gcc/linux for now) do behavior-driven/test-driven development? Aside
from the obvious cheat (using RSpec to compile, link and execute the C
code) are there tools in C to do this?

On Feb 12, 2008 10:55 AM, M. Edward (Ed) Borasky [email protected]
wrote:

This may seem like a silly question, but how do C programmers (assume
gcc/linux for now) do behavior-driven/test-driven development? Aside
from the obvious cheat (using RSpec to compile, link and execute the C
code) are there tools in C to do this?

I use boost::test since boost is a standard linux install package.
boost
has a bunch of great things to complement stl.

On Feb 12, 2008 11:55 AM, M. Edward (Ed) Borasky [email protected]
wrote:

This may seem like a silly question, but how do C programmers (assume
gcc/linux for now) do behavior-driven/test-driven development? Aside
from the obvious cheat (using RSpec to compile, link and execute the C
code) are there tools in C to do this?

I’ve gotten into the habit of writing wrapper libraries around C code
and
unit-testing them with Ruby.

On Feb 12, 2008, at 9:55 AM, M. Edward (Ed) Borasky wrote:

This may seem like a silly question, but how do C programmers
(assume gcc/linux for now) do behavior-driven/test-driven
development? Aside from the obvious cheat (using RSpec to compile,
link and execute the C code) are there tools in C to do this?

CUnit and CppUnit are the two biggies I remember from the old days.
Just a re-implementation of Kent Beck’s unit testing pattern in C and C
++ respectively. JUnit was the one that first made unit testing fun
and popular. Everyone else has pretty much cloned what was done there.

RSpec has been a breath of fresh air. Thanks, Ed :slight_smile:

Blessings,
TwP

http://cunit.sourceforge.net/
http://cppunit.sourceforge.net/

On Feb 12, 12:12 pm, Eric M. [email protected] wrote:

has a bunch of great things to complement stl.
I use a nice little package called CuTest.

On Feb 12, 2008 6:12 PM, Eric M. [email protected] wrote:

has a bunch of great things to complement stl.
I second this - I have used CxxTest in my Symbian days, then used it a
bit on windows,
and now we are using boost::test. So far it’s good, but the test I
have are quite small.

On Feb 12, 2008 10:55 AM, M. Edward (Ed) Borasky [email protected]
wrote:

This may seem like a silly question, but how do C programmers (assume
gcc/linux for now) do behavior-driven/test-driven development? Aside
from the obvious cheat (using RSpec to compile, link and execute the C
code) are there tools in C to do this?

I blogged about the “obvious cheat” recently. It’s an “automate-able”
way to
expose C and C++ to Ruby, and hence RSpec, using SWIG. (That is, it
could be
automated and I hope to do that eventually).
http://blog.objectmentor.com/articles/2008/02/04/unit-testing-c-and-c-with-ruby-and-rspec

It should work pretty well right now for C. There are some issues still
with
C++.

Dean W.
http://www.objectmentor.com
http://www.aspectprogramming.com
http://aquarium.rubyforge.org
http://www.contract4j.org

On Feb 12, 2008, at 9:55 AM, M. Edward (Ed) Borasky wrote:

This may seem like a silly question, but how do C programmers
(assume gcc/linux for now) do behavior-driven/test-driven
development? Aside from the obvious cheat (using RSpec to compile,
link and execute the C code) are there tools in C to do this?

i used this long ago

http://cunit.sourceforge.net/

a @ http://drawohara.com/

On 12 Feb 2008, at 16:55, M. Edward (Ed) Borasky wrote:

This may seem like a silly question, but how do C programmers
(assume gcc/linux for now) do behavior-driven/test-driven
development? Aside from the obvious cheat (using RSpec to compile,
link and execute the C code) are there tools in C to do this?

Yup. A whole bunch. There was a recent thread on the XP list that
covered many options. See http://tinyurl.com/24dn89

Cheers,

Adrian

On Feb 13, 2008 12:55 AM, M. Edward (Ed) Borasky [email protected]
wrote:

This may seem like a silly question, but how do C programmers (assume
gcc/linux for now) do behavior-driven/test-driven development? Aside
from the obvious cheat (using RSpec to compile, link and execute the C
code) are there tools in C to do this?

On Wed, Feb 13, 2008 at 01:55:33AM +0900, M. Edward (Ed) Borasky wrote:

This may seem like a silly question, but how do C programmers (assume
gcc/linux for now) do behavior-driven/test-driven development? Aside
from the obvious cheat (using RSpec to compile, link and execute the C
code) are there tools in C to do this?

I’ve tried a bunch of the unit test frameworks for C++ but never liked
any of them, so I rolled my own. A test suite is in its own file and
looks like this:

TESTSUITE(MyTestSuite)

SETUP(MyTestSuite)
{
// put code here
}

TEARDOWN(MyTestSuite)
{
// put code here
}

TESTCASE(test_name)
{
ASSERT_EQUAL(true, true);
}

Though there’s a lot that this model can’t do (e.g. there’s no
inheritance relationship between test suites), a big advantage here is
that you don’t have to specify the test case names in two places as with
most other frameworks (once for the function definition and again to add
the function to the test suite). I’d worry that I’m reinventing the
wheel, except it only took an hour or so to implement.

It’s included as part of Rice (rice.rubyforge.org).

Paul

On 2008-02-12, M. Edward (Ed) Borasky [email protected] wrote:

This may seem like a silly question, but how do C programmers (assume
gcc/linux for now) do behavior-driven/test-driven development? Aside
from the obvious cheat (using RSpec to compile, link and execute the C
code) are there tools in C to do this?

http://chneukirchen.org/repos/taptap/include/taptap.h

#include “taptap.h”
int
main()
{
plan (11);

ok(1 == 1);
ok(1 == 1, “one equals one”);

ok(1 == 2);
ok(1 == 2, “one equals two”);

is(1, 1);
is(1, 1, “one equals one”);

is(1, 2);
is(1, 2, “one equals two”);

fail(“foo”);
pass(“yay”);
pass(“yum”);

fail();
pass();

bail_out (“g’dammnit.”);

fail(“you should not see this”);

return taptap_summary();
}

$ taptap test-taptap
test-taptap… 3/11 FAILED: test/test-taptap.c:11: 1 == 2 failed
test-taptap… 4/11 FAILED: test/test-taptap.c:12: 1 == 2 failed -
one equals two
test-taptap… 7/11 FAILED: test/test-taptap.c:17: 1(1, 0x1) != 2
test-taptap… 8/11 FAILED: test/test-taptap.c:18: 1(1, 0x1) != 2 -
one equals two
test-taptap… 9/11 FAILED: test/test-taptap.c:20 - foo
test-taptap… 12/11 FAILED: test/test-taptap.c:24
BAIL OUT: g’dammnit.3/11 PASS:

test-taptap:
Tests took 0.03 seconds.
FAILED tests 3, 4, 7, 8, 9, 12
3) test/test-taptap.c:11: 1 == 2 failed
4) test/test-taptap.c:12: 1 == 2 failed - one equals two
7) test/test-taptap.c:17: 1(1, 0x1) != 2
8) test/test-taptap.c:18: 1(1, 0x1) != 2 - one equals two
9) test/test-taptap.c:20 - foo
12) test/test-taptap.c:24

Failed 6/13 tests, 53.85% okay.
WEIRD: Planned 11 tests, but ran 13.
BAILED OUT: g’dammnit.

Hi,

On Wed, Feb 27, 2008 at 12:09 AM, Christian N. <
[email protected]> wrote:

http://chneukirchen.org/repos/taptap/include/taptap.h

Very useful. Thanks :slight_smile:

Arlen