Skip to content
The autotools-unittest is a minimal starter kit when writing C++ library with autotools, google test and google mock.
C++ Shell
Find file
Latest commit 55e0c91 Feb 17, 2016 Eiichiro Iwata Fixed download link in README again

README.md

autotools-unittest

The autotools-unittest is a minimal starter kit when writing C++ library with autotools, google test(gtest) and google mock(gmock). This include gtest-1.7.0 and gmock-1.7.0, so you can use those testing framework without installation.

Requirements

  • Autoconf
  • Automake
  • Libtool

Example

0. Download and extract

$ wget "https://github.com/eiichiroi/autotools-unittest/archive/v0.4.0.tar.gz"
$ tar xzf autotools-unittest-0.4.0.tar.gz

1. Change library name

Change package name from 'autotools-unittest' to your library name. (ex. mylib)

$ mv autotools-unittest-0.4.0 mylib
$ cd mylib
$ ./scripts/change_package_name.sh mylib
===========================================================================

* ./configure.ac
* ./Makefile.am
* ./src/autotools-unittest/sample.cpp
* ./src/autotools-unittest/sample.h
* ./test/sample_test.cpp
* ./autotools-unittest.pc.in
* ./src/autotools-unittest

These files will be changed. Are you sure? [yes/NO]: yes

* ./configure.ac ... done.
* ./Makefile.am ... done.
* ./src/autotools-unittest/sample.cpp ... done.
* ./src/autotools-unittest/sample.h ... done.
* ./test/sample_test.cpp ... done.
* ./autotools-unittest.pc.in ... done.
* ./src/autotools-unittest ... done.

2. Build sample codes

$ ./autogen.sh
$ ./configure
$ make

3. Build unit tests and run

$ make check

4. Write your library

Tips

Check Coding style

You can use coding style checker(cpplint) if python is installed in your environment.

$ make check-style

If you would like to check coding style with cpplint's options, please use CPPLINT_OPTIONS variables like this.

$ make check-style CPPLINT_OPTIONS="--verbose=4"

Use advanced gtest options

You can use advanced gtest options via environment variables(GTEST_xxx).

For example, you can filter test cases as follows.

$ GTEST_FILTER="square.*" make check

For more information about advanced options, please see the following page.

http://code.google.com/p/googletest/wiki/V1_7_AdvancedGuide#Running_Test_Programs:_Advanced_Options

Report coverage

You can use coverage reporting feature if lcov is installed in your environment.

$ make coverage
...
Successfully created coverage reports into ./coverage directory.

Please check "./coverage/index.html".

By default, source codes will be complied with no-optimization(-O0 option) to get more precise results.

If you would like to get coverage reports with optimization, please use COVERAGE_OPTFLAGS variables like this.

$ make coverage COVERAGE_OPTFLAGS="-O2"

Please take care that coverage reports with optimization results in unexpected one.

Build with clang or new gcc

Execute configure with CC, CXX variables (and GCOV if you measure coverage.)

For clang:

$ ./configure CC="clang" CXX="clang++" GCOV="gcov"

For gcc 5:

$ ./configure CC="gcc-5" CXX="g++-5" GCOV="gcov-5"

Not compile with C++11 mode

Edit configure.ac and comment the following line. (Disable AX_CXX_COMPILE_STDCXX_11)

# Check for C++11 supports
#   ext: use extended mode (e.g. -std=gnu++11)
#   noext: use non-extended mode (e.g. -std=c++11)
# AX_CXX_COMPILE_STDCXX_11([noext])

And then, try again from executing autogen.sh.

$ ./autogen.sh && ./configure && make && make check

You can remove m4/ax_cxx_compile_stdcxx_11.m4. Please take care that "make dist" don't bundle not used m4 file.

Use pkg-config

Please do not forget to edit autotools-unittest.pc.in (mylib.pc.in) if you provide shared libraries. (By default, link libsample)

Libs: -L${libdir} -lsample
Something went wrong with that request. Please try again.