cmTestGenerator.cxx 3.7 KB

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