Skip to content

Commit

Permalink
Always use add_test(NAME ... COMMAND ...)
Browse files Browse the repository at this point in the history
This is for consistency - add_test(NAME ... COMMAND ...)
escapes differently than add_test(<name> <command>...).
  • Loading branch information
cxw42 committed Oct 20, 2019
1 parent 4b40da9 commit 9ff938e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 79 deletions.
36 changes: 9 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,35 +56,21 @@ endif()

# The most common test function
function(new_ec_test name ec_file src_file regex)
if(is_target)
add_test(NAME ${name} COMMAND ${EDITORCONFIG_CMD} -f ${ec_file}
"${CMAKE_CURRENT_SOURCE_DIR}/${src_file}")
else()
add_test(${name} ${EDITORCONFIG_CMD} -f ${ec_file}
"${CMAKE_CURRENT_SOURCE_DIR}/${src_file}")
endif()
add_test(NAME ${name} COMMAND ${EDITORCONFIG_CMD} -f ${ec_file}
"${CMAKE_CURRENT_SOURCE_DIR}/${src_file}")
set_tests_properties(${name} PROPERTIES PASS_REGULAR_EXPRESSION "${regex}")
endfunction()

# The tests that requires version specified
# A test that requires a version specified
function(new_ec_test_version name ec_file src_file regex version)
if(is_target)
add_test(NAME ${name} COMMAND ${EDITORCONFIG_CMD} -b ${version} -f ${ec_file}
"${CMAKE_CURRENT_SOURCE_DIR}/${src_file}")
else()
add_test(${name} ${EDITORCONFIG_CMD} -b ${version} -f ${ec_file}
"${CMAKE_CURRENT_SOURCE_DIR}/${src_file}")
endif()
add_test(NAME ${name} COMMAND ${EDITORCONFIG_CMD} -b ${version} -f ${ec_file}
"${CMAKE_CURRENT_SOURCE_DIR}/${src_file}")
set_tests_properties(${name} PROPERTIES PASS_REGULAR_EXPRESSION "${regex}")
endfunction()

# The tests that requires the full path EditorConfig files
# A test that requires the full path to the EditorConfig files
function(new_ec_test_full_ec_file_path name ec_file src_file regex)
if(is_target)
add_test(NAME ${name} COMMAND ${EDITORCONFIG_CMD} -f ${ec_file} "${src_file}")
else()
add_test(${name} ${EDITORCONFIG_CMD} -f ${ec_file} "${src_file}")
endif()
add_test(NAME ${name} COMMAND ${EDITORCONFIG_CMD} -f ${ec_file} ${src_file})
set_tests_properties(${name} PROPERTIES PASS_REGULAR_EXPRESSION "${regex}")
endfunction()

Expand All @@ -101,7 +87,7 @@ function(new_ec_test_multiline name ec_file src_file regex)
# Note: the semicolons separate list elements.
"-P" "${tests_cmakelists_dir}/cmake/ec_sort.cmake")
else()
add_test(${name} "cmake"
add_test(NAME ${name} COMMAND "cmake"
"-D" "EDITORCONFIG_CMD=${EDITORCONFIG_CMD}"
# Since variables aren't automatically passed to the inner cmake
"-D" "ECARGS:LIST=-f;${ec_file};${CMAKE_CURRENT_SOURCE_DIR}/${src_file}"
Expand All @@ -125,11 +111,7 @@ function(new_ec_cli_test)
"" "${one_value_keywords}" "${multi_value_keywords}" ${ARGN})

# Add test
if(is_target)
add_test(NAME ${P_NAME} COMMAND ${EDITORCONFIG_CMD} ${P_ARGS})
else()
add_test(${P_NAME} ${EDITORCONFIG_CMD} ${P_ARGS})
endif()
add_test(NAME ${P_NAME} COMMAND ${EDITORCONFIG_CMD} ${P_ARGS})
set_tests_properties(${name} PROPERTIES PASS_REGULAR_EXPRESSION "${P_MATCH}")

endfunction()
Expand Down
15 changes: 2 additions & 13 deletions filetree/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@

cmake_minimum_required(VERSION 3.5)

# Cause ec_backslashes to be include()d when the tests run.
# NOTE: TEST_INCLUDE_FILE is deprecated in favor of TEST_INCLUDE_FILES.
# However, TEST_INCLUDE_FILES was not added until cmake 3.10. If
# TEST_INCLUDE_FILE is ever removed, the cmake minimum version will need
# to be increased to 3.10.
SET_DIRECTORY_PROPERTIES(PROPERTIES TEST_INCLUDE_FILE
"${CMAKE_CURRENT_LIST_DIR}/cmake/ec_backslashes.cmake")

# Test for EditorConfig file in parent directory
new_ec_test(parent_directory parent_directory.in parent_directory/test.a "^key=value[ \t\n\r]*$")

Expand Down Expand Up @@ -70,14 +62,11 @@ if(WIN32)
else(WIN32)
set(path_separator_backslash_in_cmd_line_regex "^[ \t\n\r]*$")
endif(WIN32)
string(ASCII 36 Dollar)
new_ec_test_full_ec_file_path(path_separator_backslash_in_cmd_line
path_separator.in
"${CMAKE_CURRENT_SOURCE_DIR}\${BackSlashes}path\${BackSlashes}separator"
"${CMAKE_CURRENT_SOURCE_DIR}\\path\\separator"
${path_separator_backslash_in_cmd_line_regex})
# - \${BackSlashes} so that the resulting CTestTestfile.cmake will
# include the reference ${BackSlashes} in the generated add_test() line.
# - $BackSlashes is defined in ./cmake/ec_backslashes.cmake, included
# by the TEST_INCLUDE_FILE line above.

# Tests path separator match below top of path
new_ec_test(nested_path_separator path_separator.in nested/path/separator "^[ \t\n\r]*$")
Expand Down
39 changes: 0 additions & 39 deletions filetree/cmake/ec_backslashes.cmake

This file was deleted.

0 comments on commit 9ff938e

Please sign in to comment.