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
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)
# 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
@@ -35,6 +33,16 @@ libmurrayc_tuple_utils_@MURRAYC_TUPLE_UTILS_API_VERSION@_la_LDFLAGS = -no-undefi
library_includedir = $(includedir)/$(MURRAYC_TUPLE_UTILS_MODULE_NAME)
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 = \
tests/test_tuple_cat \
@@ -56,63 +64,63 @@ tests_test_tuple_cat_SOURCES = \
tests_test_tuple_cat_CXXFLAGS = \
$(COMMON_CXXFLAGS)
tests_test_tuple_cat_LDADD = \
$(PROJECT_LIBS)
$(COMMON_LIBS)
tests_test_tuple_cdr_SOURCES = \
tests/test_tuple_cdr.cc
tests_test_tuple_cdr_CXXFLAGS = \
$(COMMON_CXXFLAGS)
tests_test_tuple_cdr_LDADD = \
$(PROJECT_LIBS)
$(COMMON_LIBS)
tests_test_tuple_end_SOURCES = \
tests/test_tuple_end.cc
tests_test_tuple_end_CXXFLAGS = \
$(COMMON_CXXFLAGS)
tests_test_tuple_end_LDADD = \
$(PROJECT_LIBS)
$(COMMON_LIBS)
tests_test_tuple_for_each_SOURCES = \
tests/test_tuple_for_each.cc
tests_test_tuple_for_each_CXXFLAGS = \
$(COMMON_CXXFLAGS)
tests_test_tuple_for_each_LDADD = \
$(PROJECT_LIBS)
$(COMMON_LIBS)
tests_test_tuple_interlace_SOURCES = \
tests/test_tuple_interlace.cc
tests_test_tuple_interlace_CXXFLAGS = \
$(COMMON_CXXFLAGS)
tests_test_tuple_interlace_LDADD = \
$(PROJECT_LIBS)
$(COMMON_LIBS)
tests_test_tuple_print_SOURCES = \
tests/test_tuple_print.cc
tests_test_tuple_print_CXXFLAGS = \
$(COMMON_CXXFLAGS)
tests_test_tuple_print_LDADD = \
$(PROJECT_LIBS)
$(COMMON_LIBS)
tests_test_tuple_start_SOURCES = \
tests/test_tuple_start.cc
tests_test_tuple_start_CXXFLAGS = \
$(COMMON_CXXFLAGS)
tests_test_tuple_start_LDADD = \
$(PROJECT_LIBS)
$(COMMON_LIBS)
tests_test_tuple_subset_SOURCES = \
tests/test_tuple_subset.cc
tests_test_tuple_subset_CXXFLAGS = \
$(COMMON_CXXFLAGS)
tests_test_tuple_subset_LDADD = \
$(PROJECT_LIBS)
$(COMMON_LIBS)
tests_test_tuple_transform_each_SOURCES = \
tests/test_tuple_transform_each.cc
tests_test_tuple_transform_each_CXXFLAGS = \
$(COMMON_CXXFLAGS)
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 <utility>
//#include <functional>
#include "gtest/gtest.h"
void
test_tuple_type_cat() {
TEST(TupleCatTest, Simple) {
using type_tuple_is = std::tuple<int, short>;
using type_tuple_dc = std::tuple<double, char>;
using type_tuple_cat =
@@ -36,8 +36,7 @@ test_tuple_type_cat() {
/** We don't want to test std::tuple_cat() here,
* but this a demonstration that std::ref() works with std::tuple_cat().
void
test_tuple_cat_stdref() {
TEST(TupleCatText, StdRef) {
std::string a = "yadda1";
std::string b = "yaddayadda1";
auto t_one =
@@ -52,20 +51,10 @@ test_tuple_cat_stdref() {
c = 3;
d = 'b';
assert(std::get<0>(t_both) == "hello");
assert(std::get<1>(t_both) == "world");
assert(std::get<2>(t_both) == 3);
assert(std::get<3>(t_both) == 'b');
EXPECT_EQ("hello", std::get<0>(t_both));
EXPECT_EQ("world", std::get<1>(t_both));
EXPECT_EQ(3, std::get<2>(t_both));
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 <utility>
#include <functional>
#include "gtest/gtest.h"
void
test_tuple_type_cdr() {
TEST(TestTupleCdr, Type) {
using type_tuple_isd = std::tuple<int, short, double>;
using type_tuple_sd = std::tuple<short, double>;
using type_tuple_suffix = tupleutils::tuple_type_cdr<type_tuple_isd>::type;
static_assert(std::tuple_size<type_tuple_suffix>::value == 2,
"unexpected tuple_cdr()ed tuple size.");
static_assert(std::is_same<type_tuple_suffix, type_tuple_sd>::value,
"unexpected tuple_cdr()ed tuple type");
}
void
test_tuple_cdr() {
TEST(TestTupleCdr, Simple) {
auto t_larger =
std::make_tuple(nullptr, std::string("hello"), std::string("world"));
auto t_suffix = tupleutils::tuple_cdr(t_larger);
assert(std::get<0>(t_suffix) == "hello");
assert(std::get<1>(t_suffix) == "world");
EXPECT_EQ("hello", std::get<0>(t_suffix));
EXPECT_EQ("world", std::get<1>(t_suffix));
using type_tuple_suffix = std::tuple<std::string, std::string>;
static_assert(std::tuple_size<decltype(t_suffix)>::value == 2,
"unexpected cdr()ed tuple size.");
static_assert(std::is_same<decltype(t_suffix), type_tuple_suffix>::value,
"unexpected cdr()ed tuple type");
}
void
test_tuple_cdr_stdref() {
TEST(TestTupleCdr, StdRef) {
std::string b = "yadda";
std::string c = "yaddayadda";
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:
//assert(std::get<1>(t_larger) == "hello");
assert(std::get<0>(t_suffix) == "hello");
assert(std::get<1>(t_suffix) == "world");
EXPECT_EQ("hello", std::get<0>(t_suffix));
EXPECT_EQ("world", std::get<1>(t_suffix));
}
constexpr
void
test_tuple_cdr_constexpr() {
// TODO: Does this test function itself need to be constexpr,
// and if so, how can we do that with googletest?
TEST(TestTupleCdr, ConstExpr) {
constexpr auto str_hello = "hello";
constexpr auto str_world = "world";
@@ -77,17 +77,8 @@ test_tuple_cdr_constexpr() {
constexpr auto t_suffix = tupleutils::tuple_cdr(t_larger);
static_assert(std::get<0>(t_suffix) == str_hello,
"unexpected tuple element value.");
static_assert(std::get<1>(t_suffix) == str_world,
"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 <tuple-utils/tuple_end.h>
#include <functional>
#include <gtest/gtest.h>
void
test_tuple_type_end() {
TEST(TupleEndTest, Type) {
{
using type_tuple = std::tuple<int, short, double>;
using type_tuple_end = tupleutils::tuple_type_end<type_tuple, 1>::type;
@@ -55,8 +55,7 @@ test_tuple_type_end() {
}
}
void
test_tuple_end() {
TEST(TupleEndTest, Simple) {
// 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,
"unexpected tuple_end()ed tuple size.");
assert(std::get<0>(t_suffix) == nullptr);
assert(std::get<1>(t_suffix) == "hello");
assert(std::get<2>(t_suffix) == "world");
EXPECT_EQ(nullptr, std::get<0>(t_suffix));
EXPECT_EQ("hello", std::get<1>(t_suffix));
EXPECT_EQ("world", std::get<2>(t_suffix));
static_assert(std::is_same<decltype(t_suffix), decltype(t_original)>::value,
"unexpected end()ed tuple type");
@@ -96,8 +95,8 @@ test_tuple_end() {
static_assert(std::tuple_size<decltype(t_suffix)>::value == 2,
"unexpected tuple_end()ed tuple size.");
assert(std::get<0>(t_suffix) == "hello");
assert(std::get<1>(t_suffix) == "world");
EXPECT_EQ("hello", std::get<0>(t_suffix));
EXPECT_EQ("world", std::get<1>(t_suffix));
using type_tuple_suffix = std::tuple<std::string, std::string>;
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,
"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>;
static_assert(std::is_same<decltype(t_suffix), type_tuple_suffix>::value,
"unexpected end()ed tuple type");
}
}
void
test_tuple_end_stdref() {
TEST(TestTupleEnd, StdRef) {
std::string c = "yadda";
std::string d = "yaddayadda";
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:
//assert(std::get<0>(t_larger) == "hello");
assert(std::get<0>(t_suffix) == "hello");
assert(std::get<1>(t_suffix) == "world");
EXPECT_EQ("hello", std::get<0>(t_suffix));
EXPECT_EQ("world", std::get<1>(t_suffix));
}
constexpr
void
test_tuple_end_constexpr() {
// TODO: Does this test function itself need to be constexpr,
// and if so, how can we do that with googletest?
TEST(TestTupleEnd, ConstExpr) {
constexpr auto str_hello = "hello";
constexpr auto str_world = "world";
@@ -150,17 +148,7 @@ test_tuple_end_constexpr() {
static_assert(std::tuple_size<decltype(t_suffix)>::value == 2,
"unexpected tuple_end()ed tuple size.");
assert(std::get<0>(t_suffix) == str_hello);
assert(std::get<1>(t_suffix) == str_world);
EXPECT_EQ(str_hello, std::get<0>(t_suffix));
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.