🌱 Add test-specific mock include directives#1139
Draft
JannisRln wants to merge 1 commit intoThrowTheSwitch:masterfrom
Draft
🌱 Add test-specific mock include directives#1139JannisRln wants to merge 1 commit intoThrowTheSwitch:masterfrom
JannisRln wants to merge 1 commit intoThrowTheSwitch:masterfrom
Conversation
Global CMock include options apply to all generated mocks, which can introduce unwanted dependencies or conflicts in unrelated tests. Add test-file build directives for injecting headers into a specific generated mock for the current test executable only. This allows tests to provide mock-specific types, macros, or configuration headers without changing production headers or global CMock configuration. The generic TEST_MOCK_INCLUDE directive maps to the existing CMock pre-original-header include location. Location-specific variants are also supported for finer control. Add parser coverage for the new directives and document their usage.
91b768c to
a19d793
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🍍
Summary
This draft PR adds support for test-specific mock include directives. Issue 1138
The goal is to allow a test file to inject additional headers into a
specific generated mock without applying those includes globally to all
generated mocks.
Example:
This should inject
test_driver_types.honly into the generated mock formock_driver.hfor the current test executable.Motivation
CMock already supports global include configuration options such as:
These options are useful, but they apply globally. In larger embedded
projects this can lead to unwanted includes, unnecessary dependencies, or
conflicts in unrelated tests.
This PR adds test-specific build directive macros so additional mock
headers can be scoped to one test and one mock.
Added directives
TEST_MOCK_INCLUDE(...)is treated as an alias forTEST_MOCK_INCLUDE_H_PRE_ORIG_HEADER(...).PL Open in Unity Pull 830
Current status
This is currently a draft PR.
The parser-level specs for
TestContextExtractorpass locally:However, I have not yet been able to run the full test suite locally.
Some tests require
gcc, which is not currently available in my localenvironment. We use the project.yaml file to define the gcc location
I am also not fully certain yet that my manual end-to-end test is using
the modified local Ceedling instance rather than another installed
Ceedling version. Because of that, I am opening this as a draft for early
feedback on the approach before marking it ready for review.
Notes for reviewers
I would especially appreciate feedback on:
mock generation
Testing
Completed locally:
bundle exec rspec ./spec/test_context_extractor_spec.rbResult:
Not completed locally yet:
Documentation
This PR also adds documentation for the new test-specific mock include
directives.