ctest.cxx 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 a non-interactive mode. "
  95. "On Windows this means that in non-interactive mode, all system debug pop up windows are blocked. "
  96. "In dashboard mode (Experimental, Nightly, Continuous), the default is non-interactive. "
  97. "When just running tests not for a dashboard the default is to allow popups and interactive "
  98. "debugging."},
  99. {"--build-and-test", "Build and run a test.",
  100. "This option allows a test to be compiled and then run. "
  101. "CMake is run on the source tree and then based on the generator the build is run. "
  102. "The arguments to this command line are the source and binary directories. "
  103. "Other options that affect this mode are --build-target --build-nocmake, --build-run-dir, "
  104. "--build-two-config, --build-exe-dir, --build-generator, --build-project,"
  105. "--build-makeprogram "
  106. "--build-noclean, --build-options"},
  107. {"--build-target", "Specify a specific target to build.",
  108. "This option goes with the --build-and-test option, if left out the all target is built." },
  109. {"--build-nocmake", "Run the build without running cmake first.",
  110. "Skip the cmake step." },
  111. {"--build-run-dir", "Specify directory to run programs from.",
  112. "Directory where programs will be after it has been compiled." },
  113. {"--build-two-config", "Run CMake twice", "" },
  114. {"--build-exe-dir", "Specify the directory for the executable.", "" },
  115. {"--build-generator", "Specify the generator to use.", "" },
  116. {"--build-project", "Specify the name of the project to build.", "" },
  117. {"--build-makeprogram", "Specify the make program to use.", "" },
  118. {"--build-noclean", "Skip the make clean step.", "" },
  119. {"--build-options", "Add extra options to the build step.", "" },
  120. {"--tomorrow-tag", "Nightly or experimental starts with next day tag.",
  121. "This is useful if the build will not finish in one day." },
  122. {0,0,0}
  123. };
  124. //----------------------------------------------------------------------------
  125. static const cmDocumentationEntry cmDocumentationSeeAlso[] =
  126. {
  127. {0, "cmake", 0},
  128. {0, "ccmake", 0},
  129. {0, 0, 0}
  130. };
  131. // this is a test driver program for cmCTest.
  132. int main (int argc, char *argv[])
  133. {
  134. cmSystemTools::EnableMSVCDebugHook();
  135. int nocwd = 0;
  136. if ( cmSystemTools::GetCurrentWorkingDirectory().size() == 0 )
  137. {
  138. std::cerr << "Current working directory cannot be established." << std::endl;
  139. nocwd = 1;
  140. }
  141. // If there is a testing input file, check for documentation options
  142. // only if there are actually arguments. We want running without
  143. // arguments to run tests.
  144. if(argc > 1 || !cmSystemTools::FileExists("DartTestfile.txt"))
  145. {
  146. if(argc == 1)
  147. {
  148. std::cout << "*********************************" << std::endl;
  149. std::cout << "No test configuration file found!" << std::endl;
  150. std::cout << "*********************************" << std::endl;
  151. }
  152. cmDocumentation doc;
  153. if(doc.CheckOptions(argc, argv) || nocwd)
  154. {
  155. // Construct and print requested documentation.
  156. doc.SetName("ctest");
  157. doc.SetNameSection(cmDocumentationName);
  158. doc.SetUsageSection(cmDocumentationUsage);
  159. doc.SetDescriptionSection(cmDocumentationDescription);
  160. doc.SetOptionsSection(cmDocumentationOptions);
  161. doc.SetSeeAlsoList(cmDocumentationSeeAlso);
  162. return doc.PrintRequestedDocumentation(std::cout)? 0:1;
  163. }
  164. }
  165. #ifdef _WIN32
  166. std::string comspec = "cmw9xcom.exe";
  167. cmSystemTools::SetWindows9xComspecSubstitute(comspec.c_str());
  168. #endif
  169. cmCTest inst;
  170. // copy the args to a vector
  171. std::vector<std::string> args;
  172. for(int i =0; i < argc; ++i)
  173. {
  174. args.push_back(argv[i]);
  175. }
  176. // run ctest
  177. int res = inst.Run(args);
  178. cmListFileCache::ClearCache();
  179. return res;
  180. }