summaryrefslogtreecommitdiffstats
path: root/Source/ctest.cxx
blob: 3eb555195035db2fa87bd8b2e86c382ae688d259 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*============================================================================
  CMake - Cross Platform Makefile Generator
  Copyright 2000-2009 Kitware, Inc., Insight Software Consortium

  Distributed under the OSI-approved BSD License (the "License");
  see accompanying file Copyright.txt for details.

  This software is distributed WITHOUT ANY WARRANTY; without even the
  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  See the License for more information.
============================================================================*/
#include "cmCTest.h"
#include "cmSystemTools.h"

// Need these for documentation support.
#include "cmake.h"
#include "cmDocumentation.h"

#include "CTest/cmCTestScriptHandler.h"
#include "CTest/cmCTestLaunch.h"
#include "cmsys/Encoding.hxx"

//----------------------------------------------------------------------------
static const char * cmDocumentationName[][2] =
{
  {0,
   "  ctest - Testing driver provided by CMake."},
  {0,0}
};

//----------------------------------------------------------------------------
static const char * cmDocumentationUsage[][2] =
{
  {0,
   "  ctest [options]"},
  {0,0}
};

//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
static const char * cmDocumentationOptions[][2] =
{
  {"-C <cfg>, --build-config <cfg>", "Choose configuration to test."},
  {"-V,--verbose", "Enable verbose output from tests."},
  {"-VV,--extra-verbose", "Enable more verbose output from tests."},
  {"--debug", "Displaying more verbose internals of CTest."},
  {"--output-on-failure"},
  {"-F", "Enable failover."},
  {"-j <jobs>, --parallel <jobs>", "Run the tests in parallel using the"
   "given number of jobs."},
  {"-Q,--quiet", "Make ctest quiet."},
  {"-O <file>, --output-log <file>", "Output to log file"},
  {"-N,--show-only", "Disable actual execution of tests."},
  {"-L <regex>, --label-regex <regex>", "Run tests with labels matching "
   "regular expression."},
  {"-R <regex>, --tests-regex <regex>", "Run tests matching regular "
   "expression."},
  {"-E <regex>, --exclude-regex <regex>", "Exclude tests matching regular "
   "expression."},
  {"-LE <regex>, --label-exclude <regex>", "Exclude tests with labels "
   "matching regular expression."},
  {"-D <dashboard>, --dashboard <dashboard>", "Execute dashboard test"},
  {"-D <var>:<type>=<value>", "Define a variable for script mode"},
  {"-M <model>, --test-model <model>", "Sets the model for a dashboard"},
  {"-T <action>, --test-action <action>", "Sets the dashboard action to "
   "perform"},
  {"--track <track>", "Specify the track to submit dashboard to"},
  {"-S <script>, --script <script>", "Execute a dashboard for a "
   "configuration"},
  {"-SP <script>, --script-new-process <script>", "Execute a dashboard for a "
   "configuration"},
  {"-A <file>, --add-notes <file>", "Add a notes file with submission"},
  {"-I [Start,End,Stride,test#,test#|Test file], --tests-information",
   "Run a specific number of tests by number."},
  {"-U, --union", "Take the Union of -I and -R"},
  {"--rerun-failed", "Run only the tests that failed previously"},
  {"--max-width <width>", "Set the max width for a test name to output"},
  {"--interactive-debug-mode [0|1]", "Set the interactive mode to 0 or 1."},
  {"--no-label-summary", "Disable timing summary information for labels."},
  {"--build-and-test", "Configure, build and run a test."},
  {"--build-target", "Specify a specific target to build."},
  {"--build-nocmake", "Run the build without running cmake first."},
  {"--build-run-dir", "Specify directory to run programs from."},
  {"--build-two-config", "Run CMake twice"},
  {"--build-exe-dir", "Specify the directory for the executable."},
  {"--build-generator", "Specify the generator to use."},
  {"--build-generator-toolset", "Specify the generator-specific toolset."},
  {"--build-project", "Specify the name of the project to build."},
  {"--build-makeprogram", "Specify the make program to use."},
  {"--build-noclean", "Skip the make clean step."},
  {"--build-config-sample",
   "A sample executable to use to determine the configuration"},
  {"--build-options", "Add extra options to the build step."},

  {"--test-command", "The test to run with the --build-and-test option."},
  {"--test-timeout", "The time limit in seconds, internal use only."},
  {"--tomorrow-tag", "Nightly or experimental starts with next day tag."},
  {"--ctest-config", "The configuration file used to initialize CTest state "
  "when submitting dashboards."},
  {"--overwrite", "Overwrite CTest configuration option."},
  {"--extra-submit <file>[;<file>]", "Submit extra files to the dashboard."},
  {"--force-new-ctest-process", "Run child CTest instances as new processes"},
  {"--schedule-random", "Use a random order for scheduling tests"},
  {"--submit-index", "Submit individual dashboard tests with specific index"},
  {"--timeout <seconds>", "Set a global timeout on all tests."},
  {"--stop-time <time>",
   "Set a time at which all tests should stop running."},
  {"--http1.0", "Submit using HTTP 1.0."},
  {"--no-compress-output", "Do not compress test output when submitting."},
  {"--print-labels", "Print all available test labels."},
  {0,0}
};

