fix SEGFAULTs

issue was that mutable context had no config thus trying to get stream
caused SEGFAULT

Closes #1533, #1534
This commit is contained in:
Jozef Grajciar 2019-02-08 10:41:23 +01:00
parent c03b23c84b
commit 7f229b4ff1
3 changed files with 15 additions and 10 deletions

View File

@ -12,6 +12,7 @@
#include "catch_interfaces_reporter.h"
#include "catch_interfaces_testcase.h"
#include "catch_context.h"
#include "catch_stream.h"
#include "catch_text.h"
@ -146,15 +147,16 @@ namespace Catch {
return factories.size();
}
Option<std::size_t> list( Config const& config ) {
Option<std::size_t> list( std::shared_ptr<Config> const& config ) {
Option<std::size_t> listedCount;
if( config.listTests() )
listedCount = listedCount.valueOr(0) + listTests( config );
if( config.listTestNamesOnly() )
listedCount = listedCount.valueOr(0) + listTestsNamesOnly( config );
if( config.listTags() )
listedCount = listedCount.valueOr(0) + listTags( config );
if( config.listReporters() )
getCurrentMutableContext().setConfig( config );
if( config->listTests() )
listedCount = listedCount.valueOr(0) + listTests( *config );
if( config->listTestNamesOnly() )
listedCount = listedCount.valueOr(0) + listTestsNamesOnly( *config );
if( config->listTags() )
listedCount = listedCount.valueOr(0) + listTags( *config );
if( config->listReporters() )
listedCount = listedCount.valueOr(0) + listReporters();
return listedCount;
}

View File

@ -31,7 +31,7 @@ namespace Catch {
std::size_t listReporters();
Option<std::size_t> list( Config const& config );
Option<std::size_t> list( std::shared_ptr<Config> const& config );
} // end namespace Catch

View File

@ -10,6 +10,7 @@
#include "catch_console_colour.h"
#include "catch_enforce.h"
#include "catch_list.h"
#include "catch_context.h"
#include "catch_run_context.h"
#include "catch_stream.h"
#include "catch_test_spec.h"
@ -170,6 +171,8 @@ namespace Catch {
return 1;
auto result = m_cli.parse( clara::Args( argc, argv ) );
config();
getCurrentMutableContext().setConfig( m_config );
if( !result ) {
Catch::cerr()
<< Colour( Colour::Red )
@ -262,7 +265,7 @@ namespace Catch {
applyFilenamesAsTags( *m_config );
// Handle list request
if( Option<std::size_t> listed = list( config() ) )
if( Option<std::size_t> listed = list( m_config ) )
return static_cast<int>( *listed );
auto totals = runTests( m_config );