diff options
author | Brad King <brad.king@kitware.com> | 2022-10-05 14:42:45 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2022-10-05 16:38:12 (GMT) |
commit | 8d453ee751e9610f8b4e0a1b1fd65cb3b080c3dc (patch) | |
tree | dc9d3bfdccc971eb555377d26c258dd843b96ed3 /Tests/CheckSourceTree | |
parent | c23ebfa333208df8730a2c84635faf11fc7ad669 (diff) | |
download | CMake-8d453ee751e9610f8b4e0a1b1fd65cb3b080c3dc.zip CMake-8d453ee751e9610f8b4e0a1b1fd65cb3b080c3dc.tar.gz CMake-8d453ee751e9610f8b4e0a1b1fd65cb3b080c3dc.tar.bz2 |
Tests: Improve CheckSourceTree test
Re-implement the test using simpler approach. Enable it only when doing
an out-of-source build with a `.git` source. Run it last, serially.
Re-use the `git` tool found for version computation. Print the output
from `git status` without modification. Rely on `.gitignore` instead
of filtering out paths ourselves.
Diffstat (limited to 'Tests/CheckSourceTree')
-rw-r--r-- | Tests/CheckSourceTree/CMakeLists.txt | 6 | ||||
-rw-r--r-- | Tests/CheckSourceTree/check.cmake | 22 |
2 files changed, 28 insertions, 0 deletions
diff --git a/Tests/CheckSourceTree/CMakeLists.txt b/Tests/CheckSourceTree/CMakeLists.txt new file mode 100644 index 0000000..d5019d2 --- /dev/null +++ b/Tests/CheckSourceTree/CMakeLists.txt @@ -0,0 +1,6 @@ +add_test(NAME CMake.CheckSourceTree + COMMAND ${CMAKE_COMMAND} -D GIT_EXECUTABLE=${GIT_EXECUTABLE} + -D CMake_SOURCE_DIR=${CMake_SOURCE_DIR} + -P ${CMAKE_CURRENT_LIST_DIR}/check.cmake + ) +set_property(TEST CMake.CheckSourceTree PROPERTY RUN_SERIAL 1) diff --git a/Tests/CheckSourceTree/check.cmake b/Tests/CheckSourceTree/check.cmake new file mode 100644 index 0000000..c2e3529 --- /dev/null +++ b/Tests/CheckSourceTree/check.cmake @@ -0,0 +1,22 @@ +# Give Git access to the real home directory to get user's settings. +if(DEFINED ENV{CTEST_REAL_HOME}) + set(ENV{HOME} "$ENV{CTEST_REAL_HOME}") +endif() + +execute_process( + COMMAND "${GIT_EXECUTABLE}" status + WORKING_DIRECTORY "${CMake_SOURCE_DIR}" + OUTPUT_VARIABLE output + ERROR_VARIABLE output + RESULT_VARIABLE result + ) +string(REPLACE "\n" "\n " output " ${output}") +if(NOT result EQUAL 0) + message(FATAL_ERROR "'git status' failed (${result}):\n${output}") +endif() + +if(output MATCHES "\n[ \t#]*(Changes |new file:|modified:|Untracked )") + message(FATAL_ERROR "The source tree is not clean. 'git status' reports:\n${output}") +endif() + +message(STATUS "The source tree is clean.") |