// this is a test driver program for cmCTest.
int main (int argc, char const* const* argv)
{
  cmsys::Encoding::CommandLineArguments encoding_args =
    cmsys::Encoding::CommandLineArguments::Main(argc, argv);
  argc = encoding_args.argc();
  argv = encoding_args.argv();

  cmSystemTools::DoNotInheritStdPipes();
  cmSystemTools::EnableMSVCDebugHook();
  cmSystemTools::FindCMakeResources(argv[0]);

  // Dispatch 'ctest --launch' mode directly.
  if(argc >= 2 && strcmp(argv[1], "--launch") == 0)
    {
    return cmCTestLaunch::Main(argc, argv);
    }

  cmCTest inst;

  if ( cmSystemTools::GetCurrentWorkingDirectory().size() == 0 )
    {
    cmCTestLog(&inst, ERROR_MESSAGE,
      "Current working directory cannot be established." << std::endl);
    return 1;
    }

  // If there is a testing input file, check for documentation options
  // only if there are actually arguments.  We want running without
  // arguments to run tests.
  if(argc > 1 || !(cmSystemTools::FileExists("CTestTestfile.cmake") ||
                   cmSystemTools::FileExists("DartTestfile.txt")))
    {
    if(argc == 1)
      {
      cmCTestLog(&inst, ERROR_MESSAGE, "*********************************"
        << std::endl
        << "No test configuration file found!" << std::endl
        << "*********************************" << std::endl);
      }
    cmDocumentation doc;
    doc.addCTestStandardDocSections();
    if(doc.CheckOptions(argc, argv))
      {
      cmake hcm;
      hcm.AddCMakePaths();

      // Construct and print requested documentation.
      cmCTestScriptHandler* ch =
                 static_cast<cmCTestScriptHandler*>(inst.GetHandler("script"));
      ch->CreateCMake();

      doc.SetShowGenerators(false);
      doc.SetName("ctest");
      doc.SetSection("Name",cmDocumentationName);
      doc.SetSection("Usage",cmDocumentationUsage);
      doc.PrependSection("Options",cmDocumentationOptions);
#ifdef cout
#  undef cout
#endif
      return doc.PrintRequestedDocumentation(std::cout)? 0:1;
#define cout no_cout_use_cmCTestLog
      }
    }

  // copy the args to a vector
  std::vector<std::string> args;
  for(int i =0; i < argc; ++i)
    {
    args.push_back(argv[i]);
    }
  // run ctest
  std::string output;
  int res = inst.Run(args,&output);
  cmCTestLog(&inst, OUTPUT, output);

  return res;
}