Browse Source

Copyright.txt: Add test to check year range

Add a CMake.Copyright test that, when the CMake version number knows the
year (as it does in development versions), checks that Copyright.txt has
been updated with the current version year.
Brad King 12 years ago
parent
commit
2bbf6bd7f8
2 changed files with 25 additions and 0 deletions
  1. 22 0
      Tests/CMakeCopyright.cmake
  2. 3 0
      Tests/CMakeLists.txt

+ 22 - 0
Tests/CMakeCopyright.cmake

@@ -0,0 +1,22 @@
+if(CMAKE_VERSION MATCHES "\\.(20[0-9][0-9])[0-9][0-9][0-9][0-9](-|$)")
+  set(version_year "${CMAKE_MATCH_1}")
+  set(copyright_line_regex "^Copyright 2000-(20[0-9][0-9]) Kitware")
+  file(STRINGS "${CMAKE_CURRENT_LIST_DIR}/../Copyright.txt" copyright_line
+    LIMIT_COUNT 1 REGEX "${copyright_line_regex}")
+  if(copyright_line MATCHES "${copyright_line_regex}")
+    set(copyright_year "${CMAKE_MATCH_1}")
+    if(copyright_year LESS version_year)
+      message(FATAL_ERROR "Copyright.txt contains\n"
+        " ${copyright_line}\n"
+        "but the current version year is ${version_year}.")
+    else()
+      message(STATUS "PASSED: Copyright.txt contains\n"
+        " ${copyright_line}\n"
+        "and the current version year is ${version_year}.")
+    endif()
+  else()
+    message(FATAL_ERROR "Copyright.txt has no Copyright line of expected format!")
+  endif()
+else()
+  message(STATUS "SKIPPED: CMAKE_VERSION does not know the year: ${CMAKE_VERSION}")
+endif()

+ 3 - 0
Tests/CMakeLists.txt

@@ -161,6 +161,9 @@ if(BUILD_TESTING)
     set(CMAKE_LONG_TEST_TIMEOUT 1500)
   endif()
 
+  add_test(NAME CMake.Copyright
+    COMMAND cmake -P ${CMAKE_CURRENT_SOURCE_DIR}/CMakeCopyright.cmake)
+
   # add a bunch of standard build-and-test style tests
   ADD_TEST_MACRO(CommandLineTest CommandLineTest)
   ADD_TEST_MACRO(FindPackageTest FindPackageTest)