Skip to content

Add with_captured_parameter for mock argument capture - #107

Open
thetic wants to merge 4 commits into
mainfrom
captured-parameters
Open

thetic wants to merge 4 commits into
mainfrom
captured-parameters

Conversation

@thetic

@thetic thetic commented Sep 10, 2026 •

Copy link
Copy Markdown
Owner

Description

Adds with_captured_parameter / with_captured_parameter_of_type to the mock framework -- the mirror-image of with_output_parameter, letting a test capture a value the code under test passes into a mocked call and inspect it after the call (an argument-captor, like Mockito's ArgumentCaptor or gmock's SaveArg). This fills a gap with_parameter_of_type() can't: that method requires an exact match during the call, which doesn't work when the value can't be predicted ahead of time (a generated id, a timestamp, a struct the SUT populates).

This reimplements the idea proposed in upstream CppUTest PR #785. That PR's diff isn't portable as-is:

  • It infers copy direction from which of two pointers is non-null rather than tagging it explicitly -- fragile if either pointer is legitimately null. This PR adds an explicit MutinyCopyDirection tag + union on the existing output-parameter list node instead.
  • Its naming (withInputParameterForwarding / withInputParameter) collides with this codebase's existing "input parameter" concept (input_parameters_, check_input_parameter, has_input_parameter all mean compared parameters, not copied ones). This PR uses with_captured_parameter[_of_type] on both sides instead.

Related Issues

N/A

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Manual Verification (Optional)

N/A

Checklist

  • I have written/updated documentation in docs/ for any user-facing changes.
  • My code follows the project's naming conventions (mu::tiny namespace, INCLUDED_MU_TINY_ guards, mutiny_ C-prefix).
  • For new features, I have considered if a C-interface adapter (.h and .c.cpp) is required for parity.
  • I have reviewed the CONTRIBUTING.md file to ensure compliance with architectural guidelines.

@coveralls

coveralls commented Sep 10, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 98.963% (+0.02%) from 98.947% — captured-parameters into main

@github-actions

github-actions Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor
TestsPassed ✅Skipped ⚠️Failed
JUnit Tests1103 ran1094 passed9 skipped0 failed

@thetic
thetic force-pushed the captured-parameters branch from fb8bb7d to f6d69a4 Compare September 10, 2026 04:32
Lets a test capture a parameter the code under test passes into a
mocked call, for inspection after the call (a Mockito-style argument
captor) -- the mirror of with_output_parameter, which only moves data
test -> code under test. Reimplements the idea from long-stalled
upstream CppUTest PR #785 with an explicit copy-direction tag instead
of inferring it from which of two pointers is non-null, and with
names that don't collide with this codebase's existing "input
parameter" (compared, not copied) terminology.

Claude-Session: https://claude.ai/code/session_01QtyJLf7njTtE2dXa2y6mC6
@thetic
thetic force-pushed the captured-parameters branch from f6d69a4 to d9a2730 Compare September 10, 2026 04:35
with_captured_parameter/with_captured_parameter_of_type were inserted
mid-vtable in ActualCall and ExpectedCall, shifting the slots of every
virtual declared after them. abi_check.sh already detects this class of
break; under semver rule #4 (major version zero) it requires a minor
bump to allow it.
NamedValue::compatible_for_copying() treated any "void*" expected value as
compatible with any "const void*" actual value purely by type string,
without checking which direction the pair came from. with_output_parameter
and with_captured_parameter store their raw-pointer form with the same two
type strings but with the roles swapped, so pairing with_output_parameter()
on one side with with_captured_parameter() on the other slipped through as
a match, then failed later with a confusing "no way to copy custom type"
error instead of a clear direction-mismatch diagnostic.
MockOutputParametersListNode used a void*/const void* union alongside its
direction enum, and copy_output_parameters() repeated the same
copier/memcpy/fail chain once per direction, differing only in which side
was the source and which was the destination. Store a single const void*
and branch just on direction where the source/destination actually swap,
sharing everything else.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants