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:
FeRD (Frank Dana)
2022-06-05 13:18:16 -04:00
parent b7ddfcfe08
commit d8dcfa7776
15 changed files with 136 additions and 0 deletions

View File

@@ -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)

View File

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

View 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\".*

View 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
)

View File

@@ -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\".*

View 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
)

View File

@@ -0,0 +1,5 @@
include(RunCMake)
run_cmake(Variables)
run_cmake(Properties)
run_cmake(PropertiesSources)

View File

@@ -0,0 +1 @@
-- source_dir="src" ; binary_dir="build"

View File

@@ -0,0 +1,6 @@
set(source_dir "src")
set(binary_dir "build")
include(CMakePrintHelpers)
cmake_print_variables(source_dir binary_dir)

View File

@@ -0,0 +1,6 @@
#include "nothing.h"
void nothing()
{
(void*)0;
}

View File

@@ -0,0 +1,8 @@
#ifndef NOTHING_H
#define NOTHING_H
#include <stdlib.h>
void nothing();
#endif

View 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;
}
}
}

View File

@@ -0,0 +1,9 @@
#ifndef ROT13_H
#define ROT13_H
#include <stdlib.h>
#include <string.h>
void rot13(char* in);
#endif

View File

@@ -0,0 +1,7 @@
#include "something.h"
int main()
{
nothing();
return 0;
}

View File

@@ -0,0 +1,8 @@
#ifndef SOMETHING_H
#define SOMETHING_H
#include <stdlib.h>
#include "nothing.h"
#endif