Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
Catch::Session Class Reference

#include <catch_session.h>

Inheritance diagram for Catch::Session:
Collaboration diagram for Catch::Session:

Public Member Functions

 Session ()
 
 ~Session () override
 
void showHelp () const
 
void libIdentify ()
 
int applyCommandLine (int argc, char const *const *argv)
 
void useConfigData (ConfigData const &configData)
 
template<typename CharT >
int run (int argc, CharT const *const argv[])
 
int run ()
 
clara::Parser const & cli () const
 
void cli (clara::Parser const &newParser)
 
ConfigDataconfigData ()
 
Configconfig ()
 

Detailed Description

Definition at line 19 of file catch_session.h.

Constructor & Destructor Documentation

◆ Session()

Catch::Session::Session ( )

Definition at line 126 of file catch_session.cpp.

126 {
127 static bool alreadyInstantiated = false;
128 if( alreadyInstantiated ) {
129 CATCH_TRY { CATCH_INTERNAL_ERROR( "Only one instance of Catch::Session can ever be used" ); }
131 }
132
133 // There cannot be exceptions at startup in no-exception mode.
134#if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
135 const auto& exceptions = getRegistryHub().getStartupExceptionRegistry().getExceptions();
136 if ( !exceptions.empty() ) {
137 m_startupExceptions = true;
138 Colour colourGuard( Colour::Red );
139 Catch::cerr() << "Errors occurred during startup!" << '\n';
140 // iterate over all exceptions and notify user
141 for ( const auto& ex_ptr : exceptions ) {
142 try {
143 std::rethrow_exception(ex_ptr);
144 } catch ( std::exception const& ex ) {
145 Catch::cerr() << Column( ex.what() ).indent(2) << '\n';
146 }
147 }
148 }
149#endif
150
151 alreadyInstantiated = true;
152 m_cli = makeCommandLineParser( m_configData );
153 }
#define CATCH_TRY
#define CATCH_CATCH_ALL
#define CATCH_INTERNAL_ERROR(msg)
std::vector< std::exception_ptr > const & getExceptions() const noexcept
std::ostream & cerr()
IMutableRegistryHub & getMutableRegistryHub()
IRegistryHub const & getRegistryHub()
clara::Parser makeCommandLineParser(ConfigData &config)
virtual void registerStartupException() noexcept=0
virtual StartupExceptionRegistry const & getStartupExceptionRegistry() const =0
Here is the call graph for this function:

◆ ~Session()

Catch::Session::~Session ( )
override

Definition at line 154 of file catch_session.cpp.

154 {
156 }
Here is the call graph for this function:

Member Function Documentation

◆ applyCommandLine()

int Catch::Session::applyCommandLine ( int argc,
char const *const * argv )

Definition at line 172 of file catch_session.cpp.

172 {
173 if( m_startupExceptions )
174 return 1;
175
176 auto result = m_cli.parse( clara::Args( argc, argv ) );
177 if( !result ) {
178 config();
181 << Colour( Colour::Red )
182 << "\nError(s) in input:\n"
183 << Column( result.errorMessage() ).indent( 2 )
184 << "\n\n";
185 Catch::cerr() << "Run with -? for usage\n" << std::endl;
186 return MaxExitCode;
187 }
188
189 if( m_configData.showHelp )
190 showHelp();
191 if( m_configData.libIdentify )
192 libIdentify();
193 m_config.reset();
194 return 0;
195 }
void showHelp() const
char ** argv
IMutableContext & getCurrentMutableContext()
virtual void setConfig(IConfigPtr const &config)=0
auto parse(std::string const &exeName, TokenStream const &tokens) const -> InternalParseResult override
Definition clara.hpp:1185
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cli() [1/2]

clara::Parser const & Catch::Session::cli ( ) const

Definition at line 239 of file catch_session.cpp.

239 {
240 return m_cli;
241 }

◆ cli() [2/2]

void Catch::Session::cli ( clara::Parser const & newParser)

Definition at line 242 of file catch_session.cpp.

242 {
243 m_cli = newParser;
244 }

◆ config()

Config & Catch::Session::config ( )

Definition at line 248 of file catch_session.cpp.

248 {
249 if( !m_config )
250 m_config = std::make_shared<Config>( m_configData );
251 return *m_config;
252 }
Here is the caller graph for this function:

◆ configData()

ConfigData & Catch::Session::configData ( )

Definition at line 245 of file catch_session.cpp.

245 {
246 return m_configData;
247 }
Here is the caller graph for this function:

◆ libIdentify()

void Catch::Session::libIdentify ( )

Definition at line 164 of file catch_session.cpp.

164 {
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;
170 }
std::ostream & cout()
Version const & libraryVersion()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ run() [1/2]

int Catch::Session::run ( )

Definition at line 226 of file catch_session.cpp.

226 {
227 if( ( m_configData.waitForKeypress & WaitForKeypress::BeforeStart ) != 0 ) {
228 Catch::cout() << "...waiting for enter/ return before starting" << std::endl;
229 static_cast<void>(std::getchar());
230 }
231 int exitCode = runInternal();
232 if( ( m_configData.waitForKeypress & WaitForKeypress::BeforeExit ) != 0 ) {
233 Catch::cout() << "...waiting for enter/ return before exiting, with code: " << exitCode << std::endl;
234 static_cast<void>(std::getchar());
235 }
236 return exitCode;
237 }
WaitForKeypress::When waitForKeypress
Here is the call graph for this function:
Here is the caller graph for this function:

◆ run() [2/2]

template<typename CharT >
int Catch::Session::run ( int argc,
CharT const *const argv[] )
inline

Definition at line 36 of file catch_session.h.

36 {
37 if (m_startupExceptions)
38 return 1;
39 int returnCode = applyCommandLine(argc, argv);
40 if (returnCode == 0)
41 returnCode = run();
42 return returnCode;
43 }
int applyCommandLine(int argc, char const *const *argv)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ showHelp()

void Catch::Session::showHelp ( ) const

Definition at line 158 of file catch_session.cpp.

158 {
160 << "\nCatch v" << libraryVersion() << "\n"
161 << m_cli << std::endl
162 << "For more detailed usage please see the project docs\n" << std::endl;
163 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ useConfigData()

void Catch::Session::useConfigData ( ConfigData const & configData)

Definition at line 221 of file catch_session.cpp.

221 {
222 m_configData = configData;
223 m_config.reset();
224 }
ConfigData & configData()
Here is the call graph for this function:

The documentation for this class was generated from the following files: