API Documentation

cuke::value

class value

The value type for all values in CWT Cucumber.

cuke::value uses type erasure to store all possible types.

Public Functions

template<typename T, std::enable_if_t<std::is_same_v<T, std::size_t>, bool> = true>
inline T as() const

Retrieve a const reference to the underlying value.

This function returns a const reference to the underlying value. It casts to the given template parameter T. If this results in a bad cast, this function throws a std::runtime_error. Note: It creates a copy for std::size_t

Template Parameters:

T – Return type / target type

Returns:

Constant reference to the underlying value

template<typename T, std::enable_if_t<!std::is_same_v<T, std::size_t>, bool> = true>
inline const T &as() const

Retrieve a const reference to the underlying value.

This function returns a const reference to the underlying value. It casts to the given template parameter T. If this results in a bad cast, this function throws a std::runtime_error. Note: It creates a copy for std::size_t

Template Parameters:

T – Return type / target type

Returns:

Constant reference to the underlying value

template<typename T>
inline T copy_as() const

Retrieve a copy of the underlying value.

This function returns a copye of the underlying value. It casts to the given template parameter T. If this results in a bad cast, this function throws a std::runtime_error.

Template Parameters:

T – Return type / target type

Returns:

Copy of the underlying value

template<typename T>
inline void emplace_or_replace(T &&value)

Emplace or replace a value.

Constructs or replaces the value in a given cuke::value.

Parameters:

value – The value to store

inline value_type type() const noexcept

Type info for the underlying value.

Returns:

Returns cuke::value_type of the underlying value

inline std::string to_string() const

Converts the underlying value to a string. If not possible, this function throws a std::runtime_error.

cuke::table

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

std::size_t row_count() const noexcept

Returns the number of rows.

std::size_t col_count() const noexcept

Returns the number of cols.

std::size_t cells_count() const noexcept

Returns the number of cells.

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>(), …

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>(), …

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>

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

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

Total count of columns in this table / row.

class row_iterator

cuke::context

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

CUKE_ARG

CUKE_ARG(index)

Access variables from a step in the step body. CUKE_ARG starts 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

Hooks

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_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

Tagged Hooks

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"

Asserts

template<typename T, typename U>
inline void cuke::equal(const T &lhs, const U &rhs)

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

template<typename T, typename U>
inline void cuke::not_equal(const T &lhs, const U &rhs)

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

template<typename T, typename U>
inline void cuke::greater(const T &lhs, const U &rhs)

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

template<typename T, typename U>
inline void cuke::greater_or_equal(const T &lhs, const U &rhs)

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

template<typename T, typename U>
inline void cuke::less(const T &lhs, const U &rhs)

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

template<typename T, typename U>
inline void cuke::less_or_equal(const T &lhs, const U &rhs)

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

inline void cuke::is_true(bool condition)

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

inline void cuke::is_false(bool condition)

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