[PATCH] allow to mark a test as "Not Run" with a specific return code (#8466)

Rolf Eike Beer eike at sf-mail.de
Fri Sep 21 11:37:08 EDT 2012


---
 Source/CTest/cmCTestRunTest.cxx     |    8 +++++++-
 Source/CTest/cmCTestTestHandler.cxx |    9 +++++++++
 Source/CTest/cmCTestTestHandler.h   |    2 ++
 Source/cmTest.cxx                   |    8 ++++++++
 4 files changed, 26 insertions(+), 1 deletions(-)

diff --git a/Source/CTest/cmCTestRunTest.cxx b/Source/CTest/cmCTestRunTest.cxx
index 5eabf3f..c46788f 100644
--- a/Source/CTest/cmCTestRunTest.cxx
+++ b/Source/CTest/cmCTestRunTest.cxx
@@ -204,7 +204,13 @@ bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started)
     bool success =
       !forceFail &&  (retVal == 0 ||
       this->TestProperties->RequiredRegularExpressions.size());
-    if((success && !this->TestProperties->WillFail)
+    if(this->TestProperties->SkipReturnCode >= 0
+      && this->TestProperties->SkipReturnCode == retVal)
+      {
+      this->TestResult.Status = cmCTestTestHandler::NOT_RUN;
+      cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Skipped ");
+      }
+    else if((success && !this->TestProperties->WillFail)
       || (!success && this->TestProperties->WillFail))
       {
       this->TestResult.Status = cmCTestTestHandler::COMPLETED;
diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx
index ead449e..de02826 100644
--- a/Source/CTest/cmCTestTestHandler.cxx
+++ b/Source/CTest/cmCTestTestHandler.cxx
@@ -2114,6 +2114,14 @@ bool cmCTestTestHandler::SetTestsProperties(
               rtit->Processors = 1;
               }
             }
+          if ( key == "SKIP_RETURN_CODE" )
+            {
+            rtit->SkipReturnCode = atoi(val.c_str());
+            if(rtit->SkipReturnCode < 0 || rtit->SkipReturnCode > 255)
+              {
+              rtit->SkipReturnCode = -1;
+              }
+            }
           if ( key == "DEPENDS" )
             {
             std::vector<std::string> lval;
@@ -2249,6 +2257,7 @@ bool cmCTestTestHandler::AddTest(const std::vector<std::string>& args)
   test.ExplicitTimeout = false;
   test.Cost = 0;
   test.Processors = 1;
+  test.SkipReturnCode = -1;
   test.PreviousRuns = 0;
   if (this->UseIncludeRegExpFlag &&
     !this->IncludeTestsRegularExpression.find(testname.c_str()))
diff --git a/Source/CTest/cmCTestTestHandler.h b/Source/CTest/cmCTestTestHandler.h
index 8e59e59..1e68dc8 100644
--- a/Source/CTest/cmCTestTestHandler.h
+++ b/Source/CTest/cmCTestTestHandler.h
@@ -103,6 +103,8 @@ public:
     int Index;
     //Requested number of process slots
     int Processors;
+    // return code of test which will mark test as "not run"
+    int SkipReturnCode;
     std::vector<std::string> Environment;
     std::vector<std::string> Labels;
     std::set<std::string> LockedResources;
diff --git a/Source/cmTest.cxx b/Source/cmTest.cxx
index 912ec76..07c956f 100644
--- a/Source/cmTest.cxx
+++ b/Source/cmTest.cxx
@@ -170,6 +170,14 @@ void cmTest::DefineProperties(cmake *cm)
      "the ctest_test PARALLEL_LEVEL option.");
 
   cm->DefineProperty
+    ("SKIP_RETURN_CODE", cmProperty::TEST,
+     "Return code to mark a test as not run",
+     "Sometimes only a test itself can determine if all requirements for the "
+     "test are met. If such a situation should not be considered a hard "
+     "a return code of the process can be specified that will mark the "
+     "test as \"Not Run\" if it is encountered.");
+
+  cm->DefineProperty
     ("REQUIRED_FILES", cmProperty::TEST,
      "List of files required to run the test.",
      "If set to a list of files, the test will not be run unless all of the "
-- 
1.7.7


--nextPart4204680.kAUZqJf5np
Content-Disposition: attachment; filename="CMakeLists.txt"
Content-Transfer-Encoding: 7Bit
Content-Type: text/x-cmake; charset="UTF-8"; name="CMakeLists.txt"

cmake_minimum_required(VERSION 2.8)

project(Skip C)

add_executable(retparam retparam.c)

include(CTest)
enable_testing()


add_test(NAME normal COMMAND retparam)
add_test(NAME fail COMMAND retparam 1)
add_test(NAME skip0 COMMAND retparam)
set_tests_properties(skip0 PROPERTIES SKIP_RETURN_CODE 0)
add_test(NAME skip77 COMMAND retparam 77)
set_tests_properties(skip77 PROPERTIES SKIP_RETURN_CODE 77)
add_test(NAME noskip COMMAND retparam)
set_tests_properties(noskip PROPERTIES SKIP_RETURN_CODE 77)
add_test(NAME badexe COMMAND notexistant)

--nextPart4204680.kAUZqJf5np
Content-Disposition: attachment; filename="retparam.c"
Content-Transfer-Encoding: 7Bit
Content-Type: text/x-csrc; charset="UTF-8"; name="retparam.c"

#include <stdlib.h>

int main(int argc, char **argv)
{
 if (argc < 2)
  return 0;
 else if (argc == 2)
  return atoi(argv[1]);
 else
  return argc;
}

--nextPart4204680.kAUZqJf5np--

--nextPart5035303.Sm9d1IYLh5
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: This is a digitally signed message part.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.18 (GNU/Linux)

iEYEABECAAYFAlBcisQACgkQXKSJPmm5/E4tgACgplMCH+JDTqb8w+k0OHMWRQOi
eD4An1etphLeOu007P7WzPAY6SPtAAS+
=7sM1
-----END PGP SIGNATURE-----

--nextPart5035303.Sm9d1IYLh5--



More information about the cmake-developers mailing list