mirror of
https://github.com/Kitware/CMake.git
synced 2026-02-18 05:01:50 -06:00
Tests: Add tests for CMakePrintHelpers
Add three tests in Tests/RunCMake/PrintHelpers, meant to verify basic functionality of the module. Tests are: * Variables: Test the results of a cmake_print_variables() call on two variables set within the test script. * Properties: Test cmake_print_properties() calls on a pair of SOURCES and a pair of TARGETS, printing some basic properties. * PropertiesSources: Specifically verify the results of a cmake_print_properties() call for the SOURCES property of a TARGET. Prior to the fix introduced alongside these tests, it was a known bug that such a request caused a FATAL_ERROR.
This commit is contained in:
@@ -464,6 +464,7 @@ add_RunCMake_test(load_cache)
|
||||
add_RunCMake_test(math)
|
||||
add_RunCMake_test(message)
|
||||
add_RunCMake_test(option)
|
||||
add_RunCMake_test(PrintHelpers)
|
||||
add_RunCMake_test(project -DCMake_TEST_RESOURCES=${CMake_TEST_RESOURCES})
|
||||
add_RunCMake_test(project_injected)
|
||||
add_RunCMake_test(DependencyProviders)
|
||||
|
||||
3
Tests/RunCMake/PrintHelpers/CMakeLists.txt
Normal file
3
Tests/RunCMake/PrintHelpers/CMakeLists.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
cmake_minimum_required(VERSION 3.23)
|
||||
project(${RunCMake_TEST} C)
|
||||
include(${RunCMake_TEST}.cmake)
|
||||
14
Tests/RunCMake/PrintHelpers/Properties-stdout.txt
Normal file
14
Tests/RunCMake/PrintHelpers/Properties-stdout.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
.*Properties for TARGET nothing:.*
|
||||
.*nothing.LINKER_LANGUAGE = <NOTFOUND>.*
|
||||
.*nothing.TYPE = \"STATIC_LIBRARY\".*
|
||||
.*Properties for TARGET something:.*
|
||||
.*something.LINKER_LANGUAGE = <NOTFOUND>.*
|
||||
.*something.TYPE = \"EXECUTABLE\".*
|
||||
+
|
||||
.*
|
||||
.*Properties for SOURCE nothing.c:.*
|
||||
.*nothing.c.COMPILE_DEFINITIONS = <NOTFOUND>.*
|
||||
.*nothing.c.LANGUAGE = \"C\".*
|
||||
.*Properties for SOURCE something.c:.*
|
||||
.*something.c.COMPILE_DEFINITIONS = \"SOMETHING=1\".*
|
||||
.*something.c.LANGUAGE = \"C\".*
|
||||
26
Tests/RunCMake/PrintHelpers/Properties.cmake
Normal file
26
Tests/RunCMake/PrintHelpers/Properties.cmake
Normal file
@@ -0,0 +1,26 @@
|
||||
enable_language(C)
|
||||
|
||||
set_property(SOURCE nothing.c PROPERTY LANGUAGE C)
|
||||
set_property(SOURCE something.c PROPERTY
|
||||
COMPILE_DEFINITIONS SOMETHING=1)
|
||||
|
||||
add_library(nothing STATIC nothing.c nothing.h)
|
||||
|
||||
add_executable(something something.c something.h)
|
||||
target_link_libraries(something PUBLIC nothing)
|
||||
|
||||
include(CMakePrintHelpers)
|
||||
|
||||
cmake_print_properties(
|
||||
TARGETS nothing something
|
||||
PROPERTIES
|
||||
LINKER_LANGUAGE
|
||||
TYPE
|
||||
)
|
||||
|
||||
cmake_print_properties(
|
||||
SOURCES nothing.c something.c
|
||||
PROPERTIES
|
||||
COMPILE_DEFINITIONS
|
||||
LANGUAGE
|
||||
)
|
||||
@@ -0,0 +1,8 @@
|
||||
.*Properties for TARGET rot13:.*
|
||||
.*rot13.SOURCES = \"rot13.c;rot13.h\".*
|
||||
.*rot13.POSITION_INDEPENDENT_CODE = \"True\".*
|
||||
+
|
||||
.*--.*
|
||||
.*Properties for SOURCE rot13.c:.*
|
||||
.*rot13.c.LOCATION = \"[^\"]*/PrintHelpers/rot13.c\".*
|
||||
.*rot13.c.LANGUAGE = \"C\".*
|
||||
19
Tests/RunCMake/PrintHelpers/PropertiesSources.cmake
Normal file
19
Tests/RunCMake/PrintHelpers/PropertiesSources.cmake
Normal file
@@ -0,0 +1,19 @@
|
||||
set_property(SOURCE rot13.c PROPERTY LANGUAGE C)
|
||||
|
||||
add_library(rot13 SHARED rot13.c rot13.h)
|
||||
|
||||
include(CMakePrintHelpers)
|
||||
|
||||
cmake_print_properties(
|
||||
TARGETS rot13
|
||||
PROPERTIES
|
||||
SOURCES
|
||||
POSITION_INDEPENDENT_CODE
|
||||
)
|
||||
|
||||
cmake_print_properties(
|
||||
SOURCES rot13.c
|
||||
PROPERTIES
|
||||
LOCATION
|
||||
LANGUAGE
|
||||
)
|
||||
5
Tests/RunCMake/PrintHelpers/RunCMakeTest.cmake
Normal file
5
Tests/RunCMake/PrintHelpers/RunCMakeTest.cmake
Normal file
@@ -0,0 +1,5 @@
|
||||
include(RunCMake)
|
||||
|
||||
run_cmake(Variables)
|
||||
run_cmake(Properties)
|
||||
run_cmake(PropertiesSources)
|
||||
1
Tests/RunCMake/PrintHelpers/Variables-stdout.txt
Normal file
1
Tests/RunCMake/PrintHelpers/Variables-stdout.txt
Normal file
@@ -0,0 +1 @@
|
||||
-- source_dir="src" ; binary_dir="build"
|
||||
6
Tests/RunCMake/PrintHelpers/Variables.cmake
Normal file
6
Tests/RunCMake/PrintHelpers/Variables.cmake
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
set(source_dir "src")
|
||||
set(binary_dir "build")
|
||||
|
||||
include(CMakePrintHelpers)
|
||||
cmake_print_variables(source_dir binary_dir)
|
||||
6
Tests/RunCMake/PrintHelpers/nothing.c
Normal file
6
Tests/RunCMake/PrintHelpers/nothing.c
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "nothing.h"
|
||||
|
||||
void nothing()
|
||||
{
|
||||
(void*)0;
|
||||
}
|
||||
8
Tests/RunCMake/PrintHelpers/nothing.h
Normal file
8
Tests/RunCMake/PrintHelpers/nothing.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef NOTHING_H
|
||||
#define NOTHING_H
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
void nothing();
|
||||
|
||||
#endif
|
||||
15
Tests/RunCMake/PrintHelpers/rot13.c
Normal file
15
Tests/RunCMake/PrintHelpers/rot13.c
Normal file
@@ -0,0 +1,15 @@
|
||||
#include "rot13.h"
|
||||
|
||||
void rot13(char* in)
|
||||
{
|
||||
char* end = in + strlen(in);
|
||||
for (char* c = in; c < end; c++) {
|
||||
if (*c >= 'a' && *c <= 'z') {
|
||||
*c += (*c < 'n') ? 13 : -13;
|
||||
continue;
|
||||
}
|
||||
if (*c >= 'A' && *c <= 'Z') {
|
||||
*c += (*c < 'N') ? 13 : -13;
|
||||
}
|
||||
}
|
||||
}
|
||||
9
Tests/RunCMake/PrintHelpers/rot13.h
Normal file
9
Tests/RunCMake/PrintHelpers/rot13.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef ROT13_H
|
||||
#define ROT13_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void rot13(char* in);
|
||||
|
||||
#endif
|
||||
7
Tests/RunCMake/PrintHelpers/something.c
Normal file
7
Tests/RunCMake/PrintHelpers/something.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "something.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
nothing();
|
||||
return 0;
|
||||
}
|
||||
8
Tests/RunCMake/PrintHelpers/something.h
Normal file
8
Tests/RunCMake/PrintHelpers/something.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef SOMETHING_H
|
||||
#define SOMETHING_H
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "nothing.h"
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user