How do you create tests for "make check" with GNU autotools

I'm using Check 0.9.10

    configure.ac
    Makefile.am
    src/Makefile.am
    src/foo.c
    tests/check_foo.c
    tests/Makefile.am
  1. ./configure.ac

    PKG_CHECK_MODULES([CHECK], [check >= 0.9.10])

  2. ./tests/Makefile.am for test codes

    TESTS = check_foo
    check_PROGRAMS = check_foo
    check_foo_SOURCES = check_foo.c $(top_builddir)/src/foo.h
    check_foo_CFLAGS = @CHECK_CFLAGS@
    
  3. and write test code, ./tests/check_foo.c

    START_TEST (test_foo)
    {
        ck_assert( foo() == 0 );
        ck_assert_int_eq( foo(), 0);
    }
    END_TEST
    
    /// And there are some tcase_xxx codes to run this test
    

Using check you can use timeout and raise signal. it is very helpful.


To make test run when you issue make check, you need to add them to the TESTS variable

Assuming you've already built the executable that runs the unit tests, you just add the name of the executable to the TESTS variable like this:

TESTS=my-test-executable

It should then be automatically run when you make check, and if the executable returns a non-zero value, it will report that as a test failure. If you have multiple unit test executables, just list them all in the TESTS variable:

TESTS=my-first-test my-second-test my-third-test

and they will all get run.