Tests: Add environment generator tests

This commit is contained in:
Eicke Herbertz 2019-05-04 23:54:58 +02:00 committed by Brad King
parent a48ce8f4bf
commit d0f0ba0f7a
24 changed files with 128 additions and 0 deletions

View File

@ -23,4 +23,10 @@ if(NOT CTEST_CONFIGURATION_TYPE)
message("Guessing configuration ${CTEST_CONFIGURATION_TYPE}")
endif()
# Isolate tests from user configuration in the environment.
unset(ENV{CMAKE_GENERATOR})
unset(ENV{CMAKE_GENERATOR_INSTANCE})
unset(ENV{CMAKE_GENERATOR_PLATFORM})
unset(ENV{CMAKE_GENERATOR_TOOLSET})
@TEST_HOME_ENV_CODE@

View File

@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.14)
project(EnvGenerator C)
if(CMAKE_GENERATOR MATCHES "Visual Studio")
message(STATUS "CMAKE_VS_PLATFORM_NAME='${CMAKE_VS_PLATFORM_NAME}'")
endif()
add_custom_command(
OUTPUT output.txt
COMMAND ${CMAKE_COMMAND} -E echo CustomCommand > output.txt
)
add_custom_target(CustomTarget ALL DEPENDS output.txt)

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,2 @@
^CMake Error at CMakeLists.+
No CMAKE_C_COMPILER could be found.

View File

@ -0,0 +1,2 @@
^CMake Error at CMakeLists.+
.+Platform='fromcli'.+

View File

@ -0,0 +1 @@
-- CMAKE_VS_PLATFORM_NAME='(x64|Win32)'

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,2 @@
^CMake Error at CMakeLists.+
.+(Platform Toolset = 'fromcli'|Specified platform toolset \(fromcli\) is not installed or invalid).+

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,5 @@
^CMake Error: No generator specified for -G
CMake Error: CMAKE_GENERATOR was set but the specified generator doesn't exist. Using CMake default.
Generators.*
\* (Unix Makefiles|Visual Studio).*

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,2 @@
^CMake Error at CMakeLists.+
could not find specified instance of Visual Studio.+

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,4 @@
^CMake Error: No generator specified for -G
Generators.*
\* Ninja.*

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,2 @@
^CMake Error at CMakeLists.+
No CMAKE_C_COMPILER could be found.

View File

@ -0,0 +1,2 @@
^CMake Error at CMakeLists.+
.+Platform='invalid'.+

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,2 @@
^CMake Error at CMakeLists.+
.+(Platform Toolset = 'invalid'|Specified platform toolset \(invalid\) is not installed or invalid).+

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,4 @@
^CMake Error: No generator specified for -G
Generators.*
\* (Unix Makefiles|Visual Studio).*

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,7 @@
^Warning: Environment variable CMAKE_GENERATOR_INSTANCE will be ignored, because CMAKE_GENERATOR is not set.
Warning: Environment variable CMAKE_GENERATOR_PLATFORM will be ignored, because CMAKE_GENERATOR is not set.
Warning: Environment variable CMAKE_GENERATOR_TOOLSET will be ignored, because CMAKE_GENERATOR is not set.
CMake Error: No generator specified for -G
Generators.*
\* (Unix Makefiles|Visual Studio).*

View File

