[mlpack-git] master: better boost test output (fc6fd23)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Tue Feb 24 11:21:01 EST 2015


Repository : https://github.com/mlpack/mlpack

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/9d8462ce094e5c4403f39cc8e335f5a8ae963223...750018deea47095152b4feb2c0760b34ea5543da

>---------------------------------------------------------------

commit fc6fd23ee69d7e94a632c1f3ef0ab66a75518c26
Author: apir8181 <kazenoyumechen at gmail.com>
Date:   Tue Feb 24 22:52:13 2015 +0800

    better boost test output


>---------------------------------------------------------------

fc6fd23ee69d7e94a632c1f3ef0ab66a75518c26
 CMakeLists.txt                   |  6 ++++++
 src/mlpack/CMakeLists.txt        |  2 +-
 src/mlpack/tests/mlpack_test.cpp | 34 ++++++++++++++++++++++++++++++++--
 3 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3bc3859..39b0137 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -15,6 +15,7 @@ option(DEBUG "Compile with debugging information" ON)
 option(PROFILE "Compile with profiling information" ON)
 option(ARMA_EXTRA_DEBUG "Compile with extra Armadillo debugging symbols." OFF)
 option(MATLAB_BINDINGS "Compile MATLAB bindings if MATLAB is found." OFF)
+option(TEST_VERBOSE "Running test cases with verbose ouput" OFF)
 
 # This is as of yet unused.
 #option(PGO "Use profile-guided optimization if not a debug build" ON)
@@ -55,6 +56,11 @@ if(CMAKE_COMPILER_IS_GNUCC AND PROFILE)
   set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
 endif(CMAKE_COMPILER_IS_GNUCC AND PROFILE)
 
+# If the user asked for running test cases with verbose output, turn that on.
+if(TEST_VERBOSE)
+  add_definitions(-DTEST_VERBOSE)
+endif(TEST_VERBOSE)
+
 # If the user asked for extra Armadillo debugging output, turn that on.
 if(ARMA_EXTRA_DEBUG)
   add_definitions(-DARMA_EXTRA_DEBUG)
diff --git a/src/mlpack/CMakeLists.txt b/src/mlpack/CMakeLists.txt
index 5d52218..9092d4a 100644
--- a/src/mlpack/CMakeLists.txt
+++ b/src/mlpack/CMakeLists.txt
@@ -77,7 +77,7 @@ add_dependencies(mlpack mlpack_headers)
 
 # For 'make test'.
 add_custom_target(test
-  ${CMAKE_BINARY_DIR}/bin/mlpack_test
+  ${CMAKE_BINARY_DIR}/bin/mlpack_test "--log_level=test_suite" # Set UTF runtime param
   WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/ # This is where test files are put.
   COMMENT "Running MLPACK test"
   DEPENDS mlpack_test)
diff --git a/src/mlpack/tests/mlpack_test.cpp b/src/mlpack/tests/mlpack_test.cpp
index c012389..123b7f9 100644
--- a/src/mlpack/tests/mlpack_test.cpp
+++ b/src/mlpack/tests/mlpack_test.cpp
@@ -1,11 +1,14 @@
 /**
  * @file mlpack_test.cpp
  *
- * Simple file defining the name of the overall test for MLPACK.  Each
- * individual test is contained in its own file.
+ * Simple file defining the name of the overall test for MLPACK, and set up
+ * global test fixture for each test. Each individual test is contained in
+ * its own file.
  */
 #define BOOST_TEST_MODULE MLPACKTest
 
+#include <mlpack/core/util/log.hpp>
+
 #include <boost/version.hpp>
 
 // We only need to do this for old Boost versions.
@@ -15,3 +18,30 @@
 
 #include <boost/test/unit_test.hpp>
 #include "old_boost_test_definitions.hpp"
+
+/**
+ * Provide a global fixture for each test.
+ *
+ * A global fixture is expected to be implemented as a class where the class
+ * constructor serves as a setup method and class destructor serves as teardown
+ * method. 
+ * 
+ * By default, Log::objects should have their output redirected, otherwise
+ * the UTF test output would be drown out by Log::Debug and Log::Warn messages.
+ *
+ * For more detailed test output, set cmake flag TEST_VERBOSE=ON.
+ */
+struct GlobalFixture {
+  GlobalFixture()
+  {
+#ifndef TEST_VERBOSE
+#ifdef DEBUG
+    mlpack::Log::Debug.ignoreInput = true;
+#endif
+    mlpack::Log::Info.ignoreInput = true;
+    mlpack::Log::Warn.ignoreInput = true;
+#endif
+  }
+};
+
+BOOST_GLOBAL_FIXTURE(GlobalFixture);



More information about the mlpack-git mailing list