cmAddTestCommand.cxx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Insight Consortium. All rights reserved.
  8. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmAddTestCommand.h"
  14. #include "cmCacheManager.h"
  15. // cmExecutableCommand
  16. bool cmAddTestCommand::InitialPass(std::vector<std::string> const& args)
  17. {
  18. // First argument is the name of the test
  19. // Second argument is the name of the executable to run (a target or external
  20. // program)
  21. // Remaining arguments are the arguments to pass to the executable
  22. if(args.size() < 2 )
  23. {
  24. this->SetError("called with incorrect number of arguments");
  25. return false;
  26. }
  27. // store the arguments for the final pass
  28. // also expand any CMake variables
  29. m_Args.erase(m_Args.begin(), m_Args.end());
  30. std::string temp;
  31. for (std::vector<std::string>::const_iterator j = args.begin();
  32. j != args.end(); ++j)
  33. {
  34. temp = *j;
  35. m_Makefile->ExpandVariablesInString(temp);
  36. m_Args.push_back(temp);
  37. }
  38. return true;
  39. }
  40. // we append to the file in the final pass because Enable Testing command
  41. // creates the file in the final pass.
  42. void cmAddTestCommand::FinalPass()
  43. {
  44. // Create a full path filename for output Testfile
  45. std::string fname;
  46. fname = m_Makefile->GetStartOutputDirectory();
  47. fname += "/";
  48. fname += "DartTestfile.txt";
  49. // If the file doesn't exist, then ENABLE_TESTING hasn't been run
  50. if (cmSystemTools::FileExists(fname.c_str()))
  51. {
  52. // Open the output Testfile
  53. std::ofstream fout(fname.c_str(), std::ios::app);
  54. if (!fout)
  55. {
  56. cmSystemTools::Error("Error Writing ", fname.c_str());
  57. return;
  58. }
  59. std::vector<std::string>::iterator it;
  60. // for each arg in the test
  61. fout << "ADD_TEST(";
  62. it = m_Args.begin();
  63. fout << (*it).c_str();
  64. ++it;
  65. for (; it != m_Args.end(); ++it)
  66. {
  67. if(it->find(" ") != std::string::npos)
  68. {
  69. fout << " \"" << *it << "\"";
  70. }
  71. else
  72. {
  73. fout << " " << *it;
  74. }
  75. }
  76. fout << ")" << std::endl;
  77. fout.close();
  78. }
  79. return;
  80. }