mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-18 00:02:21 +08:00
color: Add tests for CMAKE_COLOR_DIAGNOSTICS
This commit is contained in:
@@ -278,6 +278,9 @@ endif()
|
||||
add_RunCMake_test(CMakeDependentOption)
|
||||
add_RunCMake_test(CMakeRoleGlobalProperty)
|
||||
add_RunCMake_test(CMakeRelease -DCMake_TEST_JQ=${CMake_TEST_JQ})
|
||||
if(CMAKE_GENERATOR MATCHES "Make|Ninja")
|
||||
add_RunCMake_test(Color)
|
||||
endif()
|
||||
if(UNIX AND "${CMAKE_GENERATOR}" MATCHES "Unix Makefiles|Ninja")
|
||||
add_RunCMake_test(CompilerChange)
|
||||
endif()
|
||||
|
3
Tests/RunCMake/Color/CMakeLists.txt
Normal file
3
Tests/RunCMake/Color/CMakeLists.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
cmake_minimum_required(VERSION 3.23)
|
||||
project(${RunCMake_TEST} NONE)
|
||||
include(${RunCMake_TEST}.cmake)
|
9
Tests/RunCMake/Color/DiagCommon.cmake
Normal file
9
Tests/RunCMake/Color/DiagCommon.cmake
Normal file
@@ -0,0 +1,9 @@
|
||||
enable_language(C)
|
||||
|
||||
set(CMAKE_C_COMPILE_OPTIONS_COLOR_DIAGNOSTICS -DCOLOR_ON)
|
||||
set(CMAKE_C_COMPILE_OPTIONS_COLOR_DIAGNOSTICS_OFF -DCOLOR_OFF)
|
||||
|
||||
add_library(diag STATIC diag.c)
|
||||
if(DEFINED EXPECT_COLOR)
|
||||
target_compile_definitions(diag PRIVATE EXPECT_COLOR=${EXPECT_COLOR})
|
||||
endif()
|
8
Tests/RunCMake/Color/DiagDefault.cmake
Normal file
8
Tests/RunCMake/Color/DiagDefault.cmake
Normal file
@@ -0,0 +1,8 @@
|
||||
include(DiagCommon.cmake)
|
||||
|
||||
if(DEFINED CMAKE_COLOR_DIAGNOSTICS)
|
||||
message(FATAL_ERROR "CMAKE_COLOR_DIAGNOSTICS incorrectly defined.")
|
||||
endif()
|
||||
if(CMAKE_GENERATOR MATCHES "Make" AND NOT DEFINED CMAKE_COLOR_MAKEFILE)
|
||||
message(FATAL_ERROR "CMAKE_COLOR_MAKEFILE incorrectly not defined.")
|
||||
endif()
|
6
Tests/RunCMake/Color/DiagOff.cmake
Normal file
6
Tests/RunCMake/Color/DiagOff.cmake
Normal file
@@ -0,0 +1,6 @@
|
||||
set(EXPECT_COLOR 0)
|
||||
include(DiagCommon.cmake)
|
||||
|
||||
if(DEFINED CMAKE_COLOR_MAKEFILE)
|
||||
message(FATAL_ERROR "CMAKE_COLOR_MAKEFILE incorrectly defined.")
|
||||
endif()
|
6
Tests/RunCMake/Color/DiagOn.cmake
Normal file
6
Tests/RunCMake/Color/DiagOn.cmake
Normal file
@@ -0,0 +1,6 @@
|
||||
set(EXPECT_COLOR 1)
|
||||
include(DiagCommon.cmake)
|
||||
|
||||
if(DEFINED CMAKE_COLOR_MAKEFILE)
|
||||
message(FATAL_ERROR "CMAKE_COLOR_MAKEFILE incorrectly defined.")
|
||||
endif()
|
14
Tests/RunCMake/Color/RunCMakeTest.cmake
Normal file
14
Tests/RunCMake/Color/RunCMakeTest.cmake
Normal file
@@ -0,0 +1,14 @@
|
||||
include(RunCMake)
|
||||
|
||||
unset(ENV{CMAKE_COLOR_DIAGNOSTICS})
|
||||
|
||||
function(run_Diag case)
|
||||
set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/Diag${case}-build")
|
||||
run_cmake_with_options(Diag${case} ${ARGN})
|
||||
set(RunCMake_TEST_NO_CLEAN 1)
|
||||
run_cmake_command(Diag${case}-build ${CMAKE_COMMAND} --build . --config Debug)
|
||||
endfunction()
|
||||
|
||||
run_Diag(On -DCMAKE_COLOR_DIAGNOSTICS=ON)
|
||||
run_Diag(Off -DCMAKE_COLOR_DIAGNOSTICS=OFF)
|
||||
run_Diag(Default)
|
28
Tests/RunCMake/Color/diag.c
Normal file
28
Tests/RunCMake/Color/diag.c
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifdef EXPECT_COLOR
|
||||
# if EXPECT_COLOR
|
||||
# ifndef COLOR_ON
|
||||
# error "COLOR_ON incorrectly not defined"
|
||||
# endif
|
||||
# ifdef COLOR_OFF
|
||||
# error "COLOR_OFF incorrectly defined"
|
||||
# endif
|
||||
# else
|
||||
# ifdef COLOR_ON
|
||||
# error "COLOR_ON incorrectly defined"
|
||||
# endif
|
||||
# ifndef COLOR_OFF
|
||||
# error "COLOR_OFF incorrectly not defined"
|
||||
# endif
|
||||
# endif
|
||||
#else
|
||||
# ifdef COLOR_ON
|
||||
# error "COLOR_ON incorrectly defined"
|
||||
# endif
|
||||
# ifdef COLOR_OFF
|
||||
# error "COLOR_OFF incorrectly defined"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
void diag(void)
|
||||
{
|
||||
}
|
6
Tests/RunCMake/CommandLine/EnvColorDefault.cmake
Normal file
6
Tests/RunCMake/CommandLine/EnvColorDefault.cmake
Normal file
@@ -0,0 +1,6 @@
|
||||
if(DEFINED CMAKE_COLOR_DIAGNOSTICS)
|
||||
message(FATAL_ERROR "CMAKE_COLOR_DIAGNOSTICS incorrectly defined.")
|
||||
endif()
|
||||
if(CMAKE_GENERATOR MATCHES "Make" AND NOT DEFINED CMAKE_COLOR_MAKEFILE)
|
||||
message(FATAL_ERROR "CMAKE_COLOR_MAKEFILE incorrectly not defined.")
|
||||
endif()
|
1
Tests/RunCMake/CommandLine/EnvColorOn-stdout.txt
Normal file
1
Tests/RunCMake/CommandLine/EnvColorOn-stdout.txt
Normal file
@@ -0,0 +1 @@
|
||||
-- CMAKE_COLOR_DIAGNOSTICS='ON'
|
4
Tests/RunCMake/CommandLine/EnvColorOn.cmake
Normal file
4
Tests/RunCMake/CommandLine/EnvColorOn.cmake
Normal file
@@ -0,0 +1,4 @@
|
||||
message(STATUS "CMAKE_COLOR_DIAGNOSTICS='${CMAKE_COLOR_DIAGNOSTICS}'")
|
||||
if(DEFINED CMAKE_COLOR_MAKEFILE)
|
||||
message(FATAL_ERROR "CMAKE_COLOR_MAKEFILE incorrectly defined.")
|
||||
endif()
|
@@ -416,6 +416,14 @@ function(run_EnvironmentToolchain)
|
||||
endfunction()
|
||||
run_EnvironmentToolchain()
|
||||
|
||||
function(run_EnvironmentColor)
|
||||
set(ENV{CMAKE_COLOR_DIAGNOSTICS} "ON")
|
||||
run_cmake(EnvColorOn)
|
||||
unset(ENV{CMAKE_COLOR_DIAGNOSTICS})
|
||||
run_cmake(EnvColorDefault)
|
||||
endfunction()
|
||||
run_EnvironmentColor()
|
||||
|
||||
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)
|
||||
|
Reference in New Issue
Block a user