Commit bba2ea2b authored by Manuel Günther's avatar Manuel Günther
Browse files

Made error messages more precise (doesn't solve the issue, though)

parent d9f6aafd
Pipeline #6884 passed with stages
in 12 minutes and 40 seconds
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <bob.extension/documentation.h> #include <bob.extension/documentation.h>
#include <bob.core/logging.h> #include <bob.core/logging.h>
#include <boost/format.hpp>
#include <boost/shared_array.hpp> #include <boost/shared_array.hpp>
...@@ -201,13 +202,16 @@ BOB_CATCH_FUNCTION("_log_message_mt", 0) ...@@ -201,13 +202,16 @@ BOB_CATCH_FUNCTION("_log_message_mt", 0)
} }
static void _test(const std::string& expected, const std::string& obtained, const std::string& step){
if (expected != obtained)
throw std::runtime_error((boost::format("The string '%s' in step %swas not '%s' as expected") % obtained % step % expected).str());
}
static auto _output_disable_doc = bob::extension::FunctionDoc( static auto _output_disable_doc = bob::extension::FunctionDoc(
"_test_output_disable", "_test_output_disable",
"Writes C++ messages with and without being visible" "Writes C++ messages with and without being visible and raises exceptions when an error occurs."
) )
.add_prototype("", "success") .add_prototype("", "")
.add_return("success", "bool", "The success of the test")
; ;
PyObject* output_disable(PyObject*, PyObject* args, PyObject* kwds) { PyObject* output_disable(PyObject*, PyObject* args, PyObject* kwds) {
BOB_TRY BOB_TRY
...@@ -220,16 +224,13 @@ BOB_TRY ...@@ -220,16 +224,13 @@ BOB_TRY
std::streambuf * oldout = std::cout.rdbuf(out.rdbuf()); std::streambuf * oldout = std::cout.rdbuf(out.rdbuf());
std::streambuf * olderr = std::cerr.rdbuf(err.rdbuf()); std::streambuf * olderr = std::cerr.rdbuf(err.rdbuf());
bool success = true;
try {
bob::core::log_level(bob::core::DEBUG); bob::core::log_level(bob::core::DEBUG);
bob::core::debug << "This is a debug message" << std::endl; bob::core::debug << "This is a debug message" << std::endl;
bob::core::info << "This is an info message" << std::endl; bob::core::info << "This is an info message" << std::endl;
bob::core::warn << "This is a warning message" << std::endl; bob::core::warn << "This is a warning message" << std::endl;
bob::core::error << "This is an error message" << std::endl; bob::core::error << "This is an error message" << std::endl;
success = success && out.str() == "This is a debug message\nThis is an info message\n"; _test(out.str(), "This is a debug message\nThis is an info message\n", "debug");
success = success && err.str() == "This is a warning message\nThis is an error message\n"; _test(err.str(), "This is a warning message\nThis is an error message\n", "debug");
out.str(""); out.str("");
err.str(""); err.str("");
...@@ -238,8 +239,8 @@ BOB_TRY ...@@ -238,8 +239,8 @@ BOB_TRY
bob::core::info << "This is an info message" << std::endl; bob::core::info << "This is an info message" << std::endl;
bob::core::warn << "This is a warning message" << std::endl; bob::core::warn << "This is a warning message" << std::endl;
bob::core::error << "This is an error message" << std::endl; bob::core::error << "This is an error message" << std::endl;
success = success && out.str() == ""; _test(out.str(), "", "error");
success = success && err.str() == "This is an error message\n"; _test(err.str(), "This is an error message\n", "error");
out.str(""); out.str("");
err.str(""); err.str("");
...@@ -248,12 +249,8 @@ BOB_TRY ...@@ -248,12 +249,8 @@ BOB_TRY
bob::core::info << "This is an info message" << std::endl; bob::core::info << "This is an info message" << std::endl;
bob::core::warn << "This is a warning message" << std::endl; bob::core::warn << "This is a warning message" << std::endl;
bob::core::error << "This is an error message" << std::endl; bob::core::error << "This is an error message" << std::endl;
success = success && out.str() == ""; _test(out.str(), "", "disable");
success = success && err.str() == ""; _test(err.str(), "", "disable");
} catch(...){
success = false;
}
// make sure that cout and cerr are redirected to their original streams // make sure that cout and cerr are redirected to their original streams
std::cout.rdbuf( oldout ); std::cout.rdbuf( oldout );
...@@ -261,10 +258,7 @@ BOB_TRY ...@@ -261,10 +258,7 @@ BOB_TRY
bob::core::log_level(bob::core::DEBUG); bob::core::log_level(bob::core::DEBUG);
if (success) Py_RETURN_NONE;
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
BOB_CATCH_FUNCTION("_test_output_disable", 0) BOB_CATCH_FUNCTION("_test_output_disable", 0)
} }
......
...@@ -77,4 +77,4 @@ def test_from_cxx_multithreaded(): ...@@ -77,4 +77,4 @@ def test_from_cxx_multithreaded():
def test_from_cxx_disable(): def test_from_cxx_disable():
from bob.core._test import _test_output_disable from bob.core._test import _test_output_disable
assert _test_output_disable(), "The C++ test function returned false, indicating an (unknonw) error" _test_output_disable()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment