Marcel Loose wrote:
> On 19/09/12 08:18, Rolf Eike Beer wrote:
> > David Cole wrote:
> >> I don't like it. Existing tests that run and return, for example, a
> >> number
> >> of errors that occurred, will magically appear as "not run" when that
> >> number just so happens to be 77.
> >> 
> >> If there are enough people who think this is "simple and works" and are
> >> not
> >> concerned about the accidental matching of an intentional return value of
> >> 77 that does NOT mean "not run" ... then I will relent and say, so be it,
> >> and allow it in.
> >> 
> >> But only if there are some people who speak up here or add notes to the
> >> bug.
> >> 
> >> It just seems wrong to me to treat 77 as some special number here.
> > 
> > I would still go and make that a target property where you can set the
> > return code where something is considered skipped. The only question is:
> > how to name the property?

> I already suggested to use a test property three years ago (see issue
> #8466). At that time David was very much against it, fearing to find "a
> ***huuuuuuggggeee*** can of worms right underneath the surface." Seems
> I'm slowly getting more fellow thinkers ;)

When you look at the issue you may notice that I said basically the same as 
above nearly 2 years ago ;)

But this time I have a patch ;) I've attached the test I used, for sure that 
needs to be make a proper testcase. I wonder if we should do stricter checking 
for the arguments passed to the property, e.g. if someone passes a string or 
other junk. But the same would apply to things like PROCESSORS.

Eike
-- 
>From 524546ff26a7f25c21ad30d17aa3b0aba619cf21 Mon Sep 17 00:00:00 2001
From: Rolf Eike Beer <e...@sf-mail.de>
Date: Fri, 21 Sep 2012 17:37:08 +0200
Subject: [PATCH] allow to mark a test as "Not Run" with a specific return
 code (#8466)

---
 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

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)
#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;
}

Attachment: signature.asc
Description: This is a digitally signed message part.

--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers

Reply via email to