cmAddTestCommand.cxx 2.3 KB

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