Permalink
Browse files

Added googletest

Roughly based on this:
https://stackoverflow.com/questions/35998856/how-can-i-use-google-test-with-my-project-that-builds-via-autotools/36000856#36000856

This integrates googletest/gtest with the regular autotools "make check"
system. googletest then puts nicer output in test-suite.log than we
would normally get there.

This is not particularly useful in this project because so many of the
tests are actually compile-time tests with static_assert().
  • Loading branch information...
murraycu committed Sep 23, 2016
1 parent dfa8a2c commit 88b38c9b68aaf6d287cd27cf15b352337ff5bc85
View
@@ -0,0 +1,3 @@
[submodule "googletest"]
path = googletest
url = git@github.com:google/googletest.git
View
@@ -19,11 +19,9 @@ SUBDIRS = $(doc_subdirs)
pkgconfigdir = $(libdir)/pkgconfig pkgconfigdir = $(libdir)/pkgconfig
nodist_pkgconfig_DATA = $(MURRAYC_TUPLE_UTILS_MODULE_NAME).pc nodist_pkgconfig_DATA = $(MURRAYC_TUPLE_UTILS_MODULE_NAME).pc
AM_CPPFLAGS = -I$(top_builddir) -I$(top_srcdir) AM_CPPFLAGS = -I$(top_builddir) -I$(top_srcdir) -I$(top_srcdir)/googletest/googletest/include
AM_CXXFLAGS = $(PROJECT_WXXFLAGS) AM_CXXFLAGS = $(PROJECT_WXXFLAGS)
# TODO: Why do we still need to specify this for each executable that we build?
COMMON_CXXFLAGS = $(PROJECT_CFLAGS) $(PROJECT_WXXFLAGS) $(BOOST_CPPFLAGS)
include $(top_srcdir)/tuple-utils/filelist.am include $(top_srcdir)/tuple-utils/filelist.am
@@ -35,6 +33,16 @@ libmurrayc_tuple_utils_@MURRAYC_TUPLE_UTILS_API_VERSION@_la_LDFLAGS = -no-undefi
library_includedir = $(includedir)/$(MURRAYC_TUPLE_UTILS_MODULE_NAME) library_includedir = $(includedir)/$(MURRAYC_TUPLE_UTILS_MODULE_NAME)
nobase_library_include_HEADERS = $(h_sources_public) nobase_library_include_HEADERS = $(h_sources_public)
# Build googletest:
check_LTLIBRARIES = libgtest.la
libgtest_la_SOURCES = googletest/googletest/src/gtest-all.cc googletest/googletest/src/gtest_main.cc
libgtest_la_CPPFLAGS = -I$(top_srcdir)/googletest/googletest/include -I$(top_srcdir)/googletest/googletest
libgtest_la_LDFLAGS = -pthread
# TODO: Why do we still need to specify this for each executable that we build?
COMMON_CXXFLAGS = $(PROJECT_CFLAGS) $(PROJECT_WXXFLAGS) $(BOOST_CPPFLAGS)
COMMON_LIBS = $(PROJECT_LIBS) libgtest.la
check_PROGRAMS = \ check_PROGRAMS = \
tests/test_tuple_cat \ tests/test_tuple_cat \
@@ -56,63 +64,63 @@ tests_test_tuple_cat_SOURCES = \
tests_test_tuple_cat_CXXFLAGS = \ tests_test_tuple_cat_CXXFLAGS = \
$(COMMON_CXXFLAGS) $(COMMON_CXXFLAGS)
tests_test_tuple_cat_LDADD = \ tests_test_tuple_cat_LDADD = \
$(PROJECT_LIBS) $(COMMON_LIBS)
tests_test_tuple_cdr_SOURCES = \ tests_test_tuple_cdr_SOURCES = \
tests/test_tuple_cdr.cc tests/test_tuple_cdr.cc
tests_test_tuple_cdr_CXXFLAGS = \ tests_test_tuple_cdr_CXXFLAGS = \
$(COMMON_CXXFLAGS) $(COMMON_CXXFLAGS)
tests_test_tuple_cdr_LDADD = \ tests_test_tuple_cdr_LDADD = \
$(PROJECT_LIBS) $(COMMON_LIBS)
tests_test_tuple_end_SOURCES = \ tests_test_tuple_end_SOURCES = \
tests/test_tuple_end.cc tests/test_tuple_end.cc
tests_test_tuple_end_CXXFLAGS = \ tests_test_tuple_end_CXXFLAGS = \
$(COMMON_CXXFLAGS) $(COMMON_CXXFLAGS)
tests_test_tuple_end_LDADD = \ tests_test_tuple_end_LDADD = \
$(PROJECT_LIBS) $(COMMON_LIBS)
tests_test_tuple_for_each_SOURCES = \ tests_test_tuple_for_each_SOURCES = \
tests/test_tuple_for_each.cc tests/test_tuple_for_each.cc
tests_test_tuple_for_each_CXXFLAGS = \ tests_test_tuple_for_each_CXXFLAGS = \
$(COMMON_CXXFLAGS) $(COMMON_CXXFLAGS)
tests_test_tuple_for_each_LDADD = \ tests_test_tuple_for_each_LDADD = \
$(PROJECT_LIBS) $(COMMON_LIBS)
tests_test_tuple_interlace_SOURCES = \ tests_test_tuple_interlace_SOURCES = \
tests/test_tuple_interlace.cc tests/test_tuple_interlace.cc
tests_test_tuple_interlace_CXXFLAGS = \ tests_test_tuple_interlace_CXXFLAGS = \
$(COMMON_CXXFLAGS) $(COMMON_CXXFLAGS)
tests_test_tuple_interlace_LDADD = \ tests_test_tuple_interlace_LDADD = \
$(PROJECT_LIBS) $(COMMON_LIBS)
tests_test_tuple_print_SOURCES = \ tests_test_tuple_print_SOURCES = \
tests/test_tuple_print.cc tests/test_tuple_print.cc
tests_test_tuple_print_CXXFLAGS = \ tests_test_tuple_print_CXXFLAGS = \
$(COMMON_CXXFLAGS) $(COMMON_CXXFLAGS)
tests_test_tuple_print_LDADD = \ tests_test_tuple_print_LDADD = \
$(PROJECT_LIBS) $(COMMON_LIBS)
tests_test_tuple_start_SOURCES = \ tests_test_tuple_start_SOURCES = \
tests/test_tuple_start.cc tests/test_tuple_start.cc
tests_test_tuple_start_CXXFLAGS = \ tests_test_tuple_start_CXXFLAGS = \
$(COMMON_CXXFLAGS) $(COMMON_CXXFLAGS)
tests_test_tuple_start_LDADD = \ tests_test_tuple_start_LDADD = \
$(PROJECT_LIBS) $(COMMON_LIBS)
tests_test_tuple_subset_SOURCES = \ tests_test_tuple_subset_SOURCES = \
tests/test_tuple_subset.cc tests/test_tuple_subset.cc
tests_test_tuple_subset_CXXFLAGS = \ tests_test_tuple_subset_CXXFLAGS = \
$(COMMON_CXXFLAGS) $(COMMON_CXXFLAGS)
tests_test_tuple_subset_LDADD = \ tests_test_tuple_subset_LDADD = \
$(PROJECT_LIBS) $(COMMON_LIBS)
tests_test_tuple_transform_each_SOURCES = \ tests_test_tuple_transform_each_SOURCES = \
tests/test_tuple_transform_each.cc tests/test_tuple_transform_each.cc
tests_test_tuple_transform_each_CXXFLAGS = \ tests_test_tuple_transform_each_CXXFLAGS = \
$(COMMON_CXXFLAGS) $(COMMON_CXXFLAGS)
tests_test_tuple_transform_each_LDADD = \ tests_test_tuple_transform_each_LDADD = \
$(PROJECT_LIBS) $(COMMON_LIBS)
Submodule googletest added at ecd530
View
@@ -19,9 +19,9 @@
#include <tuple-utils/tuple_cat.h> #include <tuple-utils/tuple_cat.h>
#include <utility> #include <utility>
//#include <functional> //#include <functional>
#include "gtest/gtest.h"
void TEST(TupleCatTest, Simple) {
test_tuple_type_cat() {
using type_tuple_is = std::tuple<int, short>; using type_tuple_is = std::tuple<int, short>;
using type_tuple_dc = std::tuple<double, char>; using type_tuple_dc = std::tuple<double, char>;
using type_tuple_cat = using type_tuple_cat =
@@ -36,8 +36,7 @@ test_tuple_type_cat() {
/** We don't want to test std::tuple_cat() here, /** We don't want to test std::tuple_cat() here,
* but this a demonstration that std::ref() works with std::tuple_cat(). * but this a demonstration that std::ref() works with std::tuple_cat().
void TEST(TupleCatText, StdRef) {
test_tuple_cat_stdref() {
std::string a = "yadda1"; std::string a = "yadda1";
std::string b = "yaddayadda1"; std::string b = "yaddayadda1";
auto t_one = auto t_one =
@@ -52,20 +51,10 @@ test_tuple_cat_stdref() {
c = 3; c = 3;
d = 'b'; d = 'b';
assert(std::get<0>(t_both) == "hello"); EXPECT_EQ("hello", std::get<0>(t_both));
assert(std::get<1>(t_both) == "world"); EXPECT_EQ("world", std::get<1>(t_both));
assert(std::get<2>(t_both) == 3); EXPECT_EQ(3, std::get<2>(t_both));
assert(std::get<3>(t_both) == 'b'); EXPECT_EQ('b', std::get<3>(t_both));
} }
*/ */
int
main() {
test_tuple_type_cat();
// There is no typeutils::tuple_cat() because std::tuple_cat() exists:
// test_tuple_cat();
//test_tuple_cat_stdref();
return EXIT_SUCCESS;
}
View
@@ -19,37 +19,37 @@
#include <tuple-utils/tuple_cdr.h> #include <tuple-utils/tuple_cdr.h>
#include <utility> #include <utility>
#include <functional> #include <functional>
#include "gtest/gtest.h"
void TEST(TestTupleCdr, Type) {
test_tuple_type_cdr() {
using type_tuple_isd = std::tuple<int, short, double>; using type_tuple_isd = std::tuple<int, short, double>;
using type_tuple_sd = std::tuple<short, double>; using type_tuple_sd = std::tuple<short, double>;
using type_tuple_suffix = tupleutils::tuple_type_cdr<type_tuple_isd>::type; using type_tuple_suffix = tupleutils::tuple_type_cdr<type_tuple_isd>::type;
static_assert(std::tuple_size<type_tuple_suffix>::value == 2, static_assert(std::tuple_size<type_tuple_suffix>::value == 2,
"unexpected tuple_cdr()ed tuple size."); "unexpected tuple_cdr()ed tuple size.");
static_assert(std::is_same<type_tuple_suffix, type_tuple_sd>::value, static_assert(std::is_same<type_tuple_suffix, type_tuple_sd>::value,
"unexpected tuple_cdr()ed tuple type"); "unexpected tuple_cdr()ed tuple type");
} }
void TEST(TestTupleCdr, Simple) {
test_tuple_cdr() {
auto t_larger = auto t_larger =
std::make_tuple(nullptr, std::string("hello"), std::string("world")); std::make_tuple(nullptr, std::string("hello"), std::string("world"));
auto t_suffix = tupleutils::tuple_cdr(t_larger); auto t_suffix = tupleutils::tuple_cdr(t_larger);
assert(std::get<0>(t_suffix) == "hello"); EXPECT_EQ("hello", std::get<0>(t_suffix));
assert(std::get<1>(t_suffix) == "world"); EXPECT_EQ("world", std::get<1>(t_suffix));
using type_tuple_suffix = std::tuple<std::string, std::string>; using type_tuple_suffix = std::tuple<std::string, std::string>;
static_assert(std::tuple_size<decltype(t_suffix)>::value == 2, static_assert(std::tuple_size<decltype(t_suffix)>::value == 2,
"unexpected cdr()ed tuple size."); "unexpected cdr()ed tuple size.");
static_assert(std::is_same<decltype(t_suffix), type_tuple_suffix>::value, static_assert(std::is_same<decltype(t_suffix), type_tuple_suffix>::value,
"unexpected cdr()ed tuple type"); "unexpected cdr()ed tuple type");
} }
void TEST(TestTupleCdr, StdRef) {
test_tuple_cdr_stdref() {
std::string b = "yadda"; std::string b = "yadda";
std::string c = "yaddayadda"; std::string c = "yaddayadda";
auto t_larger = std::make_tuple(1, std::ref(b), std::ref(c)); auto t_larger = std::make_tuple(1, std::ref(b), std::ref(c));
@@ -62,13 +62,13 @@ test_tuple_cdr_stdref() {
//This works, but it's not what we are testing here: //This works, but it's not what we are testing here:
//assert(std::get<1>(t_larger) == "hello"); //assert(std::get<1>(t_larger) == "hello");
assert(std::get<0>(t_suffix) == "hello"); EXPECT_EQ("hello", std::get<0>(t_suffix));
assert(std::get<1>(t_suffix) == "world"); EXPECT_EQ("world", std::get<1>(t_suffix));
} }
constexpr // TODO: Does this test function itself need to be constexpr,
void // and if so, how can we do that with googletest?
test_tuple_cdr_constexpr() { TEST(TestTupleCdr, ConstExpr) {
constexpr auto str_hello = "hello"; constexpr auto str_hello = "hello";
constexpr auto str_world = "world"; constexpr auto str_world = "world";
@@ -77,17 +77,8 @@ test_tuple_cdr_constexpr() {
constexpr auto t_suffix = tupleutils::tuple_cdr(t_larger); constexpr auto t_suffix = tupleutils::tuple_cdr(t_larger);
static_assert(std::get<0>(t_suffix) == str_hello, static_assert(std::get<0>(t_suffix) == str_hello,
"unexpected tuple element value."); "unexpected tuple element value.");
static_assert(std::get<1>(t_suffix) == str_world, static_assert(std::get<1>(t_suffix) == str_world,
"unexpected tuple element value."); "unexpected tuple element value.");
} }
int
main() {
test_tuple_type_cdr();
test_tuple_cdr();
test_tuple_cdr_stdref();
test_tuple_cdr_constexpr();
return EXIT_SUCCESS;
}
View
@@ -18,9 +18,9 @@
#include <cstdlib> #include <cstdlib>
#include <tuple-utils/tuple_end.h> #include <tuple-utils/tuple_end.h>
#include <functional> #include <functional>
#include <gtest/gtest.h>
void TEST(TupleEndTest, Type) {
test_tuple_type_end() {
{ {
using type_tuple = std::tuple<int, short, double>; using type_tuple = std::tuple<int, short, double>;
using type_tuple_end = tupleutils::tuple_type_end<type_tuple, 1>::type; using type_tuple_end = tupleutils::tuple_type_end<type_tuple, 1>::type;
@@ -55,8 +55,7 @@ test_tuple_type_end() {
} }
} }
void TEST(TupleEndTest, Simple) {
test_tuple_end() {
// Test that tuple_end<0> gives an empty tuple: // Test that tuple_end<0> gives an empty tuple:
{ {
@@ -80,9 +79,9 @@ test_tuple_end() {
static_assert(std::tuple_size<decltype(t_suffix)>::value == 3, static_assert(std::tuple_size<decltype(t_suffix)>::value == 3,
"unexpected tuple_end()ed tuple size."); "unexpected tuple_end()ed tuple size.");
assert(std::get<0>(t_suffix) == nullptr); EXPECT_EQ(nullptr, std::get<0>(t_suffix));
assert(std::get<1>(t_suffix) == "hello"); EXPECT_EQ("hello", std::get<1>(t_suffix));
assert(std::get<2>(t_suffix) == "world"); EXPECT_EQ("world", std::get<2>(t_suffix));
static_assert(std::is_same<decltype(t_suffix), decltype(t_original)>::value, static_assert(std::is_same<decltype(t_suffix), decltype(t_original)>::value,
"unexpected end()ed tuple type"); "unexpected end()ed tuple type");
@@ -96,8 +95,8 @@ test_tuple_end() {
static_assert(std::tuple_size<decltype(t_suffix)>::value == 2, static_assert(std::tuple_size<decltype(t_suffix)>::value == 2,
"unexpected tuple_end()ed tuple size."); "unexpected tuple_end()ed tuple size.");
assert(std::get<0>(t_suffix) == "hello"); EXPECT_EQ("hello", std::get<0>(t_suffix));
assert(std::get<1>(t_suffix) == "world"); EXPECT_EQ("world", std::get<1>(t_suffix));
using type_tuple_suffix = std::tuple<std::string, std::string>; using type_tuple_suffix = std::tuple<std::string, std::string>;
static_assert(std::is_same<decltype(t_suffix), type_tuple_suffix>::value, static_assert(std::is_same<decltype(t_suffix), type_tuple_suffix>::value,
@@ -112,16 +111,15 @@ test_tuple_end() {
static_assert(std::tuple_size<decltype(t_suffix)>::value == 1, static_assert(std::tuple_size<decltype(t_suffix)>::value == 1,
"unexpected tuple_end()ed tuple size."); "unexpected tuple_end()ed tuple size.");
assert(std::get<0>(t_suffix) == "world"); EXPECT_EQ("world", std::get<0>(t_suffix));
using type_tuple_suffix = std::tuple<std::string>; using type_tuple_suffix = std::tuple<std::string>;
static_assert(std::is_same<decltype(t_suffix), type_tuple_suffix>::value, static_assert(std::is_same<decltype(t_suffix), type_tuple_suffix>::value,
"unexpected end()ed tuple type"); "unexpected end()ed tuple type");
} }
} }
void TEST(TestTupleEnd, StdRef) {
test_tuple_end_stdref() {
std::string c = "yadda"; std::string c = "yadda";
std::string d = "yaddayadda"; std::string d = "yaddayadda";
auto t_larger = std::make_tuple(1, 2, std::ref(c), std::ref(d)); auto t_larger = std::make_tuple(1, 2, std::ref(c), std::ref(d));
@@ -132,14 +130,14 @@ test_tuple_end_stdref() {
//This works, but it's not what we are testing here: //This works, but it's not what we are testing here:
//assert(std::get<0>(t_larger) == "hello"); //assert(std::get<0>(t_larger) == "hello");
assert(std::get<0>(t_suffix) == "hello"); EXPECT_EQ("hello", std::get<0>(t_suffix));
assert(std::get<1>(t_suffix) == "world"); EXPECT_EQ("world", std::get<1>(t_suffix));
} }
constexpr // TODO: Does this test function itself need to be constexpr,
void // and if so, how can we do that with googletest?
test_tuple_end_constexpr() { TEST(TestTupleEnd, ConstExpr) {
constexpr auto str_hello = "hello"; constexpr auto str_hello = "hello";
constexpr auto str_world = "world"; constexpr auto str_world = "world";
@@ -150,17 +148,7 @@ test_tuple_end_constexpr() {
static_assert(std::tuple_size<decltype(t_suffix)>::value == 2, static_assert(std::tuple_size<decltype(t_suffix)>::value == 2,
"unexpected tuple_end()ed tuple size."); "unexpected tuple_end()ed tuple size.");
assert(std::get<0>(t_suffix) == str_hello); EXPECT_EQ(str_hello, std::get<0>(t_suffix));
assert(std::get<1>(t_suffix) == str_world); EXPECT_EQ(str_world, std::get<1>(t_suffix));
} }
int
main() {
test_tuple_type_end();
test_tuple_end();
test_tuple_end_stdref();
test_tuple_end_constexpr();
return EXIT_SUCCESS;
}
Oops, something went wrong.

0 comments on commit 88b38c9

Please sign in to comment.