How do you create tests for “make check” with GNU autotools

后端 未结 5 1416
情歌与酒
情歌与酒 2021-02-01 16:03

I\'m using GNU autotools for the build system on a particular project. I want to start writing automated tests for verifcation. I would like to just type \"make check\" to have

5条回答
  •  悲哀的现实
    2021-02-01 16:42

    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.

提交回复
热议问题