Page 1 of 1

C unit tester

Posted: Tue Nov 07, 2006 5:32 am
by lastcraft
Hi.

I doubt if C coding gets a big following here, but this should at least explain why SimpleTest got a little stalled ;).

I wrote a pure C (actually C99) unit tester with mocks called Cgreen. It's at...
http://www.lastcraft.com/cgreen.php
http://sourceforge.net/projects/cgreen/

It means you can now do stuff like...

Code: Select all

static void drops_line_ending_from_word_and_stops() {
    will_return(stub_stream, 't');
    will_return(stub_stream, 'h');
    will_return(stub_stream, 'e');
    will_return(stub_stream, '\n');
    assert_string_equal(read_paragraph(&stub_stream, NULL), "the");
}
Here we are testing read_paragraph() with a mock function called stub_stream().

The Cgreen unit tester has the usual bunch of assertions, expectations and reporting options. Also, if you are running more than one test (the norm), each runs in a separate process. Wouldn't want seg faults stopping the test run.

yours, Marcus

Posted: Tue Nov 07, 2006 7:46 am
by feyd
Cool stuff Marcus, too bad I don't do C anymore. :D

Posted: Tue Nov 07, 2006 9:59 am
by Ambush Commander
Really cool. But perhaps we're not the target demographic. ;-)

Posted: Mon Nov 20, 2006 8:27 pm
by lastcraft
Hi...
Ambush Commander wrote:Really cool. But perhaps we're not the target demographic. ;-)
Yeah I know, but I had no one else to tell :cry:.

yours, Marcus

Posted: Mon Nov 20, 2006 8:40 pm
by Ambush Commander
Hmm... where to get the word out...

You could try some newsgroups on C as well as on unit-testing...

Posted: Sun Dec 17, 2006 10:19 pm
by lastcraft
Hi.

Just to say, released a new version with a different mock syntax...

Code: Select all

int my_callback(int i, char *s) {
    return (int)mock(i, s);
}
In the test you can set up an expectation like so...

Code: Select all

expect(my_callback, want(i, 7), want_string(s, "Hello"));
My last unprompted post here about Cgreen, I promise.

yours, Marcus