From 32318c9919e55a79dc1ef8b5dbbcdbc409a35403 Mon Sep 17 00:00:00 2001 From: Andre Sailer <andre.philippe.sailer@cern.ch> Date: Tue, 16 Aug 2022 13:41:21 +0200 Subject: [PATCH] DDTest: add test to ensure GrammarParsed/Unparsed are not includable, fix pragma for error Unknown pragma error --- DDCore/include/DD4hep/GrammarParsed.h | 2 +- DDCore/include/DD4hep/GrammarUnparsed.h | 2 +- DDTest/CMakeLists.txt | 16 ++++++++++++++++ DDTest/src/test_failToCompileGrammar.cc | 8 ++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 DDTest/src/test_failToCompileGrammar.cc diff --git a/DDCore/include/DD4hep/GrammarParsed.h b/DDCore/include/DD4hep/GrammarParsed.h index 95785c647..ebf2e6059 100644 --- a/DDCore/include/DD4hep/GrammarParsed.h +++ b/DDCore/include/DD4hep/GrammarParsed.h @@ -22,7 +22,7 @@ #define DD4HEP_GRAMMARPARSED_H #if defined(DD4HEP_GRAMMARUNPARSED_H) -#pragma error "The header files GrammarParsed.h and GrammarUnparsed.h may not be included in the same compilation unit!" +#error "The header files GrammarParsed.h and GrammarUnparsed.h may not be included in the same compilation unit!" #endif /// Framework include files diff --git a/DDCore/include/DD4hep/GrammarUnparsed.h b/DDCore/include/DD4hep/GrammarUnparsed.h index 68036d292..aa0a53362 100644 --- a/DDCore/include/DD4hep/GrammarUnparsed.h +++ b/DDCore/include/DD4hep/GrammarUnparsed.h @@ -22,7 +22,7 @@ #define DD4HEP_GRAMMARUNPARSED_H #if defined(DD4HEP_GRAMMARPARSED_H) -#pragma error "The header files GrammarParsed.h and GrammarUnparsed.h may not be included in the same compilation unit!" +#error "The header files GrammarParsed.h and GrammarUnparsed.h may not be included in the same compilation unit!" #endif // Framework include files diff --git a/DDTest/CMakeLists.txt b/DDTest/CMakeLists.txt index d12761d7f..aa6d658f2 100644 --- a/DDTest/CMakeLists.txt +++ b/DDTest/CMakeLists.txt @@ -96,3 +96,19 @@ if (DD4HEP_USE_GEANT4) endif() install(DIRECTORY include/DD4hep DESTINATION include) + + +# Test that GrammarUnparsed and GrammarParsed fail to be compiled +add_executable(test_failToCompile src/test_failToCompileGrammar.cc) +target_link_libraries(test_failToCompile DD4hep::DDCore) +# Avoid building these targets normally +set_target_properties(test_failToCompile PROPERTIES + EXCLUDE_FROM_ALL TRUE + EXCLUDE_FROM_DEFAULT_BUILD TRUE) + +add_test(NAME TestFailToCompile + COMMAND ${CMAKE_COMMAND} --build . --target test_failToCompile --config $<CONFIGURATION> + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) +set_tests_properties(TestFailToCompile + PROPERTIES + PASS_REGULAR_EXPRESSION "The header files GrammarParsed.h and GrammarUnparsed.h may not be included in the same compilation unit") diff --git a/DDTest/src/test_failToCompileGrammar.cc b/DDTest/src/test_failToCompileGrammar.cc new file mode 100644 index 000000000..2b1f2022c --- /dev/null +++ b/DDTest/src/test_failToCompileGrammar.cc @@ -0,0 +1,8 @@ +#include <DD4hep/GrammarParsed.h> +#include <DD4hep/GrammarUnparsed.h> + + +int main () +{ + return 0; +} -- GitLab