Hi there,

I like to add the option "--no-return-code" to ctest.

We use ctest on Jenkins in a shell build step. Jenkins will FAIL the build
if the last command (ctest) will return a non-zero return code even the
configured UNSTABLE/FAIL threshold is not reached.

The only work-around is to call another useless command after it. This
won't be necessary if ctest could ignore the return codes.

Best regards
  André Klitzing
From 2829f563b5b7454337471e44e3e648e0acddc9a7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9=20Klitzing?= <aklitz...@gmail.com>
Date: Thu, 13 Aug 2015 21:52:10 +0200
Subject: [PATCH] CTest: Add a new --no-return-code option

This option tells ctest to ignore every return code of tests and
return 0 (SUCCESS) even if a test failed. This is useful to run
ctest on Jenkins without failing the build and let Jenkins
decide if a build is UNSTABLE or FAILED regarding of a defined
threshold.
---
 Source/cmCTest.cxx | 6 ++++++
 Source/cmCTest.h   | 3 +++
 Source/ctest.cxx   | 3 ++-
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx
index b976469..287a798 100644
--- a/Source/cmCTest.cxx
+++ b/Source/cmCTest.cxx
@@ -311,6 +311,7 @@ cmCTest::cmCTest()
   this->RunConfigurationScript = false;
   this->UseHTTP10              = false;
   this->PrintLabels            = false;
+  this->NoReturnCode           = false;
   this->CompressTestOutput     = true;
   this->CompressMemCheckOutput = true;
   this->TestModel              = cmCTest::EXPERIMENTAL;
@@ -2103,6 +2104,11 @@ bool cmCTest::HandleCommandLineArguments(size_t &i,
     this->PrintLabels = true;
     }
 
+  if(this->CheckArgument(arg, "--no-return-code"))
+    {
+    this->NoReturnCode = true;
+    }
+
   if(this->CheckArgument(arg, "--http1.0"))
     {
     this->UseHTTP10 = true;
diff --git a/Source/cmCTest.h b/Source/cmCTest.h
index 73c2807..976dae8 100644
--- a/Source/cmCTest.h
+++ b/Source/cmCTest.h
@@ -231,6 +231,8 @@ public:
 
   bool ShouldPrintLabels() { return this->PrintLabels; }
 
+  bool GetNoReturnCode() { return this->NoReturnCode; }
+
   bool ShouldCompressTestOutput();
   bool ShouldCompressMemCheckOutput();
   bool CompressString(std::string& str);
@@ -451,6 +453,7 @@ private:
   bool LabelSummary;
   bool UseHTTP10;
   bool PrintLabels;
+  bool NoReturnCode;
   bool Failover;
   bool BatchJobs;
 
diff --git a/Source/ctest.cxx b/Source/ctest.cxx
index afcbd61..93deb74 100644
--- a/Source/ctest.cxx
+++ b/Source/ctest.cxx
@@ -113,6 +113,7 @@ static const char * cmDocumentationOptions[][2] =
   {"--http1.0", "Submit using HTTP 1.0."},
   {"--no-compress-output", "Do not compress test output when submitting."},
   {"--print-labels", "Print all available test labels."},
+  {"--no-return-code", "Ignore every return code and returns 0 even on failed tests."},
   {0,0}
 };
 
@@ -194,6 +195,6 @@ int main (int argc, char const* const* argv)
   int res = inst.Run(args,&output);
   cmCTestLog(&inst, OUTPUT, output);
 
-  return res;
+  return inst.GetNoReturnCode() ? EXIT_SUCCESS : res;
 }
 
-- 
2.5.0

-- 

Powered by www.kitware.com

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

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

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

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

Reply via email to