mocking

Mock external dependencies in C tests using weak symbol wrappers.

Updated Jun 3, 2026
One-click install
npx skills add https://github.com/mgreenly/ikigai --skill mocking
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: mocking
Source: https://github.com/mgreenly/ikigai/tree/main/.claude/library/mocking
Command: npx skills add https://github.com/mgreenly/ikigai --skill mocking

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Mock external dependencies in tests.

Core Features & Use Cases

  • MOCKABLE pattern: zero-overhead wrappers for deterministic unit tests by providing weak symbol overrides in debug builds.
  • Override in tests: replace the weak symbols in your test files to simulate failures or specific behavior without changing production code.
  • Wrappers list: provides a structured set of wrappers for common POSIX and C stdlib calls to keep tests hermetic.
  • Use Case: test a module that depends on open/read/write by substituting mock implementations during CI runs.

Quick Start

Add wrapper.h and wrapper.c, replace calls with wrappers, and override weak symbols in tests to simulate failures.

Frequently Asked Questions about mocking

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I mock external dependencies in C unit tests?

To mock external dependencies in C unit tests, you introduce wrapper.h and wrapper.c files, replace direct library calls with wrappers, and override weak symbols in test files to simulate specific behaviors or failures deterministically.

What is the MOCKABLE pattern for mocking POSIX and C stdlib calls?

The MOCKABLE pattern for mocking POSIX and C stdlib calls provides zero-overhead wrappers using weak symbol overrides in debug builds, allowing test files to substitute mock implementations without modifying production code.

Can I use weak symbols to test curl, talloc, and yyjson libraries?

Yes, you can use weak symbols to test curl, talloc, and yyjson libraries by replacing direct calls with wrappers from wrapper.c and overriding them in your test files to simulate failures or specific behaviors during CI runs.

How do I simulate open, read, and write failures in hermetic C tests?

You simulate open, read, and write failures in hermetic C tests by replacing direct system calls with wrappers and overriding the weak symbols in your test files to inject mock implementations that return failure conditions.

Does mocking external dependencies with wrappers require changing production code?

Mocking external dependencies with wrappers requires replacing direct calls with wrappers in production code, but the weak symbol override mechanism ensures that test mock implementations inject behavior changes without altering the production logic itself.

What are the limitations of using weak symbols for mocking C dependencies?

A limitation of using weak symbols for mocking C dependencies is that you must replace direct calls with wrappers across your codebase, requiring modifications to existing source files to enable test overrides and deterministic behavior.