STYLE: Fix line-too-long
[cmake.git] / Source / ctest.cxx
blob1d4c9b284b0b666e0a946c76fe5d72931da02d1e
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: ctest.cxx,v $
5 Language: C++
6 Date: $Date: 2008-09-22 18:04:12 $
7 Version: $Revision: 1.103 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmCTest.h"
18 #include "cmSystemTools.h"
20 // Need these for documentation support.
21 #include "cmake.h"
22 #include "cmDocumentation.h"
24 #include "CTest/cmCTestScriptHandler.h"
25 //----------------------------------------------------------------------------
26 static const char * cmDocumentationName[][3] =
28 {0,
29 " ctest - Testing driver provided by CMake.", 0},
30 {0,0,0}
33 //----------------------------------------------------------------------------
34 static const char * cmDocumentationUsage[][3] =
36 {0,
37 " ctest [options]", 0},
38 {0,0,0}
41 //----------------------------------------------------------------------------
42 static const char * cmDocumentationDescription[][3] =
44 {0,
45 "The \"ctest\" executable is the CMake test driver program. "
46 "CMake-generated build trees created for projects that use "
47 "the ENABLE_TESTING and ADD_TEST commands have testing support. "
48 "This program will run the tests and report results.", 0},
49 {0,0,0}
52 //----------------------------------------------------------------------------
53 static const char * cmDocumentationOptions[][3] =
55 {"-C <cfg>, --build-config <cfg>", "Choose configuration to test.",
56 "Some CMake-generated build trees can have multiple build configurations "
57 "in the same tree. This option can be used to specify which one should "
58 "be tested. Example configurations are \"Debug\" and \"Release\"."},
59 {"-V,--verbose", "Enable verbose output from tests.",
60 "Test output is normally suppressed and only summary information is "
61 "displayed. This option will show all test output."},
62 {"-VV,--extra-verbose", "Enable more verbose output from tests.",
63 "Test output is normally suppressed and only summary information is "
64 "displayed. This option will show even more test output."},
65 {"--debug", "Displaying more verbose internals of CTest.",
66 "This feature will result in large number of output that is mostly "
67 "useful for debugging dashboard problems."},
68 {"-Q,--quiet", "Make ctest quiet.",
69 "This option will suppress all the output. The output log file will "
70 "still be generated if the --output-log is specified. Options such "
71 "as --verbose, --extra-verbose, and --debug are ignored if --quiet is "
72 "specified."},
73 {"-O <file>, --output-log <file>", "Output to log file",
74 "This option tells ctest to write all its output to a log file."},
75 {"-N,--show-only", "Disable actual execution of tests.",
76 "This option tells ctest to list the tests that would be run but not "
77 "actually run them. Useful in conjunction with the -R and -E options."},
78 {"-R <regex>, --tests-regex <regex>", "Run tests matching regular "
79 "expression.",
80 "This option tells ctest to run only the tests whose names match the "
81 "given regular expression."},
82 {"-E <regex>, --exclude-regex <regex>", "Exclude tests matching regular "
83 "expression.",
84 "This option tells ctest to NOT run the tests whose names match the "
85 "given regular expression."},
86 {"-D <dashboard>, --dashboard <dashboard>", "Execute dashboard test",
87 "This option tells ctest to perform act as a Dart client and perform "
88 "a dashboard test. All tests are <Mode><Test>, where Mode can be "
89 "Experimental, Nightly, and Continuous, and Test can be Start, Update, "
90 "Configure, Build, Test, Coverage, and Submit."},
91 {"-M <model>, --test-model <model>", "Sets the model for a dashboard",
92 "This option tells ctest to act as a Dart client "
93 "where the TestModel can be Experimental, "
94 "Nightly, and Continuous. Combining -M and -T is similar to -D"},
95 {"-T <action>, --test-action <action>", "Sets the dashboard action to "
96 "perform",
97 "This option tells ctest to act as a Dart client "
98 "and perform some action such as start, build, test etc. "
99 "Combining -M and -T is similar to -D"},
100 {"--track <track>", "Specify the track to submit dashboard to",
101 "Submit dashboard to specified track instead of default one. By "
102 "default, the dashboard is submitted to Nightly, Experimental, or "
103 "Continuous track, but by specifying this option, the track can be "
104 "arbitrary."},
105 {"-S <script>, --script <script>", "Execute a dashboard for a "
106 "configuration",
107 "This option tells ctest to load in a configuration script which sets "
108 "a number of parameters such as the binary and source directories. Then "
109 "ctest will do what is required to create and run a dashboard. This "
110 "option basically sets up a dashboard and then runs ctest -D with the "
111 "appropriate options."},
112 {"-SP <script>, --script-new-process <script>", "Execute a dashboard for a "
113 "configuration",
114 "This option does the same operations as -S but it will do them in a "
115 "seperate process. This is primarily useful in cases where the script "
116 "may modify the environment and you do not want the modified enviroment "
117 "to impact other -S scripts."},
118 {"-A <file>, --add-notes <file>", "Add a notes file with submission",
119 "This option tells ctest to include a notes file when submitting "
120 "dashboard. "},
121 {"-I [Start,End,Stride,test#,test#|Test file], --tests-information",
122 "Run a specific number of tests by number.",
123 "This option causes ctest to run tests starting at number Start, ending "
124 "at number End, and incrementing by Stride. Any additional numbers after "
125 "Stride are considered individual test numbers. Start, End,or stride "
126 "can be empty. Optionally a file can be given that contains the same "
127 "syntax as the command line."},
128 {"-U, --union", "Take the Union of -I and -R",
129 "When both -R and -I are specified by default the intersection of "
130 "tests are run. By specifying -U the union of tests is run instead."},
131 {"--max-width <width>", "Set the max width for a test name to output",
132 "Set the maximum width for each test name to show in the output. This "
133 "allows the user to widen the output to avoid cliping the test name which "
134 "can be very annoying."},
135 {"--interactive-debug-mode [0|1]", "Set the interactive mode to 0 or 1.",
136 "This option causes ctest to run tests in either an interactive mode or "
137 "a non-interactive mode. On Windows this means that in non-interactive "
138 "mode, all system debug pop up windows are blocked. In dashboard mode "
139 "(Experimental, Nightly, Continuous), the default is non-interactive. "
140 "When just running tests not for a dashboard the default is to allow "
141 "popups and interactive "
142 "debugging."},
143 {"--build-and-test", "Configure, build and run a test.",
144 "This option tells ctest to configure (i.e. run cmake on), build, and or "
145 "execute a test. The configure and test steps are optional. The arguments "
146 "to this command line are the source and binary directories. By default "
147 "this will run CMake on the Source/Bin directories specified unless "
148 "--build-nocmake is specified. Both --build-makeprogram and "
149 "--build-generator MUST be provided to use --built-and-test. If "
150 "--test-command is specified then that will be run after the build is "
151 "complete. Other options that affect this mode are --build-target "
152 "--build-nocmake, --build-run-dir, "
153 "--build-two-config, --build-exe-dir, --build-project,"
154 "--build-noclean, --build-options"},
155 {"--build-target", "Specify a specific target to build.",
156 "This option goes with the --build-and-test option, if left out the all "
157 "target is built." },
158 {"--build-nocmake", "Run the build without running cmake first.",
159 "Skip the cmake step." },
160 {"--build-run-dir", "Specify directory to run programs from.",
161 "Directory where programs will be after it has been compiled." },
162 {"--build-two-config", "Run CMake twice", "" },
163 {"--build-exe-dir", "Specify the directory for the executable.", "" },
164 {"--build-generator", "Specify the generator to use.", "" },
165 {"--build-project", "Specify the name of the project to build.", "" },
166 {"--build-makeprogram", "Specify the make program to use.", "" },
167 {"--build-noclean", "Skip the make clean step.", "" },
168 {"--build-config-sample",
169 "A sample executable to use to determine the configuraiton",
170 "A sample executable to use to determine the configuraiton that "
171 "should be used. e.g. Debug/Release/etc" },
172 {"--build-options", "Add extra options to the build step.",
173 "This option must be the last option with the exception of --test-command"
176 {"--test-command", "The test to run with the --build-and-test option.", ""
178 {"--test-timeout", "The time limit in seconds, internal use only.", ""
180 {"--tomorrow-tag", "Nightly or experimental starts with next day tag.",
181 "This is useful if the build will not finish in one day." },
182 {"--ctest-config", "The configuration file used to initialize CTest state "
183 "when submitting dashboards.",
184 "This option tells CTest to use different initialization file instead of "
185 "CTestConfiguration.tcl. This way multiple initialization files can be "
186 "used for example to submit to multiple dashboards." },
187 {"--overwrite", "Overwrite CTest configuration option.",
188 "By default ctest uses configuration options from configuration file. "
189 "This option will overwrite the configuration option." },
190 {"--extra-submit <file>[;<file>]", "Submit extra files to the dashboard.",
191 "This option will submit extra files to the dashboard." },
192 {"--force-new-ctest-process", "Run child CTest instances as new processes",
193 "By default CTest will run child CTest instances within the same process. "
194 "If this behavior is not desired, this argument will enforce new "
195 "processes for child CTest processes." },
196 {"--submit-index", "Submit individual dashboard tests with specific index",
197 "This option allows performing the same CTest action (such as test) "
198 "multiple times and submit all stages to the same dashboard (Dart2 "
199 "required). Each execution requires different index." },
200 {0,0,0}
203 //----------------------------------------------------------------------------
204 static const char * cmDocumentationSeeAlso[][3] =
206 {0, "cmake", 0},
207 {0, "ccmake", 0},
208 {0, 0, 0}
211 // this is a test driver program for cmCTest.
212 int main (int argc, char *argv[])
214 cmSystemTools::DoNotInheritStdPipes();
215 cmSystemTools::EnableMSVCDebugHook();
216 cmSystemTools::FindExecutableDirectory(argv[0]);
217 int nocwd = 0;
218 cmCTest inst;
220 if ( cmSystemTools::GetCurrentWorkingDirectory().size() == 0 )
222 cmCTestLog(&inst, ERROR_MESSAGE,
223 "Current working directory cannot be established." << std::endl);
224 nocwd = 1;
227 // If there is a testing input file, check for documentation options
228 // only if there are actually arguments. We want running without
229 // arguments to run tests.
230 if(argc > 1 || !(cmSystemTools::FileExists("CTestTestfile.cmake") ||
231 cmSystemTools::FileExists("DartTestfile.txt")))
233 if(argc == 1)
235 cmCTestLog(&inst, ERROR_MESSAGE, "*********************************"
236 << std::endl
237 << "No test configuration file found!" << std::endl
238 << "*********************************" << std::endl);
240 cmDocumentation doc;
241 if(doc.CheckOptions(argc, argv) || nocwd)
243 // Construct and print requested documentation.
244 std::vector<cmDocumentationEntry> commands;
245 cmCTestScriptHandler* ch =
246 static_cast<cmCTestScriptHandler*>(inst.GetHandler("script"));
247 ch->CreateCMake();
248 ch->GetCommandDocumentation(commands);
250 doc.SetName("ctest");
251 doc.SetSection("Name",cmDocumentationName);
252 doc.SetSection("Usage",cmDocumentationUsage);
253 doc.SetSection("Description",cmDocumentationDescription);
254 doc.SetSection("Options",cmDocumentationOptions);
255 doc.SetSection("Commands",commands);
256 doc.SetSeeAlsoList(cmDocumentationSeeAlso);
257 #ifdef cout
258 # undef cout
259 #endif
260 return doc.PrintRequestedDocumentation(std::cout)? 0:1;
261 #define cout no_cout_use_cmCTestLog
265 #ifdef _WIN32
266 std::string comspec = "cmw9xcom.exe";
267 cmSystemTools::SetWindows9xComspecSubstitute(comspec.c_str());
268 #endif
269 // copy the args to a vector
270 std::vector<std::string> args;
271 for(int i =0; i < argc; ++i)
273 args.push_back(argv[i]);
275 // run ctest
276 std::string output;
277 int res = inst.Run(args,&output);
278 cmCTestLog(&inst, OUTPUT, output);
280 return res;