cmTestGenerator.cxx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 "cmTestGenerator.h"
  14. #include "cmSystemTools.h"
  15. #include "cmTest.h"
  16. //----------------------------------------------------------------------------
  17. cmTestGenerator
  18. ::cmTestGenerator(cmTest* test,
  19. std::vector<std::string> const& configurations):
  20. cmScriptGenerator("CTEST_CONFIGURATION_TYPE", configurations),
  21. Test(test)
  22. {
  23. this->ActionsPerConfig = false;
  24. this->TestGenerated = false;
  25. }
  26. //----------------------------------------------------------------------------
  27. cmTestGenerator
  28. ::~cmTestGenerator()
  29. {
  30. }
  31. //----------------------------------------------------------------------------
  32. void cmTestGenerator::GenerateScriptConfigs(std::ostream& os,
  33. Indent const& indent)
  34. {
  35. // First create the tests.
  36. this->cmScriptGenerator::GenerateScriptConfigs(os, indent);
  37. // Now generate the test properties.
  38. if(this->TestGenerated)
  39. {
  40. cmTest* test = this->Test;
  41. std::ostream& fout = os;
  42. cmPropertyMap::const_iterator pit;
  43. cmPropertyMap* mpit = &test->GetProperties();
  44. if ( mpit->size() )
  45. {
  46. fout << "SET_TESTS_PROPERTIES(" << test->GetName() << " PROPERTIES ";
  47. for ( pit = mpit->begin(); pit != mpit->end(); ++ pit )
  48. {
  49. fout << " " << pit->first.c_str() << " \"";
  50. const char* value = pit->second.GetValue();
  51. for ( ; *value; ++ value )
  52. {
  53. switch ( *value )
  54. {
  55. case '\\':
  56. case '"':
  57. case ' ':
  58. case '#':
  59. case '(':
  60. case ')':
  61. case '$':
  62. case '^':
  63. fout << "\\" << *value;
  64. break;
  65. case '\t':
  66. fout << "\\t";
  67. break;
  68. case '\n':
  69. fout << "\\n";
  70. break;
  71. case '\r':
  72. fout << "\\r";
  73. break;
  74. default:
  75. fout << *value;
  76. }
  77. }
  78. fout << "\"";
  79. }
  80. fout << ")" << std::endl;
  81. }
  82. }
  83. }
  84. //----------------------------------------------------------------------------
  85. void cmTestGenerator::GenerateScriptActions(std::ostream& fout,
  86. Indent const& indent)
  87. {
  88. this->TestGenerated = true;
  89. // Get the test command line to be executed.
  90. std::vector<std::string> const& command = this->Test->GetCommand();
  91. std::string exe = command[0];
  92. cmSystemTools::ConvertToUnixSlashes(exe);
  93. fout << indent;
  94. fout << "ADD_TEST(";
  95. fout << this->Test->GetName() << " \"" << exe << "\"";
  96. for(std::vector<std::string>::const_iterator argit = command.begin()+1;
  97. argit != command.end(); ++argit)
  98. {
  99. // Just double-quote all arguments so they are re-parsed
  100. // correctly by the test system.
  101. fout << " \"";
  102. for(std::string::const_iterator c = argit->begin();
  103. c != argit->end(); ++c)
  104. {
  105. // Escape quotes within arguments. We should escape
  106. // backslashes too but we cannot because it makes the result
  107. // inconsistent with previous behavior of this command.
  108. if((*c == '"'))
  109. {
  110. fout << '\\';
  111. }
  112. fout << *c;
  113. }
  114. fout << "\"";
  115. }
  116. fout << ")" << std::endl;
  117. }