-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move default TestListener creation and add tests for it
- Loading branch information
Showing
6 changed files
with
96 additions
and
13 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
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,21 @@ | ||
#include "DefaultTestListener.h" | ||
|
||
#include "LogTestListener.h" | ||
|
||
namespace rc { | ||
namespace detail { | ||
|
||
std::unique_ptr<TestListener> | ||
makeDefaultTestListener(const Configuration &config, std::ostream &os) { | ||
return std::unique_ptr<TestListener>( | ||
new LogTestListener(os, config.verboseProgress, config.verboseShrinking)); | ||
} | ||
|
||
TestListener &globalTestListener() { | ||
static const auto listener = | ||
makeDefaultTestListener(configuration(), std::cerr); | ||
return *listener; | ||
} | ||
|
||
} // namespace detail | ||
} // namespace rc |
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,22 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
|
||
#include "rapidcheck/detail/TestListener.h" | ||
#include "rapidcheck/detail/Configuration.h" | ||
|
||
namespace rc { | ||
namespace detail { | ||
|
||
/// Creates a default `TestListener`. | ||
/// | ||
/// @param config The configuration describing the listener. | ||
/// @param os The output stream to print information to. | ||
std::unique_ptr<TestListener> | ||
makeDefaultTestListener(const Configuration &config, std::ostream &os); | ||
|
||
/// Returns the global default `TestListener`. | ||
TestListener &globalTestListener(); | ||
|
||
} // namespace detail | ||
} // namespace rc |
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,49 @@ | ||
#include <catch.hpp> | ||
|
||
#include "detail/DefaultTestListener.h" | ||
|
||
using namespace rc; | ||
using namespace rc::detail; | ||
|
||
TEST_CASE("makeDefaultTestListener") { | ||
std::ostringstream os; | ||
|
||
SECTION( | ||
"should not print anything on test case finished if verboseProgress == " | ||
"false") { | ||
Configuration config; | ||
config.verboseProgress = false; | ||
const auto listener = makeDefaultTestListener(config, os); | ||
listener->onTestCaseFinished(CaseDescription()); | ||
REQUIRE(os.str().empty()); | ||
} | ||
|
||
SECTION("should print . on test case success if verboseProgress == true") { | ||
Configuration config; | ||
config.verboseProgress = true; | ||
const auto listener = makeDefaultTestListener(config, os); | ||
CaseDescription desc; | ||
desc.result = CaseResult(CaseResult::Type::Success); | ||
listener->onTestCaseFinished(desc); | ||
REQUIRE(os.str() == "."); | ||
} | ||
|
||
SECTION( | ||
"should not print anything on shrink tried if verboseShrinking == false") { | ||
Configuration config; | ||
config.verboseShrinking = false; | ||
const auto listener = makeDefaultTestListener(config, os); | ||
listener->onShrinkTried(CaseDescription(), false); | ||
REQUIRE(os.str().empty()); | ||
} | ||
|
||
SECTION("should print . on unaccepted shrink if verboseShrinking == true") { | ||
Configuration config; | ||
config.verboseShrinking = true; | ||
const auto listener = makeDefaultTestListener(config, os); | ||
CaseDescription desc; | ||
desc.result = CaseResult(CaseResult::Type::Success); | ||
listener->onShrinkTried(desc, false); | ||
REQUIRE(os.str() == "."); | ||
} | ||
} |