1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmAddTestCommand.cxx,v $
6 Date: $Date: 2009-03-16 14:51:11 $
7 Version: $Revision: 1.32 $
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 "cmAddTestCommand.h"
19 #include "cmTestGenerator.h"
24 // cmExecutableCommand
26 ::InitialPass(std::vector
<std::string
> const& args
, cmExecutionStatus
&)
28 if(!args
.empty() && args
[0] == "NAME")
30 return this->HandleNameMode(args
);
33 // First argument is the name of the test Second argument is the name of
34 // the executable to run (a target or external program) Remaining arguments
35 // are the arguments to pass to the executable
38 this->SetError("called with incorrect number of arguments");
42 // Collect the command with arguments.
43 std::vector
<std::string
> command
;
44 for(std::vector
<std::string
>::const_iterator it
= args
.begin() + 1;
45 it
!= args
.end(); ++it
)
47 command
.push_back(*it
);
50 // Create the test but add a generator only the first time it is
51 // seen. This preserves behavior from before test generators.
52 cmTest
* test
= this->Makefile
->GetTest(args
[0].c_str());
55 // If the test was already added by a new-style signature do not
56 // allow it to be duplicated.
57 if(!test
->GetOldStyle())
60 e
<< " given test name \"" << args
[0]
61 << "\" which already exists in this directory.";
62 this->SetError(e
.str().c_str());
68 test
= this->Makefile
->CreateTest(args
[0].c_str());
69 test
->SetOldStyle(true);
70 this->Makefile
->AddTestGenerator(new cmTestGenerator(test
));
72 test
->SetCommand(command
);
77 //----------------------------------------------------------------------------
78 bool cmAddTestCommand::HandleNameMode(std::vector
<std::string
> const& args
)
81 std::vector
<std::string
> configurations
;
82 std::vector
<std::string
> command
;
84 // Read the arguments.
91 Doing doing
= DoingName
;
92 for(unsigned int i
=1; i
< args
.size(); ++i
)
94 if(args
[i
] == "COMMAND")
98 this->SetError(" may be given at most one COMMAND.");
101 doing
= DoingCommand
;
103 else if(args
[i
] == "CONFIGURATIONS")
105 if(!configurations
.empty())
107 this->SetError(" may be given at most one set of CONFIGURATIONS.");
110 doing
= DoingConfigs
;
112 else if(doing
== DoingName
)
117 else if(doing
== DoingCommand
)
119 command
.push_back(args
[i
]);
121 else if(doing
== DoingConfigs
)
123 configurations
.push_back(args
[i
]);
128 e
<< " given unknown argument:\n " << args
[i
] << "\n";
129 this->SetError(e
.str().c_str());
134 // Require a test name.
137 this->SetError(" must be given non-empty NAME.");
141 // Require a command.
144 this->SetError(" must be given non-empty COMMAND.");
148 // Require a unique test name within the directory.
149 if(this->Makefile
->GetTest(name
.c_str()))
152 e
<< " given test NAME \"" << name
153 << "\" which already exists in this directory.";
154 this->SetError(e
.str().c_str());
159 cmTest
* test
= this->Makefile
->CreateTest(name
.c_str());
160 test
->SetOldStyle(false);
161 test
->SetCommand(command
);
162 this->Makefile
->AddTestGenerator(new cmTestGenerator(test
, configurations
));