diff options
author | Sebastien Barre <sebastien.barre@kitware.com> | 2002-01-18 17:03:32 (GMT) |
---|---|---|
committer | Sebastien Barre <sebastien.barre@kitware.com> | 2002-01-18 17:03:32 (GMT) |
commit | 914e051fd781b2f90e731e4bf967b5bcccc56962 (patch) | |
tree | 6543b6d67672291ecf91de40af8bf6742f52739f /Tests | |
parent | 6d1a312c7b9fb89d1f3e1da992941fec2e4df7ac (diff) | |
download | CMake-914e051fd781b2f90e731e4bf967b5bcccc56962.zip CMake-914e051fd781b2f90e731e4bf967b5bcccc56962.tar.gz CMake-914e051fd781b2f90e731e4bf967b5bcccc56962.tar.bz2 |
Increase coverage, add tests
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/Complex/CMakeLists.txt | 8 | ||||
-rw-r--r-- | Tests/Complex/Executable/complex.cxx | 158 | ||||
-rw-r--r-- | Tests/Complex/Library/CMakeLists.txt | 26 | ||||
-rw-r--r-- | Tests/Complex/Library/create_file.cxx | 2 | ||||
-rw-r--r-- | Tests/Complex/VarTests.txt | 31 | ||||
-rw-r--r-- | Tests/Complex/cmTestConfigure.h.in | 22 | ||||
-rw-r--r-- | Tests/ComplexOneConfig/CMakeLists.txt | 8 | ||||
-rw-r--r-- | Tests/ComplexOneConfig/Executable/complex.cxx | 158 | ||||
-rw-r--r-- | Tests/ComplexOneConfig/Library/CMakeLists.txt | 26 | ||||
-rw-r--r-- | Tests/ComplexOneConfig/Library/create_file.cxx | 2 | ||||
-rw-r--r-- | Tests/ComplexOneConfig/VarTests.txt | 31 | ||||
-rw-r--r-- | Tests/ComplexOneConfig/cmTestConfigure.h.in | 22 | ||||
-rw-r--r-- | Tests/ComplexRelativePaths/CMakeLists.txt | 8 | ||||
-rw-r--r-- | Tests/ComplexRelativePaths/Executable/complex.cxx | 158 | ||||
-rw-r--r-- | Tests/ComplexRelativePaths/Library/CMakeLists.txt | 26 | ||||
-rw-r--r-- | Tests/ComplexRelativePaths/Library/create_file.cxx | 2 | ||||
-rw-r--r-- | Tests/ComplexRelativePaths/VarTests.txt | 31 | ||||
-rw-r--r-- | Tests/ComplexRelativePaths/cmTestConfigure.h.in | 22 |
18 files changed, 660 insertions, 81 deletions
diff --git a/Tests/Complex/CMakeLists.txt b/Tests/Complex/CMakeLists.txt index 51a5656..10f270e 100644 --- a/Tests/Complex/CMakeLists.txt +++ b/Tests/Complex/CMakeLists.txt @@ -50,4 +50,12 @@ ENDIF (EXECUTABLE_OUTPUT_PATH) SUBDIRS(Library Executable) SUBDIR_DEPENDS(Executable Library) +# +# Exec program +# Increase coverage. +# +OPTION(EXEC_PROGRAM "Test EXEC_PROGRAM" ON) +IF (EXEC_PROGRAM) + EXEC_PROGRAM("echo EXEC_PROGRAM") +ENDIF (EXEC_PROGRAM) diff --git a/Tests/Complex/Executable/complex.cxx b/Tests/Complex/Executable/complex.cxx index f48ce99..5740dfc 100644 --- a/Tests/Complex/Executable/complex.cxx +++ b/Tests/Complex/Executable/complex.cxx @@ -29,6 +29,26 @@ void Passed(const char* Message, const char* m2="") passed++; } +void TestAndRemoveFile(const char* filename) +{ + struct stat fs; + if (stat(filename, &fs) != 0) + { + Failed("Could not find file: ", filename); + } + else + { + if (unlink(filename) != 0) + { + Failed("Unable to remove file. It does not imply that this test failed, but it *will* be corrupted thereafter if this file is not removed: ", filename); + } + else + { + Passed("Find and remove file: ", filename); + } + } +} + int main() { if(sharedFunction() != 1) @@ -82,6 +102,13 @@ int main() Passed("ONE_VAR is defined."); #endif +#ifndef ONE_VAR_IS_DEFINED + Failed("cmakedefine, SET or VARIABLE_REQUIRES is broken, " + "ONE_VAR_IS_DEFINED is not defined."); +#else + Passed("ONE_VAR_IS_DEFINED is defined."); +#endif + #ifdef ZERO_VAR Failed("cmakedefine is broken, ZERO_VAR is defined."); #else @@ -89,12 +116,11 @@ int main() #endif #ifndef STRING_VAR - Failed("configureFile is broken, STRING_VAR is not defined."); + Failed("the CONFIGURE_FILE command is broken, STRING_VAR is not defined."); #else if(strcmp(STRING_VAR, "CMake is great") != 0) { - Failed("CMake is not great, so the SET command," - "or the configurefile comand is broken. STRING_VAR== ", + Failed("the SET or CONFIGURE_FILE command is broken. STRING_VAR == ", STRING_VAR); } else @@ -103,28 +129,122 @@ int main() } #endif - // Attach a post-build custom-command to the lib. - // It run ${CREATE_FILE_EXE} which will create the file - // ${Complex_BINARY_DIR}/postbuild.txt. - // The 'complex' executable will then test if this file exists, - // and remove it. +#ifndef FOREACH_VAR1 + Failed("the FOREACH, SET or CONFIGURE_FILE command is broken, " + "FOREACH_VAR1 is not defined."); +#else + if(strcmp(FOREACH_VAR1, "VALUE1") != 0) + { + Failed("the FOREACH, SET or CONFIGURE_FILE command is broken, " + "FOREACH_VAR1 == ", FOREACH_VAR1); + } + else + { + Passed("FOREACH_VAR1 == ", FOREACH_VAR1); + } +#endif - struct stat fs; - if (stat(BINARY_DIR "/postbuild.txt", &fs) != 0) +#ifndef FOREACH_VAR2 + Failed("the FOREACH, SET or CONFIGURE_FILE command is broken, " + "FOREACH_VAR2 is not defined."); +#else + if(strcmp(FOREACH_VAR2, "VALUE2") != 0) { - Failed("Could not find " BINARY_DIR "/postbuild.txt (created as a post-build custom command for the shared lib)."); + Failed("the FOREACH, SET or CONFIGURE_FILE command is broken, " + "FOREACH_VAR2 == ", FOREACH_VAR2); } else { - if (unlink(BINARY_DIR "/postbuild.txt") != 0) - { - Failed("Unable to remove " BINARY_DIR "/postbuild.txt (does not imply that this test failed, but it *will* be corrupted thereafter if this file is not removed)."); - } - else - { - Passed("Find and remove " BINARY_DIR "/postbuild.txt (created as a post-build custom command for the shared lib)."); - } + Passed("FOREACH_VAR2 == ", FOREACH_VAR2); + } +#endif + +#ifndef FILENAME_VAR_PATH_NAME + Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " + "FILENAME_VAR_PATH_NAME is not defined."); +#else + if(strcmp(FILENAME_VAR_PATH_NAME, "Complex") != 0) + { + Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " + "FILENAME_VAR_PATH_NAME == ", FILENAME_VAR_PATH_NAME); + } + else + { + Passed("FILENAME_VAR_PATH_NAME == ", FILENAME_VAR_PATH_NAME); } +#endif + +#ifndef FILENAME_VAR_NAME + Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " + "FILENAME_VAR_NAME is not defined."); +#else + if(strcmp(FILENAME_VAR_NAME, "VarTests.txt") != 0) + { + Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " + "FILENAME_VAR_NAME == ", FILENAME_VAR_NAME); + } + else + { + Passed("FILENAME_VAR_NAME == ", FILENAME_VAR_NAME); + } +#endif + +#ifndef FILENAME_VAR_EXT + Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " + "FILENAME_VAR_EXT is not defined."); +#else + if(strcmp(FILENAME_VAR_EXT, ".txt") != 0) + { + Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " + "FILENAME_VAR_EXT == ", FILENAME_VAR_EXT); + } + else + { + Passed("FILENAME_VAR_EXT == ", FILENAME_VAR_EXT); + } +#endif + +#ifndef FILENAME_VAR_NAME_WE + Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " + "FILENAME_VAR_NAME_WE is not defined."); +#else + if(strcmp(FILENAME_VAR_NAME_WE, "VarTests") != 0) + { + Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " + "FILENAME_VAR_NAME_WE == ", FILENAME_VAR_NAME_WE); + } + else + { + Passed("FILENAME_VAR_NAME_WE == ", FILENAME_VAR_NAME_WE); + } +#endif + +#ifndef PATH_VAR_NAME + Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " + "PATH_VAR_NAME is not defined."); +#else + if(strcmp(PATH_VAR_NAME, "Complex") != 0) + { + Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " + "PATH_VAR_NAME == ", PATH_VAR_NAME); + } + else + { + Passed("PATH_VAR_NAME == ", PATH_VAR_NAME); + } +#endif + + // A post-build custom-command has been attached to the lib. + // It run ${CREATE_FILE_EXE} which will create the file + // ${Complex_BINARY_DIR}/postbuild.txt. + + TestAndRemoveFile(BINARY_DIR "/postbuild.txt"); + + // A custom target has been created. + // It run ${CREATE_FILE_EXE} which will create the file + // ${Complex_BINARY_DIR}/custom_target1.txt. + + TestAndRemoveFile(BINARY_DIR "/custom_target1.txt"); std::cout << "Passed: " << passed << "\n"; if(failed) diff --git a/Tests/Complex/Library/CMakeLists.txt b/Tests/Complex/Library/CMakeLists.txt index 73f5ab4..473f2b3 100644 --- a/Tests/Complex/Library/CMakeLists.txt +++ b/Tests/Complex/Library/CMakeLists.txt @@ -1,24 +1,44 @@ AUX_SOURCE_DIRECTORY(ExtraSources LibrarySources) -SOURCE_FILES(LibrarySources file2) +# SOURCE_FILES_REMOVE is used for Coverage +SOURCE_FILES(LibrarySources file2 GENERATED create_file.cxx) +SOURCE_FILES_REMOVE(LibrarySources create_file.cxx) ADD_LIBRARY(CMakeTestLibrary LibrarySources) SOURCE_FILES(SharedLibrarySources sharedFile) ADD_LIBRARY(CMakeTestLibraryShared SHARED SharedLibrarySources) +# +# Small utility used to create file +# UTILITY_SOURCE(CREATE_FILE_EXE create_file "." create_file.cxx) ADD_EXECUTABLE(create_file create_file.cxx) -ADD_DEPENDENCIES(CMakeTestLibraryShared create_file) - +# # Attach a post-build custom-command to the lib. # It run ${CREATE_FILE_EXE} which will create the file # ${Complex_BINARY_DIR}/postbuild.txt. # The 'complex' executable will then test if this file exists, # and remove it. +# +ADD_DEPENDENCIES(CMakeTestLibraryShared create_file) ADD_CUSTOM_COMMAND(SOURCE CMakeTestLibraryShared COMMAND ${CREATE_FILE_EXE} ARGS "${Complex_BINARY_DIR}/postbuild.txt" TARGET CMakeTestLibraryShared) +# +# Add custom target +# It run ${CREATE_FILE_EXE} which will create the file +# ${Complex_BINARY_DIR}/custom_target1.txt. +# The 'complex' executable will then test if this file exists, +# and remove it. +# +ADD_CUSTOM_TARGET(custom_target1 + ALL + ${CREATE_FILE_EXE} + "${Complex_BINARY_DIR}/custom_target1.txt") + +ADD_DEPENDENCIES(custom_target1 create_file) + diff --git a/Tests/Complex/Library/create_file.cxx b/Tests/Complex/Library/create_file.cxx index 68a9bb8..d415519 100644 --- a/Tests/Complex/Library/create_file.cxx +++ b/Tests/Complex/Library/create_file.cxx @@ -22,7 +22,7 @@ int main (int argc, char *argv[]) return EXIT_FAILURE; } - fprintf(stdout, "Creating %s!\n", argv[1]); + fprintf(stdout, ">> Creating %s!\n", argv[1]); return EXIT_SUCCESS; } diff --git a/Tests/Complex/VarTests.txt b/Tests/Complex/VarTests.txt index 0ff9953..0775636 100644 --- a/Tests/Complex/VarTests.txt +++ b/Tests/Complex/VarTests.txt @@ -1,11 +1,36 @@ - SET (ZERO_VAR 0) + IF(ZERO_VAR) -ADD_DEFINITIONS(-DSHOULD_NOT_BE_DEFINED) + ADD_DEFINITIONS(-DSHOULD_NOT_BE_DEFINED) ELSE(ZERO_VAR) -ADD_DEFINITIONS(-DSHOULD_BE_DEFINED) + ADD_DEFINITIONS(-DSHOULD_BE_DEFINED) ENDIF(ZERO_VAR) SET(ONE_VAR 1) +VARIABLE_REQUIRES(ONE_VAR + ONE_VAR_IS_DEFINED ONE_VAR) + SET(STRING_VAR "CMake is great" CACHE STRING "test a cache variable") + +FOREACH (INDEX 1 2) + SET(FOREACH_VAR${INDEX} "VALUE${INDEX}") +ENDFOREACH(INDEX) + +FIND_FILE(FILENAME_VAR "VarTests.txt" ${Complex_SOURCE_DIR}) + +GET_FILENAME_COMPONENT(FILENAME_VAR_PATH ${FILENAME_VAR} PATH) +GET_FILENAME_COMPONENT(FILENAME_VAR_PATH_NAME ${FILENAME_VAR_PATH} NAME) +GET_FILENAME_COMPONENT(FILENAME_VAR_NAME ${FILENAME_VAR} NAME) +GET_FILENAME_COMPONENT(FILENAME_VAR_EXT ${FILENAME_VAR} EXT) +GET_FILENAME_COMPONENT(FILENAME_VAR_NAME_WE ${FILENAME_VAR} NAME_WE) + +FIND_PATH(PATH_VAR "VarTests.txt" ${Complex_SOURCE_DIR}) +GET_FILENAME_COMPONENT(PATH_VAR_NAME ${PATH_VAR} NAME) + +# Coverage only + +BUILD_COMMAND(BUILD_COMMAND_VAR ${CMAKE_MAKE_PROGRAM}) +BUILD_NAME(BUILD_NAME_VAR) +SITE_NAME(SITE_NAME_VAR) + diff --git a/Tests/Complex/cmTestConfigure.h.in b/Tests/Complex/cmTestConfigure.h.in index 5c2563b..3c3e2fa 100644 --- a/Tests/Complex/cmTestConfigure.h.in +++ b/Tests/Complex/cmTestConfigure.h.in @@ -1,10 +1,30 @@ #cmakedefine ONE_VAR +#cmakedefine ONE_VAR_IS_DEFINED #cmakedefine ZERO_VAR + #define STRING_VAR "${STRING_VAR}" -#define BINARY_DIR "${Complex_BINARY_DIR}" +#define FOREACH_VAR1 "${FOREACH_VAR1}" +#define FOREACH_VAR2 "${FOREACH_VAR2}" + +#define FILENAME_VAR_PATH_NAME "${FILENAME_VAR_PATH_NAME}" +#define FILENAME_VAR_NAME "${FILENAME_VAR_NAME}" +#define FILENAME_VAR_EXT "${FILENAME_VAR_EXT}" +#define FILENAME_VAR_NAME_WE "${FILENAME_VAR_NAME_WE}" + +#define PATH_VAR_NAME "${PATH_VAR_NAME}" #cmakedefine CMAKE_NO_STD_NAMESPACE #cmakedefine CMAKE_NO_ANSI_STREAM_HEADERS #cmakedefine CMAKE_NO_ANSI_FOR_SCOPE +// Needed to check for files + +#define BINARY_DIR "${Complex_BINARY_DIR}" + +// Coverage only + +#define BUILD_COMMAND_VAR "${BUILD_COMMAND_VAR}" +#define BUILD_NAME_VAR "${BUILD_NAME_VAR}" +#define SITE_NAME_VAR "${SITE_NAME_VAR}" + diff --git a/Tests/ComplexOneConfig/CMakeLists.txt b/Tests/ComplexOneConfig/CMakeLists.txt index 51a5656..10f270e 100644 --- a/Tests/ComplexOneConfig/CMakeLists.txt +++ b/Tests/ComplexOneConfig/CMakeLists.txt @@ -50,4 +50,12 @@ ENDIF (EXECUTABLE_OUTPUT_PATH) SUBDIRS(Library Executable) SUBDIR_DEPENDS(Executable Library) +# +# Exec program +# Increase coverage. +# +OPTION(EXEC_PROGRAM "Test EXEC_PROGRAM" ON) +IF (EXEC_PROGRAM) + EXEC_PROGRAM("echo EXEC_PROGRAM") +ENDIF (EXEC_PROGRAM) diff --git a/Tests/ComplexOneConfig/Executable/complex.cxx b/Tests/ComplexOneConfig/Executable/complex.cxx index f48ce99..5740dfc 100644 --- a/Tests/ComplexOneConfig/Executable/complex.cxx +++ b/Tests/ComplexOneConfig/Executable/complex.cxx @@ -29,6 +29,26 @@ void Passed(const char* Message, const char* m2="") passed++; } +void TestAndRemoveFile(const char* filename) +{ + struct stat fs; + if (stat(filename, &fs) != 0) + { + Failed("Could not find file: ", filename); + } + else + { + if (unlink(filename) != 0) + { + Failed("Unable to remove file. It does not imply that this test failed, but it *will* be corrupted thereafter if this file is not removed: ", filename); + } + else + { + Passed("Find and remove file: ", filename); + } + } +} + int main() { if(sharedFunction() != 1) @@ -82,6 +102,13 @@ int main() Passed("ONE_VAR is defined."); #endif +#ifndef ONE_VAR_IS_DEFINED + Failed("cmakedefine, SET or VARIABLE_REQUIRES is broken, " + "ONE_VAR_IS_DEFINED is not defined."); +#else + Passed("ONE_VAR_IS_DEFINED is defined."); +#endif + #ifdef ZERO_VAR Failed("cmakedefine is broken, ZERO_VAR is defined."); #else @@ -89,12 +116,11 @@ int main() #endif #ifndef STRING_VAR - Failed("configureFile is broken, STRING_VAR is not defined."); + Failed("the CONFIGURE_FILE command is broken, STRING_VAR is not defined."); #else if(strcmp(STRING_VAR, "CMake is great") != 0) { - Failed("CMake is not great, so the SET command," - "or the configurefile comand is broken. STRING_VAR== ", + Failed("the SET or CONFIGURE_FILE command is broken. STRING_VAR == ", STRING_VAR); } else @@ -103,28 +129,122 @@ int main() } #endif - // Attach a post-build custom-command to the lib. - // It run ${CREATE_FILE_EXE} which will create the file - // ${Complex_BINARY_DIR}/postbuild.txt. - // The 'complex' executable will then test if this file exists, - // and remove it. +#ifndef FOREACH_VAR1 + Failed("the FOREACH, SET or CONFIGURE_FILE command is broken, " + "FOREACH_VAR1 is not defined."); +#else + if(strcmp(FOREACH_VAR1, "VALUE1") != 0) + { + Failed("the FOREACH, SET or CONFIGURE_FILE command is broken, " + "FOREACH_VAR1 == ", FOREACH_VAR1); + } + else + { + Passed("FOREACH_VAR1 == ", FOREACH_VAR1); + } +#endif - struct stat fs; - if (stat(BINARY_DIR "/postbuild.txt", &fs) != 0) +#ifndef FOREACH_VAR2 + Failed("the FOREACH, SET or CONFIGURE_FILE command is broken, " + "FOREACH_VAR2 is not defined."); +#else + if(strcmp(FOREACH_VAR2, "VALUE2") != 0) { - Failed("Could not find " BINARY_DIR "/postbuild.txt (created as a post-build custom command for the shared lib)."); + Failed("the FOREACH, SET or CONFIGURE_FILE command is broken, " + "FOREACH_VAR2 == ", FOREACH_VAR2); } else { - if (unlink(BINARY_DIR "/postbuild.txt") != 0) - { - Failed("Unable to remove " BINARY_DIR "/postbuild.txt (does not imply that this test failed, but it *will* be corrupted thereafter if this file is not removed)."); - } - else - { - Passed("Find and remove " BINARY_DIR "/postbuild.txt (created as a post-build custom command for the shared lib)."); - } + Passed("FOREACH_VAR2 == ", FOREACH_VAR2); + } +#endif + +#ifndef FILENAME_VAR_PATH_NAME + Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " + "FILENAME_VAR_PATH_NAME is not defined."); +#else + if(strcmp(FILENAME_VAR_PATH_NAME, "Complex") != 0) + { + Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " + "FILENAME_VAR_PATH_NAME == ", FILENAME_VAR_PATH_NAME); + } + else + { + Passed("FILENAME_VAR_PATH_NAME == ", FILENAME_VAR_PATH_NAME); } +#endif + +#ifndef FILENAME_VAR_NAME + Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " + "FILENAME_VAR_NAME is not defined."); +#else + if(strcmp(FILENAME_VAR_NAME, "VarTests.txt") != 0) + { + Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " + "FILENAME_VAR_NAME == ", FILENAME_VAR_NAME); + } + else + { + Passed("FILENAME_VAR_NAME == ", FILENAME_VAR_NAME); + } +#endif + +#ifndef FILENAME_VAR_EXT + Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " + "FILENAME_VAR_EXT is not defined."); +#else + if(strcmp(FILENAME_VAR_EXT, ".txt") != 0) + { + Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " + "FILENAME_VAR_EXT == ", FILENAME_VAR_EXT); + } + else + { + Passed("FILENAME_VAR_EXT == ", FILENAME_VAR_EXT); + } +#endif + +#ifndef FILENAME_VAR_NAME_WE + Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " + "FILENAME_VAR_NAME_WE is not defined."); +#else + if(strcmp(FILENAME_VAR_NAME_WE, "VarTests") != 0) + { + Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " + "FILENAME_VAR_NAME_WE == ", FILENAME_VAR_NAME_WE); + } + else + { + Passed("FILENAME_VAR_NAME_WE == ", FILENAME_VAR_NAME_WE); + } +#endif + +#ifndef PATH_VAR_NAME + Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " + "PATH_VAR_NAME is not defined."); +#else + if(strcmp(PATH_VAR_NAME, "Complex") != 0) + { + Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " + "PATH_VAR_NAME == ", PATH_VAR_NAME); + } + else + { + Passed("PATH_VAR_NAME == ", PATH_VAR_NAME); + } +#endif + + // A post-build custom-command has been attached to the lib. + // It run ${CREATE_FILE_EXE} which will create the file + // ${Complex_BINARY_DIR}/postbuild.txt. + + TestAndRemoveFile(BINARY_DIR "/postbuild.txt"); + + // A custom target has been created. + // It run ${CREATE_FILE_EXE} which will create the file + // ${Complex_BINARY_DIR}/custom_target1.txt. + + TestAndRemoveFile(BINARY_DIR "/custom_target1.txt"); std::cout << "Passed: " << passed << "\n"; if(failed) diff --git a/Tests/ComplexOneConfig/Library/CMakeLists.txt b/Tests/ComplexOneConfig/Library/CMakeLists.txt index 73f5ab4..473f2b3 100644 --- a/Tests/ComplexOneConfig/Library/CMakeLists.txt +++ b/Tests/ComplexOneConfig/Library/CMakeLists.txt @@ -1,24 +1,44 @@ AUX_SOURCE_DIRECTORY(ExtraSources LibrarySources) -SOURCE_FILES(LibrarySources file2) +# SOURCE_FILES_REMOVE is used for Coverage +SOURCE_FILES(LibrarySources file2 GENERATED create_file.cxx) +SOURCE_FILES_REMOVE(LibrarySources create_file.cxx) ADD_LIBRARY(CMakeTestLibrary LibrarySources) SOURCE_FILES(SharedLibrarySources sharedFile) ADD_LIBRARY(CMakeTestLibraryShared SHARED SharedLibrarySources) +# +# Small utility used to create file +# UTILITY_SOURCE(CREATE_FILE_EXE create_file "." create_file.cxx) ADD_EXECUTABLE(create_file create_file.cxx) -ADD_DEPENDENCIES(CMakeTestLibraryShared create_file) - +# # Attach a post-build custom-command to the lib. # It run ${CREATE_FILE_EXE} which will create the file # ${Complex_BINARY_DIR}/postbuild.txt. # The 'complex' executable will then test if this file exists, # and remove it. +# +ADD_DEPENDENCIES(CMakeTestLibraryShared create_file) ADD_CUSTOM_COMMAND(SOURCE CMakeTestLibraryShared COMMAND ${CREATE_FILE_EXE} ARGS "${Complex_BINARY_DIR}/postbuild.txt" TARGET CMakeTestLibraryShared) +# +# Add custom target +# It run ${CREATE_FILE_EXE} which will create the file +# ${Complex_BINARY_DIR}/custom_target1.txt. +# The 'complex' executable will then test if this file exists, +# and remove it. +# +ADD_CUSTOM_TARGET(custom_target1 + ALL + ${CREATE_FILE_EXE} + "${Complex_BINARY_DIR}/custom_target1.txt") + +ADD_DEPENDENCIES(custom_target1 create_file) + diff --git a/Tests/ComplexOneConfig/Library/create_file.cxx b/Tests/ComplexOneConfig/Library/create_file.cxx index 68a9bb8..d415519 100644 --- a/Tests/ComplexOneConfig/Library/create_file.cxx +++ b/Tests/ComplexOneConfig/Library/create_file.cxx @@ -22,7 +22,7 @@ int main (int argc, char *argv[]) return EXIT_FAILURE; } - fprintf(stdout, "Creating %s!\n", argv[1]); + fprintf(stdout, ">> Creating %s!\n", argv[1]); return EXIT_SUCCESS; } diff --git a/Tests/ComplexOneConfig/VarTests.txt b/Tests/ComplexOneConfig/VarTests.txt index 0ff9953..0775636 100644 --- a/Tests/ComplexOneConfig/VarTests.txt +++ b/Tests/ComplexOneConfig/VarTests.txt @@ -1,11 +1,36 @@ - SET (ZERO_VAR 0) + IF(ZERO_VAR) -ADD_DEFINITIONS(-DSHOULD_NOT_BE_DEFINED) + ADD_DEFINITIONS(-DSHOULD_NOT_BE_DEFINED) ELSE(ZERO_VAR) -ADD_DEFINITIONS(-DSHOULD_BE_DEFINED) + ADD_DEFINITIONS(-DSHOULD_BE_DEFINED) ENDIF(ZERO_VAR) SET(ONE_VAR 1) +VARIABLE_REQUIRES(ONE_VAR + ONE_VAR_IS_DEFINED ONE_VAR) + SET(STRING_VAR "CMake is great" CACHE STRING "test a cache variable") + +FOREACH (INDEX 1 2) + SET(FOREACH_VAR${INDEX} "VALUE${INDEX}") +ENDFOREACH(INDEX) + +FIND_FILE(FILENAME_VAR "VarTests.txt" ${Complex_SOURCE_DIR}) + +GET_FILENAME_COMPONENT(FILENAME_VAR_PATH ${FILENAME_VAR} PATH) +GET_FILENAME_COMPONENT(FILENAME_VAR_PATH_NAME ${FILENAME_VAR_PATH} NAME) +GET_FILENAME_COMPONENT(FILENAME_VAR_NAME ${FILENAME_VAR} NAME) +GET_FILENAME_COMPONENT(FILENAME_VAR_EXT ${FILENAME_VAR} EXT) +GET_FILENAME_COMPONENT(FILENAME_VAR_NAME_WE ${FILENAME_VAR} NAME_WE) + +FIND_PATH(PATH_VAR "VarTests.txt" ${Complex_SOURCE_DIR}) +GET_FILENAME_COMPONENT(PATH_VAR_NAME ${PATH_VAR} NAME) + +# Coverage only + +BUILD_COMMAND(BUILD_COMMAND_VAR ${CMAKE_MAKE_PROGRAM}) +BUILD_NAME(BUILD_NAME_VAR) +SITE_NAME(SITE_NAME_VAR) + diff --git a/Tests/ComplexOneConfig/cmTestConfigure.h.in b/Tests/ComplexOneConfig/cmTestConfigure.h.in index 5c2563b..3c3e2fa 100644 --- a/Tests/ComplexOneConfig/cmTestConfigure.h.in +++ b/Tests/ComplexOneConfig/cmTestConfigure.h.in @@ -1,10 +1,30 @@ #cmakedefine ONE_VAR +#cmakedefine ONE_VAR_IS_DEFINED #cmakedefine ZERO_VAR + #define STRING_VAR "${STRING_VAR}" -#define BINARY_DIR "${Complex_BINARY_DIR}" +#define FOREACH_VAR1 "${FOREACH_VAR1}" +#define FOREACH_VAR2 "${FOREACH_VAR2}" + +#define FILENAME_VAR_PATH_NAME "${FILENAME_VAR_PATH_NAME}" +#define FILENAME_VAR_NAME "${FILENAME_VAR_NAME}" +#define FILENAME_VAR_EXT "${FILENAME_VAR_EXT}" +#define FILENAME_VAR_NAME_WE "${FILENAME_VAR_NAME_WE}" + +#define PATH_VAR_NAME "${PATH_VAR_NAME}" #cmakedefine CMAKE_NO_STD_NAMESPACE #cmakedefine CMAKE_NO_ANSI_STREAM_HEADERS #cmakedefine CMAKE_NO_ANSI_FOR_SCOPE +// Needed to check for files + +#define BINARY_DIR "${Complex_BINARY_DIR}" + +// Coverage only + +#define BUILD_COMMAND_VAR "${BUILD_COMMAND_VAR}" +#define BUILD_NAME_VAR "${BUILD_NAME_VAR}" +#define SITE_NAME_VAR "${SITE_NAME_VAR}" + diff --git a/Tests/ComplexRelativePaths/CMakeLists.txt b/Tests/ComplexRelativePaths/CMakeLists.txt index 51a5656..10f270e 100644 --- a/Tests/ComplexRelativePaths/CMakeLists.txt +++ b/Tests/ComplexRelativePaths/CMakeLists.txt @@ -50,4 +50,12 @@ ENDIF (EXECUTABLE_OUTPUT_PATH) SUBDIRS(Library Executable) SUBDIR_DEPENDS(Executable Library) +# +# Exec program +# Increase coverage. +# +OPTION(EXEC_PROGRAM "Test EXEC_PROGRAM" ON) +IF (EXEC_PROGRAM) + EXEC_PROGRAM("echo EXEC_PROGRAM") +ENDIF (EXEC_PROGRAM) diff --git a/Tests/ComplexRelativePaths/Executable/complex.cxx b/Tests/ComplexRelativePaths/Executable/complex.cxx index f48ce99..5740dfc 100644 --- a/Tests/ComplexRelativePaths/Executable/complex.cxx +++ b/Tests/ComplexRelativePaths/Executable/complex.cxx @@ -29,6 +29,26 @@ void Passed(const char* Message, const char* m2="") passed++; } +void TestAndRemoveFile(const char* filename) +{ + struct stat fs; + if (stat(filename, &fs) != 0) + { + Failed("Could not find file: ", filename); + } + else + { + if (unlink(filename) != 0) + { + Failed("Unable to remove file. It does not imply that this test failed, but it *will* be corrupted thereafter if this file is not removed: ", filename); + } + else + { + Passed("Find and remove file: ", filename); + } + } +} + int main() { if(sharedFunction() != 1) @@ -82,6 +102,13 @@ int main() Passed("ONE_VAR is defined."); #endif +#ifndef ONE_VAR_IS_DEFINED + Failed("cmakedefine, SET or VARIABLE_REQUIRES is broken, " + "ONE_VAR_IS_DEFINED is not defined."); +#else + Passed("ONE_VAR_IS_DEFINED is defined."); +#endif + #ifdef ZERO_VAR Failed("cmakedefine is broken, ZERO_VAR is defined."); #else @@ -89,12 +116,11 @@ int main() #endif #ifndef STRING_VAR - Failed("configureFile is broken, STRING_VAR is not defined."); + Failed("the CONFIGURE_FILE command is broken, STRING_VAR is not defined."); #else if(strcmp(STRING_VAR, "CMake is great") != 0) { - Failed("CMake is not great, so the SET command," - "or the configurefile comand is broken. STRING_VAR== ", + Failed("the SET or CONFIGURE_FILE command is broken. STRING_VAR == ", STRING_VAR); } else @@ -103,28 +129,122 @@ int main() } #endif - // Attach a post-build custom-command to the lib. - // It run ${CREATE_FILE_EXE} which will create the file - // ${Complex_BINARY_DIR}/postbuild.txt. - // The 'complex' executable will then test if this file exists, - // and remove it. +#ifndef FOREACH_VAR1 + Failed("the FOREACH, SET or CONFIGURE_FILE command is broken, " + "FOREACH_VAR1 is not defined."); +#else + if(strcmp(FOREACH_VAR1, "VALUE1") != 0) + { + Failed("the FOREACH, SET or CONFIGURE_FILE command is broken, " + "FOREACH_VAR1 == ", FOREACH_VAR1); + } + else + { + Passed("FOREACH_VAR1 == ", FOREACH_VAR1); + } +#endif - struct stat fs; - if (stat(BINARY_DIR "/postbuild.txt", &fs) != 0) +#ifndef FOREACH_VAR2 + Failed("the FOREACH, SET or CONFIGURE_FILE command is broken, " + "FOREACH_VAR2 is not defined."); +#else + if(strcmp(FOREACH_VAR2, "VALUE2") != 0) { - Failed("Could not find " BINARY_DIR "/postbuild.txt (created as a post-build custom command for the shared lib)."); + Failed("the FOREACH, SET or CONFIGURE_FILE command is broken, " + "FOREACH_VAR2 == ", FOREACH_VAR2); } else { - if (unlink(BINARY_DIR "/postbuild.txt") != 0) - { - Failed("Unable to remove " BINARY_DIR "/postbuild.txt (does not imply that this test failed, but it *will* be corrupted thereafter if this file is not removed)."); - } - else - { - Passed("Find and remove " BINARY_DIR "/postbuild.txt (created as a post-build custom command for the shared lib)."); - } + Passed("FOREACH_VAR2 == ", FOREACH_VAR2); + } +#endif + +#ifndef FILENAME_VAR_PATH_NAME + Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " + "FILENAME_VAR_PATH_NAME is not defined."); +#else + if(strcmp(FILENAME_VAR_PATH_NAME, "Complex") != 0) + { + Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " + "FILENAME_VAR_PATH_NAME == ", FILENAME_VAR_PATH_NAME); + } + else + { + Passed("FILENAME_VAR_PATH_NAME == ", FILENAME_VAR_PATH_NAME); } +#endif + +#ifndef FILENAME_VAR_NAME + Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " + "FILENAME_VAR_NAME is not defined."); +#else + if(strcmp(FILENAME_VAR_NAME, "VarTests.txt") != 0) + { + Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " + "FILENAME_VAR_NAME == ", FILENAME_VAR_NAME); + } + else + { + Passed("FILENAME_VAR_NAME == ", FILENAME_VAR_NAME); + } +#endif + +#ifndef FILENAME_VAR_EXT + Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " + "FILENAME_VAR_EXT is not defined."); +#else + if(strcmp(FILENAME_VAR_EXT, ".txt") != 0) + { + Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " + "FILENAME_VAR_EXT == ", FILENAME_VAR_EXT); + } + else + { + Passed("FILENAME_VAR_EXT == ", FILENAME_VAR_EXT); + } +#endif + +#ifndef FILENAME_VAR_NAME_WE + Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " + "FILENAME_VAR_NAME_WE is not defined."); +#else + if(strcmp(FILENAME_VAR_NAME_WE, "VarTests") != 0) + { + Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " + "FILENAME_VAR_NAME_WE == ", FILENAME_VAR_NAME_WE); + } + else + { + Passed("FILENAME_VAR_NAME_WE == ", FILENAME_VAR_NAME_WE); + } +#endif + +#ifndef PATH_VAR_NAME + Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " + "PATH_VAR_NAME is not defined."); +#else + if(strcmp(PATH_VAR_NAME, "Complex") != 0) + { + Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " + "PATH_VAR_NAME == ", PATH_VAR_NAME); + } + else + { + Passed("PATH_VAR_NAME == ", PATH_VAR_NAME); + } +#endif + + // A post-build custom-command has been attached to the lib. + // It run ${CREATE_FILE_EXE} which will create the file + // ${Complex_BINARY_DIR}/postbuild.txt. + + TestAndRemoveFile(BINARY_DIR "/postbuild.txt"); + + // A custom target has been created. + // It run ${CREATE_FILE_EXE} which will create the file + // ${Complex_BINARY_DIR}/custom_target1.txt. + + TestAndRemoveFile(BINARY_DIR "/custom_target1.txt"); std::cout << "Passed: " << passed << "\n"; if(failed) diff --git a/Tests/ComplexRelativePaths/Library/CMakeLists.txt b/Tests/ComplexRelativePaths/Library/CMakeLists.txt index 73f5ab4..473f2b3 100644 --- a/Tests/ComplexRelativePaths/Library/CMakeLists.txt +++ b/Tests/ComplexRelativePaths/Library/CMakeLists.txt @@ -1,24 +1,44 @@ AUX_SOURCE_DIRECTORY(ExtraSources LibrarySources) -SOURCE_FILES(LibrarySources file2) +# SOURCE_FILES_REMOVE is used for Coverage +SOURCE_FILES(LibrarySources file2 GENERATED create_file.cxx) +SOURCE_FILES_REMOVE(LibrarySources create_file.cxx) ADD_LIBRARY(CMakeTestLibrary LibrarySources) SOURCE_FILES(SharedLibrarySources sharedFile) ADD_LIBRARY(CMakeTestLibraryShared SHARED SharedLibrarySources) +# +# Small utility used to create file +# UTILITY_SOURCE(CREATE_FILE_EXE create_file "." create_file.cxx) ADD_EXECUTABLE(create_file create_file.cxx) -ADD_DEPENDENCIES(CMakeTestLibraryShared create_file) - +# # Attach a post-build custom-command to the lib. # It run ${CREATE_FILE_EXE} which will create the file # ${Complex_BINARY_DIR}/postbuild.txt. # The 'complex' executable will then test if this file exists, # and remove it. +# +ADD_DEPENDENCIES(CMakeTestLibraryShared create_file) ADD_CUSTOM_COMMAND(SOURCE CMakeTestLibraryShared COMMAND ${CREATE_FILE_EXE} ARGS "${Complex_BINARY_DIR}/postbuild.txt" TARGET CMakeTestLibraryShared) +# +# Add custom target +# It run ${CREATE_FILE_EXE} which will create the file +# ${Complex_BINARY_DIR}/custom_target1.txt. +# The 'complex' executable will then test if this file exists, +# and remove it. +# +ADD_CUSTOM_TARGET(custom_target1 + ALL + ${CREATE_FILE_EXE} + "${Complex_BINARY_DIR}/custom_target1.txt") + +ADD_DEPENDENCIES(custom_target1 create_file) + diff --git a/Tests/ComplexRelativePaths/Library/create_file.cxx b/Tests/ComplexRelativePaths/Library/create_file.cxx index 68a9bb8..d415519 100644 --- a/Tests/ComplexRelativePaths/Library/create_file.cxx +++ b/Tests/ComplexRelativePaths/Library/create_file.cxx @@ -22,7 +22,7 @@ int main (int argc, char *argv[]) return EXIT_FAILURE; } - fprintf(stdout, "Creating %s!\n", argv[1]); + fprintf(stdout, ">> Creating %s!\n", argv[1]); return EXIT_SUCCESS; } diff --git a/Tests/ComplexRelativePaths/VarTests.txt b/Tests/ComplexRelativePaths/VarTests.txt index 0ff9953..0775636 100644 --- a/Tests/ComplexRelativePaths/VarTests.txt +++ b/Tests/ComplexRelativePaths/VarTests.txt @@ -1,11 +1,36 @@ - SET (ZERO_VAR 0) + IF(ZERO_VAR) -ADD_DEFINITIONS(-DSHOULD_NOT_BE_DEFINED) + ADD_DEFINITIONS(-DSHOULD_NOT_BE_DEFINED) ELSE(ZERO_VAR) -ADD_DEFINITIONS(-DSHOULD_BE_DEFINED) + ADD_DEFINITIONS(-DSHOULD_BE_DEFINED) ENDIF(ZERO_VAR) SET(ONE_VAR 1) +VARIABLE_REQUIRES(ONE_VAR + ONE_VAR_IS_DEFINED ONE_VAR) + SET(STRING_VAR "CMake is great" CACHE STRING "test a cache variable") + +FOREACH (INDEX 1 2) + SET(FOREACH_VAR${INDEX} "VALUE${INDEX}") +ENDFOREACH(INDEX) + +FIND_FILE(FILENAME_VAR "VarTests.txt" ${Complex_SOURCE_DIR}) + +GET_FILENAME_COMPONENT(FILENAME_VAR_PATH ${FILENAME_VAR} PATH) +GET_FILENAME_COMPONENT(FILENAME_VAR_PATH_NAME ${FILENAME_VAR_PATH} NAME) +GET_FILENAME_COMPONENT(FILENAME_VAR_NAME ${FILENAME_VAR} NAME) +GET_FILENAME_COMPONENT(FILENAME_VAR_EXT ${FILENAME_VAR} EXT) +GET_FILENAME_COMPONENT(FILENAME_VAR_NAME_WE ${FILENAME_VAR} NAME_WE) + +FIND_PATH(PATH_VAR "VarTests.txt" ${Complex_SOURCE_DIR}) +GET_FILENAME_COMPONENT(PATH_VAR_NAME ${PATH_VAR} NAME) + +# Coverage only + +BUILD_COMMAND(BUILD_COMMAND_VAR ${CMAKE_MAKE_PROGRAM}) +BUILD_NAME(BUILD_NAME_VAR) +SITE_NAME(SITE_NAME_VAR) + diff --git a/Tests/ComplexRelativePaths/cmTestConfigure.h.in b/Tests/ComplexRelativePaths/cmTestConfigure.h.in index 5c2563b..3c3e2fa 100644 --- a/Tests/ComplexRelativePaths/cmTestConfigure.h.in +++ b/Tests/ComplexRelativePaths/cmTestConfigure.h.in @@ -1,10 +1,30 @@ #cmakedefine ONE_VAR +#cmakedefine ONE_VAR_IS_DEFINED #cmakedefine ZERO_VAR + #define STRING_VAR "${STRING_VAR}" -#define BINARY_DIR "${Complex_BINARY_DIR}" +#define FOREACH_VAR1 "${FOREACH_VAR1}" +#define FOREACH_VAR2 "${FOREACH_VAR2}" + +#define FILENAME_VAR_PATH_NAME "${FILENAME_VAR_PATH_NAME}" +#define FILENAME_VAR_NAME "${FILENAME_VAR_NAME}" +#define FILENAME_VAR_EXT "${FILENAME_VAR_EXT}" +#define FILENAME_VAR_NAME_WE "${FILENAME_VAR_NAME_WE}" + +#define PATH_VAR_NAME "${PATH_VAR_NAME}" #cmakedefine CMAKE_NO_STD_NAMESPACE #cmakedefine CMAKE_NO_ANSI_STREAM_HEADERS #cmakedefine CMAKE_NO_ANSI_FOR_SCOPE +// Needed to check for files + +#define BINARY_DIR "${Complex_BINARY_DIR}" + +// Coverage only + +#define BUILD_COMMAND_VAR "${BUILD_COMMAND_VAR}" +#define BUILD_NAME_VAR "${BUILD_NAME_VAR}" +#define SITE_NAME_VAR "${SITE_NAME_VAR}" + |