ENH: Add test for string and file commands

This commit is contained in:
Andy Cedilnik 2003-07-10 14:29:30 -04:00
parent c4275f54c7
commit b75c229444
4 changed files with 96 additions and 0 deletions

View File

@ -168,6 +168,11 @@ IF(BUILD_TESTING)
${CMake_BINARY_DIR}/Tests/SystemInformation
DumpInformation)
ADD_TEST(StringFileTest ${EXECUTABLE_OUTPUT_PATH}/cmaketest
${CMake_SOURCE_DIR}/Tests/StringFileTest
${CMake_BINARY_DIR}/Tests/StringFileTest
StringFileTest)
ADD_TEST(TryCompile ${EXECUTABLE_OUTPUT_PATH}/cmaketest
${CMake_SOURCE_DIR}/Tests/TryCompile
${CMake_BINARY_DIR}/Tests/TryCompile

View File

@ -0,0 +1,46 @@
PROJECT(StringFileTest)
INCLUDE_DIRECTORIES(${StringFileTest_BINARY_DIR})
FILE(READ "${CMAKE_CURRENT_SOURCE_DIR}/InputFile.h.in" infile)
STRING(REGEX MATCH "[cC][mM][aA][kK][eE]" rmvar "CMake is great")
STRING(REGEX MATCHALL "[cC][mM][aA][kK][eE]" rmallvar "CMake is better than cmake or CMake")
STRING(REGEX REPLACE "[Aa][uU][tT][oO]([cC][oO][nN][fF]|[mM][aA][kK][eE])"
"CMake" rrepvar "People should use Autoconf and Automake")
STRING(COMPARE EQUAL "CMake" "Autoconf" nceqvar)
STRING(COMPARE EQUAL "CMake" "CMake" ceqvar)
STRING(COMPARE NOTEQUAL "CMake" "Autoconf" cneqvar)
STRING(COMPARE NOTEQUAL "CMake" "CMake" ncneqvar)
STRING(COMPARE LESS "before" "after" nclvar)
STRING(COMPARE LESS "max" "min" clvar)
STRING(COMPARE GREATER "before" "after" cgvar)
STRING(COMPARE GREATER "max" "min" ncgvar)
STRING(ASCII 67 109 97 107 101 savar)
STRING(TOUPPER "CMake" tuvar)
STRING(TOLOWER "CMake" tlvar)
FILE(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Includes")
SET(file "${CMAKE_CURRENT_BINARY_DIR}/Includes/Values.h")
FILE(WRITE "${file}" "/* this file is generated */\n")
FOREACH(var
rmvar
rmallvar
rrepvar
nceqvar
ceqvar
cneqvar
ncneqvar
nclvar
clvar
cgvar
ncgvar
savar
tuvar
tlvar)
FILE(APPEND "${file}" "#define ${var} \"${${var}}\"")
ENDFOREACH(var)
STRING(REGEX REPLACE "includefile" "${file}" outfile "${infile}")
FILE(WRITE "${CMAKE_CURRENT_BINARY_DIR}/OutputFile.h" "${outfile}")
ADD_EXECUTABLE(StringFileTest StringFile.cxx)

View File

@ -0,0 +1,21 @@
#include "includefile"
int CheckMethod(const char* var, const char* val )
{
if ( !var )
{
printf("Var not specified\n");
return 1;
}
if ( !val )
{
printf("Val not specified\n");
return 1;
}
if ( strcmp(var, val) != 0)
{
printf("Var (%s) and Val (%s) are not the same...\n", var, val);
return 1;
}
return 0;
}

View File

@ -0,0 +1,24 @@
#include <stdio.h>
#include "OutputFile.h"
int main(int, char*[])
{
int res = 0;
res += CheckMethod(rmvar, "CMake");
res += CheckMethod(rmallvar, "CMake;cmake;CMake");
res += CheckMethod(rrepvar, "People should use CMake and CMake");
res += CheckMethod(nceqvar, "0");
res += CheckMethod(ceqvar, "1");
res += CheckMethod(cneqvar, "1");
res += CheckMethod(ncneqvar, "0");
res += CheckMethod(nclvar, "0");
res += CheckMethod(clvar, "1");
res += CheckMethod(cgvar, "1");
res += CheckMethod(ncgvar, "0");
res += CheckMethod(savar, "Cmake");
res += CheckMethod(tuvar, "CMAKE");
res += CheckMethod(tlvar, "cmake");
return res;
}