Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Unit testing of C source code

by theorbtwo (Prior)
on Sep 28, 2007 at 11:04 UTC ( #641507=note: print w/replies, xml ) Need Help??

in reply to Unit testing of C source code

Perl's testing framework doesn't actually require in any way that the thing being tested is perl. There's a reasonably well-defined protocol that governs what the test outputs, all you need is some code to output that, and it doesn't matter the code that outputs it is perl, C, python, or brainf*ck. There's a fairly good article on the Test Anything Protocol on WP, or just run any existing test with perl -Mblib t/ and observe what it outputs.

Warning: Do not use without understanding. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).

Replies are listed 'Best First'.
Re^2: Unit testing of C source code
by lima1 (Curate) on Sep 28, 2007 at 13:17 UTC
    Yeah, but it is also quite easy to implement a Test::More like testsuite in C with libtab ( This library is pretty small, so you can ship it with your program. I just added a 't' directory in my autoconf based project and put the libtab header and sources there. Tests look pretty much the same as in Perl:
    # t/simple_tests.c #include <stdio.h> #include "tap.h" #include "something.h" int main(void) { plan_tests(1); /* * A simple example of a test. */ ok(1 + 1 == 2, "Basic arithmetic works"); return exit_status(); /* Return the correct exit code */ }
    A simple t/ could look like this:
    # binaries check_PROGRAMS = simple_tests simple_tests_SOURCES = simple_tests.c tap.c ../src/something.c\ tap.h ../src/something.h simple_tests_CFLAGS = -Wall --pedantic -std=c99 -I ../src TESTS = simple_tests
    Then add 't' in your main
    SUBDIRS = src t
    Then you can run the tests with 'make check'.
Re^2: Unit testing of C source code
by perlfan (Vicar) on Sep 28, 2007 at 14:30 UTC
    After learning the wonders of creating a CPAN module package, I'd highly consider using it to manage the building and testing of even non-Perl projects. I have not had to do this yet, but when I do it will be the first thing I try for sure.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://641507]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (1)
As of 2023-06-03 18:08 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (16 votes). Check out past polls.