ENH: Put test labels in MemCheck results

This refactors generation of <Test> element headers and footers in
cmCTestTestHandler and re-uses it in cmCTestMemCheckHandler.  The change
removes duplicate code and enables the new <Labels> element for MemCheck
results.
This commit is contained in:
Brad King 2009-02-02 13:24:26 -05:00
parent eea054d82c
commit cc2092d5bb
3 changed files with 59 additions and 65 deletions

View File

@ -337,30 +337,8 @@ void cmCTestMemCheckHandler::GenerateDartOutput(std::ostream& os)
}
this->CleanTestOutput(memcheckstr,
static_cast<size_t>(this->CustomMaximumFailedTestOutputSize));
os << "\t<Test Status=\"";
if ( result->Status == cmCTestMemCheckHandler::COMPLETED )
{
os << "passed";
}
else if ( result->Status == cmCTestMemCheckHandler::NOT_RUN )
{
os << "notrun";
}
else
{
os << "failed";
}
std::string testPath = result->Path + "/" + result->Name;
os << "\">\n"
<< "\t\t<Name>" << cmCTest::MakeXMLSafe(result->Name) << "</Name>\n"
<< "\t\t<Path>" << cmCTest::MakeXMLSafe(
this->CTest->GetShortPathToFile(result->Path.c_str())) << "</Path>\n"
<< "\t\t<FullName>" << cmCTest::MakeXMLSafe(
this->CTest->GetShortPathToFile(testPath.c_str())) << "</FullName>\n"
<< "\t\t<FullCommandLine>"
<< cmCTest::MakeXMLSafe(result->FullCommandLine)
<< "</FullCommandLine>\n"
<< "\t\t<Results>" << std::endl;
this->WriteTestResultHeader(os, result);
os << "\t\t<Results>" << std::endl;
for ( kk = 0; cmCTestMemCheckResultLongStrings[kk]; kk ++ )
{
if ( memcheckresults[kk] )
@ -375,8 +353,8 @@ void cmCTestMemCheckHandler::GenerateDartOutput(std::ostream& os)
os
<< "\t\t</Results>\n"
<< "\t<Log>\n" << memcheckstr << std::endl
<< "\t</Log>\n"
<< "\t</Test>" << std::endl;
<< "\t</Log>\n";
this->WriteTestResultFooter(os, result);
if ( current < cc )
{
cmCTestLog(this->CTest, HANDLER_OUTPUT, "#" << std::flush);

View File

@ -1472,30 +1472,8 @@ void cmCTestTestHandler::GenerateDartOutput(std::ostream& os)
for ( cc = 0; cc < this->TestResults.size(); cc ++ )
{
cmCTestTestResult *result = &this->TestResults[cc];
os << "\t<Test Status=\"";
if ( result->Status == cmCTestTestHandler::COMPLETED )
{
os << "passed";
}
else if ( result->Status == cmCTestTestHandler::NOT_RUN )
{
os << "notrun";
}
else
{
os << "failed";
}
std::string testPath = result->Path + "/" + result->Name;
os << "\">\n"
<< "\t\t<Name>" << cmCTest::MakeXMLSafe(result->Name) << "</Name>\n"
<< "\t\t<Path>" << cmCTest::MakeXMLSafe(
this->CTest->GetShortPathToFile(result->Path.c_str())) << "</Path>\n"
<< "\t\t<FullName>" << cmCTest::MakeXMLSafe(
this->CTest->GetShortPathToFile(testPath.c_str())) << "</FullName>\n"
<< "\t\t<FullCommandLine>"
<< cmCTest::MakeXMLSafe(result->FullCommandLine)
<< "</FullCommandLine>\n"
<< "\t\t<Results>" << std::endl;
this->WriteTestResultHeader(os, result);
os << "\t\t<Results>" << std::endl;
if ( result->Status != cmCTestTestHandler::NOT_RUN )
{
if ( result->Status != cmCTestTestHandler::COMPLETED ||
@ -1547,21 +1525,7 @@ void cmCTestTestHandler::GenerateDartOutput(std::ostream& os)
<< "</Value>\n"
<< "\t\t\t</Measurement>\n"
<< "\t\t</Results>\n";
if(!result->Properties->Labels.empty())
{
os << "\t\t<Labels>\n";
std::vector<std::string> const& labels = result->Properties->Labels;
for(std::vector<std::string>::const_iterator li = labels.begin();
li != labels.end(); ++li)
{
os << "\t\t\t<Label>" << cmCTest::MakeXMLSafe(*li) << "</Label>\n";
}
os << "\t\t</Labels>\n";
}
os
<< "\t</Test>" << std::endl;
this->WriteTestResultFooter(os, result);
}
os << "\t<EndDateTime>" << this->EndTest << "</EndDateTime>\n"
@ -1573,6 +1537,55 @@ void cmCTestTestHandler::GenerateDartOutput(std::ostream& os)
this->CTest->EndXML(os);
}
//----------------------------------------------------------------------------
void cmCTestTestHandler::WriteTestResultHeader(std::ostream& os,
cmCTestTestResult* result)
{
os << "\t<Test Status=\"";
if ( result->Status == cmCTestTestHandler::COMPLETED )
{
os << "passed";
}
else if ( result->Status == cmCTestTestHandler::NOT_RUN )
{
os << "notrun";
}
else
{
os << "failed";
}
std::string testPath = result->Path + "/" + result->Name;
os << "\">\n"
<< "\t\t<Name>" << cmCTest::MakeXMLSafe(result->Name) << "</Name>\n"
<< "\t\t<Path>" << cmCTest::MakeXMLSafe(
this->CTest->GetShortPathToFile(result->Path.c_str())) << "</Path>\n"
<< "\t\t<FullName>" << cmCTest::MakeXMLSafe(
this->CTest->GetShortPathToFile(testPath.c_str())) << "</FullName>\n"
<< "\t\t<FullCommandLine>"
<< cmCTest::MakeXMLSafe(result->FullCommandLine)
<< "</FullCommandLine>\n";
}
//----------------------------------------------------------------------------
void cmCTestTestHandler::WriteTestResultFooter(std::ostream& os,
cmCTestTestResult* result)
{
if(!result->Properties->Labels.empty())
{
os << "\t\t<Labels>\n";
std::vector<std::string> const& labels = result->Properties->Labels;
for(std::vector<std::string>::const_iterator li = labels.begin();
li != labels.end(); ++li)
{
os << "\t\t\t<Label>" << cmCTest::MakeXMLSafe(*li) << "</Label>\n";
}
os << "\t\t</Labels>\n";
}
os
<< "\t</Test>" << std::endl;
}
//----------------------------------------------------------------------
int cmCTestTestHandler::ExecuteCommands(std::vector<cmStdString>& vec)
{

View File

@ -134,6 +134,9 @@ protected:
virtual void GenerateTestCommand(std::vector<const char*>& args);
int ExecuteCommands(std::vector<cmStdString>& vec);
void WriteTestResultHeader(std::ostream& os, cmCTestTestResult* result);
void WriteTestResultFooter(std::ostream& os, cmCTestTestResult* result);
//! Clean test output to specified length
bool CleanTestOutput(std::string& output, size_t length);