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.
  • Loading branch information...
1 parent 0cb9228 commit 5d6f53d622d657658430d0940c2a81299a9d2b04 @murraycu committed Dec 8, 2016
Showing with 82 additions and 92 deletions.
  1. +3 −0 .gitmodules
  2. +52 −2 Makefile_tests.am
  3. +1 −0 configure.ac
  4. +1 −0 googletest
  5. +7 −0 po/POTFILES.skip
  6. +1 −0 tests/CMakeLists.txt
  7. +17 −90 tests/test_rename_strings.cc
View
@@ -0,0 +1,3 @@
+[submodule "googletest"]
+ path = googletest
+ url = https://github.com/google/googletest.git
View
@@ -19,16 +19,66 @@
check_PROGRAMS = \
tests/test_rename_strings
+# Build the gtest static library.
+# Note that this uses pthreads, so we must use -pthread when build the tests.
+gtest_top = googletest/googletest
+check_LIBRARIES = libgtest.a
+libgtest_a_SOURCES = \
+ googletest/googletest/src/gtest-all.cc \
+ googletest/googletest/src/gtest_main.cc
+libgtest_a_CPPFLAGS = \
+ -I$(top_srcdir)/$(gtest_top)/include \
+ -I$(top_srcdir)/$(gtest_top)
+libgtest_a_LDFLAGS = -pthread
+EXTRA_DIST += \
+ $(gtest_top)/src/gtest-all.cc \
+ $(gtest_top)/src/gtest-filepath.cc \
+ $(gtest_top)/src/gtest-printers.cc \
+ $(gtest_top)/src/gtest.cc \
+ $(gtest_top)/src/gtest_main.cc \
+ $(gtest_top)/src/gtest-test-part.cc \
+ $(gtest_top)/src/gtest-death-test.cc \
+ $(gtest_top)/src/gtest-port.cc \
+ $(gtest_top)/src/gtest-typed-test.cc \
+ $(gtest_top)/src/gtest-internal-inl.h \
+ $(gtest_top)/include/gtest/gtest-death-test.h \
+ $(gtest_top)/include/gtest/gtest_pred_impl.h \
+ $(gtest_top)/include/gtest/gtest-test-part.h \
+ $(gtest_top)/include/gtest/gtest.h \
+ $(gtest_top)/include/gtest/gtest-printers.h \
+ $(gtest_top)/include/gtest/gtest-typed-test.h \
+ $(gtest_top)/include/gtest/gtest-message.h \
+ $(gtest_top)/include/gtest/gtest_prod.h \
+ $(gtest_top)/include/gtest/gtest-param-test.h \
+ $(gtest_top)/include/gtest/gtest-spi.h \
+ $(gtest_top)/include/gtest/internal/gtest-death-test-internal.h \
+ $(gtest_top)/include/gtest/internal/gtest-port-arch.h \
+ $(gtest_top)/include/gtest/internal/gtest-filepath.h \
+ $(gtest_top)/include/gtest/internal/gtest-port.h \
+ $(gtest_top)/include/gtest/internal/gtest-internal.h \
+ $(gtest_top)/include/gtest/internal/gtest-string.h \
+ $(gtest_top)/include/gtest/internal/gtest-linked_ptr.h \
+ $(gtest_top)/include/gtest/internal/gtest-tuple.h \
+ $(gtest_top)/include/gtest/internal/gtest-param-util-generated.h \
+ $(gtest_top)/include/gtest/internal/gtest-type-util.h \
+ $(gtest_top)/include/gtest/internal/gtest-param-util.h \
+ $(gtest_top)/include/gtest/internal/custom/gtest.h \
+ $(gtest_top)/include/gtest/internal/custom/gtest-printers.h \
+ $(gtest_top)/include/gtest/internal/custom/gtest-port.h
+
TESTS = \
tests/test_rename_strings
prefixsuffix_includes = -I$(top_builddir)/src -I$(top_srcdir)/src -I$(top_builddir) -I$(top_srcdir)
-tests_cppflags = $(prefixsuffix_includes) $(DEPS_CFLAGS) $(PREFIXSUFFIX_WXXFLAGS)
-tests_ldadd = $(DEPS_LIBS)
+tests_cppflags = $(prefixsuffix_includes) $(DEPS_CFLAGS) $(PREFIXSUFFIX_WXXFLAGS) \
+ -I$(top_srcdir)/$(gtest_top)/include
+tests_ldadd = $(DEPS_LIBS) $(top_builddir)/libgtest.a
+tests_ldflags = -pthread
tests_test_rename_strings_SOURCES = tests/test_rename_strings.cc \
src/string_renamer.cc \
src/string_renamer.h
tests_test_rename_strings_LDADD = $(tests_ldadd)
+tests_test_rename_strings_LDFLAGS = $(tests_ldflags)
tests_test_rename_strings_CPPFLAGS = $(tests_cppflags)
View
@@ -12,6 +12,7 @@ AC_ARG_VAR([ACLOCAL_FLAGS], [aclocal flags, e.g. -I <macro dir>])
dnl Checks for programs.
AC_PROG_CXX
+AC_PROG_RANLIB
AX_CXX_COMPILE_STDCXX([14], [noext],[optional])
Submodule googletest added at a2b8a8
View
@@ -1 +1,8 @@
data/prefixsuffix.desktop.in
+googletest/googlemock/src/gmock-spec-builders.cc
+googletest/googlemock/test/gmock-matchers_test.cc
+googletest/googletest/include/gtest/internal/gtest-filepath.h
+googletest/googletest/src/gtest.cc
+googletest/googletest/test/gtest-filepath_test.cc
+googletest/googletest/test/gtest_catch_exceptions_test.py
+googletest/googletest/test/gtest_unittest.cc
@@ -12,3 +12,4 @@ add_executable (test_rename_strings
${CMAKE_SOURCE_DIR}/src/string_renamer.h)
target_link_libraries (test_rename_strings ${DEPS_LIBRARIES})
add_test (test_rename_strings ${CMAKE_CURRENT_BINARY_DIR}/test_rename_strings)
+target_link_libraries (test_rename_strings gtest gtest_main)
@@ -19,128 +19,55 @@
#include "string_renamer.h"
#include <iostream>
#include <cstdlib>
+#include <gtest/gtest.h>
-bool
-check_prefix()
-{
+TEST(TestRenameStrings, Prefix) {
const PrefixSuffix::StringRenamer renamer("oldprefix", "newprefix", "", "");
Glib::ustring renamed = renamer.get_new_basename("oldprefixabc");
- if (renamed != "newprefixabc") {
- std::cerr << G_STRFUNC << ": Unexpected result: " << renamed << std::endl;
- return false;
- }
+ EXPECT_EQ("newprefixabc", renamed);
renamed = renamer.get_new_basename("aoldprefixabc");
- if (renamed != "aoldprefixabc") {
- std::cerr << G_STRFUNC << ": Unexpected result: " << renamed << std::endl;
- return false;
- }
-
- return true;
+ EXPECT_EQ("aoldprefixabc", renamed);
}
-bool
-check_prefix_remove()
-{
+TEST(TestRenameStrings, PrefixRemove) {
const PrefixSuffix::StringRenamer renamer("oldprefix", "", "", "");
Glib::ustring renamed = renamer.get_new_basename("oldprefixabc");
- if (renamed != "abc") {
- std::cerr << G_STRFUNC << ": Unexpected result: " << renamed << std::endl;
- return false;
- }
+ EXPECT_EQ("abc", renamed);
renamed = renamer.get_new_basename("aoldprefixabc");
- if (renamed != "aoldprefixabc") {
- std::cerr << G_STRFUNC << ": Unexpected result: " << renamed << std::endl;
- return false;
- }
-
- return true;
+ EXPECT_EQ("aoldprefixabc", renamed);
}
-bool
-check_suffix()
-{
+TEST(TestRenameStrings, Suffix) {
const PrefixSuffix::StringRenamer renamer("", "", "oldsuffix", "newsuffix");
Glib::ustring renamed = renamer.get_new_basename("abcoldsuffix");
- if (renamed != "abcnewsuffix") {
- std::cerr << G_STRFUNC << ": Unexpected result: " << renamed << std::endl;
- return false;
- }
+ EXPECT_EQ("abcnewsuffix", renamed);
renamed = renamer.get_new_basename("abcoldsuffixa");
- if (renamed != "abcoldsuffixa") {
- std::cerr << G_STRFUNC << ": Unexpected result: " << renamed << std::endl;
- return false;
- }
-
- return true;
+ EXPECT_EQ("abcoldsuffixa", renamed);
}
-bool
-check_extension_suffix()
-{
+TEST(TestRenameStrings, ExtensionSuffix) {
// Check that it doesn't change when it shouldn't:
const PrefixSuffix::StringRenamer renamer("", "", ".jpg", ".png");
Glib::ustring renamed = renamer.get_new_basename("something");
- if (renamed != "something") {
- std::cerr << G_STRFUNC << ": Unexpected result: " << renamed << std::endl;
- return false;
- }
+ EXPECT_EQ("something", renamed);
// Check that it doesn't change when it shouldn't, again:
renamed = renamer.get_new_basename("something.foo");
- if (renamed != "something.foo") {
- std::cerr << G_STRFUNC << ": Unexpected result: " << renamed << std::endl;
- return false;
- }
+ EXPECT_EQ("something.foo", renamed);
// Check that it does change when it should:
renamed = renamer.get_new_basename("something.jpg");
- if (renamed != "something.png") {
- std::cerr << G_STRFUNC << ": Unexpected result: " << renamed << std::endl;
- return false;
- }
-
- return true;
+ EXPECT_EQ("something.png", renamed);
}
-bool
-check_suffix_remove()
-{
+TEST(TestRenameStrings, SuffixRemove) {
const PrefixSuffix::StringRenamer renamer("", "", "suffixtoremove", "");
Glib::ustring renamed = renamer.get_new_basename("abcsuffixtoremove");
- if (renamed != "abc") {
- std::cerr << G_STRFUNC << ": Unexpected result: " << renamed << std::endl;
- return false;
- }
+ EXPECT_EQ("abc", renamed);
renamed = renamer.get_new_basename("abcsuffixtoremovea");
- if (renamed != "abcsuffixtoremovea") {
- std::cerr << G_STRFUNC << ": Unexpected result: " << renamed << std::endl;
- return false;
- }
-
- return true;
-}
-
-int
-main()
-{
- if (!check_prefix())
- return EXIT_FAILURE;
-
- if (!check_prefix_remove())
- return EXIT_FAILURE;
-
- if (!check_suffix())
- return EXIT_FAILURE;
-
- if (!check_suffix_remove())
- return EXIT_FAILURE;
-
- if (!check_extension_suffix())
- return EXIT_FAILURE;
-
- return EXIT_SUCCESS;
+ EXPECT_EQ("abcsuffixtoremovea", renamed);
}

0 comments on commit 5d6f53d

Please sign in to comment.