Tests: Add test for bad foreach inside a function

Add test for a case fixed by commit 6a4a61d9e1 (cmForEachCommand:
prevent leakage, 2017-10-09).  Prior to that fix, this test case
could trigger an assertion failure.

Fixes: #17464
This commit is contained in:
Brad King
2017-11-16 11:06:11 -05:00
parent c1930caffe
commit fb114a40aa
6 changed files with 18 additions and 0 deletions

View File

@@ -218,6 +218,7 @@ add_RunCMake_test(find_library)
add_RunCMake_test(find_package)
add_RunCMake_test(find_path)
add_RunCMake_test(find_program -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME})
add_RunCMake_test(foreach)
add_RunCMake_test(get_filename_component)
add_RunCMake_test(get_property)
add_RunCMake_test(if)

View File

@@ -0,0 +1 @@
1

View File

@@ -0,0 +1,5 @@
^CMake Error at BadRangeInFunction.cmake:2 \(foreach\):
foreach called with incorrect range specification: start 2, stop 1, step 1
Call Stack \(most recent call first\):
BadRangeInFunction.cmake:5 \(func\)
CMakeLists.txt:3 \(include\)$

View File

@@ -0,0 +1,5 @@
function(func)
foreach(bad_range RANGE 2 1 1)
endforeach()
endfunction()
func()

View File

@@ -0,0 +1,3 @@
cmake_minimum_required(VERSION 3.10)
project(${RunCMake_TEST} NONE)
include(${RunCMake_TEST}.cmake)

View File

@@ -0,0 +1,3 @@
include(RunCMake)
run_cmake(BadRangeInFunction)