1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
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 "cmAddTestCommand.h"
14 #include "cmTestGenerator.h"
19 // cmExecutableCommand
21 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
23 if(!args.empty() && args[0] == "NAME")
25 return this->HandleNameMode(args);
28 // First argument is the name of the test Second argument is the name of
29 // the executable to run (a target or external program) Remaining arguments
30 // are the arguments to pass to the executable
33 this->SetError("called with incorrect number of arguments");
37 // Collect the command with arguments.
38 std::vector<std::string> command;
39 for(std::vector<std::string>::const_iterator it = args.begin() + 1;
40 it != args.end(); ++it)
42 command.push_back(*it);
45 // Create the test but add a generator only the first time it is
46 // seen. This preserves behavior from before test generators.
47 cmTest* test = this->Makefile->GetTest(args[0].c_str());
50 // If the test was already added by a new-style signature do not
51 // allow it to be duplicated.
52 if(!test->GetOldStyle())
55 e << " given test name \"" << args[0]
56 << "\" which already exists in this directory.";
57 this->SetError(e.str().c_str());
63 test = this->Makefile->CreateTest(args[0].c_str());
64 test->SetOldStyle(true);
65 this->Makefile->AddTestGenerator(new cmTestGenerator(test));
67 test->SetCommand(command);
72 //----------------------------------------------------------------------------
73 bool cmAddTestCommand::HandleNameMode(std::vector<std::string> const& args)
76 std::vector<std::string> configurations;
77 std::string working_directory;
78 std::vector<std::string> command;
80 // Read the arguments.
85 DoingWorkingDirectory,
88 Doing doing = DoingName;
89 for(unsigned int i=1; i < args.size(); ++i)
91 if(args[i] == "COMMAND")
95 this->SetError(" may be given at most one COMMAND.");
100 else if(args[i] == "CONFIGURATIONS")
102 if(!configurations.empty())
104 this->SetError(" may be given at most one set of CONFIGURATIONS.");
107 doing = DoingConfigs;
109 else if(args[i] == "WORKING_DIRECTORY")
111 if(!working_directory.empty())
113 this->SetError(" may be given at most one WORKING_DIRECTORY.");
116 doing = DoingWorkingDirectory;
118 else if(doing == DoingName)
123 else if(doing == DoingCommand)
125 command.push_back(args[i]);
127 else if(doing == DoingConfigs)
129 configurations.push_back(args[i]);
131 else if(doing == DoingWorkingDirectory)
133 working_directory = args[i];
139 e << " given unknown argument:\n " << args[i] << "\n";
140 this->SetError(e.str().c_str());
145 // Require a test name.
148 this->SetError(" must be given non-empty NAME.");
152 // Require a command.
155 this->SetError(" must be given non-empty COMMAND.");
159 // Require a unique test name within the directory.
160 if(this->Makefile->GetTest(name.c_str()))
163 e << " given test NAME \"" << name
164 << "\" which already exists in this directory.";
165 this->SetError(e.str().c_str());
170 cmTest* test = this->Makefile->CreateTest(name.c_str());
171 test->SetOldStyle(false);
172 test->SetCommand(command);
173 if(!working_directory.empty())
175 test->SetProperty("WORKING_DIRECTORY", working_directory.c_str());
177 this->Makefile->AddTestGenerator(new cmTestGenerator(test, configurations));