forked from Snaipe/Criterion
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'features/new-logging' into bleeding
- Loading branch information
Showing
23 changed files
with
431 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ Criterion | |
starter | ||
assert | ||
hooks | ||
logging | ||
env | ||
output | ||
parameterized | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
Logging messages | ||
================ | ||
|
||
Sometimes, it might be useful to print some output from within a test | ||
or fixture -- and while this can be done trivially with a ``printf``, | ||
it doesn't integrate well with the current output, nor does it work | ||
*at all* when the process is testing a redirected stdout. | ||
|
||
For these cases, Criterion exposes a logging facility: | ||
|
||
.. code-block:: c | ||
#include <criterion/criterion.h> | ||
#include <criterion/logging.h> | ||
Test(suite_name, test_name) { | ||
cr_log_info("This is an informational message. They are not displayed " | ||
"by default."); | ||
cr_log_warn("This is a warning. They indicate some possible malfunction " | ||
"or misconfiguration in the test."); | ||
cr_log_error("This is an error. They indicate serious problems and " | ||
"are usually shown before the test is aborted."); | ||
} | ||
``cr_log_info``, ``cr_log_warn`` and ``cr_log_error`` are all macros expanding | ||
to a call to the ``cr_log`` function. All of them take a mandatory format string, | ||
followed by optional parameters; for instance: | ||
|
||
.. code-block:: c | ||
cr_log_info("%d + %d = %d", 1, 2, 3); | ||
If using C++, the output stream objects ``info``, ``warn`` and ``error`` are | ||
defined within the ``criterion::logging`` namespace, and can be used in | ||
conjunction with ``operator<<``: | ||
|
||
.. code-block:: c++ | ||
|
||
#include <criterion/criterion.h> | ||
#include <criterion/logging.h> | ||
|
||
using criterion::logging::info; | ||
using criterion::logging::warn; | ||
using criterion::logging::error; | ||
|
||
Test(suite_name, test_name) { | ||
info << "This is an informational message. " | ||
<< "They are not displayed by default." | ||
<< std::flush; | ||
warn << "This is a warning. " | ||
<< "They indicate some possible malfunction " | ||
<< "or misconfiguration in the test." | ||
<< std::flush; | ||
error << "This is an error. " | ||
<< "They indicate serious problems and " | ||
<< "are usually shown before the test is aborted." | ||
<< std::flush; | ||
} | ||
|
||
Note that empty messages are ignored, and newlines in the log message splits | ||
the passed string into as many messages are there are lines. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright © 2015-2016 Franklin "Snaipe" Mathieu <http://snai.pe/> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
#ifndef CRITERION_INTERNAL_DEPRECATION_H_ | ||
# define CRITERION_INTERNAL_DEPRECATION_H_ | ||
|
||
# define CR_DEPRECATED(Msg) CR_DEPRECATED_(message (Msg)) | ||
|
||
# ifdef _MSC_VER | ||
# define CR_DEPRECATED_(Msg) __pragma(Msg) | ||
# else | ||
# define CR_DEPRECATED_(Msg) _Pragma(#Msg) | ||
# endif | ||
|
||
#endif /* !CRITERION_INTERNAL_DEPRECATION_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include <criterion/criterion.h> | ||
#include <criterion/logging.h> | ||
|
||
Test(logging, simple) { | ||
cr_log_info("This is an informational message. They are not displayed " | ||
"by default."); | ||
cr_log_warn("This is a warning. They indicate some possible malfunction " | ||
"or misconfiguration in the test."); | ||
cr_log_error("This is an error. They indicate serious problems and " | ||
"are usually shown before the test is aborted."); | ||
} | ||
|
||
Test(logging, format) { | ||
cr_log_info("Log messages are %s.", "printf-formatted strings"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include <criterion/criterion.h> | ||
#include <criterion/logging.h> | ||
|
||
using criterion::logging::info; | ||
using criterion::logging::warn; | ||
using criterion::logging::error; | ||
|
||
Test(logging, stream) { | ||
info << "This is an informational message. They are not displayed " | ||
"by default." | ||
<< std::endl; | ||
warn << "This is a warning. They indicate some possible malfunction " | ||
"or misconfiguration in the test." | ||
<< std::endl; | ||
error << "This is an error. They indicate serious problems and " | ||
"are usually shown before the test is aborted." | ||
<< std::endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.