mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-04 05:10:10 -05:00
Increase coverage, add tests
This commit is contained in:
@@ -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.
|
||||
|
||||
struct stat fs;
|
||||
if (stat(BINARY_DIR "/postbuild.txt", &fs) != 0)
|
||||
#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("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_VAR1 == ", FOREACH_VAR1);
|
||||
}
|
||||
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_VAR1 == ", FOREACH_VAR1);
|
||||
}
|
||||
#endif
|
||||
|
||||
#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("the FOREACH, SET or CONFIGURE_FILE command is broken, "
|
||||
"FOREACH_VAR2 == ", FOREACH_VAR2);
|
||||
}
|
||||
else
|
||||
{
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user