Enable build and execution of tests again using CTest.
authorAndreas Schuh <andreas.schuh.84@gmail.com>
Thu, 1 Aug 2013 00:47:13 +0000 (01:47 +0100)
committerAndreas Schuh <andreas.schuh.84@gmail.com>
Thu, 1 Aug 2013 00:47:13 +0000 (01:47 +0100)
CMakeLists.txt
test/CMakeLists.txt [new file with mode: 0644]
test/gflags_strip_flags_test.cc
test/gflags_unittest.cc

index b9d4f03..84a0818 100644 (file)
@@ -135,6 +135,20 @@ include_directories ("${PROJECT_BINARY_DIR}/include/${GFLAGS_NAMESPACE}")
 add_library (gflags ${GFLAGS_SRCS})
 
 # ----------------------------------------------------------------------------
+# testing
+
+# TODO(andreas) Replace Bash scripts such that tests can be run on Windows (e.g., Python).
+#               The gflags_unittest.sh script should best be replaced by multiple
+#               add_test commands in the test/CMakeLists.txt file.
+if (UNIX)
+  include (CTest)
+  if (BUILD_TESTING)
+    enable_testing ()
+    add_subdirectory (test)
+  endif ()
+endif ()
+
+# ----------------------------------------------------------------------------
 # installation
 if (WIN32)
   set (RUNTIME_INSTALL_DIR Bin)
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
new file mode 100644 (file)
index 0000000..1157426
--- /dev/null
@@ -0,0 +1,34 @@
+## gflags tests
+
+# ----------------------------------------------------------------------------
+# output directories
+set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/Testing/bin")
+set (CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/Testing/lib")
+set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/Testing/lib")
+
+set (TEMPDIR "${PROJECT_BINARY_DIR}/Testing/Temporary")
+
+# ----------------------------------------------------------------------------
+# common link libraries
+link_libraries (gflags)
+
+# ----------------------------------------------------------------------------
+# test executables
+add_executable (strip_flags gflags_strip_flags_test.cc)
+add_executable (unittest    gflags_unittest.cc)
+
+# ----------------------------------------------------------------------------
+# test commands
+add_test (
+  NAME    strip_flags
+  COMMAND /bin/bash "${CMAKE_CURRENT_SOURCE_DIR}/gflags_strip_flags_test.sh"
+          "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/strip_flags"
+)
+
+add_test (
+  NAME    unittest
+  COMMAND /bin/bash "${CMAKE_CURRENT_SOURCE_DIR}/gflags_unittest.sh"
+          "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unittest"
+          "${CMAKE_CURRENT_SOURCE_DIR}" # <srcdir>
+          "${TEMPDIR}/unittest"         # <tempdir>
+)
index 001ccd3..25ef53a 100644 (file)
@@ -40,8 +40,8 @@
 
 #include <stdio.h>
 
-using GOOGLE_NAMESPACE::SetUsageMessage;
-using GOOGLE_NAMESPACE::ParseCommandLineFlags;
+using GFLAGS_NAMESPACE::SetUsageMessage;
+using GFLAGS_NAMESPACE::ParseCommandLineFlags;
 
 
 DEFINE_bool(test, true, "This text should be stripped out");
index cce60d9..4edf3df 100644 (file)
@@ -53,18 +53,18 @@ EXPECT_DEATH_INIT
 // works.  But don't bother on windows; the windows port is so new
 // it never had the old location-names.
 #ifndef _MSC_VER
-#include <google/gflags_completions.h>
-void (*unused_fn)() = &GOOGLE_NAMESPACE::HandleCommandLineCompletions;
+#include <gflags/gflags_completions.h>
+void (*unused_fn)() = &GFLAGS_NAMESPACE::HandleCommandLineCompletions;
 #endif
 
 using std::string;
 using std::vector;
-using GOOGLE_NAMESPACE::int32;
-using GOOGLE_NAMESPACE::FlagRegisterer;
-using GOOGLE_NAMESPACE::StringFromEnv;
-using GOOGLE_NAMESPACE::RegisterFlagValidator;
-using GOOGLE_NAMESPACE::CommandLineFlagInfo;
-using GOOGLE_NAMESPACE::GetAllFlags;
+using GFLAGS_NAMESPACE::int32;
+using GFLAGS_NAMESPACE::FlagRegisterer;
+using GFLAGS_NAMESPACE::StringFromEnv;
+using GFLAGS_NAMESPACE::RegisterFlagValidator;
+using GFLAGS_NAMESPACE::CommandLineFlagInfo;
+using GFLAGS_NAMESPACE::GetAllFlags;
 
 DEFINE_string(test_tmpdir, "/tmp/gflags_unittest", "Dir we use for temp files");
 #ifdef _MSC_VER  // in MSVC, we run from the vsprojects directory
@@ -236,7 +236,7 @@ namespace fLI {
 }
 using fLI::FLAGS_tldflag2;
 
-_START_GOOGLE_NAMESPACE_
+namespace GFLAGS_NAMESPACE {
 
 namespace {
 
@@ -253,9 +253,9 @@ static string TmpFile(const string& basename) {
 // Must be called after ParseCommandLineFlags().
 static const char* GetFlagFileFlag() {
 #ifdef _MSC_VER
-  static const string flagfile = FLAGS_srcdir + "\\src\\gflags_unittest_flagfile";
+  static const string flagfile = FLAGS_srcdir + "\\gflags_unittest_flagfile";
 #else
-  static const string flagfile = FLAGS_srcdir + "/src/gflags_unittest_flagfile";
+  static const string flagfile = FLAGS_srcdir + "/gflags_unittest_flagfile";
 #endif
   static const string flagfile_flag = string("--flagfile=") + flagfile;
   return flagfile_flag.c_str();
@@ -1526,9 +1526,9 @@ int main(int argc, char **argv) {
   return exit_status;
 }
 
-_END_GOOGLE_NAMESPACE_
+} // GFLAGS_NAMESPACE
 
 int main(int argc, char** argv) {
-  return GOOGLE_NAMESPACE::main(argc, argv);
+  return GFLAGS_NAMESPACE::main(argc, argv);
 }