MockaccinoGenerate C++ GoogleMock mocks and stubs from C source/header files — one command, no boilerplate. Writing unit tests for C code means faking its dependencies, and hand-writing a gmock wrapper for every function in a header is slow, repetitive work. Mockaccino does it for you: point it at a It's built for the people who feel that pain most: testing embedded, firmware, or legacy C with a C++/GoogleTest harness, where the dependency you want to fake is a header full of plain C functions. Why MockaccinoThere are three ways to turn C into mocks, and Mockaccino ships all of them, switchable per command:
The regex backend is the original superpower: it parses with regular expressions, not a real compiler, so it generates a usable mock without resolving includes, building the project, or understanding your custom type modifiers. That's exactly the situation embedded/legacy C testing puts you in — and where compiler-based tools tend to choke. The clang backend covers the other half: when your header is clean and compilable, it asks a real The AI parser backend asks a language model to do the extraction wherever the regex backend would use a regular expression — so it shares the regex backend's tolerance for non-compiling input but can read signatures regex heuristics miss. The model comes from whatever's available (Copilot via Quick start
What it generatesMock (
|
| Setting | Description |
|---|---|
outputPath |
Where to write generated files. Supports ${workspaceFolder}. Empty → next to the input file. |
ignoredFunctionNames |
Comma-separated function names to skip (e.g. main). |
skipStaticFunctions |
Skip static functions. |
skipExternFunctions |
Skip extern functions. |
skipFunctionsWithImplicitReturnType |
Skip functions with an implicit (int) return — these are often function-like macros. |
disableDoubleMocking |
Don't mock files that already contain _mock / _stub in their name. |
copyright |
Copyright notice inserted into generated files ($YEAR is expanded). |
mockSourceExtension |
Extension for the generated C-wrapper source files (_mock / _stub): cc (default) or cpp. |
mockHeaderExtension |
Extension for the generated mock header (_mock): h (default) or hpp. The include guard and the #include in the generated _mock source follow it. |
C++ class mocks
| Setting | Description |
|---|---|
cpp.enabled |
Also generate gmock mock classes for C++ interfaces in the file (into the same _mock.h, default on). |
cpp.onlyVirtualOrInterfaceClasses |
Only mock interface-like classes — abstract, or name-matched via cpp.interfaceNamePatterns (default on). Off → mock any class with an overridable virtual method. |
cpp.interfaceNamePatterns |
Case-insensitive name substrings that also select a class for mocking (e.g. interface). Empty by default — only abstract classes are mocked. |
cpp.flattenNamespaces |
Layout of namespaced mock classes. On (default): one flat global class encoding the scope (class app_Outer_Inner_Mock : public app::Outer::Inner). Off: mirror the source namespaces (namespace app { class Outer_Inner_Mock : public Outer::Inner {…}; }). |
Regex backend
| Setting | Description |
|---|---|
additionalPreprocessorDirectives |
Macro definitions prepended before parsing — teach Mockaccino your vendor modifiers (FUNC, P2VAR, …) so they resolve to plain types. |
treatLonelyPreprocIfAsActive |
Treat a lone #if … #endif as active, so conditionally-compiled functions still get mocked. |
Clang backend
| Setting | Description |
|---|---|
clangPath |
Path to the clang executable. Empty → use clang on PATH. |
includeDirectories |
-I project include dirs. Supports ${workspaceFolder}. |
clangSystemHeaderPaths |
-isystem system header dirs (a custom libc/SDK). Leave empty to use clang's own headers. |
clangExtraArgs |
Extra clang arguments passed verbatim (-nostdinc, -resource-dir=…, -target=…, -std=c11). |
The clang backend also reads include paths from the C/C++ extension's configuration (
C_Cpp.default.includePathand.vscode/c_cpp_properties.json). When a header exists in more than one include directory, clang uses the first match in-Iorder — Mockaccino lists yourincludeDirectoriesfirst, so they win.
AI parser backend
| Setting | Description |
|---|---|
ai.inputMode |
What the model sees: fullFile (the whole source, model resolves context), declarations (default — only the candidate declaration strings the regex preprocessor extracts; cheaper), or declarationsWithContext (those declarations to extract, plus the whole file as read-only type context). |
ai.preferredModelSource |
Preferred model: sampling (the calling MCP client's model — Copilot supports it, Claude Code doesn't), vscodeLm (the editor's model, e.g. Copilot), or claudeCli (shells out to the claude CLI). Falls back to the other available sources on failure; the source actually used is reported. |
ai.enableClaudeCli |
Allow the claudeCli model source (off by default). |
ai.claudePath |
Path to the claude CLI for the claudeCli source. Empty → use claude on PATH. |
ai.claudeArgs |
Extra arguments passed to the claude CLI (e.g. --model). The prompt is always sent on stdin with -p. |
MCP server
| Setting | Description |
|---|---|
mcp.enabled |
Run the Mockaccino MCP server so AI clients can generate mocks/stubs (default on). |
mcp.port |
Localhost TCP port for the server. 0 picks a free port each start; set a fixed port if you wire it into Claude Code via .mcp.json so the URL stays stable across restarts. |
mcp.enableClangBackend |
Allow MCP clients to use the clang backend (off by default; regex is always available over MCP). |
mcp.enableAiBackend |
Allow MCP clients to use the AI backend (off by default; regex is always available over MCP). |
MCP server
Mockaccino runs an in-process MCP server (in the extension host) that exposes the same mock/stub generation to AI clients, with two tools mirroring the palette (generate_mock / generate_stub). Each tool takes a backend (regex / clang / ai), an optional file path (defaults to the active editor), and an optional outputDir. After generating, the result reports the written file paths, the effective and configured output directories, and the comment-stripped key content of each file, so the model can act on it without a second round-trip. Regex is always available; clang and ai are gated by mcp.enableClangBackend / mcp.enableAiBackend.
- Copilot (agent mode) discovers the contributed server automatically — no setup.
- Claude Code does not auto-discover VS Code-contributed servers. Run Mockaccino: add MCP server to Claude Code (.mcp.json) to write the server entry (pointing at the in-extension HTTP endpoint) into your project's
.mcp.json. Pinmcp.portso the URL stays stable. The server is only reachable while VS Code is open.
How parsing works
- Regex backend — the file's preprocessor directives (and any you add in settings) are evaluated, comments and function bodies are stripped, and the remaining function declarations are matched with regular expressions. No include is read and no AST is built, so it needs no knowledge of your type names and tolerates unusual C dialects. The trade-off: very unusual declarators may need a helper macro definition (or the clang backend).
- Clang backend — the source is handed to
clang -ast-dump=json(fed on stdin, so unsaved edits and#include "sibling.h"both work). Mockaccino reads the resulting AST and mocks only the functions declared in the opened file — includes are parsed for type resolution but not mocked. - AI parser backend — wherever the regex backend would match a declaration with a regular expression, this asks a language model to return the structured function list instead (the same shape the other backends produce), then renders through the identical template path. It shares the regex backend's tolerance for non-compiling input;
ai.inputModecontrols whether the model sees the whole file or just the extracted candidate declarations. The C++ class path uses the same heuristic extractor as the regex backend.
clang's diagnostics (and any generation errors) are logged to a “Mockaccino” tab in the Terminal panel and to the matching Output channel (View → Output → Mockaccino). If clang reports errors, you'll get a warning that the generated mock may be incomplete and the log is brought into view with the details.
Requirements
- Regex backend: none.
- Clang backend: a
clangexecutable onPATHor set viamockaccino.clangPath. - AI parser backend: a reachable language model — Copilot (or another
vscode.lmprovider), an MCP client that supports sampling, or theclaudeCLI (enablemockaccino.ai.enableClaudeCli).
Scope & limitations
- Mockaccino mocks free C functions (C-linkage symbols) and, in the same run, C++ interface classes (gmock mock classes, both written into the single
_mock.h). The C++ class path covers namespaces, nested classes, andconst/noexcept/overridemethods; templated classes, operator overloads, and ref-qualified methods are skipped (MVP). - The regex backend is heuristic by design: most signatures are handled, but exotic declarators (e.g. function-pointer parameters) may need a configured macro, the AI parser, or the clang backend. The clang backend parses C++ classes from a real AST for exact resolution.
- The clang backend needs the file — and the includes its signatures depend on — to parse.
- The AI parser backend needs a reachable model and is non-deterministic; its output quality depends on the model. The C++ class path reuses the regex heuristic extractor.
Links
- Marketplace: https://marketplace.visualstudio.com/items?itemName=SelerLabs.mockaccino
- GitHub: https://github.com/Veenkar/mockaccino
- Contact: veenkar@gmail.com
License
Licensed under the GNU GPL v3.