Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
bob
bob.core
Commits
d16c34a8
There was a problem fetching the pipeline summary.
Commit
d16c34a8
authored
8 years ago
by
André Anjos
Browse files
Options
Downloads
Patches
Plain Diff
Previous fix (for issue
#6
) did not work as expected, moving all checks to this module
parent
5d97ac23
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Pipeline
#
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bob/core/test.cpp
+31
-42
31 additions, 42 deletions
bob/core/test.cpp
with
31 additions
and
42 deletions
bob/core/test.cpp
+
31
−
42
View file @
d16c34a8
...
...
@@ -207,34 +207,24 @@ static void _test(const std::string& obtained, const std::string& expected, cons
throw
std
::
runtime_error
((
boost
::
format
(
"The string
\"
%s
\"
in step %s was not
\"
%s
\"
as expected"
)
%
obtained
%
step
%
expected
).
str
());
}
// Proper redirection of a stream. If exception or similar is thrown, correctly
// resets the modified standard stream.
// See: http://stackoverflow.com/questions/5419356/redirect-stdout-stderr-to-a-string
class
_ostream_redirect
{
public:
_ostream_redirect
(
std
::
ostream
&
s
)
:
m_stream
(
s
),
m_buffer
(),
m_old
(
m_stream
.
rdbuf
(
m_buffer
.
rdbuf
()))
{
}
void
str
(
const
char
*
v
)
{
m_buffer
.
str
(
v
);
}
class
StringStreamOutputDevice
:
public
boost
::
iostreams
::
sink
{
std
::
string
str
()
{
return
m_buffer
.
str
();
}
public:
~
_ostream_redirect
()
{
m_stream
.
rdbuf
(
m_old
);
StringStreamOutputDevice
(
boost
::
shared_ptr
<
std
::
stringstream
>
d
)
:
m_buffer
(
d
)
{
}
virtual
~
StringStreamOutputDevice
()
{
}
virtual
std
::
streamsize
write
(
const
char
*
s
,
std
::
streamsize
n
)
{
if
(
m_buffer
)
m_buffer
->
write
(
s
,
n
);
return
n
;
}
virtual
void
close
()
{
m_buffer
.
reset
();
}
private
:
std
::
ostream
&
m_stream
;
std
::
stringstream
m_buffer
;
std
::
streambuf
*
m_old
;
boost
::
shared_ptr
<
std
::
stringstream
>
m_buffer
;
};
...
...
@@ -258,45 +248,44 @@ BOB_TRY
//libbob_core.so may be loaded from another module and, because of python's
//insular loading system, this and the other module may not share the same
//pointers to those streams.
boost
::
iostreams
::
stream
<
bob
::
core
::
AutoOutputDevice
>
debug
(
"stdout"
);
boost
::
iostreams
::
stream
<
bob
::
core
::
AutoOutputDevice
>
info
(
"stdout"
);
boost
::
iostreams
::
stream
<
bob
::
core
::
AutoOutputDevice
>
warn
(
"stderr"
);
boost
::
iostreams
::
stream
<
bob
::
core
::
AutoOutputDevice
>
error
(
"stderr"
);
_ostream_redirect
out
(
std
::
cout
);
_ostream_redirect
err
(
std
::
cerr
);
boost
::
shared_ptr
<
std
::
stringstream
>
out
(
new
std
::
stringstream
(
""
));
boost
::
shared_ptr
<
std
::
stringstream
>
err
(
new
std
::
stringstream
(
""
));
boost
::
iostreams
::
stream
<
StringStreamOutputDevice
>
debug
(
out
);
boost
::
iostreams
::
stream
<
StringStreamOutputDevice
>
info
(
out
);
boost
::
iostreams
::
stream
<
StringStreamOutputDevice
>
warn
(
err
);
boost
::
iostreams
::
stream
<
StringStreamOutputDevice
>
error
(
err
);
//equivalent to: bob::core::log_level(bob::core::DEBUG);
debug
<<
"This is a debug message"
<<
std
::
endl
;
info
<<
"This is an info message"
<<
std
::
endl
;
warn
<<
"This is a warning message"
<<
std
::
endl
;
error
<<
"This is an error message"
<<
std
::
endl
;
_test
(
out
.
str
(),
"This is a debug message
\n
This is an info message
\n
"
,
"debug"
);
_test
(
err
.
str
(),
"This is a warning message
\n
This is an error message
\n
"
,
"debug"
);
_test
(
out
->
str
(),
"This is a debug message
\n
This is an info message
\n
"
,
"debug"
);
_test
(
err
->
str
(),
"This is a warning message
\n
This is an error message
\n
"
,
"debug"
);
//equivalent to: bob::core::log_level(bob::core::ERROR);
out
.
str
(
""
);
err
.
str
(
""
);
debug
->
reset
(
"null"
);
info
->
reset
(
"null"
);
warn
->
reset
(
"null"
);
out
->
str
(
""
);
err
->
str
(
""
);
debug
->
close
(
);
info
->
close
(
);
warn
->
close
(
);
debug
<<
"This is a debug message"
<<
std
::
endl
;
info
<<
"This is an info message"
<<
std
::
endl
;
warn
<<
"This is a warning message"
<<
std
::
endl
;
error
<<
"This is an error message"
<<
std
::
endl
;
_test
(
out
.
str
(),
""
,
"error"
);
_test
(
err
.
str
(),
"This is an error message
\n
"
,
"error"
);
_test
(
out
->
str
(),
""
,
"error"
);
_test
(
err
->
str
(),
"This is an error message
\n
"
,
"error"
);
//equivalent to: bob::core::log_level(bob::core::DISABLE);
out
.
str
(
""
);
err
.
str
(
""
);
error
->
reset
(
"null"
);
out
->
str
(
""
);
err
->
str
(
""
);
error
->
close
(
);
debug
<<
"This is a debug message"
<<
std
::
endl
;
info
<<
"This is an info message"
<<
std
::
endl
;
warn
<<
"This is a warning message"
<<
std
::
endl
;
error
<<
"This is an error message"
<<
std
::
endl
;
_test
(
out
.
str
(),
""
,
"disable"
);
_test
(
err
.
str
(),
""
,
"disable"
);
_test
(
out
->
str
(),
""
,
"disable"
);
_test
(
err
->
str
(),
""
,
"disable"
);
Py_RETURN_NONE
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment