[Cmake-commits] [cmake-commits] king committed cmAddTestCommand.cxx 1.31 1.32 cmAddTestCommand.h 1.16 1.17 cmTest.cxx 1.12 1.13 cmTest.h 1.7 1.8 cmTestGenerator.cxx 1.2 1.3 cmTestGenerator.h 1.1 1.2
cmake-commits at cmake.org
cmake-commits at cmake.org
Mon Mar 16 10:51:28 EDT 2009
Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv30106/Source
Modified Files:
cmAddTestCommand.cxx cmAddTestCommand.h cmTest.cxx cmTest.h
cmTestGenerator.cxx cmTestGenerator.h
Log Message:
ENH: Add NAME mode to ADD_TEST command
This creates command mode add_test(NAME ...). This signature is
extensible with more keyword arguments later. The main purpose is to
enable automatic replacement of target names with built target file
locations. A side effect of this feature is support for tests that only
run under specific configurations.
Index: cmAddTestCommand.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmAddTestCommand.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -C 2 -d -r1.16 -r1.17
*** cmAddTestCommand.h 23 Jan 2008 15:27:59 -0000 1.16
--- cmAddTestCommand.h 16 Mar 2009 14:51:13 -0000 1.17
***************
*** 71,79 ****
"system (like tclsh). The test will be run with the current working "
"directory set to the CMakeList.txt files corresponding directory "
! "in the binary tree.";
}
cmTypeMacro(cmAddTestCommand, cmCommand);
!
};
--- 71,89 ----
"system (like tclsh). The test will be run with the current working "
"directory set to the CMakeList.txt files corresponding directory "
! "in the binary tree."
! "\n"
! " add_test(NAME <name> [CONFIGURATIONS [Debug|Release|...]]\n"
! " COMMAND <command> [arg1 [arg2 ...]])\n"
! "If COMMAND specifies an executable target (created by "
! "add_executable) it will automatically be replaced by the location "
! "of the executable created at build time. "
! "If a CONFIGURATIONS option is given then the test will be executed "
! "only when testing under one of the named configurations."
! ;
}
cmTypeMacro(cmAddTestCommand, cmCommand);
! private:
! bool HandleNameMode(std::vector<std::string> const& args);
};
Index: cmTestGenerator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmTestGenerator.cxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -C 2 -d -r1.2 -r1.3
*** cmTestGenerator.cxx 16 Mar 2009 14:42:40 -0000 1.2
--- cmTestGenerator.cxx 16 Mar 2009 14:51:23 -0000 1.3
***************
*** 17,21 ****
--- 17,24 ----
#include "cmTestGenerator.h"
+ #include "cmLocalGenerator.h"
+ #include "cmMakefile.h"
#include "cmSystemTools.h"
+ #include "cmTarget.h"
#include "cmTest.h"
***************
*** 27,31 ****
Test(test)
{
! this->ActionsPerConfig = false;
this->TestGenerated = false;
}
--- 30,34 ----
Test(test)
{
! this->ActionsPerConfig = !test->GetOldStyle();
this->TestGenerated = false;
}
***************
*** 93,99 ****
//----------------------------------------------------------------------------
! void cmTestGenerator::GenerateScriptActions(std::ostream& fout,
Indent const& indent)
{
this->TestGenerated = true;
--- 96,163 ----
//----------------------------------------------------------------------------
! void cmTestGenerator::GenerateScriptActions(std::ostream& os,
Indent const& indent)
{
+ if(this->ActionsPerConfig)
+ {
+ // This is the per-config generation in a single-configuration
+ // build generator case. The superclass will call our per-config
+ // method.
+ this->cmScriptGenerator::GenerateScriptActions(os, indent);
+ }
+ else
+ {
+ // This is an old-style test, so there is only one config.
+ //assert(this->Test->GetOldStyle());
+ this->GenerateOldStyle(os, indent);
+ }
+ }
+
+ //----------------------------------------------------------------------------
+ void cmTestGenerator::GenerateScriptForConfig(std::ostream& os,
+ const char* config,
+ Indent const& indent)
+ {
+ this->TestGenerated = true;
+
+ // Start the test command.
+ os << indent << "ADD_TEST(" << this->Test->GetName() << " ";
+
+ // Get the test command line to be executed.
+ std::vector<std::string> const& command = this->Test->GetCommand();
+
+ // Check whether the command executable is a target whose name is to
+ // be translated.
+ std::string exe = command[0];
+ cmMakefile* mf = this->Test->GetMakefile();
+ cmTarget* target = mf->FindTargetToUse(exe.c_str());
+ if(target && target->GetType() == cmTarget::EXECUTABLE)
+ {
+ // Use the target file on disk.
+ exe = target->GetFullPath(config);
+ }
+ else
+ {
+ // Use the command name given.
+ cmSystemTools::ConvertToUnixSlashes(exe);
+ }
+
+ // Generate the command line with full escapes.
+ cmLocalGenerator* lg = mf->GetLocalGenerator();
+ os << lg->EscapeForCMake(exe.c_str());
+ for(std::vector<std::string>::const_iterator ci = command.begin()+1;
+ ci != command.end(); ++ci)
+ {
+ os << " " << lg->EscapeForCMake(ci->c_str());
+ }
+
+ // Finish the test command.
+ os << ")\n";
+ }
+
+ //----------------------------------------------------------------------------
+ void cmTestGenerator::GenerateOldStyle(std::ostream& fout,
+ Indent const& indent)
+ {
this->TestGenerated = true;
Index: cmTest.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmTest.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -C 2 -d -r1.7 -r1.8
*** cmTest.h 16 Mar 2009 14:42:37 -0000 1.7
--- cmTest.h 16 Mar 2009 14:51:20 -0000 1.8
***************
*** 64,67 ****
--- 64,71 ----
cmMakefile *GetMakefile() { return this->Makefile;};
+ /** Get/Set whether this is an old-style test. */
+ bool GetOldStyle() const { return this->OldStyle; }
+ void SetOldStyle(bool b) { this->OldStyle = b; }
+
private:
cmPropertyMap Properties;
***************
*** 69,72 ****
--- 73,78 ----
std::vector<std::string> Command;
+ bool OldStyle;
+
// The cmMakefile instance that owns this target. This should
// always be set.
Index: cmTest.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmTest.cxx,v
retrieving revision 1.12
retrieving revision 1.13
diff -C 2 -d -r1.12 -r1.13
*** cmTest.cxx 16 Mar 2009 14:42:33 -0000 1.12
--- cmTest.cxx 16 Mar 2009 14:51:14 -0000 1.13
***************
*** 24,27 ****
--- 24,28 ----
{
this->Makefile = 0;
+ this->OldStyle = true;
}
Index: cmTestGenerator.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmTestGenerator.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C 2 -d -r1.1 -r1.2
*** cmTestGenerator.h 16 Mar 2009 14:40:37 -0000 1.1
--- cmTestGenerator.h 16 Mar 2009 14:51:23 -0000 1.2
***************
*** 37,40 ****
--- 37,44 ----
virtual void GenerateScriptConfigs(std::ostream& os, Indent const& indent);
virtual void GenerateScriptActions(std::ostream& os, Indent const& indent);
+ virtual void GenerateScriptForConfig(std::ostream& os,
+ const char* config,
+ Indent const& indent);
+ void GenerateOldStyle(std::ostream& os, Indent const& indent);
cmTest* Test;
Index: cmAddTestCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmAddTestCommand.cxx,v
retrieving revision 1.31
retrieving revision 1.32
diff -C 2 -d -r1.31 -r1.32
*** cmAddTestCommand.cxx 16 Mar 2009 14:42:29 -0000 1.31
--- cmAddTestCommand.cxx 16 Mar 2009 14:51:11 -0000 1.32
***************
*** 26,29 ****
--- 26,34 ----
::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
{
+ if(!args.empty() && args[0] == "NAME")
+ {
+ return this->HandleNameMode(args);
+ }
+
// First argument is the name of the test Second argument is the name of
// the executable to run (a target or external program) Remaining arguments
***************
*** 46,52 ****
// seen. This preserves behavior from before test generators.
cmTest* test = this->Makefile->GetTest(args[0].c_str());
! if(!test)
{
test = this->Makefile->CreateTest(args[0].c_str());
this->Makefile->AddTestGenerator(new cmTestGenerator(test));
}
--- 51,71 ----
// seen. This preserves behavior from before test generators.
cmTest* test = this->Makefile->GetTest(args[0].c_str());
! if(test)
! {
! // If the test was already added by a new-style signature do not
! // allow it to be duplicated.
! if(!test->GetOldStyle())
! {
! cmOStringStream e;
! e << " given test name \"" << args[0]
! << "\" which already exists in this directory.";
! this->SetError(e.str().c_str());
! return false;
! }
! }
! else
{
test = this->Makefile->CreateTest(args[0].c_str());
+ test->SetOldStyle(true);
this->Makefile->AddTestGenerator(new cmTestGenerator(test));
}
***************
*** 55,56 ****
--- 74,165 ----
return true;
}
+
+ //----------------------------------------------------------------------------
+ bool cmAddTestCommand::HandleNameMode(std::vector<std::string> const& args)
+ {
+ std::string name;
+ std::vector<std::string> configurations;
+ std::vector<std::string> command;
+
+ // Read the arguments.
+ enum Doing {
+ DoingName,
+ DoingCommand,
+ DoingConfigs,
+ DoingNone
+ };
+ Doing doing = DoingName;
+ for(unsigned int i=1; i < args.size(); ++i)
+ {
+ if(args[i] == "COMMAND")
+ {
+ if(!command.empty())
+ {
+ this->SetError(" may be given at most one COMMAND.");
+ return false;
+ }
+ doing = DoingCommand;
+ }
+ else if(args[i] == "CONFIGURATIONS")
+ {
+ if(!configurations.empty())
+ {
+ this->SetError(" may be given at most one set of CONFIGURATIONS.");
+ return false;
+ }
+ doing = DoingConfigs;
+ }
+ else if(doing == DoingName)
+ {
+ name = args[i];
+ doing = DoingNone;
+ }
+ else if(doing == DoingCommand)
+ {
+ command.push_back(args[i]);
+ }
+ else if(doing == DoingConfigs)
+ {
+ configurations.push_back(args[i]);
+ }
+ else
+ {
+ cmOStringStream e;
+ e << " given unknown argument:\n " << args[i] << "\n";
+ this->SetError(e.str().c_str());
+ return false;
+ }
+ }
+
+ // Require a test name.
+ if(name.empty())
+ {
+ this->SetError(" must be given non-empty NAME.");
+ return false;
+ }
+
+ // Require a command.
+ if(command.empty())
+ {
+ this->SetError(" must be given non-empty COMMAND.");
+ return false;
+ }
+
+ // Require a unique test name within the directory.
+ if(this->Makefile->GetTest(name.c_str()))
+ {
+ cmOStringStream e;
+ e << " given test NAME \"" << name
+ << "\" which already exists in this directory.";
+ this->SetError(e.str().c_str());
+ return false;
+ }
+
+ // Add the test.
+ cmTest* test = this->Makefile->CreateTest(name.c_str());
+ test->SetOldStyle(false);
+ test->SetCommand(command);
+ this->Makefile->AddTestGenerator(new cmTestGenerator(test, configurations));
+
+ return true;
+ }
More information about the Cmake-commits
mailing list