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