Skip to content

Mock same-named headers by directory - #1326

Merged
mkarlesky merged 7 commits into
next_versionfrom
feature/same-named-mocks
Oct 18, 2026
Merged

mkarlesky merged 7 commits into
next_versionfrom
feature/same-named-mocks

Conversation

@mkarlesky

@mkarlesky mkarlesky commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

A test can name two same-named headers by directory, but it could not mock both. CMock and Unity's runner named a mock by filename alone, so the two mocks shared an include guard and lifecycle symbols. That affected traditional mocks and MOCK_PARTIAL_PUBLIC_MODULE_AT Partials alike.

ThrowTheSwitch/Unity#854 and ThrowTheSwitch/CMock#540 add :mock_name_include_folder to both tools. next_version already pins their merge commits (2eece702), so this PR changes no submodule. It enables the option and hands CMock the folder each mock's #include names. It also carries #1325's pending example, which now passes.

Behavior

The new :cmock ↳ :mock_name_include_folder setting defaults to true in Ceedling and is mirrored into :test_runner, like :mock_prefix and :mock_suffix. A mock included as drivers/uart/mock_config.h gets the guard and lifecycle functions drivers_uart_mock_config, and the runner calls those same names. A bare #include "mock_config.h", or one with a leading ./ only, keeps its current name.

The folder is the #include as written, not the mock's mirrored location, because the runner sees only the #include.

  • Placement unchanged: when the folder ends the mirrored location. That holds for every Partial and for any #include that spells part of the real header's path.
  • Placement moved: an #include spelling more path than the mirror holds places its mock below the per-test mock root at the written path, which the root search path still reaches.
  • Option off: CMock receives no folder and names by filename alone.

The CMock configuration, with the new option, is part of each mock's cache meta, so toggling it regenerates mocks.

Changes

  • MockDetails: gains include_path, the #include as the test wrote it (test_invoker_types.rb, test_build_planner.rb).
  • TestBuildExecutor#mock_folder_and_path: derives CMock's folder and the mock's directory. stage_generate_mocks passes both to generate_mock.
  • Generator#generate_mock(folder:): roots CMock above the folder and passes the folder to setup_mocks. Plugin hooks still receive the mock's own directory as :output_path.
  • Default and mirroring: defaults.rb, and RUNNER_CMOCK_OPTIONS in configurator.rb.
  • Module Generator: a comment for NAMING, after 99a87b94 removed the bumpy/camel swap that Unity#855 made unnecessary.
  • PIPELINE.md: describes the naming and placement.

Tests

  • Unit:
    • the folder rule: a bare #include, a folder that ends the mirror, a leading ./, a deeper written path, and the option off;
    • generate_mock roots CMock above the folder, passes the folder, and reports the mock's own directory to plugins;
    • mirroring into :test_runner;
    • MockDetails#include_path.
  • System: the traditional same-named mock example (from Cover mocking two same-named headers in one test #1325) and the Partial one in partials_module_disambiguation_spec.rb now pass.
  • Runs:
    • units (4724) and integration (480) pass on Apple Clang 15, and integration passes on GCC 14 in Docker;
    • system specs pass in Docker (GCC 14): same_named_modules, partials_module_disambiguation, header_include_path_validation, conditional_mock_includes, delta_builds, plugin_delta_builds, mocks_partials_configuration_validation.
  • RuboCop: rake lint is clean across 503 files. The backlog is unchanged at 835 and lists no new file.

Changelog, Known Issues, Breaking Changes and mkdocs edits will follow as uncommitted diffs after CI.

🤖 Generated with Claude Code

mkarlesky and others added 5 commits October 17, 2026 17:58
A test mocking two headers that share a basename, each named by its
directory, is the traditional-mock counterpart of the pending Partial
example. It stays pending until CMock and Unity can name a mock by the
folder its #include names.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CMock and Unity's runner generator name a mock's include guard and
lifecycle functions by its filename alone, so two same-named mocks in one
test collide. With :cmock -> :mock_name_include_folder both tools fold the
directory a test's #include names into that identity instead.

Ceedling enables the option by default and mirrors it into :test_runner.
Each mock records its #include as written, and stage_generate_mocks hands
that directory to CMock as its folder. The mock keeps its mirrored location
whenever the folder ends it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Generator#generate_mock roots CMock above the folder, hands it the folder,
and reports the mock's own directory to plugins. A leading ./ is dropped
from the folder, as the runner drops it. PIPELINE.md describes the naming
and placement.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mkarlesky
mkarlesky force-pushed the feature/same-named-mocks branch from df8c1d8 to 040f875 Compare October 17, 2026 22:12
@mkarlesky
mkarlesky marked this pull request as ready for review October 17, 2026 22:12
mkarlesky and others added 2 commits October 17, 2026 18:42
Ceedling now hands the mock generator the folder each mock's #include
names, and the runner names its lifecycle calls by that folder. The FFF
plugin's stand-in for CMock took no folder, so mock generation failed.
It now takes the folder, writes the fake below its root at that folder,
and names the fake's guard and control functions as CMock does under
:mock_name_include_folder, so the runner's calls link.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mkarlesky
mkarlesky merged commit 2446ec9 into next_version Oct 18, 2026
@mkarlesky
mkarlesky deleted the feature/same-named-mocks branch October 18, 2026 01:37
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.

1 participant