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