1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmTestGenerator.cxx,v $
6 Date: $Date: 2009-03-16 14:51:23 $
7 Version: $Revision: 1.3 $
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 "cmTestGenerator.h"
19 #include "cmLocalGenerator.h"
20 #include "cmMakefile.h"
21 #include "cmSystemTools.h"
25 //----------------------------------------------------------------------------
27 ::cmTestGenerator(cmTest
* test
,
28 std::vector
<std::string
> const& configurations
):
29 cmScriptGenerator("CTEST_CONFIGURATION_TYPE", configurations
),
32 this->ActionsPerConfig
= !test
->GetOldStyle();
33 this->TestGenerated
= false;
36 //----------------------------------------------------------------------------
42 //----------------------------------------------------------------------------
43 void cmTestGenerator::GenerateScriptConfigs(std::ostream
& os
,
46 // First create the tests.
47 this->cmScriptGenerator::GenerateScriptConfigs(os
, indent
);
49 // Now generate the test properties.
50 if(this->TestGenerated
)
52 cmTest
* test
= this->Test
;
53 std::ostream
& fout
= os
;
54 cmPropertyMap::const_iterator pit
;
55 cmPropertyMap
* mpit
= &test
->GetProperties();
58 fout
<< "SET_TESTS_PROPERTIES(" << test
->GetName() << " PROPERTIES ";
59 for ( pit
= mpit
->begin(); pit
!= mpit
->end(); ++ pit
)
61 fout
<< " " << pit
->first
.c_str() << " \"";
62 const char* value
= pit
->second
.GetValue();
63 for ( ; *value
; ++ value
)
75 fout
<< "\\" << *value
;
92 fout
<< ")" << std::endl
;
97 //----------------------------------------------------------------------------
98 void cmTestGenerator::GenerateScriptActions(std::ostream
& os
,
101 if(this->ActionsPerConfig
)
103 // This is the per-config generation in a single-configuration
104 // build generator case. The superclass will call our per-config
106 this->cmScriptGenerator::GenerateScriptActions(os
, indent
);
110 // This is an old-style test, so there is only one config.
111 //assert(this->Test->GetOldStyle());
112 this->GenerateOldStyle(os
, indent
);
116 //----------------------------------------------------------------------------
117 void cmTestGenerator::GenerateScriptForConfig(std::ostream
& os
,
119 Indent
const& indent
)
121 this->TestGenerated
= true;
123 // Start the test command.
124 os
<< indent
<< "ADD_TEST(" << this->Test
->GetName() << " ";
126 // Get the test command line to be executed.
127 std::vector
<std::string
> const& command
= this->Test
->GetCommand();
129 // Check whether the command executable is a target whose name is to
131 std::string exe
= command
[0];
132 cmMakefile
* mf
= this->Test
->GetMakefile();
133 cmTarget
* target
= mf
->FindTargetToUse(exe
.c_str());
134 if(target
&& target
->GetType() == cmTarget::EXECUTABLE
)
136 // Use the target file on disk.
137 exe
= target
->GetFullPath(config
);
141 // Use the command name given.
142 cmSystemTools::ConvertToUnixSlashes(exe
);
145 // Generate the command line with full escapes.
146 cmLocalGenerator
* lg
= mf
->GetLocalGenerator();
147 os
<< lg
->EscapeForCMake(exe
.c_str());
148 for(std::vector
<std::string
>::const_iterator ci
= command
.begin()+1;
149 ci
!= command
.end(); ++ci
)
151 os
<< " " << lg
->EscapeForCMake(ci
->c_str());
154 // Finish the test command.
158 //----------------------------------------------------------------------------
159 void cmTestGenerator::GenerateOldStyle(std::ostream
& fout
,
160 Indent
const& indent
)
162 this->TestGenerated
= true;
164 // Get the test command line to be executed.
165 std::vector
<std::string
> const& command
= this->Test
->GetCommand();
167 std::string exe
= command
[0];
168 cmSystemTools::ConvertToUnixSlashes(exe
);
171 fout
<< this->Test
->GetName() << " \"" << exe
<< "\"";
173 for(std::vector
<std::string
>::const_iterator argit
= command
.begin()+1;
174 argit
!= command
.end(); ++argit
)
176 // Just double-quote all arguments so they are re-parsed
177 // correctly by the test system.
179 for(std::string::const_iterator c
= argit
->begin();
180 c
!= argit
->end(); ++c
)
182 // Escape quotes within arguments. We should escape
183 // backslashes too but we cannot because it makes the result
184 // inconsistent with previous behavior of this command.
193 fout
<< ")" << std::endl
;