cmAddTestCommand.cxx 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. m_Args.erase(m_Args.begin(), m_Args.end());
  29. std::copy(args.begin(),args.end(),std::back_inserter(m_Args));
  30. return true;
  31. }
  32. // we append to the file in the final pass because Enable Testing command
  33. // creates the file in the final pass.
  34. void cmAddTestCommand::FinalPass()
  35. {
  36. // Expand any CMake variables
  37. std::vector<std::string>::iterator s;
  38. for (s = m_Args.begin(); s != m_Args.end(); ++s)
  39. {
  40. m_Makefile->ExpandVariablesInString(*s);
  41. }
  42. // Create a full path filename for output Testfile
  43. std::string fname;
  44. fname = m_Makefile->GetStartOutputDirectory();
  45. fname += "/";
  46. fname += "DartTestfile.txt";
  47. // If the file doesn't exist, then ENABLE_TESTING hasn't been run
  48. if (cmSystemTools::FileExists(fname.c_str()))
  49. {
  50. // Open the output Testfile
  51. std::ofstream fout(fname.c_str(), std::ios::app);
  52. if (!fout)
  53. {
  54. cmSystemTools::Error("Error Writing ", fname.c_str());
  55. return;
  56. }
  57. std::vector<std::string>::iterator it;
  58. // for each arg in the test
  59. fout << "ADD_TEST(";
  60. it = m_Args.begin();
  61. fout << (*it).c_str();
  62. ++it;
  63. for (; it != m_Args.end(); ++it)
  64. {
  65. if(it->find(" ") != std::string::npos)
  66. {
  67. fout << " \"" << *it << "\"";
  68. }
  69. else
  70. {
  71. fout << " " << *it;
  72. }
  73. }
  74. fout << ")" << std::endl;
  75. fout.close();
  76. }
  77. return;
  78. }