ENH: Add a way for test to intentionally fail

This commit is contained in:
Andy Cedilnik 2005-09-06 23:31:41 -04:00
parent 52b808257d
commit fcce3ac0a1
4 changed files with 134 additions and 4 deletions

View File

@ -27,6 +27,7 @@
#include "cmGlobalGenerator.h"
#include "cmLocalGenerator.h"
#include "cmCommand.h"
#include "cmSystemTools.h"
#include <stdlib.h>
#include <math.h>
@ -168,6 +169,46 @@ bool cmCTestAddTestCommand::InitialPass(std::vector<std::string> const& args)
return m_TestHandler->AddTest(args);
}
//----------------------------------------------------------------------
class cmCTestSetTestsPropertiesCommand : public cmCommand
{
public:
/**
* This is a virtual constructor for the command.
*/
virtual cmCommand* Clone()
{
cmCTestSetTestsPropertiesCommand* c = new cmCTestSetTestsPropertiesCommand;
c->m_TestHandler = m_TestHandler;
return c;
}
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
virtual bool InitialPass(std::vector<std::string> const&);
/**
* The name of the command as specified in CMakeList.txt.
*/
virtual const char* GetName() { return "SET_TESTS_PROPERTIES";}
// Unused methods
virtual const char* GetTerseDocumentation() { return ""; }
virtual const char* GetFullDocumentation() { return ""; }
cmTypeMacro(cmCTestSetTestsPropertiesCommand, cmCommand);
cmCTestTestHandler* m_TestHandler;
};
//----------------------------------------------------------------------
bool cmCTestSetTestsPropertiesCommand::InitialPass(std::vector<std::string> const& args)
{
return m_TestHandler->SetTestsProperties(args);
}
//----------------------------------------------------------------------
// Try to find an executable, if found fullPath will be set to the full path
// of where it was found. The directory and filename to search for are passed
@ -700,9 +741,18 @@ void cmCTestTestHandler::ProcessDirectory(std::vector<cmStdString> &passed,
{
if (res == cmsysProcess_State_Exited && retVal == 0)
{
cmCTestLog(m_CTest, HANDLER_OUTPUT, " Passed" << std::endl);
cmCTestLog(m_CTest, HANDLER_OUTPUT, " Passed");
passed.push_back(testname);
cres.m_Status = cmCTestTestHandler::COMPLETED;
if ( it->m_WillFail )
{
cmCTestLog(m_CTest, HANDLER_OUTPUT, " - But it should fail!");
cres.m_Status = cmCTestTestHandler::FAILED;
}
else
{
cres.m_Status = cmCTestTestHandler::COMPLETED;
}
cmCTestLog(m_CTest, HANDLER_OUTPUT, std::endl);
}
else
{
@ -746,7 +796,13 @@ void cmCTestTestHandler::ProcessDirectory(std::vector<cmStdString> &passed,
}
else
{
cmCTestLog(m_CTest, HANDLER_OUTPUT, "***Failed" << std::endl);
cmCTestLog(m_CTest, HANDLER_OUTPUT, "***Failed");
if ( it->m_WillFail )
{
cres.m_Status = cmCTestTestHandler::COMPLETED;
cmCTestLog(m_CTest, HANDLER_OUTPUT, " - supposed to fail");
}
cmCTestLog(m_CTest, HANDLER_OUTPUT, std::endl);
}
failed.push_back(testname);
}
@ -1013,6 +1069,11 @@ void cmCTestTestHandler::GetListOfTests()
newCom2->m_TestHandler = this;
cm.AddCommand(newCom2);
// Add handler for SET_SOURCE_FILES_PROPERTIES
cmCTestSetTestsPropertiesCommand* newCom3 = new cmCTestSetTestsPropertiesCommand;
newCom3->m_TestHandler = this;
cm.AddCommand(newCom3);
const char* testFilename;
if( cmSystemTools::FileExists("CTestTestfile.cmake") )
{
@ -1401,6 +1462,54 @@ bool cmCTestTestHandler::CleanTestOutput(std::string& output, size_t remove_thre
return true;
}
//----------------------------------------------------------------------
bool cmCTestTestHandler::SetTestsProperties(const std::vector<std::string>& args)
{
std::vector<std::string>::const_iterator it;
std::vector<cmStdString> tests;
bool found = false;
for ( it = args.begin(); it != args.end(); ++ it )
{
if ( *it == "PROPERTIES" )
{
found = true;
break;
}
tests.push_back(*it);
}
if ( !found )
{
return false;
}
++ it; // skip PROPERTIES
for ( ; it != args.end(); ++ it )
{
std::string key = *it;
++ it;
if ( it == args.end() )
{
break;
}
std::string val = *it;
std::vector<cmStdString>::const_iterator tit;
for ( tit = tests.begin(); tit != tests.end(); ++ tit )
{
tm_ListOfTests::iterator rtit;
for ( rtit = m_TestList.begin(); rtit != m_TestList.end(); ++ rtit )
{
if ( *tit == rtit->m_Name )
{
if ( key == "WILL_FAIL" )
{
rtit->m_WillFail = cmSystemTools::IsOn(val.c_str());
}
}
}
}
}
return true;
}
//----------------------------------------------------------------------
bool cmCTestTestHandler::AddTest(const std::vector<std::string>& args)
{
@ -1455,6 +1564,7 @@ bool cmCTestTestHandler::AddTest(const std::vector<std::string>& args)
test.m_Args = args;
test.m_Directory = cmSystemTools::GetCurrentWorkingDirectory();
test.m_IsInBasedOnREOptions = true;
test.m_WillFail = false;
if (this->m_UseIncludeRegExp && !m_IncludeTestsRegularExpression.find(testname.c_str()))
{
test.m_IsInBasedOnREOptions = false;

View File

@ -68,6 +68,11 @@ public:
*/
bool AddTest(const std::vector<std::string>& args);
/*
* Set tests properties
*/
bool SetTestsProperties(const std::vector<std::string>& args);
struct cmCTestTestResult
{
std::string m_Name;
@ -91,6 +96,7 @@ protected:
cmStdString m_Directory;
std::vector<std::string> m_Args;
bool m_IsInBasedOnREOptions;
bool m_WillFail;
};

View File

@ -177,7 +177,17 @@ void cmLocalGenerator::GenerateTestFiles()
fout << "\"";
}
fout << ")" << std::endl;
std::map<cmStdString,cmStdString>::const_iterator pit;
const std::map<cmStdString,cmStdString>* mpit = &test->GetProperties();
if ( mpit->size() )
{
fout << "SET_TESTS_PROPERTIES(" << test->GetName() << " PROPERTIES ";
for ( pit = mpit->begin(); pit != mpit->end(); ++ pit )
{
fout << " " << pit->first.c_str() << " \"" << pit->second.c_str() << "\"";
}
fout << ")" << std::endl;
}
}
if ( this->Children.size())
{

View File

@ -52,6 +52,10 @@ public:
void SetProperty(const char *prop, const char *value);
const char *GetProperty(const char *prop) const;
bool GetPropertyAsBool(const char *prop) const;
const std::map<cmStdString,cmStdString>& GetProperties() const
{
return m_Properties;
}
private:
std::map<cmStdString,cmStdString> m_Properties;