1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmTestGenerator.cxx,v $
6 Date: $Date: 2009-08-11 13:54:55 $
7 Version: $Revision: 1.5 $
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 "cmGeneratorExpression.h"
20 #include "cmLocalGenerator.h"
21 #include "cmMakefile.h"
22 #include "cmSystemTools.h"
26 //----------------------------------------------------------------------------
28 ::cmTestGenerator(cmTest
* test
,
29 std::vector
<std::string
> const& configurations
):
30 cmScriptGenerator("CTEST_CONFIGURATION_TYPE", configurations
),
33 this->ActionsPerConfig
= !test
->GetOldStyle();
34 this->TestGenerated
= false;
37 //----------------------------------------------------------------------------
43 //----------------------------------------------------------------------------
44 void cmTestGenerator::GenerateScriptConfigs(std::ostream
& os
,
47 // First create the tests.
48 this->cmScriptGenerator::GenerateScriptConfigs(os
, indent
);
50 // Now generate the test properties.
51 if(this->TestGenerated
)
53 cmTest
* test
= this->Test
;
54 cmMakefile
* mf
= test
->GetMakefile();
55 cmLocalGenerator
* lg
= mf
->GetLocalGenerator();
56 std::ostream
& fout
= os
;
57 cmPropertyMap::const_iterator pit
;
58 cmPropertyMap
* mpit
= &test
->GetProperties();
61 fout
<< "SET_TESTS_PROPERTIES(" << test
->GetName() << " PROPERTIES ";
62 for ( pit
= mpit
->begin(); pit
!= mpit
->end(); ++ pit
)
64 fout
<< " " << pit
->first
65 << " " << lg
->EscapeForCMake(pit
->second
.GetValue());
67 fout
<< ")" << std::endl
;
72 //----------------------------------------------------------------------------
73 void cmTestGenerator::GenerateScriptActions(std::ostream
& os
,
76 if(this->ActionsPerConfig
)
78 // This is the per-config generation in a single-configuration
79 // build generator case. The superclass will call our per-config
81 this->cmScriptGenerator::GenerateScriptActions(os
, indent
);
85 // This is an old-style test, so there is only one config.
86 //assert(this->Test->GetOldStyle());
87 this->GenerateOldStyle(os
, indent
);
91 //----------------------------------------------------------------------------
92 void cmTestGenerator::GenerateScriptForConfig(std::ostream
& os
,
96 this->TestGenerated
= true;
98 // Set up generator expression evaluation context.
99 cmMakefile
* mf
= this->Test
->GetMakefile();
100 cmGeneratorExpression
ge(mf
, config
, this->Test
->GetBacktrace());
102 // Start the test command.
103 os
<< indent
<< "ADD_TEST(" << this->Test
->GetName() << " ";
105 // Get the test command line to be executed.
106 std::vector
<std::string
> const& command
= this->Test
->GetCommand();
108 // Check whether the command executable is a target whose name is to
110 std::string exe
= command
[0];
111 cmTarget
* target
= mf
->FindTargetToUse(exe
.c_str());
112 if(target
&& target
->GetType() == cmTarget::EXECUTABLE
)
114 // Use the target file on disk.
115 exe
= target
->GetFullPath(config
);
119 // Use the command name given.
120 exe
= ge
.Process(exe
.c_str());
121 cmSystemTools::ConvertToUnixSlashes(exe
);
124 // Generate the command line with full escapes.
125 cmLocalGenerator
* lg
= mf
->GetLocalGenerator();
126 os
<< lg
->EscapeForCMake(exe
.c_str());
127 for(std::vector
<std::string
>::const_iterator ci
= command
.begin()+1;
128 ci
!= command
.end(); ++ci
)
130 os
<< " " << lg
->EscapeForCMake(ge
.Process(*ci
));
133 // Finish the test command.
137 //----------------------------------------------------------------------------
138 void cmTestGenerator::GenerateOldStyle(std::ostream
& fout
,
139 Indent
const& indent
)
141 this->TestGenerated
= true;
143 // Get the test command line to be executed.
144 std::vector
<std::string
> const& command
= this->Test
->GetCommand();
146 std::string exe
= command
[0];
147 cmSystemTools::ConvertToUnixSlashes(exe
);
150 fout
<< this->Test
->GetName() << " \"" << exe
<< "\"";
152 for(std::vector
<std::string
>::const_iterator argit
= command
.begin()+1;
153 argit
!= command
.end(); ++argit
)
155 // Just double-quote all arguments so they are re-parsed
156 // correctly by the test system.
158 for(std::string::const_iterator c
= argit
->begin();
159 c
!= argit
->end(); ++c
)
161 // Escape quotes within arguments. We should escape
162 // backslashes too but we cannot because it makes the result
163 // inconsistent with previous behavior of this command.
172 fout
<< ")" << std::endl
;