Skip to content

Mock same-named headers by directory - #1326

Draft
mkarlesky wants to merge 4 commits into
next_versionfrom
feature/same-named-mocks
Draft

mkarlesky wants to merge 4 commits into
next_versionfrom
feature/same-named-mocks

Conversation

@mkarlesky

@mkarlesky mkarlesky commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Blocked on ThrowTheSwitch/Unity#854 and ThrowTheSwitch/CMock#540. This branch's submodules pin those unmerged PR commits. They move to the merged upstream commits before this PR leaves draft. Builds on #1325.

A test can name two same-named headers by directory but cannot mock both. CMock and Unity's runner name a mock by filename alone, so the two mocks share an include guard and lifecycle symbols. This affects traditional mocks and MOCK_PARTIAL_PUBLIC_MODULE_AT Partials alike. The upstream PRs add :mock_name_include_folder to both tools. This PR enables it and hands CMock the folder each mock's #include names.

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. The runner calls those same names. A bare #include "mock_config.h" keeps its current name.

The folder is the #include as written, not the mock's mirrored location. The runner sees only the #include, so CMock must name from the same source. The two differ for a bare include of a header in a subdirectory, which header_include_path_validation_spec.rb covers.

Mock placement is 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. 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. With the option set to false, CMock receives no folder and behaves exactly as before.

Changes

  • lib/ceedling/test_invoker/test_invoker_types.rb, test_build_planner.rb: MockDetails gains include_path, the #include as the test wrote it.
  • lib/ceedling/test_invoker/test_build_executor.rb: mock_folder_and_path derives CMock's folder and the mock's directory. stage_generate_mocks passes both to generate_mock.
  • lib/ceedling/generators/generator.rb: generate_mock accepts folder:. It derives CMock's :mock_path by removing the folder from output_path and passes the folder to setup_mocks. Plugin hooks still receive the mock's own directory as :output_path.
  • lib/ceedling/defaults.rb, lib/ceedling/config/configurator.rb: the default and its mirroring into :test_runner.
  • Specs: unit coverage for the folder rule, the mirroring and the new MockDetails field. The Partial and traditional same-named mock examples are no longer pending.
  • vendor/cmock, vendor/unity: pinned to the upstream PR commits.

mkarlesky and others added 4 commits October 8, 2026 13:05
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>
Both pins point at unmerged upstream PR commits. They move to the merged
upstream commits before this branch merges.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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.

1 participant