API Documentation
Objects & Functions
-
class value
The value type for all values in CWT Cucumber.
cuke::value uses type erasure to store all possible types.
Public Functions
-
inline void emplace_or_replace(const std::string &value)
Emplace or replace a value.
Constructs or replaces the value in a given cuke::value.
- Parameters:
value – The value to store
-
inline bool is_nil() const noexcept
Checks if the cuke::value is nil.
- Returns:
True if it is a nil type, else its false
-
inline std::string to_string()
Converts the underlying value to a string.
If not possible, this function throws a std::runtime_error
-
inline void emplace_or_replace(const std::string &value)
-
class table
The table which holds the data for tables / datatables.
CWT Cucumber creates a table and stores it. In a step you can create / access a table if available with CUKE_TABLE()
Public Functions
-
bool append_row(value_array &&data)
Appends a row to the datatable.
Appending a row only works if the given row is the same length as the rows in the existing table.
- Parameters:
data – Data to be appended
- Returns:
Returns true if data is appended succesfully
-
std::size_t cells_count() const noexcept
Returns the number of cells.
-
std::size_t col_count() const noexcept
Returns the number of cols.
-
const value_array &data() const noexcept
Returns a const reference to the underlying data.
-
value_array &data() noexcept
Returns a reference to the underlying data.
-
bool empty() const noexcept
Checks if the table is empty or not.
-
hash_access hashes() const
Returns a wrapper to the row iterator for hashes.
Use hashes() for range based loops, e.g.: for (const auto& row : t.hashes()) Now you can iteratoe over each row. Access the elements by their identifier. Note: Each element is a cuke::value this means you have to cast it, like row[“CELL A”].as<int>(), row[“CELL B”].as<std::string>(), …
-
row operator[](std::size_t idx) const
Access a row by index.
- Parameters:
idx – Rows index to access
- Returns:
Returns a row object.
-
raw_access raw() const
Returns a wrapper to the row iterator for raw access.
Use raw() for range based loops, e.g.: for (const auto& row : t.raw()) Now you can iteratoe over each row. Access the elements by their index. Note: Each element is a cuke::value this means you have to cast it, like row[0].as<int>(), row[0].as<std::string>(), …
-
std::size_t row_count() const noexcept
Returns the number of rows.
-
cuke::table::pair rows_hash() const
Returns a wrapper to the row iterator for hashes.
This works only for a total column count of 2. If the column count is not equal to 2 this function throws a std::runtime_error. The first column is then the key, the second is the value. cuke::table::pair is an alias for std::unordered_map<std::string, cuke::value>
-
std::vector<std::string> to_string_array() const noexcept
Converts the table to a std::vector<std::string>.
The vector represents each row as one string, with ‘|’ as delimiter
-
class hash_access
-
class raw_access
-
class row
A row object to represent a row in a table.
This holds all values of the dedicated row. Access to the values (cuke::value) with the operator[] by index. If it is created as hash row / pair an access by string literals is possible too
Public Functions
-
inline std::size_t col_count() const noexcept
Total count of columns in this table / row.
-
const cuke::value &operator[](std::size_t idx) const
Access to a cell.
- Parameters:
idx – Columns index to access
- Returns:
Returns a const reference to the cuke::value in this cell
-
const cuke::value &operator[](std::string_view key) const
Access to a cell, when the header is available with the according keys.
- Parameters:
key – Columns key to access
- Returns:
Returns a const reference to the cuke::value in this cell
-
inline std::size_t col_count() const noexcept
-
class row_iterator
-
bool append_row(value_array &&data)
-
template<typename T>
inline T &cuke::context() Creates and returns a object of the given type to the scenario context.
After a scenario all objects are destroyed in the scenario context. If the object does not exist in this context, the default constructor is called and the object created.
- Template Parameters:
T – The object to create or access
- Returns:
A reference to the object of type T
-
template<typename T, typename ...Args>
inline T &cuke::context(Args&&... args) Creates and returns a object of the given type to the scenario context.
After a scenario all objects are destroyed in the scenario context. If the object does not exist in this context, the arguments are forwarded to the dedicated constructor.
The arguments are ignored when the object is already in this context.
- Template Parameters:
T – The object to create or access
Args – Variadic template parameter to forward all arguments to the dedicated constructor
- Returns:
A reference to the object of type T
-
class cwt_cucumber
Core class for running CWT-Cucumber tests.
This class handles initialization with program arguments, parsing feature files, executing all scenarios, evaluating results, and printing output to the console.
Public Functions
-
cwt_cucumber(int argc, const char *argv[])
Constructs the Cucumber runner with command-line arguments.
- Parameters:
argc – Number of command-line arguments.
argv – Array of command-line argument strings.
-
bool export_catalog(std::size_t json_indents = 2) const noexcept
Exports a catalog of implemented steps.
- Parameters:
json_indents – Number of spaces to use for JSON indentation (default is 2).
- Returns:
trueif export succeeded, otherwisefalse.
-
results::test_status final_result() const noexcept
Returns the final test status after executing all tests.
- Returns:
results::test_statusindicating overall success or failure.
-
bool print_help() const noexcept
Prints the help message to stdout.
- Returns:
trueif help was printed, otherwisefalse.
-
void print_results() const noexcept
Prints a summary of test results to stdout.
Includes passed/failed scenarios, skipped steps, and optionally verbose output.
-
void run_tests() const noexcept
Executes all parsed tests/scenarios.
Note
Results are stored internally and can be retrieved using
final_result().
-
cwt_cucumber(int argc, const char *argv[])
-
cuke::results::test_status cuke::entry_point(int argc, const char *argv[])
Entry point to parse command-line arguments and execute all tests.
This function acts as a convenient wrapper around the
cwt_cucumberclass. It constructs the object, parses the arguments, executes the tests, and returns the final test status.- Parameters:
argc – Number of command-line arguments.
argv – Array of command-line argument strings.
- Returns:
The final test status after executing all scenarios.
-
void cuke::skip_scenario()
Sets the current scenario to be skipped.
This function sets the runtime option to skip the currently executing scenario. The scenario will not be executed, but it will appear in the test report as skipped. After applying this option, the runtime will automatically reset it.
-
void cuke::ignore_scenario()
Ignores the current scenario.
This function sets the runtime option to ignore the currently executing scenario. The scenario will not be executed and not be reported. After applying this option, the runtime will automatically reset it.
-
void cuke::fail_scenario(const std::string_view msg = "")
Sets the current scenario as failed.
This function sets the runtime option to fail the currently executing scenario. After applying this option, the runtime will automatically reset it.
- Parameters:
msg – Optional message describing the reason for failure.
-
void cuke::fail_step(const std::string_view msg = "")
Sets the current step as failed.
This function sets the runtime option to fail the currently executing step.
- Parameters:
msg – Optional message describing the reason for failure. Default is an empty string. After applying this option, the runtime will automatically reset it.
Asserts
-
template<typename T, typename U>
inline void cuke::equal(const T &lhs, const U &rhs, const std::optional<std::string> &custom_msg = std::nullopt) Compares the given values to be equal.
If not, the current step and scenario are set to Failed.
The given types must be comparable. If they are not comparable (like string and integer), the current step and the scenario are set to failed.
- Parameters:
lhs – Left hand side parameter
rhs – Right hand side parameter
custom_msg – Custom optional error message given by the developer
-
template<typename T, typename U>
inline void cuke::not_equal(const T &lhs, const U &rhs, const std::optional<std::string> &custom_msg = std::nullopt) Compares the given values not to be equal.
If not, the current step and scenario are set to Failed.
The given types must be comparable. If they are not comparable (like string and integer), the current step and the scenario are set to failed.
- Parameters:
lhs – Left hand side parameter
rhs – Right hand side parameter
custom_msg – Custom optional error message given by the developer
-
template<typename T, typename U>
inline void cuke::greater(const T &lhs, const U &rhs, const std::optional<std::string> &custom_msg = std::nullopt) Compares whether the first value (left) is greater than the second value (right).
If not, the current step and scenario are set to Failed.
The given types must be comparable. If they are not comparable (like string and integer), the current step and the scenario are set to failed.
- Parameters:
lhs – Left hand side parameter
rhs – Right hand side parameter
custom_msg – Custom optional error message given by the developer
-
template<typename T, typename U>
inline void cuke::greater_or_equal(const T &lhs, const U &rhs, const std::optional<std::string> &custom_msg = std::nullopt) Compares whether the first value (left) is greater or equal than the second value (right).
If not, the current step and scenario are set to Failed.
The given types must be comparable. If they are not comparable (like string and integer), the current step and the scenario are set to failed.
- Parameters:
lhs – Left hand side parameter
rhs – Right hand side parameter
custom_msg – Custom optional error message given by the developer
-
template<typename T, typename U>
inline void cuke::less(const T &lhs, const U &rhs, const std::optional<std::string> &custom_msg = std::nullopt) Compares whether the first value (left) is less the second value (right).
If not, the current step and scenario are set to Failed.
The given types must be comparable. If they are not comparable (like string and integer), the current step and the scenario are set to failed.
- Parameters:
lhs – Left hand side parameter
rhs – Right hand side parameter
custom_msg – Custom optional error message given by the developer
-
template<typename T, typename U>
inline void cuke::less_or_equal(const T &lhs, const U &rhs, const std::optional<std::string> &custom_msg = std::nullopt) Compares whether the first value (left) is less or equal than the second value (right).
If not, the current step and scenario are set to Failed.
The given types must be comparable. If they are not comparable (like string and integer), the current step and the scenario are set to failed.
- Parameters:
lhs – Left hand side parameter
rhs – Right hand side parameter
custom_msg – Custom optional error message given by the developer
-
inline void cuke::is_true(bool condition, const std::optional<std::string> &custom_msg = std::nullopt)
Asserts the given condition to true.
If it is false, the current step and scenario are set to Failed.
- Parameters:
condition – Bool expression to be evaluated
custom_msg – Custom optional error message given by the developer
-
inline void cuke::is_false(bool condition, const std::optional<std::string> &custom_msg = std::nullopt)
Asserts the given condition to false.
If it is true, the current step and scenario are set to Failed.
- Parameters:
condition – Bool expression to be evaluated
custom_msg – Custom optional error message given by the developer
Macros
-
STEP(function_name, definition)
-
GIVEN(function_name, definition)
An alias to STEP(name,step) to increase readability of your code.
-
WHEN(function_name, definition)
An alias to STEP(function_name, definition) to increase readability of your code.
-
THEN(function_name, definition)
An alias to STEP(function_name, definition) to increase readability of your code.
-
CUKE_ARG(index)
Access variables from a step in the step body.
CUKE_ARGstarts at index 1 on the first value from the left side.C++ auto type deduction does not work here. The underlying function is overloaded by return type.
- Parameters:
index – Variable index to access
- Returns:
The value from the index in the given step
-
CUKE_DOC_STRING()
Access a doc string in a step.
Use std::string as type here, e.g.:
std::string doc = CUKE_DOC_STRING();orstd::string_view doc = CUKE_DOC_STRING();C++ auto type deduction does not work here. It’s essentially the same as CUKE_ARG(..), with index == last.
-
CUKE_TABLE()
Access a table in a step.
Use cuke::table (or const cuke::table&) as type, e.g.
const cuke::table& my_table = CUKE_TABLE();C++ auto type deduction does not work here. It’s essentially the same as CUKE_ARG(..), with index == last.
-
CUSTOM_PARAMETER(function_name, key, pattern, description)
Creates a custom expression type to use in steps.
- Parameters:
function_name – A unique function name in order to find the callback. The function name has no technical impact.
key – The unique key for the expression. Provide this value with curly braces, e.g. ‘{my custom parameter}’
pattern – The regex pattern to match the step in the feature file with the given expression.
description – Optional description: This description is only printed as is in the steps-catalog.
-
CUKE_PARAM_ARG(index)
Access capture groups from a custom expression in its callback.
CUKE_PARAM_ARGstarts at index 1 on the first capture group from the left side.- Parameters:
index – Variable index to access
- Returns:
The value from the index in the given step
-
BEFORE(function_name)
Creates a hook which is executed before every Scenario.
- Parameters:
function_name – A unique function name, this function name has no technical impact
-
AFTER(function_name)
Creates a hook which is executed after every scenario.
- Parameters:
function_name – A unique function name, this function name has no technical impact
-
BEFORE_T(function_name, tag_expression)
Creates a hook with a tag expression, which can run before a tagged scenario.
Before running a tagged scenario, the tag expression is evaluated. If it evaluates to true, the hook is executed.
- Parameters:
function_name – A unique function name, this function name has no technical impact
tag_expression – A tag expression (bool condition), like
"@tag1 and
@tag2"
-
AFTER_T(function_name, tag_expression)
Creates a hook with a tag expression, which can run after a tagged scenario.
After running a tagged scenario, the tag expression is evaluated. If it evaluates to true, the hook is executed.
- Parameters:
function_name – A unique function name, this function name has no technical impact
tag_expression – A tag expression (bool condition), e.g.
"@tag1 and
@tag2"
-
BEFORE_STEP(function_name)
Creates a hook which is executed before every step.
- Parameters:
function_name – A unique function name, this function name has no technical impact
-
AFTER_STEP(function_name)
Creates a hook which is executed after every step.
- Parameters:
function_name – A unique function name, this function name has no technical impact
-
BEFORE_ALL(function_name)
Creates a hook which is executed before any scenario/feature.
- Parameters:
function_name – A unique function name, this function name has no technical impact
-
AFTER_ALL(function_name)
Creates a hook which is executed after the test run.
- Parameters:
function_name – A unique function name, this function name has no technical impact