cmCTest.h 4.88 KB
Newer Older
1
2
/*=========================================================================

3
  Program:   CMake - Cross-Platform Makefile Generator
4
5
6
7
8
  Module:    $RCSfile$
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

9
10
  Copyright (c) 2002 Kitware, Inc., Insight Consortium.  All rights reserved.
  See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
11

Will Schroeder's avatar
Will Schroeder committed
12
13
14
     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notices for more information.
15
16
17

=========================================================================*/

18
19
20
#ifndef cmCTest_h
#define cmCTest_h

21
22

#include "cmStandardIncludes.h"
Bill Hoffman's avatar
Bill Hoffman committed
23

24
class cmCTest
25
26
{
public:
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
  /**
   * Initialize and finalize testing
   */
  void Initialize();
  void Finalize();

  /**
   * Process the tests. This is the main routine. The execution of the
   * tests should look like this:
   *
   * ctest foo;
   * foo.Initialize();
   * // Set some things on foo
   * foo.ProcessTests();
   * foo.Finalize();
   */
  int ProcessTests();

  /**
   * Try to build the project
   */
48
49
50
51
52
53
  int BuildDirectory();

  /**
   * Try to run tests of the project
   */
  int TestDirectory();
54

Andy Cedilnik's avatar
Andy Cedilnik committed
55
56
57
58
59
  /**
   * Try to get coverage of the project
   */
  int CoverageDirectory();

60
61
62
  /**
   * Do revision control update of directory
   */
63
  int UpdateDirectory();
64

65
66
67
  /**
   * Do configure the project
   */
68
  int ConfigureDirectory();
69

Andy Cedilnik's avatar
Andy Cedilnik committed
70
71
72
73
74
75
76
77
78
79
80
  /**
   * Do submit testing results
   */
  int SubmitResults();
  std::string GetSubmitResultsPrefix();

  /**
   * Check if CTest file exists
   */
  bool CTestFileExists(const std::string& filename);

81
82
83
  /**
   * Run the test for a directory and any subdirectories
   */
84
85
  void ProcessDirectory(std::vector<std::string> &passed, 
                        std::vector<std::string> &failed);
86
87
88
89

  /**
   * Find the executable for a test
   */
Andy Cedilnik's avatar
Andy Cedilnik committed
90
  std::string FindTheExecutable(const char *exe);
91

92
93
94
95
96
  /**
   * Set the cmake test
   */
  bool SetTest(const char*);

97
98
99
100
101
102
103
104
105
  /**
   * Set the cmake test mode (experimental, nightly, continuous).
   */
  void SetTestModel(int mode)
    {
    m_TestModel = mode;
    }
  std::string GetTestModelString();

106
107
108
  /**
   * constructor
   */
109
  cmCTest();
110
111
112
113
114
115
116

  bool m_UseIncludeRegExp;
  std::string m_IncludeRegExp;

  bool m_UseExcludeRegExp;
  bool m_UseExcludeRegExpFirst;
  std::string m_ExcludeRegExp;
Ken Martin's avatar
Ken Martin committed
117

118
  std::string m_ConfigType;
119
  bool m_Verbose;
120
  bool m_DartMode;
121
  bool m_ShowOnly;
122

123
124
125
126
127
128
  enum {
    EXPERIMENTAL,
    NIGHTLY,
    CONTINUOUS
  };

129
private:
130
  enum {
Andy Cedilnik's avatar
Andy Cedilnik committed
131
132
    FIRST_TEST     = 0,
    UPDATE_TEST    = 1,
Andy Cedilnik's avatar
Andy Cedilnik committed
133
134
135
136
137
138
139
140
141
    START_TEST     = 2,
    CONFIGURE_TEST = 3,
    BUILD_TEST     = 4,
    TEST_TEST      = 5,
    COVERAGE_TEST  = 6,
    PURIFY_TEST    = 7,
    SUBMIT_TEST    = 8,
    ALL_TEST       = 9,
    LAST_TEST      = 10
142
143
144
145
146
147
148
149
150
151
152
153
154
  };

  struct cmCTestTestResult
  {
    std::string m_Name;
    std::string m_Path;
    std::string m_FullCommandLine;
    double      m_ExecutionTime;
    int         m_ReturnValue;
    std::string m_CompletionStatus;
    std::string m_Output;
  };

155
156
157
158
159
160
161
162
163
164
165
166
  struct cmCTestBuildErrorWarning
  {
    bool        m_Error;
    int         m_LogLine;
    std::string m_Text;
    std::string m_SourceFile;
    std::string m_SourceFileTail;
    int         m_LineNumber;
    std::string m_PreContext;
    std::string m_PostContext;
  };

Andy Cedilnik's avatar
Andy Cedilnik committed
167
168
169
170
171
172
173
  // Some structures needed for cvs update
  struct StringPair : 
    public std::pair<std::string, std::string>{};
  struct UpdateFiles : public std::vector<StringPair>{};
  struct AuthorsToUpdatesMap : 
    public std::map<std::string, UpdateFiles>{};

Andy Cedilnik's avatar
Andy Cedilnik committed
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
  struct cmCTestCoverage
  {
    cmCTestCoverage()
      {
        m_FullPath = "";
        m_Covered = false;
        m_Tested = 0;
        m_UnTested = 0;
        m_Lines.clear();
      }
    std::string      m_FullPath;
    bool             m_Covered;
    int              m_Tested;
    int              m_UnTested;
    std::vector<int> m_Lines;
  };

191
192
  typedef std::vector<cmCTestTestResult> tm_TestResultsVector;
  typedef std::map<std::string, std::string> tm_DartConfigurationMap;
Andy Cedilnik's avatar
Andy Cedilnik committed
193
  typedef std::map<std::string, cmCTestCoverage> tm_CoverageMap;
194
195
196
197
198

  tm_TestResultsVector    m_TestResults;
  std::string             m_ToplevelPath;
  tm_DartConfigurationMap m_DartConfiguration;
  int                     m_Tests[LAST_TEST];
199
200
  
  std::string             m_CurrentTag;
201

202
203
204
205
  std::string             m_StartBuild;
  std::string             m_EndBuild;
  std::string             m_StartTest;
  std::string             m_EndTest;
206

Andy Cedilnik's avatar
Andy Cedilnik committed
207
  int                     m_TestModel;
208

209
210
211
212
213
214
  /**
   * Generate the Dart compatible output
   */
  void GenerateDartOutput(std::ostream& os);
  void GenerateDartBuildOutput(std::ostream& os, 
                               std::vector<cmCTestBuildErrorWarning>);
215

Andy Cedilnik's avatar
Andy Cedilnik committed
216
217
  bool OpenOutputFile(const std::string& path, 
                      const std::string& name, std::ofstream& stream);  
218
  std::string MakeXMLSafe(const std::string&);
219
220
};

221
#endif