YAML reference

Complete schema for mockware template files.

Top-level structure

headers:              # required โ€” map of header path โ†’ header config
  "path/to/header.h":   # key is the include path, determines output location
    language: c           # "c" (default) or "cpp"
    includes: []          # quoted includes: #include "file.h"
    system_includes: []   # angle includes: #include <file.h>
    macros: {}            # #define entries
    types: {}             # typedef entries
    enums: {}             # enum definitions
    functions: {}         # C function declarations
    namespaces: {}        # C++ namespaces (classes + functions)

Macros

Two forms: simple value and function-like (variadic).

macros:
  # Simple #define NAME value
  ESP_OK: "0"
  GPIO_OUT: "1"

  # Function-like #define NAME(...) body
  ESP_LOGI:
    kind: variadic
    body: "((void)0)"

  # Function-like with fixed params: #define NAME(x) body
  pdMS_TO_TICKS:
    kind: variadic
    body: "((x) / portTICK_PERIOD_MS)"

Types

Two forms: simple typedef and full definition.

types:
  # Simple: typedef int esp_err_t;
  esp_err_t: int

  # Complex: raw definition string
  wifi_init_config_t:
    definition: |
      typedef struct {
          int magic;
      } wifi_init_config_t;

  gpio_config_t:
    definition: "typedef struct { int pin; int mode; } gpio_config_t;"

Enums

enums:
  wifi_mode_t:
    values:
      WIFI_MODE_NULL: 0
      WIFI_MODE_STA: 1
      WIFI_MODE_AP: 2

  # Generates:
  # typedef enum {
  #     WIFI_MODE_NULL = 0,
  #     WIFI_MODE_STA = 1,
  #     WIFI_MODE_AP = 2,
  # } wifi_mode_t;

Functions (C)

FieldRequiredDescription
returnNoReturn type (default: void)
paramsNoList of typed params (default: empty)
bodyNoCustom implementation (default: auto-generated based on return type)
functions:
  gpio_set_level:
    return: esp_err_t
    params: ["int pin", "int level"]
    body: "return ESP_OK;"     # custom body

  gpio_get_level:
    return: int
    params: ["int pin"]          # no body โ†’ auto-generated: "return 0;"

  nvs_flash_init:
    return: esp_err_t
    params: []                  # auto: "return 0;"

Auto-generated body rules

Return typeGenerated body
void(empty)
boolreturn false;
int, numeric typesreturn 0;
Pointer types (*)return NULL;
struct ...return (type){0};
enum ...return 0;
Anything elsereturn 0;

Generated C code pattern

Each function foo generates three things:

// 1. Default implementation (static)
static int foo_default(int x) {
    return 0;
}

// 2. Overridable function pointer (extern in mockware/fakes.h)
int (*foo_mock)(int x) = foo_default;

// 3. Public dispatcher
int foo(int x) {
    return foo_mock(x);
}

C++ namespaces

namespaces:
  drivers:
    # Free functions inside namespace
    functions:
      sensor_isr_handler:
        return: void
        params: ["int irq", "void (*callback)(void*)"]

    # Enums inside namespace
    enums:
      sensor_mode_t:
        values:
          SENSOR_MODE_SLEEP: 0
          SENSOR_MODE_ACTIVE: 1

    # Classes inside namespace
    classes:
      TemperatureSensor:
        constructors: []
        destructor: ~
        methods: {}
        static_methods: {}
        member_variables: {}

Classes

FieldDescription
constructorsList of constructor configs: {params: [], body: "", init_list: []}
destructorDestructor body (~ = default, "" = default, omit = default)
methodsVirtual methods with return, params, body, const
static_methodsStatic class methods
member_variablesMap of name โ†’ type (with optional default: "bool = false")
classes:
  BLEDevice:
    constructors:
      - params: []
      - params: ["const char* name"]
        body: "this->name_ = name;"
    destructor: ~
    methods:
      init:
        return: bool
        params: ["const char* device_name"]
        body: "return true;"
      start_advertising:
        return: bool
        params: []
        # no body โ†’ auto: "return false;"
      is_connected:
        return: bool
        params: []
        is_const: true              # โ†’ bool is_connected() const
    static_methods:
      get_instance:
        return: "nimble::BLEDevice*"
        params: []
    member_variables:
      initialized_: "bool = false"   # default value in constructor init list
      device_name_: "std::string"

Generated C++ class pattern

// Header: include/device/sensor.hpp
namespace drivers {

class TemperatureSensor {
public:
    TemperatureSensor() : last_value_(0.0f) {}
    TemperatureSensor(int pin) : pin_(pin), last_value_(0.0f) {}
    virtual ~TemperatureSensor() = default;

    virtual float read() { return 25.0f; }
    virtual sensor_err_t calibrate() { return 0; }
    static float get_reference_voltage() { return 3.3f; }

protected:
    int pin_;
    float last_value_;
};

void sensor_isr_handler(int irq, void (*callback)(void*));

}  // namespace drivers

Test usage (virtual override)

// In your test file:
struct MockSensor : public drivers::TemperatureSensor {
    float read() override { return 42.0f; }
    sensor_err_t calibrate() override {
        calibrate_called_ = true;
        return 0;
    }
    bool calibrate_called_ = false;
};

TEST_CASE("mock sensor") {
    MockSensor sensor;
    REQUIRE(sensor.read() == 42.0f);

    sensor.calibrate();
    REQUIRE(sensor.calibrate_called_);
}

Includes

includes:             # Quoted includes: #include "file.h"
  - "esp_err.h"
  - "esp_event.h"

system_includes:      # Angle includes: #include <file.h>
  - <stdint.h>
  - <cstdint>

Complete C example

# mock_template.yml
headers:
  "esp_err.h":
    macros:
      ESP_OK: "0"
    types:
      esp_err_t: int

  "driver/gpio.h":
    language: c
    includes: ["esp_err.h"]
    macros:
      GPIO_OUT: "1"
    enums:
      gpio_mode_t:
        values:
          GPIO_MODE_OUTPUT: 0
          GPIO_MODE_INPUT: 1
    types:
      gpio_config_t:
        definition: "typedef struct { int pin; int mode; } gpio_config_t;"
    functions:
      gpio_set_level:
        return: esp_err_t
        params: ["int pin", "int level"]

  "esp_timer.h":
    includes: ["esp_err.h"]
    types:
      esp_timer_handle_t: void*
    functions:
      esp_timer_get_time:
        return: int64_t
        params: []

  "nvs_flash.h":
    includes: ["esp_err.h"]
    functions:
      nvs_flash_init:
        return: esp_err_t
        params: []
      nvs_flash_erase:
        return: esp_err_t
        params: []

Complete C++ example

# cpp_template.yml
headers:
  "drivers/sensor.hpp":
    language: cpp
    includes: ["<cstdint>"]
    types:
      sensor_err_t: int
    enums:
      sensor_mode_t:
        values:
          SLEEP: 0
          ACTIVE: 1
    namespaces:
      drivers:
        classes:
          TemperatureSensor:
            constructors:
              - params: ["int pin"]
            methods:
              read:
                return: float
                params: []
              calibrate:
                return: sensor_err_t
                params: []
            static_methods:
              get_ref:
                return: float
                params: []
            member_variables:
              pin_: int
              last_val_: "float = 0.0f"
        functions:
          isr_handler:
            return: void
            params: ["int irq"]