tts v2.3.0
The Tiny Test System
 
Loading...
Searching...
No Matches
tts::options Struct Reference

Command line arguments lightweight processor. More...

#include <tts/tools/option.hpp>

Detailed Description

Command line arguments lightweight processor.

See also
arguments

Example

#define TTS_MAIN
#include <tts/tts.hpp>
TTS_CASE( "CLI test - flag" )
{
// Will fail if the test is not called via
// ./mytest.exe --pass--the-test or ./mytest.exe -W
TTS_EXPECT( (tts::arguments()[{"--pass--the-test","-W"}]) );
// Will fail if the test is not called via
// ./mytest.exe --at_last
TTS_EXPECT( tts::arguments()["--at_last"] );
};
TTS_CASE( "CLI test - setting" )
{
// Will fail if the test is not called via ./mytest.exe --xxx=13.37
TTS_EQUAL( tts::arguments().value("--xxx", 0.), 13.37);
// Will fail if the test is not called via ./mytest.exe --www=9 or ./mytest.exe -zzz=9
TTS_EQUAL( (tts::arguments().value({"--www","-zzz"}, 0)), 9);
};
#define TTS_EXPECT(EXPR,...)
Check if a given expression evaluates to true.
Definition: basic.hpp:46
#define TTS_CASE(ID)
Introduces a new test scenario and registers it into the current test driver.
Definition: case.hpp:147
inline ::tts::options const & arguments()
Retrieve the current list of command line argument.
Definition: option.hpp:158
#define TTS_EQUAL(LHS, RHS,...)
Performs equality comparison between two expressions.
Definition: relation.hpp:90

Public Member Functions

bool is_valid ()
 Checks if current options set is not empty.
 
bool operator[] (const char *f) const
 Checks if the flag f is set on the command line.
 
bool operator[] (params_t fs) const
 Checks if any flag from with the strings fs is set on the command line.
 
template<typename T >
value (const char *f, T that={}) const
 Returns a value of type T if a flag matches the string f or that otherwise.
 
template<typename T >
value (params_t fs, T that={}) const
 Returns a value of type T if a flag matches any of the strings in fs or that otherwise.