Przeglądaj źródła

cmCTest: Use concrete accessor functions for TestingHandlers

Regina Pfeifer 6 lat temu
rodzic
commit
b172a81d55

+ 4 - 7
Source/CTest/cmCTestBuildCommand.cxx

@@ -4,7 +4,6 @@
 
 #include "cmCTest.h"
 #include "cmCTestBuildHandler.h"
-#include "cmCTestGenericHandler.h"
 #include "cmGlobalGenerator.h"
 #include "cmMakefile.h"
 #include "cmMessageType.h"
@@ -39,12 +38,10 @@ cmCTestBuildCommand::~cmCTestBuildCommand()
 
 cmCTestGenericHandler* cmCTestBuildCommand::InitializeHandler()
 {
-  cmCTestGenericHandler* handler = this->CTest->GetInitializedHandler("build");
-  if (!handler) {
-    this->SetError("internal CTest error. Cannot instantiate build handler");
-    return nullptr;
-  }
-  this->Handler = static_cast<cmCTestBuildHandler*>(handler);
+  cmCTestBuildHandler* handler = this->CTest->GetBuildHandler();
+  handler->Initialize();
+
+  this->Handler = handler;
 
   const char* ctestBuildCommand =
     this->Makefile->GetDefinition("CTEST_BUILD_COMMAND");

+ 3 - 8
Source/CTest/cmCTestConfigureCommand.cxx

@@ -3,7 +3,7 @@
 #include "cmCTestConfigureCommand.h"
 
 #include "cmCTest.h"
-#include "cmCTestGenericHandler.h"
+#include "cmCTestConfigureHandler.h"
 #include "cmGlobalGenerator.h"
 #include "cmMakefile.h"
 #include "cmSystemTools.h"
@@ -142,13 +142,8 @@ cmCTestGenericHandler* cmCTestConfigureCommand::InitializeHandler()
                                        labelsForSubprojects, this->Quiet);
   }
 
-  cmCTestGenericHandler* handler =
-    this->CTest->GetInitializedHandler("configure");
-  if (!handler) {
-    this->SetError(
-      "internal CTest error. Cannot instantiate configure handler");
-    return nullptr;
-  }
+  cmCTestConfigureHandler* handler = this->CTest->GetConfigureHandler();
+  handler->Initialize();
   handler->SetQuiet(this->Quiet);
   return handler;
 }

+ 2 - 6
Source/CTest/cmCTestCoverageCommand.cxx

@@ -19,12 +19,8 @@ cmCTestGenericHandler* cmCTestCoverageCommand::InitializeHandler()
   this->CTest->SetCTestConfigurationFromCMakeVariable(
     this->Makefile, "CoverageExtraFlags", "CTEST_COVERAGE_EXTRA_FLAGS",
     this->Quiet);
-  cmCTestCoverageHandler* handler = static_cast<cmCTestCoverageHandler*>(
-    this->CTest->GetInitializedHandler("coverage"));
-  if (!handler) {
-    this->SetError("internal CTest error. Cannot instantiate test handler");
-    return nullptr;
-  }
+  cmCTestCoverageHandler* handler = this->CTest->GetCoverageHandler();
+  handler->Initialize();
 
   // If a LABELS option was given, select only files with the labels.
   if (this->LabelsMentioned) {

+ 2 - 3
Source/CTest/cmCTestMemCheckCommand.cxx

@@ -7,7 +7,6 @@
 #include <vector>
 
 #include "cmCTest.h"
-#include "cmCTestGenericHandler.h"
 #include "cmCTestMemCheckHandler.h"
 #include "cmMakefile.h"
 
@@ -20,8 +19,8 @@ cmCTestMemCheckCommand::cmCTestMemCheckCommand()
 
 cmCTestGenericHandler* cmCTestMemCheckCommand::InitializeActualHandler()
 {
-  cmCTestGenericHandler* handler =
-    this->CTest->GetInitializedHandler("memcheck");
+  cmCTestMemCheckHandler* handler = this->CTest->GetMemCheckHandler();
+  handler->Initialize();
 
   this->CTest->SetCTestConfigurationFromCMakeVariable(
     this->Makefile, "MemoryCheckType", "CTEST_MEMORYCHECK_TYPE", this->Quiet);

+ 11 - 24
Source/CTest/cmCTestSubmitCommand.cxx

@@ -3,7 +3,6 @@
 #include "cmCTestSubmitCommand.h"
 
 #include "cmCTest.h"
-#include "cmCTestGenericHandler.h"
 #include "cmCTestSubmitHandler.h"
 #include "cmMakefile.h"
 #include "cmMessageType.h"
@@ -63,12 +62,8 @@ cmCTestGenericHandler* cmCTestSubmitCommand::InitializeHandler()
     }
   }
 
-  cmCTestGenericHandler* handler =
-    this->CTest->GetInitializedHandler("submit");
-  if (!handler) {
-    this->SetError("internal CTest error. Cannot instantiate submit handler");
-    return nullptr;
-  }
+  cmCTestSubmitHandler* handler = this->CTest->GetSubmitHandler();
+  handler->Initialize();
 
   // If no FILES or PARTS given, *all* PARTS are submitted by default.
   //
@@ -90,38 +85,30 @@ cmCTestGenericHandler* cmCTestSubmitCommand::InitializeHandler()
     // But FILES with no PARTS mentioned should just submit the FILES
     // without any of the default parts.
     //
-    std::set<cmCTest::Part> noParts;
-    static_cast<cmCTestSubmitHandler*>(handler)->SelectParts(noParts);
-
-    static_cast<cmCTestSubmitHandler*>(handler)->SelectFiles(this->Files);
+    handler->SelectParts(std::set<cmCTest::Part>());
+    handler->SelectFiles(this->Files);
   }
 
   // If a PARTS option was given, select only the named parts for submission.
   //
   if (this->PartsMentioned) {
-    static_cast<cmCTestSubmitHandler*>(handler)->SelectParts(this->Parts);
+    handler->SelectParts(this->Parts);
   }
 
   // Pass along any HTTPHEADER to the handler if this option was given.
   if (!this->HttpHeaders.empty()) {
-    static_cast<cmCTestSubmitHandler*>(handler)->SetHttpHeaders(
-      this->HttpHeaders);
+    handler->SetHttpHeaders(this->HttpHeaders);
   }
 
-  static_cast<cmCTestSubmitHandler*>(handler)->SetOption(
-    "RetryDelay", this->RetryDelay.c_str());
-  static_cast<cmCTestSubmitHandler*>(handler)->SetOption(
-    "RetryCount", this->RetryCount.c_str());
-  static_cast<cmCTestSubmitHandler*>(handler)->SetOption(
-    "InternalTest", this->InternalTest ? "ON" : "OFF");
+  handler->SetOption("RetryDelay", this->RetryDelay.c_str());
+  handler->SetOption("RetryCount", this->RetryCount.c_str());
+  handler->SetOption("InternalTest", this->InternalTest ? "ON" : "OFF");
 
   handler->SetQuiet(this->Quiet);
 
   if (this->CDashUpload) {
-    static_cast<cmCTestSubmitHandler*>(handler)->SetOption(
-      "CDashUploadFile", this->CDashUploadFile.c_str());
-    static_cast<cmCTestSubmitHandler*>(handler)->SetOption(
-      "CDashUploadType", this->CDashUploadType.c_str());
+    handler->SetOption("CDashUploadFile", this->CDashUploadFile.c_str());
+    handler->SetOption("CDashUploadType", this->CDashUploadType.c_str());
   }
   return handler;
 }

+ 2 - 4
Source/CTest/cmCTestSubmitHandler.cxx

