CMakeLists.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. ## gflags tests
  2. # ----------------------------------------------------------------------------
  3. # output directories
  4. set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
  5. set (CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
  6. set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
  7. # set working directory of test commands
  8. set (GFLAGS_FLAGFILES_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
  9. # ----------------------------------------------------------------------------
  10. # common include directories and link libraries
  11. include_directories ("${CMAKE_CURRENT_SOURCE_DIR}")
  12. include_directories ("${gflags_SOURCE_DIR}/src")
  13. include_directories ("${gflags_BINARY_DIR}/include")
  14. include_directories ("${gflags_BINARY_DIR}/include/gflags")
  15. if (BUILD_SHARED_LIBS)
  16. set (type shared)
  17. if (GFLAGS_IS_A_DLL)
  18. add_definitions(-DGFLAGS_IS_A_DLL)
  19. endif ()
  20. else ()
  21. set (type static)
  22. endif ()
  23. if (BUILD_gflags_LIB)
  24. link_libraries (gflags_${type})
  25. else ()
  26. link_libraries (gflags_nothreads_${type})
  27. endif ()
  28. # ----------------------------------------------------------------------------
  29. # STRIP_FLAG_HELP
  30. add_executable (gflags_strip_flags_test gflags_strip_flags_test.cc)
  31. # Make sure the --help output doesn't print the stripped text.
  32. add_gflags_test (strip_flags_help 1 "" "This text should be stripped out" gflags_strip_flags_test --help)
  33. # Make sure the stripped text isn't in the binary at all.
  34. add_test (
  35. NAME strip_flags_binary
  36. COMMAND "${CMAKE_COMMAND}" "-DBINARY=$<TARGET_FILE:gflags_strip_flags_test>"
  37. -P "${CMAKE_CURRENT_SOURCE_DIR}/gflags_strip_flags_test.cmake"
  38. CONFIGURATIONS Release MinSizeRel
  39. )
  40. # ----------------------------------------------------------------------------
  41. # unit tests
  42. configure_file (gflags_unittest.cc gflags_unittest-main.cc COPYONLY)
  43. configure_file (gflags_unittest.cc gflags_unittest_main.cc COPYONLY)
  44. add_executable (gflags_unittest gflags_unittest.cc)
  45. add_executable (gflags_unittest-main gflags_unittest-main.cc)
  46. add_executable (gflags_unittest_main gflags_unittest_main.cc)
  47. if (OS_WINDOWS)
  48. set (SLASH "\\\\")
  49. else ()
  50. set (SLASH "/")
  51. endif ()
  52. # First, just make sure the gflags_unittest works as-is
  53. add_gflags_test(unittest 0 "" "" gflags_unittest)
  54. # --help should show all flags, including flags from gflags_reporting
  55. add_gflags_test(help-reporting 1 "${SLASH}gflags_reporting.cc:" "" gflags_unittest --help)
  56. # Make sure that --help prints even very long helpstrings.
  57. add_gflags_test(long-helpstring 1 "end of a long helpstring" "" gflags_unittest --help)
  58. # Make sure --help reflects flag changes made before flag-parsing
  59. add_gflags_test(changed_bool1 1 "-changed_bool1 (changed) type: bool default: true" "" gflags_unittest --help)
  60. add_gflags_test(changed_bool2 1 "-changed_bool2 (changed) type: bool default: false currently: true" "" gflags_unittest --help)
  61. # And on the command-line, too
  62. add_gflags_test(changeable_string_var 1 "-changeable_string_var () type: string default: \"1\" currently: \"2\"" "" gflags_unittest --changeable_string_var 2 --help)
  63. # --nohelp and --help=false should be as if we didn't say anything
  64. add_gflags_test(nohelp 0 "PASS" "" gflags_unittest --nohelp)
  65. add_gflags_test(help=false 0 "PASS" "" gflags_unittest --help=false)
  66. # --helpfull is the same as help
  67. add_gflags_test(helpfull 1 "${SLASH}gflags_reporting.cc:" "" gflags_unittest --helpfull)
  68. # --helpshort should show only flags from the gflags_unittest itself
  69. add_gflags_test(helpshort 1 "${SLASH}gflags_unittest.cc:" "${SLASH}gflags_reporting.cc:" gflags_unittest --helpshort)
  70. # --helpshort should show the tldflag we created in the gflags_unittest dir
  71. add_gflags_test(helpshort-tldflag1 1 "tldflag1" "${SLASH}google.cc:" gflags_unittest --helpshort)
  72. add_gflags_test(helpshort-tldflag2 1 "tldflag2" "${SLASH}google.cc:" gflags_unittest --helpshort)
  73. # --helpshort should work if the main source file is suffixed with [_-]main
  74. add_gflags_test(helpshort-main 1 "${SLASH}gflags_unittest-main.cc:" "${SLASH}gflags_reporting.cc:" gflags_unittest-main --helpshort)
  75. add_gflags_test(helpshort_main 1 "${SLASH}gflags_unittest_main.cc:" "${SLASH}gflags_reporting.cc:" gflags_unittest_main --helpshort)
  76. # --helpon needs an argument
  77. add_gflags_test(helpon 1 "'--helpon' is missing its argument; flag description: show help on" "" gflags_unittest --helpon)
  78. # --helpon argument indicates what file we'll show args from
  79. add_gflags_test(helpon=gflags 1 "${SLASH}gflags.cc:" "${SLASH}gflags_unittest.cc:" gflags_unittest --helpon=gflags)
  80. # another way of specifying the argument
  81. add_gflags_test(helpon_gflags 1 "${SLASH}gflags.cc:" "${SLASH}gflags_unittest.cc:" gflags_unittest --helpon gflags)
  82. # test another argument
  83. add_gflags_test(helpon=gflags_unittest 1 "${SLASH}gflags_unittest.cc:" "${SLASH}gflags.cc:" gflags_unittest --helpon=gflags_unittest)
  84. # helpmatch is like helpon but takes substrings
  85. add_gflags_test(helpmatch_reporting 1 "${SLASH}gflags_reporting.cc:" "${SLASH}gflags_unittest.cc:" gflags_unittest -helpmatch reporting)
  86. add_gflags_test(helpmatch=unittest 1 "${SLASH}gflags_unittest.cc:" "${SLASH}gflags.cc:" gflags_unittest -helpmatch=unittest)
  87. # if no flags are found with helpmatch or helpon, suggest --help
  88. add_gflags_test(helpmatch=nosuchsubstring 1 "No modules matched" "${SLASH}gflags_unittest.cc:" gflags_unittest -helpmatch=nosuchsubstring)
  89. add_gflags_test(helpon=nosuchmodule 1 "No modules matched" "${SLASH}gflags_unittest.cc:" gflags_unittest -helpon=nosuchmodule)
  90. # helppackage shows all the flags in the same dir as this unittest
  91. # --help should show all flags, including flags from google.cc
  92. add_gflags_test(helppackage 1 "${SLASH}gflags_reporting.cc:" "" gflags_unittest --helppackage)
  93. # xml!
  94. add_gflags_test(helpxml 1 "${SLASH}gflags_unittest.cc</file>" "${SLASH}gflags_unittest.cc:" gflags_unittest --helpxml)
  95. # just print the version info and exit
  96. add_gflags_test(version-1 0 "gflags_unittest" "${SLASH}gflags_unittest.cc:" gflags_unittest --version)
  97. add_gflags_test(version-2 0 "version test_version" "${SLASH}gflags_unittest.cc:" gflags_unittest --version)
  98. # --undefok is a fun flag...
  99. add_gflags_test(undefok-1 1 "unknown command line flag 'foo'" "" gflags_unittest --undefok= --foo --unused_bool)
  100. add_gflags_test(undefok-2 0 "PASS" "" gflags_unittest --undefok=foo --foo --unused_bool)
  101. # If you say foo is ok to be undefined, we'll accept --nofoo as well
  102. add_gflags_test(undefok-3 0 "PASS" "" gflags_unittest --undefok=foo --nofoo --unused_bool)
  103. # It's ok if the foo is in the middle
  104. add_gflags_test(undefok-4 0 "PASS" "" gflags_unittest --undefok=fee,fi,foo,fum --foo --unused_bool)
  105. # But the spelling has to be just right...
  106. add_gflags_test(undefok-5 1 "unknown command line flag 'foo'" "" gflags_unittest --undefok=fo --foo --unused_bool)
  107. add_gflags_test(undefok-6 1 "unknown command line flag 'foo'" "" gflags_unittest --undefok=foot --foo --unused_bool)
  108. # See if we can successfully load our flags from the flagfile
  109. add_gflags_test(flagfile.1 0 "gflags_unittest" "${SLASH}gflags_unittest.cc:" gflags_unittest "--flagfile=flagfile.1")
  110. add_gflags_test(flagfile.2 0 "PASS" "" gflags_unittest "--flagfile=flagfile.2")
  111. add_gflags_test(flagfile.3 0 "PASS" "" gflags_unittest "--flagfile=flagfile.3")
  112. # Also try to load flags from the environment
  113. add_gflags_test(fromenv=version 0 "gflags_unittest" "${SLASH}gflags_unittest.cc:" gflags_unittest --fromenv=version)
  114. add_gflags_test(tryfromenv=version 0 "gflags_unittest" "${SLASH}gflags_unittest.cc:" gflags_unittest --tryfromenv=version)
  115. add_gflags_test(fromenv=help 0 "PASS" "" gflags_unittest --fromenv=help)
  116. add_gflags_test(tryfromenv=help 0 "PASS" "" gflags_unittest --tryfromenv=help)
  117. add_gflags_test(fromenv=helpfull 1 "helpfull not found in environment" "" gflags_unittest --fromenv=helpfull)
  118. add_gflags_test(tryfromenv=helpfull 0 "PASS" "" gflags_unittest --tryfromenv=helpfull)
  119. add_gflags_test(tryfromenv=undefok 0 "PASS" "" gflags_unittest --tryfromenv=undefok --foo)
  120. add_gflags_test(tryfromenv=weirdo 1 "unknown command line flag" "" gflags_unittest --tryfromenv=weirdo)
  121. add_gflags_test(tryfromenv-multiple 0 "gflags_unittest" "${SLASH}gflags_unittest.cc:" gflags_unittest --tryfromenv=test_bool,version,unused_bool)
  122. add_gflags_test(fromenv=test_bool 1 "not found in environment" "" gflags_unittest --fromenv=test_bool)
  123. add_gflags_test(fromenv=test_bool-ok 1 "unknown command line flag" "" gflags_unittest --fromenv=test_bool,ok)
  124. # Here, the --version overrides the fromenv
  125. add_gflags_test(version-overrides-fromenv 0 "gflags_unittest" "${SLASH}gflags_unittest.cc:" gflags_unittest --fromenv=test_bool,version,ok)
  126. # Make sure -- by itself stops argv processing
  127. add_gflags_test(dashdash 0 "PASS" "" gflags_unittest -- --help)
  128. # And we should die if the flag value doesn't pass the validator
  129. add_gflags_test(always_fail 1 "ERROR: failed validation of new value 'true' for flag 'always_fail'" "" gflags_unittest --always_fail)
  130. # And if locking in validators fails
  131. # TODO(andreas): Worked on Windows 7 Release configuration, but causes
  132. # debugger abort() intervention in case of Debug configuration.
  133. #add_gflags_test(deadlock_if_cant_lock 0 "PASS" "" gflags_unittest --deadlock_if_cant_lock)
  134. # ----------------------------------------------------------------------------
  135. # use gflags_declare.h
  136. add_executable (gflags_declare_test gflags_declare_test.cc gflags_declare_flags.cc)
  137. add_test(NAME gflags_declare COMMAND gflags_declare_test --message "Hello gflags!")
  138. set_tests_properties(gflags_declare PROPERTIES PASS_REGULAR_EXPRESSION "Hello gflags!")
  139. # ----------------------------------------------------------------------------
  140. # configure Python script which configures and builds a test project
  141. if (BUILD_NC_TESTS OR BUILD_CONFIG_TESTS)
  142. find_package (PythonInterp)
  143. if (NOT PYTHON_EXECUTABLE)
  144. message (FATAL_ERROR "No Python installation found! It is required by the (negative) compilation tests."
  145. " Either install Python or set BUILD_NC_TESTS and BUILD_CONFIG_TESTS to FALSE.")
  146. endif ()
  147. set (TMPDIR "${PROJECT_BINARY_DIR}/Testing/Temporary")
  148. configure_file (gflags_build.py.in "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/build.py" @ONLY)
  149. function (add_gflags_build_test name srcdir expect_fail)
  150. set (srcdir "${CMAKE_CURRENT_SOURCE_DIR}/${srcdir}")
  151. add_test (
  152. NAME "${name}"
  153. COMMAND "${PYTHON_EXECUTABLE}" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/build.py"
  154. ${name} ${srcdir} ${expect_fail}
  155. )
  156. endfunction ()
  157. endif ()
  158. # ----------------------------------------------------------------------------
  159. # negative compilation tests
  160. option (BUILD_NC_TESTS "Request addition of negative compilation tests." OFF)
  161. mark_as_advanced (BUILD_NC_TESTS)
  162. if (BUILD_NC_TESTS)
  163. add_gflags_build_test (nc_sanity nc 0)
  164. add_gflags_build_test (nc_swapped_args nc 1)
  165. add_gflags_build_test (nc_int_instead_of_bool nc 1)
  166. add_gflags_build_test (nc_bool_in_quotes nc 1)
  167. add_gflags_build_test (nc_define_string_with_0 nc 1)
  168. endif ()
  169. # ----------------------------------------------------------------------------
  170. # build configuration test
  171. option (BUILD_CONFIG_TESTS "Request addition of package configuration tests." OFF)
  172. mark_as_advanced (BUILD_CONFIG_TESTS)
  173. if (BUILD_CONFIG_TESTS)
  174. add_gflags_build_test (cmake_config config 0)
  175. endif ()