Skip to content

deblasis/ziomock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ziomock

Test mocks for Zig. Call trackers, string spies, return mocks, error mocks — zero dependencies.

The pitch

Lightweight test doubles for Zig. Track function calls, spy on string arguments, mock return values and errors.

const ziomock = @import("ziomock");

// Track how many times something was called
var tracker: ziomock.CallTracker(10) = .{};
tracker.record();
tracker.record();
try std.testing.expect(tracker.wasCalledN(2));

// Spy on string arguments
var spy: ziomock.StringSpy(10) = .{};
spy.record("hello");
try std.testing.expect(spy.wasCalledWith("hello"));

// Mock a return value
var mock = ziomock.ReturnMock(u32).init(42);
const val = mock.call(); // 42

// Mock errors: fail N times then succeed
var err_mock = ziomock.ErrorMock(u32).init(2, 99);
const result = err_mock.call(); // error.MockError
const result2 = err_mock.call(); // error.MockError
const ok = try err_mock.call();  // 99

Install

zig fetch --save git+https://github.com/deblasis/ziomock

Then in your build.zig:

const dep = b.dependency("ziomock", .{
    .target = target,
    .optimize = optimize,
});
exe.root_module.addImport("ziomock", dep.module("ziomock"));

Requires Zig 0.16.

API

  • CallTracker(max).record() / .callCount() / .wasCalledN(n)
  • StringSpy(max).record(s) / .wasCalledWith(s)
  • ReturnMock(T).init(value) / .call()
  • ErrorMock(T).init(fail_count, value) — fail N times then succeed

Compatibility

  • Zig: 0.16.0
  • Platforms: Linux, macOS, Windows
  • Breaking changes: follows Semantic Versioning. Minor versions add features, patch versions fix bugs.

License

MIT. Copyright (c) 2026 Alessandro De Blasis.

About

Test mocks for Zig. Call trackers, string spies, return mocks, error mocks — zero dependencies.

Topics

Resources

Contributing

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

  •  

Packages

 
 
 

Contributors

Languages