@ -164,6 +164,74 @@ function(run_BuildDir)
endfunction()
run_BuildDir()
function(run_EnvironmentGenerator)
set(source_dir ${RunCMake_SOURCE_DIR}/EnvGenerator)
set(ENV{CMAKE_GENERATOR_INSTANCE} "instance")
set(ENV{CMAKE_GENERATOR_PLATFORM} "platform")
set(ENV{CMAKE_GENERATOR_TOOLSET} "toolset")
run_cmake_command(Envgen-warnings ${CMAKE_COMMAND} -G)
unset(ENV{CMAKE_GENERATOR_INSTANCE})
unset(ENV{CMAKE_GENERATOR_PLATFORM})
unset(ENV{CMAKE_GENERATOR_TOOLSET})
# Test CMAKE_GENERATOR without actual configuring
run_cmake_command(Envgen-unset ${CMAKE_COMMAND} -G)
set(ENV{CMAKE_GENERATOR} "Ninja")
run_cmake_command(Envgen-ninja ${CMAKE_COMMAND} -G)
set(ENV{CMAKE_GENERATOR} "NoSuchGenerator")
run_cmake_command(Envgen-bad ${CMAKE_COMMAND} -G)
unset(ENV{CMAKE_GENERATOR})
if(RunCMake_GENERATOR MATCHES "Visual Studio.*")
set(ENV{CMAKE_GENERATOR} "${RunCMake_GENERATOR}")
run_cmake_command(Envgen ${CMAKE_COMMAND} ${source_dir})
# Toolset is available since VS 2010.
if(RunCMake_GENERATOR MATCHES "Visual Studio [1-9][0-9]")
set(ENV{CMAKE_GENERATOR_TOOLSET} "invalid")
# Envvar shouldn't affect existing build tree
run_cmake_command(Envgen-toolset-existing ${CMAKE_COMMAND} -E chdir ..
${CMAKE_COMMAND} --build Envgen-build)
run_cmake_command(Envgen-toolset-invalid ${CMAKE_COMMAND} ${source_dir})
# Command line -G implies -T""
run_cmake_command(Envgen-G-implicit-toolset ${CMAKE_COMMAND} -G "${RunCMake_GENERATOR}" ${source_dir})
run_cmake_command(Envgen-T-toolset ${CMAKE_COMMAND} -T "fromcli" ${source_dir})
unset(ENV{CMAKE_GENERATOR_TOOLSET})
endif()
# Platform can be set only if not in generator name.
if(RunCMake_GENERATOR MATCHES "^Visual Studio [0-9]+ [0-9]+$")
set(ENV{CMAKE_GENERATOR_PLATFORM} "invalid")
# Envvar shouldn't affect existing build tree
run_cmake_command(Envgen-platform-existing ${CMAKE_COMMAND} -E chdir ..
${CMAKE_COMMAND} --build Envgen-build)
if(RunCMake_GENERATOR MATCHES "^Visual Studio 9 ")
set(RunCMake-stderr-file "Envgen-platform-invalid-stderr-vs9.txt")
endif()
run_cmake_command(Envgen-platform-invalid ${CMAKE_COMMAND} ${source_dir})
unset(RunCMake-stderr-file)
# Command line -G implies -A""
run_cmake_command(Envgen-G-implicit-platform ${CMAKE_COMMAND} -G "${RunCMake_GENERATOR}" ${source_dir})
if(RunCMake_GENERATOR MATCHES "^Visual Studio 9 ")
set(RunCMake-stderr-file "Envgen-A-platform-stderr-vs9.txt")
endif()
run_cmake_command(Envgen-A-platform ${CMAKE_COMMAND} -A "fromcli" ${source_dir})
unset(RunCMake-stderr-file)
unset(ENV{CMAKE_GENERATOR_PLATFORM})
endif()
# Instance is available since VS 2017.
if(RunCMake_GENERATOR MATCHES "Visual Studio (15|16).*")
set(ENV{CMAKE_GENERATOR_INSTANCE} "invalid")
# Envvar shouldn't affect existing build tree
run_cmake_command(Envgen-instance-existing ${CMAKE_COMMAND} -E chdir ..
${CMAKE_COMMAND} --build Envgen-build)
run_cmake_command(Envgen-instance-invalid ${CMAKE_COMMAND} ${source_dir})
unset(ENV{CMAKE_GENERATOR_INSTANCE})
endif()
unset(ENV{CMAKE_GENERATOR})
endif()
endfunction()
run_EnvironmentGenerator()
if(RunCMake_GENERATOR STREQUAL "Ninja")
# Use a single build tree for a few tests without cleaning.
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/Build-build)