Commit 126f36b8 authored by Andreas Schuh's avatar Andreas Schuh

Enable build and execution of tests again using CTest.

parent 620557cc
...@@ -134,6 +134,20 @@ include_directories ("${PROJECT_BINARY_DIR}/include") ...@@ -134,6 +134,20 @@ include_directories ("${PROJECT_BINARY_DIR}/include")
include_directories ("${PROJECT_BINARY_DIR}/include/${GFLAGS_NAMESPACE}") include_directories ("${PROJECT_BINARY_DIR}/include/${GFLAGS_NAMESPACE}")
add_library (gflags ${GFLAGS_SRCS}) 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 # installation
if (WIN32) if (WIN32)
......
## 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>
)
...@@ -40,8 +40,8 @@ ...@@ -40,8 +40,8 @@
#include <stdio.h> #include <stdio.h>
using GOOGLE_NAMESPACE::SetUsageMessage; using GFLAGS_NAMESPACE::SetUsageMessage;
using GOOGLE_NAMESPACE::ParseCommandLineFlags; using GFLAGS_NAMESPACE::ParseCommandLineFlags;
DEFINE_bool(test, true, "This text should be stripped out"); DEFINE_bool(test, true, "This text should be stripped out");
......
...@@ -53,18 +53,18 @@ EXPECT_DEATH_INIT ...@@ -53,18 +53,18 @@ EXPECT_DEATH_INIT
// works. But don't bother on windows; the windows port is so new // works. But don't bother on windows; the windows port is so new
// it never had the old location-names. // it never had the old location-names.
#ifndef _MSC_VER #ifndef _MSC_VER
#include <google/gflags_completions.h> #include <gflags/gflags_completions.h>
void (*unused_fn)() = &GOOGLE_NAMESPACE::HandleCommandLineCompletions; void (*unused_fn)() = &GFLAGS_NAMESPACE::HandleCommandLineCompletions;
#endif #endif
using std::string; using std::string;
using std::vector; using std::vector;
using GOOGLE_NAMESPACE::int32; using GFLAGS_NAMESPACE::int32;
using GOOGLE_NAMESPACE::FlagRegisterer; using GFLAGS_NAMESPACE::FlagRegisterer;
using GOOGLE_NAMESPACE::StringFromEnv; using GFLAGS_NAMESPACE::StringFromEnv;
using GOOGLE_NAMESPACE::RegisterFlagValidator; using GFLAGS_NAMESPACE::RegisterFlagValidator;
using GOOGLE_NAMESPACE::CommandLineFlagInfo; using GFLAGS_NAMESPACE::CommandLineFlagInfo;
using GOOGLE_NAMESPACE::GetAllFlags; using GFLAGS_NAMESPACE::GetAllFlags;
DEFINE_string(test_tmpdir, "/tmp/gflags_unittest", "Dir we use for temp files"); DEFINE_string(test_tmpdir, "/tmp/gflags_unittest", "Dir we use for temp files");
#ifdef _MSC_VER // in MSVC, we run from the vsprojects directory #ifdef _MSC_VER // in MSVC, we run from the vsprojects directory
...@@ -236,7 +236,7 @@ namespace fLI { ...@@ -236,7 +236,7 @@ namespace fLI {
} }
using fLI::FLAGS_tldflag2; using fLI::FLAGS_tldflag2;
_START_GOOGLE_NAMESPACE_ namespace GFLAGS_NAMESPACE {
namespace { namespace {
...@@ -253,9 +253,9 @@ static string TmpFile(const string& basename) { ...@@ -253,9 +253,9 @@ static string TmpFile(const string& basename) {
// Must be called after ParseCommandLineFlags(). // Must be called after ParseCommandLineFlags().
static const char* GetFlagFileFlag() { static const char* GetFlagFileFlag() {
#ifdef _MSC_VER #ifdef _MSC_VER
static const string flagfile = FLAGS_srcdir + "\\src\\gflags_unittest_flagfile"; static const string flagfile = FLAGS_srcdir + "\\gflags_unittest_flagfile";
#else #else
static const string flagfile = FLAGS_srcdir + "/src/gflags_unittest_flagfile"; static const string flagfile = FLAGS_srcdir + "/gflags_unittest_flagfile";
#endif #endif
static const string flagfile_flag = string("--flagfile=") + flagfile; static const string flagfile_flag = string("--flagfile=") + flagfile;
return flagfile_flag.c_str(); return flagfile_flag.c_str();
...@@ -1526,9 +1526,9 @@ int main(int argc, char **argv) { ...@@ -1526,9 +1526,9 @@ int main(int argc, char **argv) {
return exit_status; return exit_status;
} }
_END_GOOGLE_NAMESPACE_ } // GFLAGS_NAMESPACE
int main(int argc, char** argv) { int main(int argc, char** argv) {
return GOOGLE_NAMESPACE::main(argc, argv); return GFLAGS_NAMESPACE::main(argc, argv);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment