From fe390a2607afcd8f0985a54990236a3ea16643ab Mon Sep 17 00:00:00 2001
From: Ben Boeckel <ben.boeckel@kitware.com>
Date: Thu, 7 Oct 2010 12:29:43 -0400
Subject: Add 'ArgumentExpansion' test

---
 Tests/ArgumentExpansion/CMakeLists.txt | 59 ++++++++++++++++++++++++++++++++++
 Tests/CMakeLists.txt                   | 15 +++++++++
 2 files changed, 74 insertions(+)
 create mode 100644 Tests/ArgumentExpansion/CMakeLists.txt

diff --git a/Tests/ArgumentExpansion/CMakeLists.txt b/Tests/ArgumentExpansion/CMakeLists.txt
new file mode 100644
index 0000000..bd78169
--- /dev/null
+++ b/Tests/ArgumentExpansion/CMakeLists.txt
@@ -0,0 +1,59 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(ArgumentExpansion)
+
+function (argument_tester expected expected_len)
+    list(LENGTH ARGN argn_len)
+    list(LENGTH ${expected} expected_received_len)
+
+    if (NOT ${expected_received_len} EQUAL ${expected_len})
+        message(STATUS "Error: Expanding expected values isn't working")
+    endif (NOT ${expected_received_len} EQUAL ${expected_len})
+
+    if (${argn_len} EQUAL ${expected_len})
+        set(i 0)
+        while (i LESS ${argn_len})
+            list(GET ARGN ${i} argn_value)
+            list(GET ${expected} ${i} expected_value)
+
+            if (NOT ${argn_value} STREQUAL ${expected_value})
+                message(STATUS "Error: Argument ${i} doesn't match")
+                message(STATUS "    Expected: ${expected_value}")
+                message(STATUS "    Received: ${argn_value}")
+            endif (NOT ${argn_value} STREQUAL ${expected_value})
+
+            math(EXPR i "${i} + 1")
+        endwhile (i LESS ${argn_len})
+    else (${argn_len} EQUAL ${expected_len})
+        message(STATUS "Error: Lengths of arguments don't match")
+        message(STATUS "    Expected: ${expected_len}")
+        message(STATUS "    Received: ${argn_len}")
+    endif (${argn_len} EQUAL ${expected_len})
+endfunction (argument_tester expected)
+
+set(empty_test)
+message(STATUS "Test: Empty arguments")
+argument_tester(empty_test 0 ${empty_test})
+
+set(single_arg_test
+    "single arg")
+message(STATUS "Test: Single argument")
+argument_tester(single_arg_test 1 ${single_arg_test})
+
+set(multiple_arg_test
+    "first arg"
+    "second arg")
+message(STATUS "Test: Multiple arguments")
+argument_tester(multiple_arg_test 2 ${multiple_arg_test})
+
+set(nested_list_arg_test
+    "${multiple_arg_test}"
+    "first arg"
+    "second arg")
+message(STATUS "Test: Nested list argument")
+argument_tester(nested_list_arg_test 3 ${nested_list_arg_test})
+
+set(semicolon_arg_test
+    "pre\;post")
+message(STATUS "Test: Semicolon argument")
+argument_tester(semicolon_arg_test 1 ${semicolon_arg_test})
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt
index 739dcdf..a725354 100644
--- a/Tests/CMakeLists.txt
+++ b/Tests/CMakeLists.txt
@@ -368,6 +368,21 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=master -P ${CMake_SOURCE_DIR}/Utilities/
     )
   LIST(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/CustComDepend")
 
+  ADD_TEST(ArgumentExpansion  ${CMAKE_CTEST_COMMAND}
+    --build-and-test
+    "${CMake_SOURCE_DIR}/Tests/ArgumentExpansion"
+    "${CMake_BINARY_DIR}/Tests/ArgumentExpansion"
+    --build-generator ${CMAKE_TEST_GENERATOR}
+    --build-project ArgumentExpansion
+    --build-makeprogram ${CMAKE_TEST_MAKEPROGRAM}
+    --build-exe-dir "${CMake_BINARY_DIR}/Tests/ArgumentExpansion/bin"
+    )
+  IF(CMAKE_STRICT)
+    SET_TESTS_PROPERTIES(ArgumentExpansion PROPERTIES
+      FAIL_REGULAR_EXPRESSION "Error: ")
+  ENDIF(CMAKE_STRICT)
+  LIST(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/ArgumentExpansion")
+
   ADD_TEST(CustomCommand  ${CMAKE_CTEST_COMMAND}
     --build-and-test
     "${CMake_SOURCE_DIR}/Tests/CustomCommand"
-- 
cgit v0.12