ctest.cxx 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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 "cmCTest.h"
  14. #include "cmSystemTools.h"
  15. // Need these for documentation support.
  16. #include "cmake.h"
  17. #include "cmDocumentation.h"
  18. //----------------------------------------------------------------------------
  19. static const cmDocumentationEntry cmDocumentationName[] =
  20. {
  21. {0,
  22. " ctest - Testing driver provided by CMake.", 0},
  23. {0,0,0}
  24. };
  25. //----------------------------------------------------------------------------
  26. static const cmDocumentationEntry cmDocumentationUsage[] =
  27. {
  28. {0,
  29. " ctest [options]", 0},
  30. {0,0,0}
  31. };
  32. //----------------------------------------------------------------------------
  33. static const cmDocumentationEntry cmDocumentationDescription[] =
  34. {
  35. {0,
  36. "The \"ctest\" executable is the CMake test driver program. "
  37. "CMake-generated build trees created for projects that use "
  38. "the ENABLE_TESTING and ADD_TEST commands have testing support. "
  39. "This program will run the tests and report results.", 0},
  40. CMAKE_STANDARD_INTRODUCTION,
  41. {0,0,0}
  42. };
  43. //----------------------------------------------------------------------------
  44. static const cmDocumentationEntry cmDocumentationOptions[] =
  45. {
  46. {"-C <config>", "Choose configuration to test.",
  47. "Some CMake-generated build trees can have multiple build configurations "
  48. "in the same tree. This option can be used to specify which one should "
  49. "be tested. Example configurations are \"Debug\" and \"Release\"."},
  50. {"-V,--verbose", "Enable verbose output from tests.",
  51. "Test output is normally suppressed and only summary information is "
  52. "displayed. This option will show all test output."},
  53. {"-N,--show-only", "Disable actual execution of tests.",
  54. "This option tells ctest to list the tests that would be run but not "
  55. "actually run them. Useful in conjunction with the -R and -E options."},
  56. {"-R <regex>", "Run tests matching regular expression.",
  57. "This option tells ctest to run only the tests whose names match the "
  58. "given regular expression."},
  59. {"-E <regex>", "Exclude tests matching regular expression.",
  60. "This option tells ctest to NOT run the tests whose names match the "
  61. "given regular expression."},
  62. {0,0,0}
  63. };
  64. //----------------------------------------------------------------------------
  65. static const cmDocumentationEntry cmDocumentationSeeAlso[] =
  66. {
  67. {0, "cmake", 0},
  68. {0, "ccmake", 0},
  69. {0, 0, 0}
  70. };
  71. // this is a test driver program for cmCTest.
  72. int main (int argc, char *argv[])
  73. {
  74. cmSystemTools::EnableMSVCDebugHook();
  75. // If there is a testing input file, check for documentation options
  76. // only if there are actually arguments. We want running without
  77. // arguments to run tests.
  78. if(argc > 1 || !cmSystemTools::FileExists("DartTestfile.txt"))
  79. {
  80. if(argc == 1)
  81. {
  82. std::cout << "*********************************" << std::endl;
  83. std::cout << "No test configuration file found!" << std::endl;
  84. std::cout << "*********************************" << std::endl;
  85. }
  86. cmDocumentation doc;
  87. if(doc.CheckOptions(argc, argv))
  88. {
  89. // Construct and print requested documentation.
  90. doc.SetName("ctest");
  91. doc.SetNameSection(cmDocumentationName);
  92. doc.SetUsageSection(cmDocumentationUsage);
  93. doc.SetDescriptionSection(cmDocumentationDescription);
  94. doc.SetOptionsSection(cmDocumentationOptions);
  95. doc.SetSeeAlsoList(cmDocumentationSeeAlso);
  96. return doc.PrintRequestedDocumentation(std::cout)? 0:1;
  97. }
  98. }
  99. cmCTest inst;
  100. // look at the args
  101. std::vector<std::string> args;
  102. for(int i =0; i < argc; ++i)
  103. {
  104. args.push_back(argv[i]);
  105. }
  106. #ifdef _WIN32
  107. std::string comspec = "cmw9xcom.exe";
  108. cmSystemTools::SetWindows9xComspecSubstitute(comspec.c_str());
  109. #endif
  110. for(unsigned int i=1; i < args.size(); ++i)
  111. {
  112. std::string arg = args[i];
  113. if(arg.find("-C",0) == 0 && i < args.size() - 1)
  114. {
  115. inst.m_ConfigType = args[i+1];
  116. }
  117. if( arg.find("-V",0) == 0 || arg.find("--verbose",0) == 0 )
  118. {
  119. inst.m_Verbose = true;
  120. }
  121. if( arg.find("-N",0) == 0 || arg.find("--show-only",0) == 0 )
  122. {
  123. inst.m_ShowOnly = true;
  124. }
  125. if( arg.find("-D",0) == 0 && i < args.size() - 1 )
  126. {
  127. inst.m_DartMode = true;
  128. std::string targ = args[i+1];
  129. if ( targ == "Experimental" )
  130. {
  131. inst.SetTestModel(cmCTest::EXPERIMENTAL);
  132. inst.SetTest("Start");
  133. inst.SetTest("Configure");
  134. inst.SetTest("Build");
  135. inst.SetTest("Test");
  136. inst.SetTest("Coverage");
  137. inst.SetTest("Submit");
  138. }
  139. else if ( targ == "Continuous" )
  140. {
  141. inst.SetTestModel(cmCTest::CONTINUOUS);
  142. inst.SetTest("Start");
  143. inst.SetTest("Update");
  144. inst.SetTest("Configure");
  145. inst.SetTest("Build");
  146. inst.SetTest("Test");
  147. inst.SetTest("Coverage");
  148. inst.SetTest("Submit");
  149. }
  150. else if ( targ == "Nightly" )
  151. {
  152. inst.SetTestModel(cmCTest::NIGHTLY);
  153. inst.SetTest("Start");
  154. inst.SetTest("Update");
  155. inst.SetTest("Configure");
  156. inst.SetTest("Build");
  157. inst.SetTest("Test");
  158. inst.SetTest("Coverage");
  159. inst.SetTest("Submit");
  160. }
  161. else if ( targ == "MemoryCheck" )
  162. {
  163. inst.SetTestModel(cmCTest::EXPERIMENTAL);
  164. inst.SetTest("Start");
  165. inst.SetTest("Configure");
  166. inst.SetTest("Build");
  167. inst.SetTest("Purify");
  168. inst.SetTest("Coverage");
  169. inst.SetTest("Submit");
  170. }
  171. else if ( targ == "NightlyMemoryCheck" )
  172. {
  173. inst.SetTestModel(cmCTest::NIGHTLY);
  174. inst.SetTest("Start");
  175. inst.SetTest("Update");
  176. inst.SetTest("Configure");
  177. inst.SetTest("Build");
  178. inst.SetTest("Purify");
  179. inst.SetTest("Coverage");
  180. inst.SetTest("Submit");
  181. }
  182. }
  183. if( ( arg.find("-T",0) == 0 ) &&
  184. (i < args.size() -1) )
  185. {
  186. inst.m_DartMode = true;
  187. inst.SetTest(args[i+1].c_str());
  188. }
  189. if( ( arg.find("-M",0) == 0 || arg.find("--test-model",0) == 0 ) &&
  190. (i < args.size() -1) )
  191. {
  192. std::string& str = args[i+1];
  193. if ( str == "NIGHTLY" || str == "nightly" || str == "Nightly" )
  194. {
  195. inst.SetTestModel(cmCTest::NIGHTLY);
  196. }
  197. else if ( str == "CONTINUOUS" || str == "continuous" ||
  198. str == "Continuous" )
  199. {
  200. inst.SetTestModel(cmCTest::CONTINUOUS);
  201. std::cout << "Continuous" << std::endl;
  202. }
  203. else
  204. {
  205. inst.SetTestModel(cmCTest::EXPERIMENTAL);
  206. }
  207. }
  208. if(arg.find("-R",0) == 0 && i < args.size() - 1)
  209. {
  210. inst.m_UseIncludeRegExp = true;
  211. inst.m_IncludeRegExp = args[i+1];
  212. }
  213. if(arg.find("-E",0) == 0 && i < args.size() - 1)
  214. {
  215. inst.m_UseExcludeRegExp = true;
  216. inst.m_ExcludeRegExp = args[i+1];
  217. inst.m_UseExcludeRegExpFirst = inst.m_UseIncludeRegExp ? false : true;
  218. }
  219. }
  220. // call process directory
  221. inst.Initialize();
  222. int res = inst.ProcessTests();
  223. inst.Finalize();
  224. return res;
  225. }