32 const int MaxExitCode = 255;
36 CATCH_ENFORCE(reporter,
"No reporter registered with name: '" << reporterName <<
"'");
43 return createReporter(
config->getReporterName(),
config);
51 auto ret = std::unique_ptr<IStreamingReporter>(
new ListeningReporter);
52 auto&
multi =
static_cast<ListeningReporter&
>(*ret);
54 for (
auto const& listener : listeners) {
63 auto reporter = makeReporter(
config);
71 TestSpec testSpec =
config->testSpec();
74 for (
auto const& testCase : allTestCases) {
75 bool matching = (!testSpec.hasFilters() && !testCase.isHidden()) ||
78 if (!
context.aborting() && matching)
79 totals +=
context.runTest(testCase);
81 context.reporter().skipTest(testCase);
84 if (
config->warnAboutNoTests() && totals.testCases.total() == 0) {
85 ReusableStringStream testConfig;
88 for (
const auto& input :
config->getTestsOrTags()) {
89 if (!first) { testConfig <<
' '; }
94 context.reporter().noMatchingTestCases(testConfig.str());
104 for (
auto& testCase : tests) {
105 auto tags = testCase.tags;
107 std::string filename = testCase.lineInfo.file;
108 auto lastSlash = filename.find_last_of(
"\\/");
109 if (lastSlash != std::string::npos) {
110 filename.erase(0, lastSlash);
114 auto lastDot = filename.find_last_of(
'.');
115 if (lastDot != std::string::npos) {
116 filename.erase(lastDot);
119 tags.push_back(std::move(filename));
127 static bool alreadyInstantiated =
false;
128 if( alreadyInstantiated ) {
134#if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
136 if ( !exceptions.empty() ) {
137 m_startupExceptions =
true;
139 Catch::cerr() <<
"Errors occurred during startup!" <<
'\n';
141 for (
const auto& ex_ptr : exceptions ) {
143 std::rethrow_exception(ex_ptr);
144 }
catch ( std::exception
const& ex ) {
151 alreadyInstantiated =
true;
161 << m_cli << std::endl
162 <<
"For more detailed usage please see the project docs\n" << std::endl;
166 << std::left << std::setw(16) <<
"description: " <<
"A Catch test executable\n"
167 << std::left << std::setw(16) <<
"category: " <<
"testframework\n"
168 << std::left << std::setw(16) <<
"framework: " <<
"Catch Test\n"
169 << std::left << std::setw(16) <<
"version: " <<
libraryVersion() << std::endl;
173 if( m_startupExceptions )
182 <<
"\nError(s) in input:\n"
185 Catch::cerr() <<
"Run with -? for usage\n" << std::endl;
197#if defined(CATCH_CONFIG_WCHAR) && defined(WIN32) && defined(UNICODE)
200 char **utf8Argv =
new char *[ argc ];
202 for (
int i = 0; i < argc; ++i ) {
203 int bufSize = WideCharToMultiByte( CP_UTF8, 0,
argv[i], -1, NULL, 0, NULL, NULL );
205 utf8Argv[ i ] =
new char[ bufSize ];
207 WideCharToMultiByte( CP_UTF8, 0,
argv[i], -1, utf8Argv[i], bufSize, NULL, NULL );
212 for (
int i = 0; i < argc; ++i )
213 delete [] utf8Argv[ i ];
228 Catch::cout() <<
"...waiting for enter/ return before starting" << std::endl;
229 static_cast<void>(std::getchar());
231 int exitCode = runInternal();
233 Catch::cout() <<
"...waiting for enter/ return before exiting, with code: " << exitCode << std::endl;
234 static_cast<void>(std::getchar());
250 m_config = std::make_shared<Config>( m_configData );
254 int Session::runInternal() {
255 if( m_startupExceptions )
268 applyFilenamesAsTags( *m_config );
271 if( Option<std::size_t> listed =
list( m_config ) )
272 return static_cast<int>( *listed );
274 auto totals = runTests( m_config );
278 return (std::min) (MaxExitCode, (std::max) (totals.error,
static_cast<int>(totals.assertions.failed)));
280#if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
281 catch( std::exception& ex ) {
#define CATCH_INTERNAL_ERROR(msg)
#define CATCH_ENFORCE(condition, msg)
clara::Parser const & cli() const
void useConfigData(ConfigData const &configData)
ConfigData & configData()
int applyCommandLine(int argc, char const *const *argv)
std::vector< std::exception_ptr > const & getExceptions() const noexcept
auto indent(size_t newIndent) -> Column &
void seedRng(IConfig const &config)
void setTags(TestCaseInfo &testCaseInfo, std::vector< std::string > tags)
std::unique_ptr< IStreamingReporter > IStreamingReporterPtr
Version const & libraryVersion()
IMutableRegistryHub & getMutableRegistryHub()
IRegistryHub const & getRegistryHub()
IMutableContext & getCurrentMutableContext()
Option< std::size_t > list(std::shared_ptr< Config > const &config)
std::shared_ptr< IConfig const > IConfigPtr
std::vector< TestCase > const & getAllTestCasesSorted(IConfig const &config)
bool matchTest(TestCase const &testCase, TestSpec const &testSpec, IConfig const &config)
clara::Parser makeCommandLineParser(ConfigData &config)
sysio::client::http::http_context context
void multi(const bn::CurveParam &cp)
WaitForKeypress::When waitForKeypress
virtual void setConfig(IConfigPtr const &config)=0
virtual void registerStartupException() noexcept=0
virtual StartupExceptionRegistry const & getStartupExceptionRegistry() const =0
virtual IReporterRegistry const & getReporterRegistry() const =0
virtual Listeners const & getListeners() const =0
virtual IStreamingReporterPtr create(std::string const &name, IConfigPtr const &config) const =0
auto parse(std::string const &exeName, TokenStream const &tokens) const -> InternalParseResult override