| 1 |
# |
| 2 |
# Copyright (c) 2011-2018 EditorConfig Team |
| 3 |
# All rights reserved. |
| 4 |
# |
| 5 |
# Redistribution and use in source and binary forms, with or without |
| 6 |
# modification, are permitted provided that the following conditions are met: |
| 7 |
# |
| 8 |
# 1. Redistributions of source code must retain the above copyright notice, |
| 9 |
# this list of conditions and the following disclaimer. |
| 10 |
# 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 |
# this list of conditions and the following disclaimer in the documentation |
| 12 |
# and/or other materials provided with the distribution. |
| 13 |
# |
| 14 |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 15 |
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 16 |
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 17 |
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 18 |
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 19 |
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 20 |
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 21 |
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 22 |
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 23 |
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 24 |
# POSSIBILITY OF SUCH DAMAGE. |
| 25 |
# |
| 26 |
|
| 27 |
# New escape-sequence processing. |
| 28 |
cmake_minimum_required(VERSION 3.16.3) |
| 29 |
cmake_policy(VERSION 3.16.3) |
| 30 |
|
| 31 |
# Don't check any language compiler. This project is for EditorConfig Core |
| 32 |
# testing only. |
| 33 |
project(editorconfig-core-test NONE) |
| 34 |
|
| 35 |
# Where this file lives |
| 36 |
set(tests_cmakelists_dir "${CMAKE_CURRENT_LIST_DIR}") |
| 37 |
message(STATUS "Tests are in ${tests_cmakelists_dir}") |
| 38 |
|
| 39 |
# Only when we are using editorconfig-core-test independently should we check |
| 40 |
# cmake version, set EDITORCONFIG_CMD as cache string, and enable_testing() |
| 41 |
# here. |
| 42 |
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) |
| 43 |
set(EDITORCONFIG_CMD "editorconfig" CACHE STRING "editorconfig command.") |
| 44 |
set(EDITORCONFIG_CMD_IS_TARGET OFF CACHE BOOL |
| 45 |
"EDITORCONFIG_CMD names a CMake target rather than an executable.") |
| 46 |
enable_testing() |
| 47 |
message(STATUS "tests: Standalone testing enabled") |
| 48 |
endif() |
| 49 |
|
| 50 |
if(${EDITORCONFIG_CMD_IS_TARGET}) |
| 51 |
message(STATUS "tests: Using editorconfig target ${EDITORCONFIG_CMD}") |
| 52 |
else() |
| 53 |
message(STATUS "tests: Using editorconfig binary ${EDITORCONFIG_CMD}") |
| 54 |
endif() |
| 55 |
|
| 56 |
# The most common test function |
| 57 |
function(new_ec_test name ec_file src_file regex) |
| 58 |
add_test(NAME ${name} COMMAND ${EDITORCONFIG_CMD} -f ${ec_file} |
| 59 |
"${CMAKE_CURRENT_SOURCE_DIR}/${src_file}") |
| 60 |
set_tests_properties(${name} PROPERTIES PASS_REGULAR_EXPRESSION "${regex}") |
| 61 |
endfunction() |
| 62 |
|
| 63 |
# A test that requires a version specified |
| 64 |
function(new_ec_test_version name ec_file src_file regex version) |
| 65 |
add_test(NAME ${name} COMMAND ${EDITORCONFIG_CMD} -b ${version} -f ${ec_file} |
| 66 |
"${CMAKE_CURRENT_SOURCE_DIR}/${src_file}") |
| 67 |
set_tests_properties(${name} PROPERTIES PASS_REGULAR_EXPRESSION "${regex}") |
| 68 |
endfunction() |
| 69 |
|
| 70 |
# A test that requires the full path to the EditorConfig files |
| 71 |
function(new_ec_test_full_ec_file_path name ec_file src_file regex) |
| 72 |
add_test(NAME ${name} COMMAND ${EDITORCONFIG_CMD} -f ${ec_file} ${src_file}) |
| 73 |
set_tests_properties(${name} PROPERTIES PASS_REGULAR_EXPRESSION "${regex}") |
| 74 |
endfunction() |
| 75 |
|
| 76 |
# A test that returns multiple lines of output. CAUTION: filenames used in |
| 77 |
# these tests may not contain semicolons. |
| 78 |
function(new_ec_test_multiline name ec_file src_file regex) |
| 79 |
#message(STATUS "Building multiline test ${name} with tests_cmakelists_dir ${tests_cmakelists_dir}") |
| 80 |
#message(STATUS "List dir ${CMAKE_CURRENT_LIST_DIR}, source dir ${CMAKE_CURRENT_SOURCE_DIR}") |
| 81 |
if(${EDITORCONFIG_CMD_IS_TARGET}) |
| 82 |
add_test(NAME ${name} COMMAND "cmake" |
| 83 |
"-D" "EDITORCONFIG_CMD=$<TARGET_FILE:${EDITORCONFIG_CMD}>" |
| 84 |
# Since variables aren't automatically passed to the inner cmake |
| 85 |
"-D" "ECARGS:LIST=-f;${ec_file};${CMAKE_CURRENT_SOURCE_DIR}/${src_file}" |
| 86 |
# Note: the semicolons separate list elements. |
| 87 |
"-P" "${tests_cmakelists_dir}/cmake/ec_sort.cmake") |
| 88 |
else() |
| 89 |
add_test(NAME ${name} COMMAND "cmake" |
| 90 |
"-D" "EDITORCONFIG_CMD=${EDITORCONFIG_CMD}" |
| 91 |
# Since variables aren't automatically passed to the inner cmake |
| 92 |
"-D" "ECARGS:LIST=-f;${ec_file};${CMAKE_CURRENT_SOURCE_DIR}/${src_file}" |
| 93 |
# Note: the semicolons separate list elements. |
| 94 |
"-P" "${tests_cmakelists_dir}/cmake/ec_sort.cmake") |
| 95 |
endif() |
| 96 |
|
| 97 |
set_tests_properties(${name} PROPERTIES PASS_REGULAR_EXPRESSION |
| 98 |
"^[\r\n]*${regex}$") |
| 99 |
# Permit leading \n's because I can't always get rid of them using |
| 100 |
# only CMake-provided facilities. |
| 101 |
endfunction() |
| 102 |
|
| 103 |
# Tests for other CLI arguments. Usage: |
| 104 |
# new_ec_cli_test(NAME name MATCH pass_regex ARGS arguments...) |
| 105 |
function(new_ec_cli_test) |
| 106 |
# Parse args |
| 107 |
set(one_value_keywords NAME MATCH) |
| 108 |
set(multi_value_keywords ARGS) |
| 109 |
cmake_parse_arguments(P |
| 110 |
"" "${one_value_keywords}" "${multi_value_keywords}" ${ARGN}) |
| 111 |
|
| 112 |
# Add test |
| 113 |
add_test(NAME ${P_NAME} COMMAND ${EDITORCONFIG_CMD} ${P_ARGS}) |
| 114 |
set_tests_properties(${name} PROPERTIES PASS_REGULAR_EXPRESSION "${P_MATCH}") |
| 115 |
|
| 116 |
endfunction() |
| 117 |
|
| 118 |
# First, make sure the test harness works. |
| 119 |
add_subdirectory(meta) |
| 120 |
|
| 121 |
# Then test the core. |
| 122 |
add_subdirectory(glob) |
| 123 |
add_subdirectory(properties) |
| 124 |
add_subdirectory(parser) |
| 125 |
add_subdirectory(filetree) |
| 126 |
add_subdirectory(cli) |