@@ -259,8 +259,7 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP(
         upload_as += ctest_curl.Escape(this->CTest->GetCurrentTag());
         upload_as += "-";
         upload_as += ctest_curl.Escape(this->CTest->GetTestModelString());
-        cmCTestScriptHandler* ch = static_cast<cmCTestScriptHandler*>(
-          this->CTest->GetHandler("script"));
+        cmCTestScriptHandler* ch = this->CTest->GetScriptHandler();
         cmake* cm = ch->GetCMake();
         if (cm) {
           const char* subproject =
@@ -558,8 +557,7 @@ int cmCTestSubmitHandler::HandleCDashUploadFile(std::string const& file,
   //    has already been uploaded
   // TODO I added support for subproject. You would need to add
   // a "&subproject=subprojectname" to the first POST.
-  cmCTestScriptHandler* ch =
-    static_cast<cmCTestScriptHandler*>(this->CTest->GetHandler("script"));
+  cmCTestScriptHandler* ch = this->CTest->GetScriptHandler();
   cmake* cm = ch->GetCMake();
   const char* subproject = cm->GetState()->GetGlobalProperty("SubProject");
   // TODO: Encode values for a URL instead of trusting caller.

+ 4 - 1
Source/CTest/cmCTestTestCommand.cxx

@@ -4,6 +4,7 @@
 
 #include "cmCTest.h"
 #include "cmCTestGenericHandler.h"
+#include "cmCTestTestHandler.h"
 #include "cmDuration.h"
 #include "cmMakefile.h"
 #include "cmSystemTools.h"
@@ -140,5 +141,7 @@ cmCTestGenericHandler* cmCTestTestCommand::InitializeHandler()
 
 cmCTestGenericHandler* cmCTestTestCommand::InitializeActualHandler()
 {
-  return this->CTest->GetInitializedHandler("test");
+  cmCTestTestHandler* handler = this->CTest->GetTestHandler();
+  handler->Initialize();
+  return handler;
 }

+ 3 - 7
Source/CTest/cmCTestUpdateCommand.cxx

@@ -3,7 +3,7 @@
 #include "cmCTestUpdateCommand.h"
 
 #include "cmCTest.h"
-#include "cmCTestGenericHandler.h"
+#include "cmCTestUpdateHandler.h"
 #include "cmMakefile.h"
 #include "cmSystemTools.h"
 
@@ -74,12 +74,8 @@ cmCTestGenericHandler* cmCTestUpdateCommand::InitializeHandler()
   this->CTest->SetCTestConfigurationFromCMakeVariable(
     this->Makefile, "P4Options", "CTEST_P4_OPTIONS", this->Quiet);
 
-  cmCTestGenericHandler* handler =
-    this->CTest->GetInitializedHandler("update");
-  if (!handler) {
-    this->SetError("internal CTest error. Cannot instantiate update handler");
-    return nullptr;
-  }
+  cmCTestUpdateHandler* handler = this->CTest->GetUpdateHandler();
+  handler->Initialize();
   handler->SetCommand(this);
   if (source_dir.empty()) {
     this->SetError("source directory not specified. Please use SOURCE tag");

+ 3 - 9
Source/CTest/cmCTestUploadCommand.cxx

@@ -6,7 +6,6 @@
 #include <vector>
 
 #include "cmCTest.h"
-#include "cmCTestGenericHandler.h"
 #include "cmCTestUploadHandler.h"
 #include "cmMakefile.h"
 #include "cmMessageType.h"
@@ -14,14 +13,9 @@
 
 cmCTestGenericHandler* cmCTestUploadCommand::InitializeHandler()
 {
-  cmCTestGenericHandler* handler =
-    this->CTest->GetInitializedHandler("upload");
-  if (!handler) {
-    this->SetError("internal CTest error. Cannot instantiate upload handler");
-    return nullptr;
-  }
-  static_cast<cmCTestUploadHandler*>(handler)->SetFiles(this->Files);
-
+  cmCTestUploadHandler* handler = this->CTest->GetUploadHandler();
+  handler->Initialize();
+  handler->SetFiles(this->Files);
   handler->SetQuiet(this->Quiet);
   return handler;
 }

+ 89 - 111
Source/cmCTest.cxx

@@ -1010,58 +1010,54 @@ bool cmCTest::CTestFileExists(const std::string& filename)
   return cmSystemTools::FileExists(testingDir);
 }
 
-cmCTestGenericHandler* cmCTest::GetInitializedHandler(const char* handler)
+cmCTestBuildHandler* cmCTest::GetBuildHandler()
 {
-  if (cmCTestGenericHandler* testHandler = this->GetHandler(handler)) {
-    testHandler->Initialize();
-    return testHandler;
-  }
-  return nullptr;
+  return &this->Impl->BuildHandler;
 }
 
-cmCTestGenericHandler* cmCTest::GetHandler(const char* handler)
+cmCTestBuildAndTestHandler* cmCTest::GetBuildAndTestHandler()
 {
-  if (strcmp(handler, "build") == 0) {
-    return &this->Impl->BuildHandler;
-  }
-  if (strcmp(handler, "buildtest") == 0) {
-    return &this->Impl->BuildAndTestHandler;
-  }
-  if (strcmp(handler, "coverage") == 0) {
-    return &this->Impl->CoverageHandler;
-  }
-  if (strcmp(handler, "script") == 0) {
-    return &this->Impl->ScriptHandler;
-  }
-  if (strcmp(handler, "test") == 0) {
-    return &this->Impl->TestHandler;
-  }
-  if (strcmp(handler, "update") == 0) {
-    return &this->Impl->UpdateHandler;
-  }
-  if (strcmp(handler, "configure") == 0) {
-    return &this->Impl->ConfigureHandler;
-  }
-  if (strcmp(handler, "memcheck") == 0) {
-    return &this->Impl->MemCheckHandler;
-  }
-  if (strcmp(handler, "submit") == 0) {
-    return &this->Impl->SubmitHandler;
-  }
-  if (strcmp(handler, "upload") == 0) {
-    return &this->Impl->UploadHandler;
-  }
-  return nullptr;
+  return &this->Impl->BuildAndTestHandler;
 }
 
-int cmCTest::ExecuteHandler(const char* shandler)
+cmCTestCoverageHandler* cmCTest::GetCoverageHandler()
 {
-  cmCTestGenericHandler* handler = this->GetHandler(shandler);
-  if (!handler) {
-    return -1;
-  }
-  handler->Initialize();
-  return handler->ProcessHandler();
+  return &this->Impl->CoverageHandler;
+}
+
+cmCTestScriptHandler* cmCTest::GetScriptHandler()
+{
+  return &this->Impl->ScriptHandler;
+}
+
+cmCTestTestHandler* cmCTest::GetTestHandler()
+{
+  return &this->Impl->TestHandler;
+}
+
+cmCTestUpdateHandler* cmCTest::GetUpdateHandler()
+{
+  return &this->Impl->UpdateHandler;
+}
+
+cmCTestConfigureHandler* cmCTest::GetConfigureHandler()
+{
+  return &this->Impl->ConfigureHandler;
+}
+
+cmCTestMemCheckHandler* cmCTest::GetMemCheckHandler()
+{
+  return &this->Impl->MemCheckHandler;
+}
+
+cmCTestSubmitHandler* cmCTest::GetSubmitHandler()
+{
+  return &this->Impl->SubmitHandler;
+}
+
+cmCTestUploadHandler* cmCTest::GetUploadHandler()
+{
+  return &this->Impl->UploadHandler;
 }
 
 int cmCTest::ProcessSteps()
@@ -1075,7 +1071,7 @@ int cmCTest::ProcessSteps()
   }
   if (this->Impl->Parts[PartUpdate] &&
       (this->GetRemainingTimeAllowed() > std::chrono::minutes(2))) {
-    cmCTestGenericHandler* uphandler = this->GetHandler("update");
+    cmCTestUpdateHandler* uphandler = this->GetUpdateHandler();
     uphandler->SetPersistentOption(
       "SourceDirectory",
       this->GetCTestConfiguration("SourceDirectory").c_str());
@@ -1089,35 +1085,35 @@ int cmCTest::ProcessSteps()
   }
   if (this->Impl->Parts[PartConfigure] &&
       (this->GetRemainingTimeAllowed() > std::chrono::minutes(2))) {
-    if (this->GetHandler("configure")->ProcessHandler() < 0) {
+    if (this->GetConfigureHandler()->ProcessHandler() < 0) {
       res |= cmCTest::CONFIGURE_ERRORS;
     }
   }
   if (this->Impl->Parts[PartBuild] &&
       (this->GetRemainingTimeAllowed() > std::chrono::minutes(2))) {
     this->UpdateCTestConfiguration();
-    if (this->GetHandler("build")->ProcessHandler() < 0) {
+    if (this->GetBuildHandler()->ProcessHandler() < 0) {
       res |= cmCTest::BUILD_ERRORS;
     }
   }
   if ((this->Impl->Parts[PartTest] || notest) &&
       (this->GetRemainingTimeAllowed() > std::chrono::minutes(2))) {
     this->UpdateCTestConfiguration();
-    if (this->GetHandler("test")->ProcessHandler() < 0) {
+    if (this->GetTestHandler()->ProcessHandler() < 0) {
       res |= cmCTest::TEST_ERRORS;
     }
   }
   if (this->Impl->Parts[PartCoverage] &&
       (this->GetRemainingTimeAllowed() > std::chrono::minutes(2))) {
     this->UpdateCTestConfiguration();
-    if (this->GetHandler("coverage")->ProcessHandler() < 0) {
+    if (this->GetCoverageHandler()->ProcessHandler() < 0) {
       res |= cmCTest::COVERAGE_ERRORS;
     }
   }
   if (this->Impl->Parts[PartMemCheck] &&
       (this->GetRemainingTimeAllowed() > std::chrono::minutes(2))) {
     this->UpdateCTestConfiguration();
-    if (this->GetHandler("memcheck")->ProcessHandler() < 0) {
+    if (this->GetMemCheckHandler()->ProcessHandler() < 0) {
       res |= cmCTest::MEMORY_ERRORS;
     }
   }
@@ -1149,7 +1145,7 @@ int cmCTest::ProcessSteps()
   }
   if (this->Impl->Parts[PartSubmit]) {
     this->UpdateCTestConfiguration();
-    if (this->GetHandler("submit")->ProcessHandler() < 0) {
+    if (this->GetSubmitHandler()->ProcessHandler() < 0) {
       res |= cmCTest::SUBMIT_ERRORS;
     }
   }
@@ -1579,8 +1575,7 @@ void cmCTest::StartXML(cmXMLWriter& xml, bool append)
 
 void cmCTest::AddSiteProperties(cmXMLWriter& xml)
 {
-  cmCTestScriptHandler* ch =
-    static_cast<cmCTestScriptHandler*>(this->GetHandler("script"));
+  cmCTestScriptHandler* ch = this->GetScriptHandler();
   cmake* cm = ch->GetCMake();
   // if no CMake then this is the old style script and props like
   // this will not work anyway.
@@ -2172,78 +2167,75 @@ bool cmCTest::HandleCommandLineArguments(size_t& i,
   if (this->CheckArgument(arg, "-I", "--tests-information") &&
       i < args.size() - 1) {
     i++;
-    this->GetHandler("test")->SetPersistentOption("TestsToRunInformation",
-                                                  args[i].c_str());
-    this->GetHandler("memcheck")
-      ->SetPersistentOption("TestsToRunInformation", args[i].c_str());
+    this->GetTestHandler()->SetPersistentOption("TestsToRunInformation",
+                                                args[i].c_str());
+    this->GetMemCheckHandler()->SetPersistentOption("TestsToRunInformation",
+                                                    args[i].c_str());
   }
   if (this->CheckArgument(arg, "-U", "--union")) {
-    this->GetHandler("test")->SetPersistentOption("UseUnion", "true");
-    this->GetHandler("memcheck")->SetPersistentOption("UseUnion", "true");
+    this->GetTestHandler()->SetPersistentOption("UseUnion", "true");
+    this->GetMemCheckHandler()->SetPersistentOption("UseUnion", "true");
   }
   if (this->CheckArgument(arg, "-R", "--tests-regex") && i < args.size() - 1) {
     i++;
-    this->GetHandler("test")->SetPersistentOption("IncludeRegularExpression",
-                                                  args[i].c_str());
-    this->GetHandler("memcheck")
-      ->SetPersistentOption("IncludeRegularExpression", args[i].c_str());
+    this->GetTestHandler()->SetPersistentOption("IncludeRegularExpression",
+                                                args[i].c_str());
+    this->GetMemCheckHandler()->SetPersistentOption("IncludeRegularExpression",
+                                                    args[i].c_str());
   }
   if (this->CheckArgument(arg, "-L", "--label-regex") && i < args.size() - 1) {
     i++;
-    this->GetHandler("test")->SetPersistentOption("LabelRegularExpression",
-                                                  args[i].c_str());
-    this->GetHandler("memcheck")
-      ->SetPersistentOption("LabelRegularExpression", args[i].c_str());
+    this->GetTestHandler()->SetPersistentOption("LabelRegularExpression",
+                                                args[i].c_str());
+    this->GetMemCheckHandler()->SetPersistentOption("LabelRegularExpression",
+                                                    args[i].c_str());
   }
   if (this->CheckArgument(arg, "-LE", "--label-exclude") &&
       i < args.size() - 1) {
     i++;
-    this->GetHandler("test")->SetPersistentOption(
+    this->GetTestHandler()->SetPersistentOption(
+      "ExcludeLabelRegularExpression", args[i].c_str());
+    this->GetMemCheckHandler()->SetPersistentOption(
       "ExcludeLabelRegularExpression", args[i].c_str());
-    this->GetHandler("memcheck")
-      ->SetPersistentOption("ExcludeLabelRegularExpression", args[i].c_str());
   }
 
   if (this->CheckArgument(arg, "-E", "--exclude-regex") &&
       i < args.size() - 1) {
     i++;
-    this->GetHandler("test")->SetPersistentOption("ExcludeRegularExpression",
-                                                  args[i].c_str());
-    this->GetHandler("memcheck")
-      ->SetPersistentOption("ExcludeRegularExpression", args[i].c_str());
+    this->GetTestHandler()->SetPersistentOption("ExcludeRegularExpression",
+                                                args[i].c_str());
+    this->GetMemCheckHandler()->SetPersistentOption("ExcludeRegularExpression",
+                                                    args[i].c_str());
   }
 
   if (this->CheckArgument(arg, "-FA", "--fixture-exclude-any") &&
       i < args.size() - 1) {
     i++;
-    this->GetHandler("test")->SetPersistentOption(
+    this->GetTestHandler()->SetPersistentOption(
+      "ExcludeFixtureRegularExpression", args[i].c_str());
+    this->GetMemCheckHandler()->SetPersistentOption(
       "ExcludeFixtureRegularExpression", args[i].c_str());
-    this->GetHandler("memcheck")
-      ->SetPersistentOption("ExcludeFixtureRegularExpression",
-                            args[i].c_str());
   }
   if (this->CheckArgument(arg, "-FS", "--fixture-exclude-setup") &&
       i < args.size() - 1) {
     i++;
-    this->GetHandler("test")->SetPersistentOption(
+    this->GetTestHandler()->SetPersistentOption(
+      "ExcludeFixtureSetupRegularExpression", args[i].c_str());
+    this->GetMemCheckHandler()->SetPersistentOption(
       "ExcludeFixtureSetupRegularExpression", args[i].c_str());
-    this->GetHandler("memcheck")
-      ->SetPersistentOption("ExcludeFixtureSetupRegularExpression",
-                            args[i].c_str());
   }
   if (this->CheckArgument(arg, "-FC", "--fixture-exclude-cleanup") &&
       i < args.size() - 1) {
     i++;
-    this->GetHandler("test")->SetPersistentOption(
+    this->GetTestHandler()->SetPersistentOption(
+      "ExcludeFixtureCleanupRegularExpression", args[i].c_str());
+    this->GetMemCheckHandler()->SetPersistentOption(
       "ExcludeFixtureCleanupRegularExpression", args[i].c_str());
-    this->GetHandler("memcheck")
-      ->SetPersistentOption("ExcludeFixtureCleanupRegularExpression",
-                            args[i].c_str());
   }
 
   if (this->CheckArgument(arg, "--rerun-failed")) {
-    this->GetHandler("test")->SetPersistentOption("RerunFailed", "true");
-    this->GetHandler("memcheck")->SetPersistentOption("RerunFailed", "true");
+    this->GetTestHandler()->SetPersistentOption("RerunFailed", "true");
+    this->GetMemCheckHandler()->SetPersistentOption("RerunFailed", "true");
   }
   return true;
 }
@@ -2292,8 +2284,7 @@ void cmCTest::HandleScriptArguments(size_t& i, std::vector<std::string>& args,
       i < args.size() - 1) {
     this->Impl->RunConfigurationScript = true;
     i++;
-    cmCTestScriptHandler* ch =
-      static_cast<cmCTestScriptHandler*>(this->GetHandler("script"));
+    cmCTestScriptHandler* ch = this->GetScriptHandler();
     // -SR is an internal argument, -SP should be ignored when it is passed
     if (!SRArgumentSpecified) {
       ch->AddConfigurationScript(args[i].c_str(), false);
@@ -2304,16 +2295,14 @@ void cmCTest::HandleScriptArguments(size_t& i, std::vector<std::string>& args,
     SRArgumentSpecified = true;
     this->Impl->RunConfigurationScript = true;
     i++;
-    cmCTestScriptHandler* ch =
-      static_cast<cmCTestScriptHandler*>(this->GetHandler("script"));
+    cmCTestScriptHandler* ch = this->GetScriptHandler();
     ch->AddConfigurationScript(args[i].c_str(), true);
   }
 
   if (this->CheckArgument(arg, "-S", "--script") && i < args.size() - 1) {
     this->Impl->RunConfigurationScript = true;
     i++;
-    cmCTestScriptHandler* ch =
-      static_cast<cmCTestScriptHandler*>(this->GetHandler("script"));
+    cmCTestScriptHandler* ch = this->GetScriptHandler();
     // -SR is an internal argument, -S should be ignored when it is passed
     if (!SRArgumentSpecified) {
       ch->AddConfigurationScript(args[i].c_str(), true);
@@ -2537,8 +2526,8 @@ int cmCTest::ExecuteTests()
       handler->SetVerbose(this->Impl->ExtraVerbose);
       handler->SetSubmitIndex(this->Impl->SubmitIndex);
     }
-    this->GetHandler("script")->SetVerbose(this->Impl->Verbose);
-    res = this->GetHandler("script")->ProcessHandler();
+    this->GetScriptHandler()->SetVerbose(this->Impl->Verbose);
+    res = this->GetScriptHandler()->ProcessHandler();
     if (res != 0) {
       cmCTestLog(this, DEBUG,
                  "running script failing returning: " << res << std::endl);
@@ -2573,8 +2562,7 @@ int cmCTest::ExecuteTests()
 int cmCTest::RunCMakeAndTest(std::string* output)
 {
   this->Impl->Verbose = true;
-  cmCTestBuildAndTestHandler* handler =
-    static_cast<cmCTestBuildAndTestHandler*>(this->GetHandler("buildtest"));
+  cmCTestBuildAndTestHandler* handler = this->GetBuildAndTestHandler();
   int retv = handler->ProcessHandler();
   *output = handler->GetOutput();
 #ifdef CMAKE_BUILD_WITH_CMAKE
@@ -3336,14 +3324,7 @@ std::string cmCTest::GetColorCode(Color color) const
 
 cmDuration cmCTest::GetRemainingTimeAllowed()
 {
-  if (!this->GetHandler("script")) {
-    return cmCTest::MaxDuration();
-  }
-
-  cmCTestScriptHandler* ch =
-    static_cast<cmCTestScriptHandler*>(this->GetHandler("script"));
-
-  return ch->GetRemainingTimeAllowed();
+  return this->GetScriptHandler()->GetRemainingTimeAllowed();
 }
 
 cmDuration cmCTest::MaxDuration()
@@ -3353,10 +3334,7 @@ cmDuration cmCTest::MaxDuration()
 
 void cmCTest::SetRunCurrentScript(bool value)
 {
-  cmCTestScriptHandler* ch =
-    static_cast<cmCTestScriptHandler*>(this->GetHandler("script"));
-
-  ch->SetRunCurrentScript(value);
+  this->GetScriptHandler()->SetRunCurrentScript(value);
 }
 
 void cmCTest::OutputTestErrors(std::vector<char> const& process_output)

+ 20 - 9
Source/cmCTest.h

@@ -17,7 +17,16 @@
 #include <time.h>
 #include <vector>
 
-class cmCTestGenericHandler;
+class cmCTestBuildHandler;
+class cmCTestBuildAndTestHandler;
+class cmCTestCoverageHandler;
+class cmCTestScriptHandler;
+class cmCTestTestHandler;
+class cmCTestUpdateHandler;
+class cmCTestConfigureHandler;
+class cmCTestMemCheckHandler;
+class cmCTestSubmitHandler;
+class cmCTestUploadHandler;
 class cmCTestStartCommand;
 class cmGeneratedFileStream;
 class cmMakefile;
@@ -314,17 +323,19 @@ public:
               std::vector<std::string>* environment,
               Encoding encoding = cmProcessOutput::Auto);
 
-  /**
-   * Execute handler and return its result. If the handler fails, it returns
-   * negative value.
-   */
-  int ExecuteHandler(const char* handler);
-
   /**
    * Get the handler object
    */
-  cmCTestGenericHandler* GetHandler(const char* handler);
-  cmCTestGenericHandler* GetInitializedHandler(const char* handler);
+  cmCTestBuildHandler* GetBuildHandler();
+  cmCTestBuildAndTestHandler* GetBuildAndTestHandler();
+  cmCTestCoverageHandler* GetCoverageHandler();
+  cmCTestScriptHandler* GetScriptHandler();
+  cmCTestTestHandler* GetTestHandler();
+  cmCTestUpdateHandler* GetUpdateHandler();
+  cmCTestConfigureHandler* GetConfigureHandler();
+  cmCTestMemCheckHandler* GetMemCheckHandler();
+  cmCTestSubmitHandler* GetSubmitHandler();
+  cmCTestUploadHandler* GetUploadHandler();
 
   /**
    * Set the CTest variable from CMake variable

+ 1 - 2
Source/ctest.cxx

@@ -191,8 +191,7 @@ int main(int argc, char const* const* argv)
     doc.addCTestStandardDocSections();
     if (doc.CheckOptions(argc, argv)) {
       // Construct and print requested documentation.
-      cmCTestScriptHandler* ch =
-        static_cast<cmCTestScriptHandler*>(inst.GetHandler("script"));
+      cmCTestScriptHandler* ch = inst.GetScriptHandler();
       ch->CreateCMake();
 
       doc.SetShowGenerators(false);