diff options
author | Andy Cedilnik <andy.cedilnik@kitware.com> | 2005-09-07 03:31:41 (GMT) |
---|---|---|
committer | Andy Cedilnik <andy.cedilnik@kitware.com> | 2005-09-07 03:31:41 (GMT) |
commit | fcce3ac0a14e89f81cc1dfe618b0bca776bf2329 (patch) | |
tree | 86e18f2a01502f5a208fb7cfbf87788aa242571f /Source | |
parent | 52b808257dbe9536e6b035c1bdaacbfa1c9b1c36 (diff) | |
download | CMake-fcce3ac0a14e89f81cc1dfe618b0bca776bf2329.zip CMake-fcce3ac0a14e89f81cc1dfe618b0bca776bf2329.tar.gz CMake-fcce3ac0a14e89f81cc1dfe618b0bca776bf2329.tar.bz2 |
ENH: Add a way for test to intentionally fail
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CTest/cmCTestTestHandler.cxx | 116 | ||||
-rw-r--r-- | Source/CTest/cmCTestTestHandler.h | 6 | ||||
-rw-r--r-- | Source/cmLocalGenerator.cxx | 12 | ||||
-rw-r--r-- | Source/cmTest.h | 4 |
4 files changed, 134 insertions, 4 deletions
diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index 799a423..7dd6533 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -27,6 +27,7 @@ #include "cmGlobalGenerator.h" #include "cmLocalGenerator.h" #include "cmCommand.h" +#include "cmSystemTools.h" #include <stdlib.h> #include <math.h> @@ -169,6 +170,46 @@ bool cmCTestAddTestCommand::InitialPass(std::vector<std::string> const& 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 // in as well an a subdir (typically used for configuraitons such as @@ -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") ) { @@ -1402,6 +1463,54 @@ bool cmCTestTestHandler::CleanTestOutput(std::string& output, size_t remove_thre } //---------------------------------------------------------------------- +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) { const std::string& testname = args[0]; @@ -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; diff --git a/Source/CTest/cmCTestTestHandler.h b/Source/CTest/cmCTestTestHandler.h index b89eb29..7e9043f 100644 --- a/Source/CTest/cmCTestTestHandler.h +++ b/Source/CTest/cmCTestTestHandler.h @@ -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; }; diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index f0e531d..1aa0686 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -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()) { diff --git a/Source/cmTest.h b/Source/cmTest.h index 506b276..ac1087f 100644 --- a/Source/cmTest.h +++ b/Source/cmTest.h @@ -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; |