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.8.0 and gmock-1.8.0, so you can use those testing framework without installation.
- Autoconf
- Automake
- Libtool
$ wget "https://github.com/eiichiroi/autotools-unittest/archive/v0.4.0.tar.gz"
$ tar xzf autotools-unittest-0.4.0.tar.gz
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.
$ ./autogen.sh
$ ./configure
$ make
$ make check
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"
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.
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.
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"
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.
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