Skip to content

Build2 package containing Google Test and Google Mock libraries.

License

Notifications You must be signed in to change notification settings

r-sitko/googletest-build2

Repository files navigation

Google Test and Google Mock build2 package

Description

Build2 package containing Google Test and Google Mock static libraries.

Products of this package are following static libraries:

  • gtest static library without main function
  • gtest_main static library with main function
  • gmock static library (contains also gtest) without main function
  • gmock_main static library (contains also gtest) with main function

Cloning repository

git clone --recursive https://github.com/rsitko92/googletest-build2.git

Prerequisites

Running package tests

Being in root directory of project run:

  • using g++:

    bdep init -C @gcc cc config.cxx=g++
    b test
  • using clang++:

    bdep init -C @clang cc config.cxx=clang++
    b test

Using libgtest package in project with build2 build toolchain

  1. Add libgtest package dependency to manifest file:

    depends: * libgtest >= 0.1.0
  2. Add libgtest package repository to repositories.manifest file:

    :
    role: prerequisite
    location: https://github.com/rsitko92/googletest-build2.git#master
  3. Import one of the below libraries in buildfile of target application:

    • gtest without main function:

      import libs += libgtest%liba{googletest/googletest/gtest}
    • gtest with main function:

      import libs += libgtest%liba{googletest/googletest/gtest_main}
    • gmock (contains also gtest) without main function:

      import libs += libgtest%liba{googletest/googlemock/gmock}
    • gmock (contains also gtest) with main function:

      import libs += libgtest%liba{googletest/googlemock/gmock_main}
  4. Link one of the choosen libgtest static library in libs variable with target:

    Example linking to hello executable target:

    exe{hello}: {hxx ixx txx cxx}{**} $libs
  5. Add appropriate include statement(s) in source/header files:

    • Google Test:

      #include <gtest/gtest.h>
    • Google Mock:

      #include <gmock/gmock.h>