Merge topic 'start-contributing-irc-session'
828d4f5
Add several get_property() tests82106e3
GetProperty test: move doc property tests into main process56125a3
list: add tests for CMP0007 behavior48ed48f
Add test to secure the file(GLOB empty) behavior.c2a6cb6
file: remove dead code07251a8
Consolidate list() argument count testing1b078c3
Add tests for list() invalid argumentsf560977
Add tests for list() argument countd211e5d
CMakeTests: allow to call the check_cmake_test macro with a given file
This commit is contained in:
commit
9f1d379471
|
@ -22,6 +22,7 @@
|
|||
#endif
|
||||
|
||||
#undef GetCurrentDirectory
|
||||
#include <assert.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
|
@ -705,11 +706,8 @@ bool cmFileCommand::HandleStringsCommand(std::vector<std::string> const& args)
|
|||
bool cmFileCommand::HandleGlobCommand(std::vector<std::string> const& args,
|
||||
bool recurse)
|
||||
{
|
||||
if ( args.size() < 2 )
|
||||
{
|
||||
this->SetError("GLOB requires at least a variable name");
|
||||
return false;
|
||||
}
|
||||
// File commands has at least one argument
|
||||
assert(args.size() > 1);
|
||||
|
||||
std::vector<std::string>::const_iterator i = args.begin();
|
||||
|
||||
|
@ -843,11 +841,8 @@ bool cmFileCommand::HandleGlobCommand(std::vector<std::string> const& args,
|
|||
bool cmFileCommand::HandleMakeDirectoryCommand(
|
||||
std::vector<std::string> const& args)
|
||||
{
|
||||
if(args.size() < 2 )
|
||||
{
|
||||
this->SetError("called with incorrect number of arguments");
|
||||
return false;
|
||||
}
|
||||
// File command has at least one argument
|
||||
assert(args.size() > 1);
|
||||
|
||||
std::vector<std::string>::const_iterator i = args.begin();
|
||||
|
||||
|
|
|
@ -15,13 +15,14 @@
|
|||
|
||||
#include <stdlib.h> // required for atoi
|
||||
#include <ctype.h>
|
||||
#include <assert.h>
|
||||
//----------------------------------------------------------------------------
|
||||
bool cmListCommand
|
||||
::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
|
||||
{
|
||||
if(args.size() < 1)
|
||||
if(args.size() < 2)
|
||||
{
|
||||
this->SetError("must be called with at least one argument.");
|
||||
this->SetError("must be called with at least two arguments.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -243,11 +244,7 @@ bool cmListCommand::HandleGetCommand(std::vector<std::string> const& args)
|
|||
//----------------------------------------------------------------------------
|
||||
bool cmListCommand::HandleAppendCommand(std::vector<std::string> const& args)
|
||||
{
|
||||
if(args.size() < 2)
|
||||
{
|
||||
this->SetError("sub-command APPEND requires at least one argument.");
|
||||
return false;
|
||||
}
|
||||
assert(args.size() >= 2);
|
||||
|
||||
// Skip if nothing to append.
|
||||
if(args.size() < 3)
|
||||
|
@ -424,12 +421,8 @@ bool cmListCommand
|
|||
bool cmListCommand
|
||||
::HandleReverseCommand(std::vector<std::string> const& args)
|
||||
{
|
||||
if(args.size() < 2)
|
||||
{
|
||||
this->SetError("sub-command REVERSE requires a list as an argument.");
|
||||
return false;
|
||||
}
|
||||
else if(args.size() > 2)
|
||||
assert(args.size() >= 2);
|
||||
if(args.size() > 2)
|
||||
{
|
||||
this->SetError(
|
||||
"sub-command REVERSE only takes one argument.");
|
||||
|
@ -463,13 +456,8 @@ bool cmListCommand
|
|||
bool cmListCommand
|
||||
::HandleRemoveDuplicatesCommand(std::vector<std::string> const& args)
|
||||
{
|
||||
if(args.size() < 2)
|
||||
{
|
||||
this->SetError(
|
||||
"sub-command REMOVE_DUPLICATES requires a list as an argument.");
|
||||
return false;
|
||||
}
|
||||
else if(args.size() > 2)
|
||||
assert(args.size() >= 2);
|
||||
if(args.size() > 2)
|
||||
{
|
||||
this->SetError(
|
||||
"sub-command REMOVE_DUPLICATES only takes one argument.");
|
||||
|
@ -513,12 +501,8 @@ bool cmListCommand
|
|||
bool cmListCommand
|
||||
::HandleSortCommand(std::vector<std::string> const& args)
|
||||
{
|
||||
if(args.size() < 2)
|
||||
{
|
||||
this->SetError("sub-command SORT requires a list as an argument.");
|
||||
return false;
|
||||
}
|
||||
else if(args.size() > 2)
|
||||
assert(args.size() >= 2);
|
||||
if(args.size() > 2)
|
||||
{
|
||||
this->SetError(
|
||||
"sub-command SORT only takes one argument.");
|
||||
|
|
|
@ -1,30 +1,35 @@
|
|||
get_filename_component(CMakeTests_SRC_DIR ${CMAKE_CURRENT_LIST_FILE} PATH)
|
||||
|
||||
function(check_cmake_test_single prefix test testfile)
|
||||
message(STATUS "Test ${prefix}-${test}...")
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_COMMAND} -P "${testfile}"
|
||||
WORKING_DIRECTORY "${CMakeTests_BIN_DIR}"
|
||||
OUTPUT_VARIABLE stdout
|
||||
ERROR_VARIABLE stderr
|
||||
RESULT_VARIABLE result
|
||||
)
|
||||
string(REGEX REPLACE "\n" "\n out> " out " out> ${stdout}")
|
||||
string(REGEX REPLACE "\n" "\n err> " err " err> ${stderr}")
|
||||
if(NOT "${result}" STREQUAL "${${test}-RESULT}")
|
||||
message(FATAL_ERROR
|
||||
"Test ${test} result is [${result}], not [${${test}-RESULT}].\n"
|
||||
"Test ${test} output:\n"
|
||||
"${out}\n"
|
||||
"${err}")
|
||||
endif()
|
||||
if(${test}-STDERR AND NOT "${err}" MATCHES "${${test}-STDERR}")
|
||||
message(FATAL_ERROR
|
||||
"Test ${test} stderr does not match\n ${${test}-STDERR}\n"
|
||||
"Test ${test} output:\n"
|
||||
"${out}\n"
|
||||
"${err}")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(check_cmake_test prefix)
|
||||
get_filename_component(CMakeTests_BIN_DIR ${CMAKE_CURRENT_LIST_FILE} PATH)
|
||||
foreach(test ${ARGN})
|
||||
message(STATUS "Test ${prefix}-${test}...")
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_COMMAND} -P "${CMakeTests_SRC_DIR}/${prefix}-${test}.cmake"
|
||||
WORKING_DIRECTORY "${CMakeTests_BIN_DIR}"
|
||||
OUTPUT_VARIABLE stdout
|
||||
ERROR_VARIABLE stderr
|
||||
RESULT_VARIABLE result
|
||||
)
|
||||
string(REGEX REPLACE "\n" "\n out> " out " out> ${stdout}")
|
||||
string(REGEX REPLACE "\n" "\n err> " err " err> ${stderr}")
|
||||
if(NOT "${result}" STREQUAL "${${test}-RESULT}")
|
||||
message(FATAL_ERROR
|
||||
"Test ${test} result is [${result}], not [${${test}-RESULT}].\n"
|
||||
"Test ${test} output:\n"
|
||||
"${out}\n"
|
||||
"${err}")
|
||||
endif()
|
||||
if(${test}-STDERR AND NOT "${err}" MATCHES "${${test}-STDERR}")
|
||||
message(FATAL_ERROR
|
||||
"Test ${test} stderr does not match\n ${${test}-STDERR}\n"
|
||||
"Test ${test} output:\n"
|
||||
"${out}\n"
|
||||
"${err}")
|
||||
endif()
|
||||
check_cmake_test_single("${prefix}" "${test}" "${CMakeTests_SRC_DIR}/${prefix}-${test}.cmake")
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
# Checking that the call without arguments get caught by the file global protection.
|
||||
file(GLOB)
|
|
@ -12,6 +12,10 @@ set(Copy-NoDest-RESULT 1)
|
|||
set(Copy-NoDest-STDERR "given no DESTINATION")
|
||||
set(Copy-NoFile-RESULT 1)
|
||||
set(Copy-NoFile-STDERR "COPY cannot find.*/does_not_exist\\.txt")
|
||||
set(Glob-NoArg-RESULT 1)
|
||||
set(Glob-NoArg-STDERR "file must be called with at least two arguments")
|
||||
set(Make_Directory-NoArg-RESULT 1)
|
||||
set(Make-Directory-NoArg-STDERR "file must be called with at least two arguments")
|
||||
set(MD5-NoFile-RESULT 1)
|
||||
set(MD5-NoFile-STDERR "file MD5 failed to read file")
|
||||
set(MD5-BadArg1-RESULT 1)
|
||||
|
@ -42,6 +46,8 @@ check_cmake_test(File
|
|||
Copy-LateArg
|
||||
Copy-NoDest
|
||||
Copy-NoFile
|
||||
Glob-NoArg
|
||||
Make_Directory-NoArg
|
||||
MD5-NoFile
|
||||
MD5-BadArg1
|
||||
MD5-BadArg2
|
||||
|
@ -54,6 +60,11 @@ check_cmake_test(File
|
|||
SHA512-Works
|
||||
)
|
||||
|
||||
file(GLOB hum)
|
||||
if (NOT hum STREQUAL "")
|
||||
message(FATAL_ERROR "file(GLOB hum) did not return an empty string.")
|
||||
endif()
|
||||
|
||||
# Also execute each test listed in FileTestScript.cmake:
|
||||
#
|
||||
set(scriptname "@CMAKE_CURRENT_SOURCE_DIR@/FileTestScript.cmake")
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
get_property(FOO_BRIEF GLOBAL PROPERTY FOO BRIEF_DOCS)
|
||||
get_property(FOO_FULL GLOBAL PROPERTY FOO FULL_DOCS)
|
||||
|
||||
if (NOT FOO_BRIEF STREQUAL "NOTFOUND")
|
||||
message(SEND_ERROR "property FOO has BRIEF_DOCS set to '${FOO_BRIEF}'")
|
||||
endif ()
|
||||
|
||||
if (NOT FOO_FULL STREQUAL "NOTFOUND")
|
||||
message(SEND_ERROR "property FOO has FULL_DOCS set to '${FOO_FULL}'")
|
||||
endif ()
|
|
@ -1,5 +1,33 @@
|
|||
include("@CMAKE_CURRENT_SOURCE_DIR@/CheckCMakeTest.cmake")
|
||||
|
||||
get_property(FOO_BRIEF GLOBAL PROPERTY FOO BRIEF_DOCS)
|
||||
get_property(FOO_FULL GLOBAL PROPERTY FOO FULL_DOCS)
|
||||
|
||||
if (NOT FOO_BRIEF STREQUAL "NOTFOUND")
|
||||
message(SEND_ERROR "property FOO has BRIEF_DOCS set to '${FOO_BRIEF}'")
|
||||
endif ()
|
||||
|
||||
if (NOT FOO_FULL STREQUAL "NOTFOUND")
|
||||
message(SEND_ERROR "property FOO has FULL_DOCS set to '${FOO_FULL}'")
|
||||
endif ()
|
||||
|
||||
get_property(test_brief GLOBAL PROPERTY ENABLED_FEATURES BRIEF_DOCS)
|
||||
get_property(test_full GLOBAL PROPERTY ENABLED_FEATURES FULL_DOCS)
|
||||
|
||||
if(test_brief STREQUAL "NOTFOUND")
|
||||
message(SEND_ERROR "property ENABLED_FEATURES has no BRIEF_DOCS")
|
||||
endif()
|
||||
|
||||
if(test_full STREQUAL "NOTFOUND")
|
||||
message(SEND_ERROR "property ENABLED_FEATURES has no FULL_DOCS")
|
||||
endif()
|
||||
|
||||
set(test_var alpha)
|
||||
get_property(result VARIABLE PROPERTY test_var)
|
||||
if(NOT result STREQUAL "alpha")
|
||||
message(SEND_ERROR "bad value of VARIABLE PROPERTY test_var: got '${result}' instead of 'alpha'")
|
||||
endif()
|
||||
|
||||
set(Missing-Argument-RESULT 1)
|
||||
set(Missing-Argument-STDERR ".*CMake Error at (@CMAKE_CURRENT_SOURCE_DIR@/)?GetProperty-Missing-Argument.cmake:1 \\(get_property\\):.*get_property called with incorrect number of arguments.*")
|
||||
|
||||
|
@ -28,12 +56,6 @@ check_cmake_test(GetProperty
|
|||
No-Property
|
||||
)
|
||||
|
||||
set(Doc-Properties-RESULT 0)
|
||||
|
||||
check_cmake_test(GetProperty
|
||||
Doc-Properties
|
||||
)
|
||||
|
||||
set(Global-Name-RESULT 1)
|
||||
set(Global-Name-STDERR ".*CMake Error at (@CMAKE_CURRENT_SOURCE_DIR@/)?GetProperty-Global-Name.cmake:1 \\(get_property\\):.*get_property given name for GLOBAL scope\\..*")
|
||||
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
set(thelist "" NEW OLD)
|
||||
|
||||
list(GET thelist 1 thevalue)
|
||||
if (NOT thevalue STREQUAL "OLD")
|
||||
message(SEND_ERROR "returned element '${thevalue}', but expected 'OLD'")
|
||||
endif()
|
|
@ -0,0 +1,2 @@
|
|||
set(mylist alpha bravo charlie)
|
||||
list(GET mylist 3 result)
|
|
@ -0,0 +1,2 @@
|
|||
set(mylist alpha bravo charlie)
|
||||
list(INSERT mylist 3 delta)
|
|
@ -0,0 +1 @@
|
|||
list(NO_SUCH_SUBCOMMAND mylist)
|
|
@ -0,0 +1 @@
|
|||
list(LENGTH mylist result one_too_many)
|
|
@ -0,0 +1 @@
|
|||
list()
|
|
@ -0,0 +1,2 @@
|
|||
set(mylist alpha bravo charlie)
|
||||
list(REMOVE_AT mylist 3)
|
|
@ -0,0 +1,2 @@
|
|||
unset(nosuchlist)
|
||||
list(REMOVE_AT nosuchlist 0)
|
|
@ -0,0 +1,2 @@
|
|||
unset(nosuchlist)
|
||||
list(REMOVE_DUPLICATES nosuchlist)
|
|
@ -0,0 +1 @@
|
|||
list(REMOVE_DUPLICATES mylist one_too_many)
|
|
@ -0,0 +1,2 @@
|
|||
unset(nosuchlist)
|
||||
list(REMOVE_ITEM nosuchlist alpha)
|
|
@ -0,0 +1,2 @@
|
|||
unset(nosuchlist)
|
||||
list(REVERSE nosuchlist)
|
|
@ -0,0 +1 @@
|
|||
list(REVERSE mylist one_too_many)
|
|
@ -0,0 +1,2 @@
|
|||
unset(nosuchlist)
|
||||
list(SORT nosuchlist)
|
|
@ -0,0 +1 @@
|
|||
list(SORT mylist one_too_many)
|
|
@ -1,3 +1,5 @@
|
|||
include("@CMAKE_CURRENT_SOURCE_DIR@/CheckCMakeTest.cmake")
|
||||
|
||||
macro(TEST command expected)
|
||||
if("x${result}" STREQUAL "x${expected}")
|
||||
#message("TEST \"${command}\" success: \"${result}\" expected: \"${expected}\"")
|
||||
|
@ -97,3 +99,89 @@ TEST("REVERSE empty result" "")
|
|||
|
||||
list(SORT result)
|
||||
TEST("SORT empty result" "")
|
||||
|
||||
set(No-Arguments-RESULT 1)
|
||||
set(No-Arguments-STDERR ".*CMake Error at (@CMAKE_CURRENT_SOURCE_DIR@/)?List-No-Arguments.cmake:1 \\(list\\):.*list must be called with at least two arguments.*")
|
||||
|
||||
# these trigger top-level condition
|
||||
foreach(cmd IN ITEMS Append Find Get Insert Length Reverse Remove_At Remove_Duplicates Remove_Item Sort)
|
||||
set(${cmd}-No-Arguments-RESULT 1)
|
||||
set(${cmd}-No-Arguments-STDERR ".*CMake Error at List-${cmd}-No-Arguments.cmake:1 \\(list\\):.*list must be called with at least two arguments.*")
|
||||
string(TOUPPER ${cmd} cmd_upper)
|
||||
set(_test_file_name "${CMAKE_CURRENT_BINARY_DIR}/List-${cmd}-No-Arguments.cmake")
|
||||
file(WRITE "${_test_file_name}" "list(${cmd_upper})\n")
|
||||
check_cmake_test_single(List "${cmd}-No-Arguments" "${_test_file_name}")
|
||||
endforeach()
|
||||
|
||||
set(Get-List-Only-STDERR "at least three")
|
||||
set(Find-List-Only-STDERR "three")
|
||||
set(Insert-List-Only-STDERR "at least three")
|
||||
set(Length-List-Only-STDERR "two")
|
||||
set(Remove_At-List-Only-STDERR "at least two")
|
||||
set(Remove_Item-List-Only-STDERR "two or more")
|
||||
|
||||
foreach(cmd IN ITEMS Find Get Insert Length Remove_At Remove_Item)
|
||||
string(TOUPPER ${cmd} cmd_upper)
|
||||
set(${cmd}-List-Only-RESULT 1)
|
||||
set(${cmd}-List-Only-STDERR ".*CMake Error at List-${cmd}-List-Only.cmake:1 \\(list\\):.*list sub-command ${cmd_upper} requires ${${cmd}-List-Only-STDERR} arguments.*")
|
||||
set(_test_file_name "${CMAKE_CURRENT_BINARY_DIR}/List-${cmd}-List-Only.cmake")
|
||||
file(WRITE "${_test_file_name}" "list(${cmd_upper} mylist)\n")
|
||||
check_cmake_test_single(List "${cmd}-List-Only" "${_test_file_name}")
|
||||
endforeach()
|
||||
|
||||
set(Length-Too-Many-Arguments-RESULT 1)
|
||||
set(Length-Too-Many-Arguments-STDERR ".*CMake Error at (@CMAKE_CURRENT_SOURCE_DIR@/)?List-Length-Too-Many-Arguments.cmake:1 \\(list\\):.*list sub-command LENGTH requires two arguments.*")
|
||||
|
||||
set(Reverse-Too-Many-Arguments-RESULT 1)
|
||||
set(Reverse-Too-Many-Arguments-STDERR ".*CMake Error at (@CMAKE_CURRENT_SOURCE_DIR@/)?List-Reverse-Too-Many-Arguments.cmake:1 \\(list\\):.*list sub-command REVERSE only takes one argument.*")
|
||||
|
||||
set(Remove_Duplicates-Too-Many-Arguments-RESULT 1)
|
||||
set(Remove_Duplicates-Too-Many-Arguments-STDERR ".*CMake Error at (@CMAKE_CURRENT_SOURCE_DIR@/)?List-Remove_Duplicates-Too-Many-Arguments.cmake:1 \\(list\\):.*list sub-command REMOVE_DUPLICATES only takes one argument.*")
|
||||
|
||||
set(Sort-Too-Many-Arguments-RESULT 1)
|
||||
set(Sort-Too-Many-Arguments-STDERR ".*CMake Error at (@CMAKE_CURRENT_SOURCE_DIR@/)?List-Sort-Too-Many-Arguments.cmake:1 \\(list\\):.*list sub-command SORT only takes one argument.*")
|
||||
|
||||
set(Invalid-Subcommand-RESULT 1)
|
||||
set(Invalid-Subcommand-STDERR ".*CMake Error at (@CMAKE_CURRENT_SOURCE_DIR@/)?List-Invalid-Subcommand.cmake:1 \\(list\\):.*list does not recognize sub-command NO_SUCH_SUBCOMMAND.*")
|
||||
|
||||
foreach(cmd Get Insert Remove_At)
|
||||
set(${cmd}-Invalid-Index-RESULT 1)
|
||||
set(${cmd}-Invalid-Index-STDERR ".*CMake Error at (@CMAKE_CURRENT_SOURCE_DIR@/)?List-${cmd}-Invalid-Index.cmake:2 \\(list\\):.*list index: 3 out of range \\(-3, 2\\).*")
|
||||
endforeach()
|
||||
|
||||
foreach(cmd Remove_Item Reverse Remove_Duplicates Sort Remove_At)
|
||||
string(TOUPPER ${cmd} Cmd)
|
||||
set(${cmd}-Nonexistent-List-RESULT 1)
|
||||
set(${cmd}-Nonexistent-List-STDERR ".*CMake Error at (@CMAKE_CURRENT_SOURCE_DIR@/)?List-${cmd}-Nonexistent-List.cmake:2 \\(list\\):.*sub-command ${Cmd} requires list to be present.*")
|
||||
endforeach()
|
||||
|
||||
set(Get-CMP0007-Warn-RESULT 0)
|
||||
set(Get-CMP0007-Warn-STDERR ".*CMake Warning \\(dev\\) at (@CMAKE_CURRENT_SOURCE_DIR@/)?List-Get-CMP0007-Warn.cmake:3 \\(list\\):.*Policy CMP0007 is not set:.*")
|
||||
|
||||
check_cmake_test(List
|
||||
No-Arguments
|
||||
Length-Too-Many-Arguments
|
||||
Reverse-Too-Many-Arguments
|
||||
Remove_Duplicates-Too-Many-Arguments
|
||||
Sort-Too-Many-Arguments
|
||||
Invalid-Subcommand
|
||||
Get-Invalid-Index
|
||||
Insert-Invalid-Index
|
||||
Remove_Item-Nonexistent-List
|
||||
Reverse-Nonexistent-List
|
||||
Remove_Duplicates-Nonexistent-List
|
||||
Sort-Nonexistent-List
|
||||
Remove_At-Nonexistent-List
|
||||
Remove_At-Invalid-Index
|
||||
Get-CMP0007-Warn
|
||||
)
|
||||
|
||||
set(thelist "" NEW OLD)
|
||||
|
||||
foreach (_pol ${thelist})
|
||||
cmake_policy(SET CMP0007 ${_pol})
|
||||
list(GET thelist 1 thevalue)
|
||||
if (NOT thevalue STREQUAL _pol)
|
||||
message(SEND_ERROR "returned element '${thevalue}', but expected '${_pol}'")
|
||||
endif()
|
||||
endforeach (_pol)
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
file(MAKE_DIRECTORY)
|
Loading…
Reference in New Issue