Imported Upstream version 2.8.12.2
[platform/upstream/cmake.git] / Source / cmTest.cxx
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
8   This software is distributed WITHOUT ANY WARRANTY; without even the
9   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   See the License for more information.
11 ============================================================================*/
12 #include "cmTest.h"
13 #include "cmSystemTools.h"
14
15 #include "cmake.h"
16 #include "cmMakefile.h"
17
18 //----------------------------------------------------------------------------
19 cmTest::cmTest(cmMakefile* mf)
20 {
21   this->Makefile = mf;
22   this->OldStyle = true;
23   this->Properties.SetCMakeInstance(mf->GetCMakeInstance());
24   this->Backtrace = new cmListFileBacktrace;
25   this->Makefile->GetBacktrace(*this->Backtrace);
26 }
27
28 //----------------------------------------------------------------------------
29 cmTest::~cmTest()
30 {
31   delete this->Backtrace;
32 }
33
34 //----------------------------------------------------------------------------
35 cmListFileBacktrace const& cmTest::GetBacktrace() const
36 {
37   return *this->Backtrace;
38 }
39
40 //----------------------------------------------------------------------------
41 void cmTest::SetName(const char* name)
42 {
43   if ( !name )
44     {
45     name = "";
46     }
47   this->Name = name;
48 }
49
50 //----------------------------------------------------------------------------
51 void cmTest::SetCommand(std::vector<std::string> const& command)
52 {
53   this->Command = command;
54 }
55
56 //----------------------------------------------------------------------------
57 const char *cmTest::GetProperty(const char* prop) const
58 {
59   bool chain = false;
60   const char *retVal =
61     this->Properties.GetPropertyValue(prop, cmProperty::TEST, chain);
62   if (chain)
63     {
64     return this->Makefile->GetProperty(prop,cmProperty::TEST);
65     }
66   return retVal;
67 }
68
69 //----------------------------------------------------------------------------
70 bool cmTest::GetPropertyAsBool(const char* prop) const
71 {
72   return cmSystemTools::IsOn(this->GetProperty(prop));
73 }
74
75 //----------------------------------------------------------------------------
76 void cmTest::SetProperty(const char* prop, const char* value)
77 {
78   if (!prop)
79     {
80     return;
81     }
82
83   this->Properties.SetProperty(prop, value, cmProperty::TEST);
84 }
85
86 //----------------------------------------------------------------------------
87 void cmTest::AppendProperty(const char* prop, const char* value, bool asString)
88 {
89   if (!prop)
90     {
91     return;
92     }
93   this->Properties.AppendProperty(prop, value, cmProperty::TEST, asString);
94 }
95
96 //----------------------------------------------------------------------------
97 void cmTest::DefineProperties(cmake *cm)
98 {
99   cm->DefineProperty
100     ("ATTACHED_FILES", cmProperty::TEST,
101      "Attach a list of files to a dashboard submission.",
102      "Set this property to a list of files that will be encoded and "
103      "submitted to the dashboard as an addition to the test result.");
104
105   cm->DefineProperty
106     ("ATTACHED_FILES_ON_FAIL", cmProperty::TEST,
107      "Attach a list of files to a dashboard submission if the test fails.",
108      "Same as ATTACHED_FILES, but these files will only be included if the "
109      "test does not pass.");
110
111   cm->DefineProperty
112     ("COST", cmProperty::TEST,
113      "Set this to a floating point value. Tests in a test set will be "
114      "run in descending order of cost.", "This property describes the cost "
115      "of a test. You can explicitly set this value; tests with higher COST "
116      "values will run first.");
117
118   cm->DefineProperty
119     ("DEPENDS", cmProperty::TEST,
120      "Specifies that this test should only be run after the specified "
121      "list of tests.",
122      "Set this to a list of tests that must finish before this test is run.");
123
124   cm->DefineProperty
125     ("ENVIRONMENT", cmProperty::TEST,
126      "Specify environment variables that should be defined for running "
127      "a test.",
128      "If set to a list of environment variables and values of the form "
129      "MYVAR=value those environment variables will be defined while "
130      "running the test. The environment is restored to its previous state "
131      "after the test is done.");
132
133   cm->DefineProperty
134     ("FAIL_REGULAR_EXPRESSION", cmProperty::TEST,
135      "If the output matches this regular expression the test will fail.",
136      "If set, if the output matches one of "
137      "specified regular expressions, the test will fail."
138      "For example: FAIL_REGULAR_EXPRESSION \"[^a-z]Error;ERROR;Failed\"");
139
140   cm->DefineProperty
141     ("LABELS", cmProperty::TEST,
142      "Specify a list of text labels associated with a test.",
143      "The list is reported in dashboard submissions.");
144
145   cm->DefineProperty
146     ("RESOURCE_LOCK", cmProperty::TEST,
147     "Specify a list of resources that are locked by this test.",
148     "If multiple tests specify the same resource lock, they are guaranteed "
149     "not to run concurrently.");
150
151   cm->DefineProperty
152     ("MEASUREMENT", cmProperty::TEST,
153      "Specify a CDASH measurement and value to be reported for a test.",
154      "If set to a name then that name will be reported to CDASH as a "
155      "named measurement with a value of 1. You may also specify a value "
156      "by setting MEASUREMENT to \"measurement=value\".");
157
158   cm->DefineProperty
159     ("PASS_REGULAR_EXPRESSION", cmProperty::TEST,
160      "The output must match this regular expression for the test to pass.",
161      "If set, the test output will be checked "
162      "against the specified regular expressions and at least one of the"
163      " regular expressions has to match, otherwise the test will fail.");
164
165   cm->DefineProperty
166     ("PROCESSORS", cmProperty::TEST,
167      "How many process slots this test requires",
168      "Denotes the number of processors that this test will require. This is "
169      "typically used for MPI tests, and should be used in conjunction with "
170      "the ctest_test PARALLEL_LEVEL option.");
171
172   cm->DefineProperty
173     ("REQUIRED_FILES", cmProperty::TEST,
174      "List of files required to run the test.",
175      "If set to a list of files, the test will not be run unless all of the "
176      "files exist.");
177
178   cm->DefineProperty
179     ("RUN_SERIAL", cmProperty::TEST,
180      "Do not run this test in parallel with any other test.",
181      "Use this option in conjunction with the ctest_test PARALLEL_LEVEL "
182      "option to specify that this test should not be run in parallel with "
183      "any other tests.");
184
185   cm->DefineProperty
186     ("TIMEOUT", cmProperty::TEST,
187      "How many seconds to allow for this test.",
188      "This property if set will limit a test to not take more than "
189      "the specified number of seconds to run. If it exceeds that the "
190      "test process will be killed and ctest will move to the next test. "
191      "This setting takes precedence over "
192      "CTEST_TESTING_TIMEOUT.");
193
194   cm->DefineProperty
195     ("WILL_FAIL", cmProperty::TEST,
196      "If set to true, this will invert the pass/fail flag of the test.",
197      "This property can be used for tests that are expected to fail and "
198      "return a non zero return code.");
199
200   cm->DefineProperty
201     ("WORKING_DIRECTORY", cmProperty::TEST,
202      "The directory from which the test executable will be called.",
203      "If this is not set it is called from the directory the test executable "
204      "is located in.");
205 }