cmAddTestCommand.cxx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html 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. // cmExecutableCommand
  15. bool cmAddTestCommand::InitialPass(std::vector<std::string> const& args)
  16. {
  17. // First argument is the name of the test
  18. // Second argument is the name of the executable to run (a target or external
  19. // program)
  20. // Remaining arguments are the arguments to pass to the executable
  21. if(args.size() < 2 )
  22. {
  23. this->SetError("called with incorrect number of arguments");
  24. return false;
  25. }
  26. // store the arguments for the final pass
  27. // also expand any CMake variables
  28. m_Args.erase(m_Args.begin(), m_Args.end());
  29. cmSystemTools::ExpandListArguments(args, 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. // Create a full path filename for output Testfile
  37. std::string fname;
  38. fname = m_Makefile->GetStartOutputDirectory();
  39. fname += "/";
  40. fname += "DartTestfile.txt";
  41. // If the file doesn't exist, then ENABLE_TESTING hasn't been run
  42. if (cmSystemTools::FileExists(fname.c_str()))
  43. {
  44. // Open the output Testfile
  45. std::ofstream fout(fname.c_str(), std::ios::app);
  46. if (!fout)
  47. {
  48. cmSystemTools::Error("Error Writing ", fname.c_str());
  49. return;
  50. }
  51. std::vector<std::string>::iterator it;
  52. // for each arg in the test
  53. fout << "ADD_TEST(";
  54. it = m_Args.begin();
  55. fout << (*it).c_str();
  56. ++it;
  57. for (; it != m_Args.end(); ++it)
  58. {
  59. if(it->find(" ") != std::string::npos)
  60. {
  61. fout << " \"" << *it << "\"";
  62. }
  63. else
  64. {
  65. fout << " " << *it;
  66. }
  67. }
  68. fout << ")" << std::endl;
  69. fout.close();
  70. }
  71. return;
  72. }