ctest.cxx 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. {"-D <DashboardTest>", "Execute dashboard test",
  63. "This option tells ctest to perform act as a Dart client and perform "
  64. "a dashboard test. All tests are ModeTest, where Mode can be Experimental, "
  65. "Nightly, and Continuous, and Test can be Start, Update, Configure, "
  66. "Build, Test, Coverage, and Submit."},
  67. {"-M <TestModel>", "Sets the model for a dashboard",
  68. "This option tells ctest to act as a Dart client "
  69. "where the TestModel can be Experimental, "
  70. "Nightly, and Continuous. Combining -M and -T is similar to -D"},
  71. {"-T <action>", "Sets the dashboard action to perform",
  72. "This option tells ctest to act as a Dart client "
  73. "and perform some action such as start, build, test etc. "
  74. "Combining -M and -T is similar to -D"},
  75. {"-S <ConfigScript>", "Execute a dashboard for a configuration",
  76. "This option tells ctest to load in a configuration script which sets "
  77. "a number of parameters such as the binary and source directories. Then "
  78. "ctest will do what is required to create and run a dashboard. This "
  79. "option basically sets up a dashboard and then runs ctest -D with the "
  80. "appropriate options."},
  81. {"-A <Notes file>", "Add a notes file with submission",
  82. "This option tells ctest to include a notes file when submitting dashboard. "},
  83. {"-I [Start,End,Stride,test#,test#|Test file]",
  84. "Run a specific number of tests by number.",
  85. "This option causes ctest to run tests starting at number Start, ending "
  86. "at number End, and incrementing by Stride. Any additional numbers after "
  87. "Stride are considered individual test numbers. Start, End,or stride "
  88. "can be empty. Optionally a file can be given that contains the same "
  89. "syntax as the command line."},
  90. {"-U", "Take the Union of -I and -R",
  91. "When both -R and -I are specified by default the intersection of "
  92. "tests are run. By specifying -U the union of tests is run instead."},
  93. {"--interactive-debug-mode [0|1]", "Set the interactive mode to 0 or 1.",
  94. "This option causes ctest to run tests in either an interactive mode or "
  95. "a non-interactive mode. On Windows this means that in non-interactive "
  96. "mode, all system debug pop up windows are blocked. In dashboard mode "
  97. "(Experimental, Nightly, Continuous), the default is non-interactive. "
  98. "When just running tests not for a dashboard the default is to allow "
  99. "popups and interactive "
  100. "debugging."},
  101. {"--build-and-test", "Configure, build and run a test.",
  102. "This option tells ctest to configure (i.e. run cmake on), build, and or "
  103. "execute a test. The configure and test steps are optional. The arguments "
  104. "to this command line are the source and binary directories. By default "
  105. "this will run CMake on the Source/Bin directories specified unless "
  106. "--build-nocmake is specified. Both --build-makeprogram and "
  107. "--build-generator MUST be provided to use --built-and-test. If "
  108. "--test-command is specified then that will be run after the build is "
  109. "complete. Other options that affect this mode are --build-target "
  110. "--build-nocmake, --build-run-dir, "
  111. "--build-two-config, --build-exe-dir, --build-project,"
  112. "--build-noclean, --build-options"},
  113. {"--build-target", "Specify a specific target to build.",
  114. "This option goes with the --build-and-test option, if left out the all target is built." },
  115. {"--build-nocmake", "Run the build without running cmake first.",
  116. "Skip the cmake step." },
  117. {"--build-run-dir", "Specify directory to run programs from.",
  118. "Directory where programs will be after it has been compiled." },
  119. {"--build-two-config", "Run CMake twice", "" },
  120. {"--build-exe-dir", "Specify the directory for the executable.", "" },
  121. {"--build-generator", "Specify the generator to use.", "" },
  122. {"--build-project", "Specify the name of the project to build.", "" },
  123. {"--build-makeprogram", "Specify the make program to use.", "" },
  124. {"--build-noclean", "Skip the make clean step.", "" },
  125. {"--build-options", "Add extra options to the build step.",
  126. "This option must be the last option with the exception of --test-command" },
  127. {"--test-command", "The test to run with the --build-and-test option.", "" },
  128. {"--tomorrow-tag", "Nightly or experimental starts with next day tag.",
  129. "This is useful if the build will not finish in one day." },
  130. {"--ctest-config", "The configuration file used to initialize CTest state when submitting dashboards.",
  131. "This option tells CTest to use different initialization file instead of "
  132. "DartConfiguration.tcl. This way multiple initialization files can be used "
  133. "for example to submit to multiple dashboards." },
  134. {0,0,0}
  135. };
  136. //----------------------------------------------------------------------------
  137. static const cmDocumentationEntry cmDocumentationSeeAlso[] =
  138. {
  139. {0, "cmake", 0},
  140. {0, "ccmake", 0},
  141. {0, 0, 0}
  142. };
  143. // this is a test driver program for cmCTest.
  144. int main (int argc, char *argv[])
  145. {
  146. cmSystemTools::EnableMSVCDebugHook();
  147. int nocwd = 0;
  148. if ( cmSystemTools::GetCurrentWorkingDirectory().size() == 0 )
  149. {
  150. std::cerr << "Current working directory cannot be established." << std::endl;
  151. nocwd = 1;
  152. }
  153. // If there is a testing input file, check for documentation options
  154. // only if there are actually arguments. We want running without
  155. // arguments to run tests.
  156. if(argc > 1 || !cmSystemTools::FileExists("DartTestfile.txt") &&
  157. !cmSystemTools::FileExists("CTestTestfile.cmake"))
  158. {
  159. if(argc == 1)
  160. {
  161. std::cout << "*********************************" << std::endl;
  162. std::cout << "No test configuration file found!" << std::endl;
  163. std::cout << "*********************************" << std::endl;
  164. }
  165. cmDocumentation doc;
  166. if(doc.CheckOptions(argc, argv) || nocwd)
  167. {
  168. // Construct and print requested documentation.
  169. doc.SetName("ctest");
  170. doc.SetNameSection(cmDocumentationName);
  171. doc.SetUsageSection(cmDocumentationUsage);
  172. doc.SetDescriptionSection(cmDocumentationDescription);
  173. doc.SetOptionsSection(cmDocumentationOptions);
  174. doc.SetSeeAlsoList(cmDocumentationSeeAlso);
  175. return doc.PrintRequestedDocumentation(std::cout)? 0:1;
  176. }
  177. }
  178. #ifdef _WIN32
  179. std::string comspec = "cmw9xcom.exe";
  180. cmSystemTools::SetWindows9xComspecSubstitute(comspec.c_str());
  181. #endif
  182. cmCTest inst;
  183. // copy the args to a vector
  184. std::vector<std::string> args;
  185. for(int i =0; i < argc; ++i)
  186. {
  187. args.push_back(argv[i]);
  188. }
  189. // run ctest
  190. std::string output;
  191. int res = inst.Run(args,&output);
  192. std::cout << output;
  193. cmListFileCache::ClearCache();
  194. return res;
  195. }