diff options
author | Andreas Schuh <andreas.schuh.84@gmail.com> | 2013-08-01 03:31:47 +0100 |
---|---|---|
committer | Andreas Schuh <andreas.schuh.84@gmail.com> | 2013-08-01 03:31:47 +0100 |
commit | 1c9f065dd0a1d9cc732c40d5abd7a7a9a73c8204 (patch) | |
tree | 7e40cf1d83cdc694dd6f2b0836aa983f95d5f787 /test | |
parent | 7abcbdcbbd095fd6ee1d19bb012ff3f4fc7c1bdf (diff) | |
download | gflags-1c9f065dd0a1d9cc732c40d5abd7a7a9a73c8204.tar.gz gflags-1c9f065dd0a1d9cc732c40d5abd7a7a9a73c8204.tar.bz2 gflags-1c9f065dd0a1d9cc732c40d5abd7a7a9a73c8204.zip |
Add negative compilation tests.
Diffstat (limited to 'test')
-rw-r--r-- | test/CMakeLists.txt | 22 | ||||
-rw-r--r-- | test/gflags_nc.py.in | 33 | ||||
-rw-r--r-- | test/nc/CMakeLists.txt | 16 | ||||
-rw-r--r-- | test/nc/gflags_nc.cc (renamed from test/gflags_nc.cc) | 5 |
4 files changed, 76 insertions, 0 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3bd3dfe..bc16eba 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,5 +1,7 @@ ## gflags tests +find_package (PythonInterp) + # ---------------------------------------------------------------------------- # output directories set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/Testing/bin") @@ -18,12 +20,32 @@ 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 ( NAME strip_flags diff --git a/test/gflags_nc.py.in b/test/gflags_nc.py.in new file mode 100644 index 0000000..7636782 --- /dev/null +++ b/test/gflags_nc.py.in @@ -0,0 +1,33 @@ +#!/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) diff --git a/test/nc/CMakeLists.txt b/test/nc/CMakeLists.txt new file mode 100644 index 0000000..823fc67 --- /dev/null +++ b/test/nc/CMakeLists.txt @@ -0,0 +1,16 @@ +## 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) diff --git a/test/gflags_nc.cc b/test/nc/gflags_nc.cc index c283612..23398f2 100644 --- a/test/gflags_nc.cc +++ b/test/nc/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; +} |