complex: Simplify test for single-character exe name

Run the test executable as a custom command instead of depending on
cmSystemTools::RunSingleCommand.
This commit is contained in:
Brad King 2011-12-23 15:34:19 -05:00
parent 76ac88b730
commit 49d6dd67f1
6 changed files with 26 additions and 74 deletions

View File

@ -1,7 +1,9 @@
// Include code from a header that should not be compiled separately. // Include code from a header that should not be compiled separately.
#include "A.hh" #include "A.hh"
#include <stdio.h>
int main() int main()
{ {
return A(); printf("#define A_VALUE %d\n", A());
return 0;
} }

View File

@ -55,8 +55,10 @@ SET_SOURCE_FILES_PROPERTIES(complex_nobuild.cxx PROPERTIES
SET_SOURCE_FILES_PROPERTIES(complex_nobuild.c PROPERTIES SET_SOURCE_FILES_PROPERTIES(complex_nobuild.c PROPERTIES
HEADER_FILE_ONLY 1) HEADER_FILE_ONLY 1)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
ADD_EXECUTABLE(A A.cxx A.hh A.h A.txt) ADD_EXECUTABLE(A A.cxx A.hh A.h A.txt)
ADD_EXECUTABLE(complex complex testcflags.c ) ADD_CUSTOM_COMMAND(OUTPUT Aout.h COMMAND A > Aout.h VERBATIM)
ADD_EXECUTABLE(complex complex testcflags.c Aout.h)
# Sub1/NameConflictTest.c Sub2/NameConflictTest.c) # Sub1/NameConflictTest.c Sub2/NameConflictTest.c)
ADD_EXECUTABLE(complex.file complex.file.cxx complex_nobuild.cxx ADD_EXECUTABLE(complex.file complex.file.cxx complex_nobuild.cxx
complex_nobuild.c) complex_nobuild.c)

View File

@ -3,6 +3,7 @@
#include "cmTestGeneratedHeader.h" #include "cmTestGeneratedHeader.h"
#include "cmVersion.h" #include "cmVersion.h"
#include "ExtraSources/file1.h" #include "ExtraSources/file1.h"
#include "Aout.h"
#include "file2.h" #include "file2.h"
#include "sharedFile.h" #include "sharedFile.h"
extern "C" { extern "C" {
@ -148,42 +149,7 @@ extern "C" int NameConflictTest2();
int main() int main()
{ {
std::string exe = BINARY_DIR;
exe += "/bin/";
#ifdef CMAKE_INTDIR
exe += CMAKE_INTDIR;
exe += "/";
#endif
#ifdef COMPLEX_TEST_CMAKELIB #ifdef COMPLEX_TEST_CMAKELIB
// Test a single character executable to test a: in makefiles
exe += "A";
exe += cmSystemTools::GetExecutableExtension();
int ret;
std::string errorMessage;
exe = cmSystemTools::ConvertToRunCommandPath(exe.c_str());
if(cmSystemTools::RunSingleCommand(exe.c_str(), 0, &ret))
{
if(ret != 10)
{
errorMessage += exe;
errorMessage += " did not return 10";
}
}
else
{
errorMessage += exe;
errorMessage += ": failed to run.";
}
if(errorMessage.size())
{
cmFailed(errorMessage.c_str());
}
else
{
cmPassed("run Single Character executable A returned 10 as expected.");
}
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Test cmSystemTools::UpperCase // Test cmSystemTools::UpperCase
std::string str = "abc"; std::string str = "abc";
@ -1064,6 +1030,12 @@ int main()
} }
#endif #endif
#if defined(A_VALUE) && A_VALUE == 10
cmPassed("Single-character executable A worked.");
#else
cmFailed("Single-character executable A failed.");
#endif
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Summary // Summary

View File

@ -1,7 +1,9 @@
// Include code from a header that should not be compiled separately. // Include code from a header that should not be compiled separately.
#include "A.hh" #include "A.hh"
#include <stdio.h>
int main() int main()
{ {
return A(); printf("#define A_VALUE %d\n", A());
return 0;
} }

View File

@ -55,8 +55,10 @@ SET_SOURCE_FILES_PROPERTIES(complex_nobuild.cxx PROPERTIES
SET_SOURCE_FILES_PROPERTIES(complex_nobuild.c PROPERTIES SET_SOURCE_FILES_PROPERTIES(complex_nobuild.c PROPERTIES
HEADER_FILE_ONLY 1) HEADER_FILE_ONLY 1)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
ADD_EXECUTABLE(A A.cxx A.hh A.h A.txt) ADD_EXECUTABLE(A A.cxx A.hh A.h A.txt)
ADD_EXECUTABLE(complex complex testcflags.c ) ADD_CUSTOM_COMMAND(OUTPUT Aout.h COMMAND A > Aout.h VERBATIM)
ADD_EXECUTABLE(complex complex testcflags.c Aout.h)
# Sub1/NameConflictTest.c Sub2/NameConflictTest.c) # Sub1/NameConflictTest.c Sub2/NameConflictTest.c)
ADD_EXECUTABLE(complex.file complex.file.cxx complex_nobuild.cxx ADD_EXECUTABLE(complex.file complex.file.cxx complex_nobuild.cxx
complex_nobuild.c) complex_nobuild.c)

View File

@ -3,6 +3,7 @@
#include "cmTestGeneratedHeader.h" #include "cmTestGeneratedHeader.h"
#include "cmVersion.h" #include "cmVersion.h"
#include "ExtraSources/file1.h" #include "ExtraSources/file1.h"
#include "Aout.h"
#include "file2.h" #include "file2.h"
#include "sharedFile.h" #include "sharedFile.h"
extern "C" { extern "C" {
@ -148,42 +149,7 @@ extern "C" int NameConflictTest2();
int main() int main()
{ {
std::string exe = BINARY_DIR;
exe += "/bin/";
#ifdef CMAKE_INTDIR
exe += CMAKE_INTDIR;
exe += "/";
#endif
#ifdef COMPLEX_TEST_CMAKELIB #ifdef COMPLEX_TEST_CMAKELIB
// Test a single character executable to test a: in makefiles
exe += "A";
exe += cmSystemTools::GetExecutableExtension();
int ret;
std::string errorMessage;
exe = cmSystemTools::ConvertToRunCommandPath(exe.c_str());
if(cmSystemTools::RunSingleCommand(exe.c_str(), 0, &ret))
{
if(ret != 10)
{
errorMessage += exe;
errorMessage += " did not return 10";
}
}
else
{
errorMessage += exe;
errorMessage += ": failed to run.";
}
if(errorMessage.size())
{
cmFailed(errorMessage.c_str());
}
else
{
cmPassed("run Single Character executable A returned 10 as expected.");
}
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Test cmSystemTools::UpperCase // Test cmSystemTools::UpperCase
std::string str = "abc"; std::string str = "abc";
@ -1064,6 +1030,12 @@ int main()
} }
#endif #endif
#if defined(A_VALUE) && A_VALUE == 10
cmPassed("Single-character executable A worked.");
#else
cmFailed("Single-character executable A failed.");
#endif
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Summary // Summary