From fc6fd23ee69d7e94a632c1f3ef0ab66a75518c26 Mon Sep 17 00:00:00 2001 From: apir8181 Date: Tue, 24 Feb 2015 22:52:13 +0800 Subject: [PATCH] better boost test output --- 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 3bc3859673d..39b0137396b 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 5d522189cef..9092d4a2b9a 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 c01238994dc..123b7f925f5 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 + #include // We only need to do this for old Boost versions. @@ -15,3 +18,30 @@ #include #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);