https://github.com/google/googletest
brew install googletest
build from source
-
first, do some modification...
- CMakeList.txt, line:127, add quotes around the $(GOOGLETEST_VERSION} variable.
set_target_properties(gtest PROPERTIES VERSION "${GOOGLETEST_VERSION}") cxx_library(gtest_main "${cxx_strict}" src/gtest_main.cc) set_target_properties(gtest_main PROPERTIES VERSION "${GOOGLETEST_VERSION}")
-
build
cd googletest mkdir build cd build cmake .. make
$ brew --prefix googletest
/usr/local/opt/googletest
- include
/usr/local/opt/googletest/include/gtest
- lib
/usr/local/opt/googletest/lib/
include / lib from source
- include
build/../include/gtest/
- lib
build/lib/
copy to /usr/local/
cp -a ../include/gtest /usr/local/include
mkdir /usr/local/lib/gtest
cp -a lib/*.a /usr/local/lib/gtest
to check
ls /usr/local/include/gtest/
gtest-assertion-result.h gtest-message.h...
ls /usr/local/lib/gtest
libgtest.a libgtest_main.a
#include <gtest/gtest.h>
int main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
$ c++ -std=c++17 -lgtest -lgtest_main ./*.cpp && ./a.out
[==========] Running 0 tests from 0 test suites.
[==========] 0 tests from 0 test suites ran. (0 ms total)
[ PASSED ] 0 tests.
TEST(TestName, Subtest_1) {
ASSERT_TRUE(1 == 1);
}
int main(...)
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from TestName
[ RUN ] TestName.Subtest_1
[ OK ] TestName.Subtest_1 (0 ms)
[----------] 1 test from TestName (0 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (0 ms total)
[ PASSED ] 1 test.
- Success
- Non-Fatal-Failure
EXPECT_EQ()
EXPECT_NE()
EXPECT_LT()
EXPECT_LE()
- ...
- Fatal-Failure
ASSERT_EQ()
- ...