From 1b078c304db63eb6cd46fe0f22988f8241a389b2 Mon Sep 17 00:00:00 2001 From: Petr Kmoch Date: Sat, 29 Sep 2012 14:41:07 +0200 Subject: Add tests for list() invalid arguments Add tests for error reporting when list() arguments are invalid. --- Tests/CMakeTests/List-Get-Invalid-Index.cmake | 2 ++ Tests/CMakeTests/List-Insert-Invalid-Index.cmake | 2 ++ Tests/CMakeTests/List-Invalid-Subcommand.cmake | 1 + .../CMakeTests/List-Remove_At-Invalid-Index.cmake | 2 ++ .../List-Remove_At-Nonexistent-List.cmake | 2 ++ .../List-Remove_Duplicates-Nonexistent-List.cmake | 2 ++ .../List-Remove_Item-Nonexistent-List.cmake | 2 ++ .../CMakeTests/List-Reverse-Nonexistent-List.cmake | 2 ++ Tests/CMakeTests/List-Sort-Nonexistent-List.cmake | 2 ++ Tests/CMakeTests/ListTest.cmake.in | 22 ++++++++++++++++++++++ 10 files changed, 39 insertions(+) create mode 100644 Tests/CMakeTests/List-Get-Invalid-Index.cmake create mode 100644 Tests/CMakeTests/List-Insert-Invalid-Index.cmake create mode 100644 Tests/CMakeTests/List-Invalid-Subcommand.cmake create mode 100644 Tests/CMakeTests/List-Remove_At-Invalid-Index.cmake create mode 100644 Tests/CMakeTests/List-Remove_At-Nonexistent-List.cmake create mode 100644 Tests/CMakeTests/List-Remove_Duplicates-Nonexistent-List.cmake create mode 100644 Tests/CMakeTests/List-Remove_Item-Nonexistent-List.cmake create mode 100644 Tests/CMakeTests/List-Reverse-Nonexistent-List.cmake create mode 100644 Tests/CMakeTests/List-Sort-Nonexistent-List.cmake diff --git a/Tests/CMakeTests/List-Get-Invalid-Index.cmake b/Tests/CMakeTests/List-Get-Invalid-Index.cmake new file mode 100644 index 0000000..178295a --- /dev/null +++ b/Tests/CMakeTests/List-Get-Invalid-Index.cmake @@ -0,0 +1,2 @@ +set(mylist alpha bravo charlie) +list(GET mylist 3 result) diff --git a/Tests/CMakeTests/List-Insert-Invalid-Index.cmake b/Tests/CMakeTests/List-Insert-Invalid-Index.cmake new file mode 100644 index 0000000..4103d97 --- /dev/null +++ b/Tests/CMakeTests/List-Insert-Invalid-Index.cmake @@ -0,0 +1,2 @@ +set(mylist alpha bravo charlie) +list(INSERT mylist 3 delta) diff --git a/Tests/CMakeTests/List-Invalid-Subcommand.cmake b/Tests/CMakeTests/List-Invalid-Subcommand.cmake new file mode 100644 index 0000000..40f2345 --- /dev/null +++ b/Tests/CMakeTests/List-Invalid-Subcommand.cmake @@ -0,0 +1 @@ +list(NO_SUCH_SUBCOMMAND) diff --git a/Tests/CMakeTests/List-Remove_At-Invalid-Index.cmake b/Tests/CMakeTests/List-Remove_At-Invalid-Index.cmake new file mode 100644 index 0000000..d4f3921 --- /dev/null +++ b/Tests/CMakeTests/List-Remove_At-Invalid-Index.cmake @@ -0,0 +1,2 @@ +set(mylist alpha bravo charlie) +list(REMOVE_AT mylist 3) diff --git a/Tests/CMakeTests/List-Remove_At-Nonexistent-List.cmake b/Tests/CMakeTests/List-Remove_At-Nonexistent-List.cmake new file mode 100644 index 0000000..5266c7f --- /dev/null +++ b/Tests/CMakeTests/List-Remove_At-Nonexistent-List.cmake @@ -0,0 +1,2 @@ +unset(nosuchlist) +list(REMOVE_AT nosuchlist 0) diff --git a/Tests/CMakeTests/List-Remove_Duplicates-Nonexistent-List.cmake b/Tests/CMakeTests/List-Remove_Duplicates-Nonexistent-List.cmake new file mode 100644 index 0000000..218f227 --- /dev/null +++ b/Tests/CMakeTests/List-Remove_Duplicates-Nonexistent-List.cmake @@ -0,0 +1,2 @@ +unset(nosuchlist) +list(REMOVE_DUPLICATES nosuchlist) diff --git a/Tests/CMakeTests/List-Remove_Item-Nonexistent-List.cmake b/Tests/CMakeTests/List-Remove_Item-Nonexistent-List.cmake new file mode 100644 index 0000000..079e7fb --- /dev/null +++ b/Tests/CMakeTests/List-Remove_Item-Nonexistent-List.cmake @@ -0,0 +1,2 @@ +unset(nosuchlist) +list(REMOVE_ITEM nosuchlist alpha) diff --git a/Tests/CMakeTests/List-Reverse-Nonexistent-List.cmake b/Tests/CMakeTests/List-Reverse-Nonexistent-List.cmake new file mode 100644 index 0000000..977e2cc --- /dev/null +++ b/Tests/CMakeTests/List-Reverse-Nonexistent-List.cmake @@ -0,0 +1,2 @@ +unset(nosuchlist) +list(REVERSE nosuchlist) diff --git a/Tests/CMakeTests/List-Sort-Nonexistent-List.cmake b/Tests/CMakeTests/List-Sort-Nonexistent-List.cmake new file mode 100644 index 0000000..8f48e10 --- /dev/null +++ b/Tests/CMakeTests/List-Sort-Nonexistent-List.cmake @@ -0,0 +1,2 @@ +unset(nosuchlist) +list(SORT nosuchlist) diff --git a/Tests/CMakeTests/ListTest.cmake.in b/Tests/CMakeTests/ListTest.cmake.in index 27858c0..b11a295 100644 --- a/Tests/CMakeTests/ListTest.cmake.in +++ b/Tests/CMakeTests/ListTest.cmake.in @@ -133,6 +133,19 @@ set(Remove_Duplicates-Too-Many-Arguments-STDERR ".*CMake Error at (@CMAKE_CURREN 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() check_cmake_test(List No-Arguments @@ -140,4 +153,13 @@ check_cmake_test(List 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 ) -- cgit v0.12