1
0

cmAddTestCommand.cxx 2.3 KB

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