On 08/31/2015 07:36 AM, "Roman Wüger" wrote:
> Attached you will find the corrected patch.

Thanks.  I've attached a revised version.  I renamed the options
and added release notes.  I also started the test case.  Please
try completing the test and getting it to pass from there.

BTW, I noticed that there is actually a way to set these values
already.  It just is not documented.  Try this:

 $ git grep CTEST_CUSTOM_MAXIMUM_.*_TEST_OUTPUT_SIZE

to see the options.  They can be set in ctest scripts but not
on the command line.

-Brad

>From 4a1c6c75d20f3b9f4f6b40779322250ba9786d6f Mon Sep 17 00:00:00 2001
Message-Id: <4a1c6c75d20f3b9f4f6b40779322250ba9786d6f.1441048648.git.brad.k...@kitware.com>
From: =?UTF-8?q?Roman=20W=C3=BCger?= <roman.wue...@gmx.at>
Date: Mon, 31 Aug 2015 11:19:23 +0200
Subject: [PATCH] CTest learned to limit the output of passed and failed tests

---
 Help/manual/ctest.1.rst                            |  6 ++++
 Help/release/dev/ctest-custom-output-size.rst      |  7 ++++
 Source/CTest/cmCTestTestHandler.h                  |  5 +++
 Source/cmCTest.cxx                                 | 41 +++++++++++++++++++++-
 Source/ctest.cxx                                   |  4 +++
 Tests/RunCMake/ctest_test/CMakeLists.txt.in        |  1 +
 Tests/RunCMake/ctest_test/RunCMakeTest.cmake       | 11 ++++++
 .../RunCMake/ctest_test/TestOutputSize-check.cmake |  8 +++++
 8 files changed, 82 insertions(+), 1 deletion(-)
 create mode 100644 Help/release/dev/ctest-custom-output-size.rst
 create mode 100644 Tests/RunCMake/ctest_test/TestOutputSize-check.cmake

diff --git a/Help/manual/ctest.1.rst b/Help/manual/ctest.1.rst
index 50c856a..2fdf7f3 100644
--- a/Help/manual/ctest.1.rst
+++ b/Help/manual/ctest.1.rst
@@ -302,6 +302,12 @@ Options
 ``--test-command``
  The test to run with the --build-and-test option.
 
+``--test-output-size-passed <size>``
+ Limit the output for passed tests to <size> bytes.
+
+``--test-output-size-failed <size>``
+ Limit the output for failed tests to <size> bytes.
+
 ``--test-timeout``
  The time limit in seconds, internal use only.
 
diff --git a/Help/release/dev/ctest-custom-output-size.rst b/Help/release/dev/ctest-custom-output-size.rst
new file mode 100644
index 0000000..8098b93
--- /dev/null
+++ b/Help/release/dev/ctest-custom-output-size.rst
@@ -0,0 +1,7 @@
+ctest-custom-output-size
+------------------------
+
+* :manual:`ctest(1)` learned options
+  ``--test-output-size-passed`` and ``--test-output-size-failed``
+  to customize the limit on test output size submitted when
+  running as a :ref:`Dashboard Client`.
diff --git a/Source/CTest/cmCTestTestHandler.h b/Source/CTest/cmCTestTestHandler.h
index 14067d5..c635430 100644
--- a/Source/CTest/cmCTestTestHandler.h
+++ b/Source/CTest/cmCTestTestHandler.h
@@ -65,6 +65,11 @@ public:
   void SetMaxIndex(int n) {this->MaxIndex = n;}
   int GetMaxIndex() {return this->MaxIndex;}
 
+  void SetTestOutputSizePassed(int n)
+    { this->CustomMaximumPassedTestOutputSize = n; }
+  void SetTestOutputSizeFailed(int n)
+    { this->CustomMaximumFailedTestOutputSize = n; }
+
   ///! pass the -I argument down
   void SetTestsToRunInformation(const char*);
 
diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx
index b2ad4a8..6e55d89 100644
--- a/Source/cmCTest.cxx
+++ b/Source/cmCTest.cxx
@@ -2165,7 +2165,46 @@ bool cmCTest::HandleCommandLineArguments(size_t &i,
     {
     this->OutputTestOutputOnTestFailure = true;
     }
-
+  if (this->CheckArgument(arg, "--test-output-size-passed") &&
+      i < args.size() - 1)
+    {
+    i++;
+    long outputSize;
+    if (cmSystemTools::StringToLong(args[i].c_str(), &outputSize))
+      {
+      if (cmCTestTestHandler *pCTestTestHandler =
+          static_cast<cmCTestTestHandler*>(this->TestingHandlers["test"]))
+        {
+        pCTestTestHandler->SetTestOutputSizePassed(int(outputSize));
+        }
+      }
+    else
+      {
+      cmCTestLog(this, WARNING,
+                 "Invalid value for '--test-output-size-passed': " <<
+                 args[i] << "\n");
+      }
+    }
+  if (this->CheckArgument(arg, "--test-output-size-failed") &&
+      i < args.size() - 1)
+    {
+    i++;
+    long outputSize;
+    if (cmSystemTools::StringToLong(args[i].c_str(), &outputSize))
+      {
+      if (cmCTestTestHandler *pCTestTestHandler =
+          static_cast<cmCTestTestHandler*>(this->TestingHandlers["test"]))
+        {
+        pCTestTestHandler->SetTestOutputSizeFailed(int(outputSize));
+        }
+      }
+    else
+      {
+      cmCTestLog(this, WARNING,
+                 "Invalid value for '--test-output-size-failed': " <<
+                 args[i] << "\n");
+      }
+    }
   if(this->CheckArgument(arg, "-N", "--show-only"))
     {
     this->ShowOnly = true;
diff --git a/Source/ctest.cxx b/Source/ctest.cxx
index afcbd61..7fa6aed 100644
--- a/Source/ctest.cxx
+++ b/Source/ctest.cxx
@@ -46,6 +46,10 @@ static const char * cmDocumentationOptions[][2] =
   {"--debug", "Displaying more verbose internals of CTest."},
   {"--output-on-failure", "Output anything outputted by the test program "
     "if the test should fail."},
+  {"--test-output-size-passed <size>", "Limit the output for passed tests "
+    "to <size> bytes"},
+  {"--test-output-size-failed <size>", "Limit the output for failed tests "
+    "to <size> bytes"},
   {"-F", "Enable failover."},
   {"-j <jobs>, --parallel <jobs>", "Run the tests in parallel using the "
    "given number of jobs."},
diff --git a/Tests/RunCMake/ctest_test/CMakeLists.txt.in b/Tests/RunCMake/ctest_test/CMakeLists.txt.in
index cedf379..e61b556 100644
--- a/Tests/RunCMake/ctest_test/CMakeLists.txt.in
+++ b/Tests/RunCMake/ctest_test/CMakeLists.txt.in
@@ -2,3 +2,4 @@ cmake_minimum_required(VERSION 3.1)
 project(CTestTest@CASE_NAME@ NONE)
 include(CTest)
 add_test(NAME RunCMakeVersion COMMAND "${CMAKE_COMMAND}" --version)
+@CASE_CMAKELISTS_SUFFIX_CODE@
diff --git a/Tests/RunCMake/ctest_test/RunCMakeTest.cmake b/Tests/RunCMake/ctest_test/RunCMakeTest.cmake
index 76dc143..1c03232 100644
--- a/Tests/RunCMake/ctest_test/RunCMakeTest.cmake
+++ b/Tests/RunCMake/ctest_test/RunCMakeTest.cmake
@@ -59,3 +59,14 @@ function(run_TestChangeId)
   run_ctest(TestChangeId)
 endfunction()
 run_TestChangeId()
+
+function(run_TestOutputSize)
+  set(CASE_CTEST_TEST_ARGS EXCLUDE RunCMakeVersion)
+  set(CASE_CMAKELISTS_SUFFIX_CODE [[
+add_test(NAME PassingTest COMMAND ${CMAKE_COMMAND} -E echo PassingTestOutput)
+add_test(NAME FailingTest COMMAND ${CMAKE_COMMAND} -E no_such_command)
+  ]])
+
+  run_ctest(TestOutputSize)
+endfunction()
+run_TestOutputSize()
diff --git a/Tests/RunCMake/ctest_test/TestOutputSize-check.cmake b/Tests/RunCMake/ctest_test/TestOutputSize-check.cmake
new file mode 100644
index 0000000..7a2b32a
--- /dev/null
+++ b/Tests/RunCMake/ctest_test/TestOutputSize-check.cmake
@@ -0,0 +1,8 @@
+file(GLOB test_xml_file "${RunCMake_TEST_BINARY_DIR}/Testing/*/Test.xml")
+if(test_xml_file)
+  file(READ "${test_xml_file}" test_xml LIMIT 4096)
+  # TODO: actually check the content
+  set(RunCMake_TEST_FAILED "Test.xml content:\n${test_xml}")
+else()
+  set(RunCMake_TEST_FAILED "Test.xml not found")
+endif()
-- 
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