Commit 1c9f065d authored by Andreas Schuh's avatar Andreas Schuh

Add negative compilation tests.

parent 7abcbdcb
......@@ -137,20 +137,6 @@ add_library (gflags ${GFLAGS_SRCS})
add_library (gflags_nothreads ${GFLAGS_SRCS})
set_target_properties (gflags_nothreads PROPERTIES COMPILE_DEFINITIONS NO_THREADS)
# ----------------------------------------------------------------------------
# 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)
......@@ -165,7 +151,7 @@ else ()
set (CONFIG_INSTALL_DIR lib/cmake/${PACKAGE_NAME})
endif ()
install (TARGETS gflags DESTINATION ${LIBRARY_INSTALL_DIR} EXPORT gflags-lib)
install (TARGETS gflags gflags_nothreads DESTINATION ${LIBRARY_INSTALL_DIR} EXPORT gflags-lib)
install (FILES ${PUBLIC_HDRS} DESTINATION ${INCLUDE_INSTALL_DIR}/${GFLAGS_NAMESPACE})
file (RELATIVE_PATH INSTALL_PREFIX_REL2CONFIG_DIR "${CMAKE_INSTALL_PREFIX}/${CONFIG_INSTALL_DIR}" "${CMAKE_INSTALL_PREFIX}")
......@@ -192,5 +178,19 @@ endif ()
# ----------------------------------------------------------------------------
# support direct use of build tree
set (INSTALL_PREFIX_REL2CONFIG_DIR .)
export (TARGETS gflags FILE "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-export.cmake")
export (TARGETS gflags gflags_nothreads FILE "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-export.cmake")
configure_file (cmake/config.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config.cmake" @ONLY)
# ----------------------------------------------------------------------------
# testing - MUST follow the generation of the build tree config file
# 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 ()
## gflags tests
find_package (PythonInterp)
# ----------------------------------------------------------------------------
# output directories
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/Testing/bin")
......@@ -18,11 +20,31 @@ link_libraries (gflags_nothreads)
configure_file (gflags_unittest.cc gflags_unittest-main.cc COPYONLY)
configure_file (gflags_unittest.cc gflags_unittest_main.cc COPYONLY)
set (SRCDIR "${CMAKE_CURRENT_SOURCE_DIR}/nc")
configure_file (gflags_nc.py.in "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/nc.py" @ONLY)
add_executable (strip_flags gflags_strip_flags_test.cc)
add_executable (unittest gflags_unittest.cc)
add_executable (unittest2 gflags_unittest-main.cc)
add_executable (unittest3 gflags_unittest_main.cc)
# ----------------------------------------------------------------------------
# (negative) compilation tests
if (PYTHON_EXECUTABLE)
macro (add_nc_test name)
add_test (
NAME nc_${name}
COMMAND "${PYTHON_EXECUTABLE}" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/nc.py" ${name}
)
endmacro ()
add_nc_test (sanity)
add_nc_test (swapped_args)
add_nc_test (int_instead_of_bool)
add_nc_test (bool_in_quotes)
add_nc_test (define_string_with_0)
endif ()
# ----------------------------------------------------------------------------
# test commands
add_test (
......
#!/usr/bin/env python
import os
import sys
import subprocess
import shutil
CMAKE = '@CMAKE_COMMAND@'
TMPDIR = '@TEMPDIR@'
SRCDIR = '@SRCDIR@'
GFLAGS_DIR = '@gflags_BINARY_DIR@'
if __name__ == "__main__":
if len(sys.argv) != 2:
sys.stderr.write(' '.join(['usage:', sys.argv[0], '<test_name>\n']))
sys.exit(1)
test_name = sys.argv[1]
bindir = os.path.join(TMPDIR, '_'.join(['nc', test_name]))
if TMPDIR == '':
sys.stderr.write('Temporary directory not set!\n')
sys.exit(1)
# create build directory
if os.path.isdir(bindir): shutil.rmtree(bindir)
os.makedirs(bindir)
# configure the build tree
if subprocess.call([CMAKE, '-Dgflags_DIR:PATH='+GFLAGS_DIR, '-DTEST_NAME:STRING='+test_name, SRCDIR], cwd=bindir) != 0:
sys.stderr.write('Failed to configure the build tree!\n')
sys.exit(1)
# try build, which is supposed to fail (except in case of the sanity check)
if subprocess.call([CMAKE, '--build', bindir], cwd=bindir) == 0 and test_name != 'sanity':
sys.stderr.write('Build expected to fail, but it succeeded!\n')
sys.exit(1)
sys.exit(0)
## gflags negative compilation tests
cmake_minimum_required (VERSION 2.8)
if (NOT TEST_NAME)
message (FATAL_ERROR "Missing TEST_NAME CMake flag")
endif ()
string (TOUPPER ${TEST_NAME} TEST_NAME_UPPER)
project (gflags_nc_${TEST_NAME})
find_package (gflags REQUIRED)
include_directories (${gflags_INCLUDE_DIR} "${CMAKE_CURRENT_SOURCE_DIR}/..")
link_libraries (gflags_nothreads)
add_definitions (-DTEST_${TEST_NAME_UPPER})
add_executable (gflags_nc_${TEST_NAME} gflags_nc.cc)
......@@ -66,3 +66,8 @@ DEFINE_string(some_string_flag,
"Trying to construct a string by passing 0 would cause a crash.");
#endif
int main(int, char **)
{
return 0;
}
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