478 Commits

Author SHA1 Message Date
Mark VanderVoord d482f56066 Protect against more function-looking macros (Fixes#502) 2026-06-19 15:58:08 -04:00
Mark VanderVoord 1ef72ca854 Protect against function-looking structs (Fixes #513) 2026-06-19 15:10:14 -04:00
Mark VanderVoord 85058d1407 Fixed skeleton path handling, etc (#488) 2026-06-19 14:42:09 -04:00
Mark VanderVoord 411f6852f9 Add documentation to avoid problems like #518 and #521. 2026-06-19 13:50:21 -04:00
Mark VanderVoord 383c43246c Merge pull request #531 from ThrowTheSwitch/feature/better_arrays
Feature/better arrays
2026-06-19 10:53:54 -04:00
Mark VanderVoord 990954c548 Made the last two features actually cooperate. 2026-06-18 20:25:31 -04:00
Mark VanderVoord de4e53cd7b The array plugin can now compare strings as byte arrays, even though they are treated like strings everywhere else. (Fixes #262 and #177) 2026-06-18 19:56:22 -04:00
Mark VanderVoord 84705b2e84 Rename some misnamed tests. 2026-06-18 19:41:35 -04:00
Mark VanderVoord 336a52bf57 Verify #463 isn't currently an error, and won't return. 2026-06-18 18:49:03 -04:00
Mark VanderVoord aaf9559a57 Finish better identification of array pointer/len pairs.
Add fallback _ExpectWithArrayExtended when this happens for flexibility.
Fixes issue #520
2026-06-18 16:34:24 -04:00
Mark VanderVoord 8c1f88fb82 Improve the automatic detection of argument pairs related to arrays/pointers and lengths 2026-06-18 12:50:29 -04:00
Mark VanderVoord a0207f3800 void* handling within the array plugin defaults to bytes. 2026-06-16 21:41:07 -04:00
Mark VanderVoord bad95c5f54 Handle void pointers as pointer comparisons unless the array plugin gives more information. (Fixes #400) 2026-06-16 21:34:32 -04:00
Mark VanderVoord f756eeaf55 Fix handling of array of pointers (Fixes issue #450) 2026-06-16 18:14:51 -04:00
Mark VanderVoord 82ef7e53cf Fix handling of variable-length-arrays (fixed issue #479) 2026-06-16 17:39:40 -04:00
Mark VanderVoord af610445b3 flesh out tests for arrays and pointers and separate. 2026-06-16 17:02:56 -04:00
Mark VanderVoord a0de150635 Improve the array handling by making the public interfaces still use arrays. 2026-06-16 16:18:22 -04:00
Mark VanderVoord 3d4ddfdc4c Fix const pointer handling in return values 2026-06-16 15:37:14 -04:00
Mark VanderVoord 29ef16e54b Tidy handling of system tests to depend more on the defines involved then separate tracking.
Remove yml files that are no longer needed.
2026-06-16 15:20:21 -04:00
Mark VanderVoord 725e2d90ef cleanup the way defines are handled in tests. 2026-05-29 16:28:57 -04:00
Mark VanderVoord c06bbe791c run examples fully and pass optional yaml file to them.
begin to automatically reject tests based on criteria.
2026-05-29 16:09:22 -04:00
Mark VanderVoord c40a6e08c6 Refactored self-tests to use ceedling-formatted tools files 2026-05-28 16:48:53 -04:00
Mark VanderVoord 5f0296eb0a Fix naming to avoid that extra colon for parsing. 2026-05-22 14:41:22 -04:00
Mark VanderVoord 165de30b7d Bump to latest Unity 2026-05-22 14:17:29 -04:00
Mark VanderVoord 04b5b21ffd Give system tests more verbose output during testing. 2026-05-22 13:35:09 -04:00
Mark VanderVoord f20c59b029 Make the output more verbose for self-tests. 2026-05-22 11:41:00 -04:00
Mark VanderVoord 6a9e3afe14 update the create_makefile script to be independent and not require pointless middleware scripts. 2026-05-18 17:41:21 -04:00
Mark VanderVoord 13da43dc95 Merge pull request #530 from ThrowTheSwitch/refactor/inherit_targets
Refactor/inherit targets
2026-05-18 16:42:41 -04:00
Mark VanderVoord 469fe271f5 Add missing type to parsing test. 2026-05-18 16:38:07 -04:00
Mark VanderVoord a99deea71a Refactor test reporting for better final summary. 2026-05-18 16:06:36 -04:00
Mark VanderVoord be420840b3 make the cmock modifier files optional as 2nd argument in config 2026-05-16 23:40:08 -04:00
Mark VanderVoord d83c7017e0 Refactor cmock tests to identify the closest matching cmock overlay 2026-05-16 23:02:07 -04:00
Mark VanderVoord 5c6f42ae45 Tiny tweaks to prepare for next phase 2026-05-16 22:48:24 -04:00
Mark VanderVoord f7c3f73b21 Tweak naming to fall-through to the correct target 2026-05-16 14:48:47 -04:00
Mark VanderVoord f7689b8cc3 continue (update the styling of the targets) 2026-05-16 14:36:36 -04:00
Mark VanderVoord feda84f23b continuing 2026-05-15 23:53:09 -04:00
Mark VanderVoord 7d99f0f51d Start refactoring targets to use those coming from unity. so far we are refactoring to pull project-specific config 2026-05-15 23:31:56 -04:00
Mark VanderVoord 9900e4c5f5 pull in latest unity. bump version 2026-03-20 20:17:33 -04:00
Mark VanderVoord ecd7e7154c Merge pull request #527 from sullivanmj/patch-1
Fix links to other Markdown documentation
2026-03-08 16:15:18 -04:00
Matt Sullivan abcd75ffbc Fix links to other Markdown documentation 2026-03-05 09:24:40 -06:00
Mark VanderVoord f368744ca5 Updates for the new year 2026-01-23 11:19:02 -05:00
Mark VanderVoord 94dcd39765 move to latest unity. 2025-07-09 17:02:47 -04:00
Mark VanderVoord 75c3f3c7b3 minor tweaks 2025-07-09 17:02:21 -04:00
Mark VanderVoord 2671ad7046 Merge pull request #504 from bal-stan/patch-1
Fix compiler error when compiling with `-Wcast-qual` and mocking const function arguments
2025-07-09 16:25:28 -04:00
Mark VanderVoord bf9a13a8d4 Merge pull request #508 from rstahn/rstahn-patch-1
Add option 'create_error_stubs' (default is 'true')
2025-07-09 13:23:10 -04:00
Mark VanderVoord bb0b0e06f5 Fix confusing output when failing within a callback
Unset argument detail before calling callback
2025-07-04 10:48:40 -04:00
ml-physec 2bb9086214 Unset argument detail before calling callback 2025-07-04 16:32:37 +02:00
Roland Stahn ad9ce635c3 Update main.yml
Remove trigger for branch rstahn-patch-1 for final PR
2025-06-13 12:45:11 +02:00
Roland Stahn 6f2a234dca Add tests with 'create_error_stubs' set to false 2025-06-13 11:35:32 +02:00
Roland Stahn 338279285b Delete test/unit/cmock_generator_plugin_expect_c_test.rb 2025-06-13 11:32:27 +02:00
Roland Stahn 16ec975a87 Add first testcase with 'create_error_stubs' set to false
Change-Id: I33728023c1397e2bdbe62304638f578482ec8f58
2025-06-12 14:15:21 +02:00
Roland Stahn 0cefcf05f9 Update description of 'create_error_stubs'
Change-Id: Ica84be72a229a4fd90e3d5ce0b3449722699f637
2025-06-11 12:55:28 +02:00
Roland Stahn c9154a19dd Add description for 'create_error_stubs' 2025-06-08 22:57:20 +02:00
Roland Stahn 3ba7de2cb7 Style fixes 2025-06-03 13:51:15 +02:00
Roland Stahn bd41b3f939 Add option create_error_stubs to testcase 2025-06-03 13:26:34 +02:00
Roland Stahn b1d0e36aa3 Update main.yml (run tests on branches) 2025-06-03 13:18:11 +02:00
Roland Stahn d20dca34ab Add option 'create_error_stubs' in before 2025-06-03 13:14:23 +02:00
Roland Stahn f60fe4b808 Add option 'create_error_stubs'
Proposal for issue #507
2025-06-02 11:44:37 +02:00
bal-stan 076df6dd5c Fix compiler error when compiling with -Wcast-qual and mocking const function arguments 2025-04-01 16:24:48 +00:00
Mark VanderVoord 204117cb59 Merge pull request #499 from bal-stan/cast-memcpy-dest-pointers
Always cast `memcpy` source pointers to `const void *`
2025-02-18 16:33:38 -05:00
Mark VanderVoord 8ce70396d1 Merge pull request #500 from ThrowTheSwitch/mvandervoord-patch-1
Create FUNDING.yml
2025-02-17 09:15:48 -05:00
Mark VanderVoord 4eb6c1cada Create FUNDING.yml 2025-02-17 09:15:26 -05:00
bal-stan 2bcc723e10 Always cast memcpy dest pointers to const void 2025-02-13 18:06:27 +00:00
Mark VanderVoord 49435d9f33 Merge pull request #425 from ThrowTheSwitch/cmock_2_6_rc
CMock 2.6 Release Candidate
2025-01-01 12:16:21 -05:00
Mark VanderVoord f767b67162 Move to latest Unity. Update Release Notes for the pending release. 2025-01-01 12:13:48 -05:00
Mark VanderVoord a60383ec34 Update licenses to new standards... plus New Years bump 2025-01-01 12:05:55 -05:00
Mark VanderVoord d5e938e4b1 - refactor to match coding standards.
- test against Ruby 3.3 also.
2024-10-23 16:01:48 -04:00
Mark VanderVoord 7d6ec0354a If a short-path cannot be created, fallback to absolute path, even though it's more verbose. 2024-10-23 15:35:37 -04:00
Mark VanderVoord 43618c8c78 🐛 Fix problem if unity helper path is specified as relative path starting with .. 2024-10-03 10:03:33 -04:00
Mark VanderVoord 74b8ed295a Bump dependencies 2024-08-01 13:55:45 -04:00
Mark VanderVoord 6b0587fce5 Fixes to latest stylistic warnings. 2024-08-01 12:12:08 -04:00
Mark VanderVoord c83f8bddf2 Working towards gemifying and automatically reporting version. 2024-08-01 11:47:58 -04:00
Mark VanderVoord 119f6607d9 Don't need to escape symbols in brackets 2024-04-02 19:28:29 -04:00
Mark VanderVoord df73448935 Remove some stuff that shouldn't really be in config file. 2024-04-02 19:13:31 -04:00
Mark VanderVoord 9cc8fb5302 Let's enable validation of examples. failures should trip errors.
Also make them verbose so we can see what is going on.
2024-04-02 18:44:35 -04:00
Mark VanderVoord 93e2f528cc Update example project to handle pointers of different sizes and not complain on modern platforms. 2024-04-02 17:40:40 -04:00
Mark VanderVoord ecaccb428b 🪲 remove unused AbortFrame (#316) 2024-03-26 22:29:06 -04:00
Mark VanderVoord 714619eefb 🪲 protect against bad filenames with multiple .c instances in them (#348) 2024-03-22 22:04:30 -04:00
Mark VanderVoord 001bbeca51 🪲 :fail_on_unexpected_calls options now insists on required :ignore plugin (#376) 2024-03-22 21:41:45 -04:00
Mark VanderVoord 597a6d86eb Finish giving clues when you've chosen the wrong AndReturn version.
ReturnArrayThruPtr (and others) now protect sizes in parenthesis #415
2024-03-21 11:35:21 -04:00
Mark VanderVoord 3a6f1f29a3 🪲 Fixed issue where -oblah.yml isn't parsed by powershell.
:fern: `-o blah.yml` also accepted as valid input now.
2024-03-20 15:55:59 -04:00
Mark VanderVoord 0240b4ae19 ⬆️ Updated Unity and CException to latest versions. 2024-03-14 09:00:56 -04:00
Mark VanderVoord 07a0e257b5 🪲 Added fail messages when using Expect for ExpectAndReturn or vice versa. (see issue #462) 2024-03-14 08:59:31 -04:00
Mark VanderVoord 7925641d7d 📝 Add Code of Conduct and Contributing docs 2024-03-13 15:07:47 -04:00
Mark VanderVoord 4fb4fba206 Jump to next release of unity and cexception. 2024-03-09 20:09:05 -05:00
Mark VanderVoord dddd01dfa7 copied change from pr 468 2024-03-09 19:08:11 -05:00
Mark VanderVoord 3232b72205 fixed wrong quote usage. 2024-02-21 14:58:23 -05:00
Mark VanderVoord 083bbd6a38 Add to verbosity of failures to find prototypes in headers. 2024-02-21 13:52:07 -05:00
Mark VanderVoord cac4907c27 Add Argument Validation documentation, because it's a common question. 2023-11-29 11:44:06 -05:00
Mark VanderVoord 95d29ee087 Add part of our new "standard" documentation for status! woo! 2023-11-22 23:59:19 -05:00
Mark VanderVoord c2e3c742ba Fix test for const feature of return-thru-pointer 2023-11-22 20:05:20 -05:00
Mark VanderVoord b032cfa09b Merge branch 'master' into cmock_2_6_rc 2023-11-22 19:58:51 -05:00
Mark VanderVoord 9192a95089 Merge pull request #453 from NovaNekmit/NovaNekmit-patch-1
Make ReturnMemThruPtr pointers const
2023-11-22 19:57:55 -05:00
Mark VanderVoord 4f73b40698 Bump to the latest rubocop 2023-11-22 19:47:19 -05:00
Mark VanderVoord a642b1fe49 Update to latest Unity and therefore newer Rubocop standards. Tweaked scripts to match latest standards. 2023-11-22 17:40:07 -05:00
Mark VanderVoord 32049399b3 Fixes to the temp_sensor example. 2023-11-22 15:52:54 -05:00
Mark VanderVoord 097b3ec42a Let's see how we're doing if we only run on Ruby 3.x 2023-11-22 15:02:17 -05:00
Mark VanderVoord 161d58bf54 Merge branch 'master' into cmock_2_6_rc 2023-11-13 22:33:50 -05:00
Mark VanderVoord 6cf8fb9b71 Fix to incorrect handling of static inlines.
Fix to Ruby deprecated interfaces.
Fix to keep up with new C standards.
2023-11-13 22:33:16 -05:00
Mark VanderVoord c548629a47 Merge pull request #457 from Hannes103/sizeof-void
add check to prevent sizeof(void) generation
2023-08-23 08:32:14 -04:00
Hannes Bachl 5328a51508 add check to prevent sizeof(void) generation 2023-08-23 11:32:58 +02:00
NovaNekmit 6d9236d4ee Fix typos 2023-08-09 21:58:16 +02:00
NovaNekmit 9b34c01213 Update test 2023-08-09 17:12:42 +02:00
NovaNekmit 65706fa6fb Make ReturnMemThruPtr pointers const 2023-08-09 15:53:02 +02:00
Mark VanderVoord a3a48e8b1d Merge pull request #451 from informatimago/treat_as-better-error-message
Added a user-friendly error message when processing bad :treat_as
2023-07-29 07:50:07 -04:00
Pascal J. Bourguignon c05e08d99e Added a user-friendly error message when processing bad :treat_as
When the indentation after :treat_as mappings is wrong, we may get a symbol as ctype.
The error signaled by gtype.gsub is not userfriendly, so instead, we test for symbols
and issue a user friend error message in that case.
2023-07-28 11:10:54 +02:00
Mark VanderVoord ed29ce388f Merge pull request #437 from alufers/master
fix: Don't smush macros which have an escaped empty line at the end
2023-05-08 09:18:03 -04:00
alufers 3caf511b8f fix: Don't smush macros which have an escaped empty line at the end
nanopb has a habit of generating macros which end with an escaped empty line (for example for messages which are empty). They look like this:

   #define some_msg_t_FIELDLIST(X, a) \

   #define some_msg_t_CALLBACK NULL

This caused CMock to strip all of the newlines after the backslash instead of only one, which the backslash was escaping.
This in turn caused both the macros to be in one line, causing a compile error in the generated mock.
2023-04-26 14:16:41 +02:00
Mark VanderVoord e4ba3be48b newer rubies are confused about the first array argument to some functions when the array is empty... so we name the parameters when we pass them to clear things up. 2023-02-07 08:00:51 -05:00
Mark VanderVoord bbfaf0425f Handle yaml.load in a way that is ruby version agnostic. 2023-02-06 16:46:48 -05:00
Mark VanderVoord 69258f7034 Tweaks to self-test action script and bump version info 2023-02-06 16:24:23 -05:00
Mark VanderVoord 0b28344d23 bump version 2023-02-06 16:13:29 -05:00
Mark VanderVoord cde38e4752 test against all valid rubies 2023-02-06 16:13:08 -05:00
Mark VanderVoord 379a9a8d5d Merge pull request #420 from ThrowTheSwitch/bugfixes/batch1
Collection of Quick Fixes
2023-01-11 15:54:38 -05:00
Mark VanderVoord a58808d424 Fixed bug #402, getting confused with __attribute__ directives with spacing. 2023-01-11 15:43:48 -05:00
Mark VanderVoord 902b6c8b3d Fix bug in parenthetical statements being misinterpreted as functions. (Issue #414) 2023-01-10 15:35:54 -05:00
Mark VanderVoord 91bb49c4a8 Fix same bug as PR #354, but as one line. 2023-01-09 14:50:56 -05:00
Mark VanderVoord bf37ffa4a5 Merge pull request #417 from ThrowTheSwitch/testing/workaround_bundler_issue
Attempt to clear permissions on the bundler scratch file
2023-01-09 14:37:34 -05:00
Mark VanderVoord 5838025996 rubocop fix. 2023-01-09 14:30:01 -05:00
Mark VanderVoord aefdb44f0c Whooops. Forgot to remove this. 2023-01-09 14:25:05 -05:00
Mark VanderVoord 16d12416fd Force ourselves to test with Ruby 3.
Fix some issues that have been lurking.
2023-01-09 14:16:30 -05:00
Mark VanderVoord 019f88b4d9 Attempt 5: Ugh. This is ugly. 2023-01-05 17:31:52 -05:00
Mark VanderVoord 9c44090fa2 Attempt 4: another recommended fix on github. 2023-01-05 17:16:20 -05:00
Mark VanderVoord f3179c6d11 attempt 3 2023-01-05 16:56:07 -05:00
Mark VanderVoord e154536091 2nd attempt to work around bundler headaches. 2023-01-05 16:52:11 -05:00
Mark VanderVoord d7a6015f9c Merge branch 'master' into testing/workaround_bundler_issue 2023-01-05 16:33:50 -05:00
Mark VanderVoord 4b265c2f27 Attempt to clear permissions on the bundler scratch file 2023-01-05 16:33:14 -05:00
Mark VanderVoord db946f2239 Merge pull request #359 from lukzeg/feature/358_cmock_speed_up_generation
Switch places in the extern C regex to speed up mock generation
2023-01-05 15:53:48 -05:00
Mark VanderVoord b3f78b4259 Merge pull request #374 from Melirius/Calling-conventions-in-function-pointers-fix
Fix parsing of calling conventions in function pointers
2023-01-05 15:52:13 -05:00
Mark VanderVoord 5551437ea8 Merge pull request #378 from danimartin82/master
Fix skeleton file creation
2023-01-05 15:50:32 -05:00
Mark VanderVoord d3962d56c3 Merge pull request #408 from Yagoor/contribution/extern-c
Added extern "C" to cmock generated headers
2022-10-02 20:12:59 -04:00
Yago Fontoura Do Rosario 5eebd713ba Added extern "C" to cmock generated headers 2022-09-07 21:16:28 +02:00
Mark VanderVoord f65066f15d Merge pull request #404 from tz18/patch-1
Add example for the usage of ReturnThruPtr
2022-07-08 12:15:07 -04:00
Ramon Rakow c532d17f9e Update CMock_Summary.md 2022-07-08 09:11:48 -07:00
Ramon Rakow 406a9bcf2e Update CMock_Summary.md 2022-07-08 09:10:45 -07:00
Ramon Rakow 7121f51944 Add example for the usage of ReturnThruPtr
I found it difficult to decipher the correct syntax for using ReturnThruPtr, and looking at github issues and google groups messages suggests others have had the same trouble. I suggest this example to explicate the correct usage.
2022-07-07 15:21:06 -07:00
Mark VanderVoord 1b81269e78 Merge pull request #401 from nordic-krch/fix/mem_alignment
Ensure alignment of CMock_Guts_Buffer
2022-05-31 11:09:17 -04:00
Krzysztof Chruscinski 9b9f93ff7d Ensure alignment of CMock_Guts_Buffer
Another attempt to fix something that was previously fixed by
73255670 but got reversed due to breaking something else.

The issue is that CMock_Guts_Buffer was unsigned char thus it
may have been unaligned (byte aligned). Portions from this buffer
where casted to a structure. On certain architectures alignment
must be maintained when accessing 32bit or 64 bit data and that
was not maintained with byte aligned array.

Instead of using attribute that may be complier specific, changing
type of array to long long.
2022-05-30 13:18:46 +02:00
Mark VanderVoord 9934754d1f Pull in Unity.
Update documentation to match latest handling of arrays of length zero.
2022-04-19 17:31:32 -04:00
Mark VanderVoord bb0509719d Merge pull request #383 from regnerjr/patch-1
Fixes link to license file.
2022-03-21 06:57:45 -04:00
John Regner b9eec9ed6f Fixes link to license file.
License file is no longer in the docs folder, it's not at the top level so GitHub can match it.
2022-03-01 15:07:48 -08:00
Mark VanderVoord f5a76956d6 Merge pull request #381 from Tschet1/fix_runaway_regex
Fix runaway regex
2022-02-21 08:02:58 -05:00
Müller, Jan bb85af5567 Fix runaway regex
Multiple nested greedy quantifiers can cause to increase complexity of
the regular expression so that the matching in the cmock_header_parser
would take multiple minutes.
Fixed by removing one of the quantifiers that seems not to be needed.
2022-02-21 13:47:09 +01:00
Dani Martin 202721e561 Fix skeleton file creation 2021-12-17 13:18:19 +01:00
Ivan Siutsou 8b2e897d35 The same output witout convention 2021-11-07 23:04:44 +02:00
Ivan Siutsou 7100ef0e62 Fix parsing of calling conventions in function pointers 2021-11-07 21:47:51 +02:00
Mark VanderVoord 3806f7ebe3 Merge pull request #369 from JmcRobbie/master
Fixes minor typo
2021-10-13 08:03:13 -04:00
Jack McRobbie 3ec9468bbe Fixes minor typo 2021-10-11 17:13:32 +11:00
Mark VanderVoord 3d4ba8d20b Grab latest unity.
Bump Version.
2021-06-18 14:43:57 -04:00
Lukasz Zeglinski 50de50d239 Switch places in the extern C regex to speed up mock generation 2021-05-09 22:12:06 +02:00
Mark VanderVoord 3b443e551d Merge pull request #347 from ThrowTheSwitch/feature/only_config_is_shared
Update so only config is shared.
2021-02-05 15:56:22 -05:00
Mark VanderVoord 27bca0c3c4 style cleanup 2021-02-05 15:53:43 -05:00
Mark VanderVoord 9bb250ea4a Update so only config is shared. Everything else about the current job is passed. 2021-02-05 15:15:14 -05:00
Mark VanderVoord 9d092898ef Merge pull request #346 from ThrowTheSwitch/reapply_329
Revert "Revert "CMock can now compile without setjmp.h present on the…
2021-01-29 10:54:18 -05:00
Mark VanderVoord dd00b96f0d Fix broken tests for supporting exclude_setjmp. Verify cexception won't be run when this is enabled. 2021-01-29 10:47:52 -05:00
Mark VanderVoord aa5113e012 Update apt-get in the hopes that this makes multilib happy. 2021-01-29 10:12:40 -05:00
Mark VanderVoord 325b6b333a Revert "Revert "CMock can now compile without setjmp.h present on the platform""
This reverts commit 3eccb8e3d4.
2021-01-29 10:06:08 -05:00
Mark VanderVoord 73fd65928c Merge pull request #345 from ThrowTheSwitch/revert-329-master
Revert "CMock can now compile without setjmp.h present on the platform"
2021-01-28 08:15:45 -05:00
Mark VanderVoord 3eccb8e3d4 Revert "CMock can now compile without setjmp.h present on the platform" 2021-01-28 08:15:10 -05:00
Mark VanderVoord 1f939c9005 Merge pull request #329 from jmrubillon/master
CMock can now compile without setjmp.h present on the platform
2021-01-28 08:04:40 -05:00
Jean Rubillon 9e1c6c068d Fix missed has_setjmp_h convert to exclude_setjmp_h 2021-01-28 12:57:02 +00:00
Jean Rubillon 4ae268dbbe Changed has_setjmp_h option to exclude_setjmp_h 2021-01-27 18:56:02 +00:00
Mark VanderVoord d847e6777c Merge pull request #344 from ThrowTheSwitch/test/switch_to_actions
Switch to github actions
2021-01-16 22:22:34 -05:00
Mark VanderVoord dcde998087 cleanup style 2021-01-16 22:20:16 -05:00
Mark VanderVoord 38d6dccc8e Show the correct badge for this project.
Fix a bug in a test.
2021-01-16 22:15:36 -05:00
Mark VanderVoord 03acc531bf when we checkout the project, do it recursively so we get unity for our tests. :) 2021-01-16 21:33:19 -05:00
Mark VanderVoord 45920ed724 Need project present before running bundler. 2021-01-16 21:21:51 -05:00
Mark VanderVoord c4842fad0c Don't run bundler as root. 2021-01-16 21:17:55 -05:00
Mark VanderVoord 9f3cee70cd Switch to github actions 2021-01-16 21:13:55 -05:00
Mark VanderVoord 4dd557f2df Merge pull request #311 from andred/master
allow compilation with stricter warnings
2021-01-07 18:02:24 -05:00
Mark VanderVoord af1818a652 Merge pull request #327 from Hannes103/feature/sub-folder-supprt
add optional folder argument to create_mock()
2021-01-07 17:59:10 -05:00
Mark VanderVoord e352bb8c3b Merge pull request #340 from CezaryGapinski/fix-static-variables-for-enabled-inline-funcs-mocks
Fix static variables detection in headers for enabled inline function mocks
2021-01-07 17:57:36 -05:00
Mark VanderVoord 63f5e2f962 Merge pull request #341 from laurensmiers/master
Remove comments before start of inline-function-parsing
2021-01-07 17:57:17 -05:00
Cezary Gapinski 5eec2510b1 Change inline function detection to leave code not related to functions
static keyword can be used for variable in headers, like in issue #313 or ThrowTheSwitch/Ceedling#541
2020-12-15 21:10:45 +01:00
Cezary Gapinski f5984f44e8 Add test to leaves static variables for enabled inline functions mocks 2020-12-14 21:12:11 +01:00
Mark VanderVoord 9c1c6a05dc Merge pull request #337 from ollehu/master
Improve the regexps for parsing parameters to cmock.rb
2020-11-12 11:54:15 -05:00
ollehu 70d5750659 Merge branch 'master' into master 2020-11-12 16:01:43 +01:00
Mark VanderVoord 72f1c9e2b8 Merge pull request #339 from naggety/master
Allow parsing empty values for options in CLI arguments
2020-11-04 07:06:33 -05:00
Iñigo Huguet 334f46781a Allow parsing empty values for options in CLI arguments
If an option is passed via CLI, it cannot be passed with an
empty value because the Regex makes it to match 1 or more
characters.

For example, arguments `--mock_prefix=""` and `--mock_prefix=`
are invalid, because they don't match the regex and are not
recognized as options, so they're treated as files to mock.

Changing the regex to match 0 or more characters for the option
value, instead of 1 or more, solves the problem.
2020-11-04 09:42:36 +01:00
Olle Hynén Ulfsjöö ea061bbb50 Improve the regexps for parsing parameters to cmock.rb
Also, conform to the standard 80 character limit

Change-Id: I7830ddd5d65ccc06c96884c1c3d4575241f99e6d
2020-10-23 16:26:36 +02:00
Jean Rubillon 21d181380f Signal that cexception needs setjmp to be supported. 2020-09-08 21:11:54 +01:00
Jean Rubillon 72b356b97d Added option to remove setjmp.h from generated mock files as not supported on all embedded systems 2020-09-08 20:50:48 +01:00
Hannes Bachl 22a7228bbc add optional folder argument to create_mock() 2020-09-01 10:17:54 +02:00
Mark VanderVoord afa294982e Merge pull request #326 from cloudsftp/ignore_stateless
Resolve Ruby Offenses found by CI
2020-08-19 07:51:00 -04:00
cloudsftp 44f126878b remove trailing whitespace 2020-08-19 13:15:21 +02:00
cloudsftp 1987138e81 resolve ruby offenses found by CI 2020-08-19 12:40:35 +02:00
Mark VanderVoord baa946a05f Merge pull request #325 from cloudsftp/ignore_stateless
Plugin: IgnoreStateless
2020-08-19 06:38:03 -04:00
cloudsftp d304ff273a add StopIgnore to new plugin 2020-08-19 11:25:27 +02:00
cloudsftp 56faeb935f add documentation 2020-08-19 10:38:26 +02:00
cloudsftp 61ed5cc7f8 add more tests for the new plugin 2020-08-19 10:17:05 +02:00
cloudsftp 496cabff10 add more test cases for the new plugin 2020-08-18 16:56:36 +02:00
cloudsftp 94ca645061 add first simple test and remove warning "unused parameter" 2020-08-18 16:31:45 +02:00
cloudsftp d36662da2a repair failing unit tests for plugins 2020-08-18 15:33:51 +02:00
cloudsftp b735d09603 add plugin :ignore_stateless that solves ThrowTheSwitch/CMock#307 2020-08-18 15:25:55 +02:00
Mark VanderVoord 5f8ec6da7f Merge pull request #321 from michaelbrockus/let_meson_handle_flags
Letting Meson handle flags
2020-08-06 16:29:30 -04:00
Michael Brockus 3e28a5412d use files method 2020-08-06 13:26:00 -07:00
Michael Brockus 5f8e90b82a Update meson.build 2020-08-06 12:39:56 -07:00
laurens 541e7034ad Remove comments before start of inline-function-parsing 2020-06-13 12:49:33 +02:00
Mark VanderVoord eeecc49ce8 Merge pull request #312 from Skinner927/patch-1
Stop strippables default value from being parsed (Thanks @Skinner927 )
2020-06-04 13:15:31 -04:00
Dennis Skinner 175a834574 Stop strippables default value from being parsed
Default value for `:strippables` was rendering incorrectly because of markdown parsing.
2020-06-04 13:02:30 -04:00
André Draszik ec6fa2c516 Revert "drop unnecessary prototype (immediately before definition)"
This reverts commit 7fbeb40965.

This causes compilation warnings / errors when a project uses
-Wmissing-prototypes compilation flags for safety reasons:

.../test/mocks/mock_logMessages.c:685:6: warning: no previous prototype for ‘CMockExpectParameters_log_message’ [-Wmissing-prototypes]
  685 | void CMockExpectParameters_log_message(CMOCK_log_message_CALL_INSTANCE* cmock_call_instance, const char* logMessage, int messageID, severity_t severityIn)
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

etc.

Signed-off-by: André Draszik <git@andred.net>
2020-05-25 16:35:54 +01:00
André Draszik 7ee27d6891 cmock: annotate pure & const APIs (fix Wsuggest-attribute= warnings)
GCC (& Clang) have the notion of pure and const functions [1],
where those attributes are intended to help the optimiser.

Annotate a few APIs here with the appropriate key words, which
also fixes Wsuggest-attribute=pure and Wsuggest-attribute=const
warnings, which a source base might have enabled:

.../src/cmock.c: In function ‘CMock_Guts_MemNext’:
.../src/cmock.c:118:22: warning: function might be candidate for attribute ‘pure’ [-Wsuggest-attribute=pure]
  118 | CMOCK_MEM_INDEX_TYPE CMock_Guts_MemNext(CMOCK_MEM_INDEX_TYPE previous_item_index)
      |                      ^~~~~~~~~~~~~~~~~~
.../src/cmock.c: In function ‘CMock_Guts_MemEndOfChain’:
.../src/cmock.c:140:22: warning: function might be candidate for attribute ‘pure’ if it is known to return normally [-Wsuggest-attribute=pure]
  140 | CMOCK_MEM_INDEX_TYPE CMock_Guts_MemEndOfChain(CMOCK_MEM_INDEX_TYPE root_index)
      |                      ^~~~~~~~~~~~~~~~~~~~~~~~
.../src/cmock.c: In function ‘CMock_Guts_GetAddressFor’:
.../src/cmock.c:158:7: warning: function might be candidate for attribute ‘pure’ [-Wsuggest-attribute=pure]
  158 | void* CMock_Guts_GetAddressFor(CMOCK_MEM_INDEX_TYPE index)
      |       ^~~~~~~~~~~~~~~~~~~~~~~~
.../src/cmock.c: In function ‘CMock_Guts_MemBytesCapacity’:
.../src/cmock.c:173:22: warning: function might be candidate for attribute ‘const’ [-Wsuggest-attribute=const]
  173 | CMOCK_MEM_INDEX_TYPE CMock_Guts_MemBytesCapacity(void)
      |                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~
.../src/cmock.c: In function ‘CMock_Guts_MemBytesFree’:
.../src/cmock.c:181:22: warning: function might be candidate for attribute ‘pure’ [-Wsuggest-attribute=pure]
  181 | CMOCK_MEM_INDEX_TYPE CMock_Guts_MemBytesFree(void)
      |                      ^~~~~~~~~~~~~~~~~~~~~~~
.../src/cmock.c: In function ‘CMock_Guts_MemBytesUsed’:
.../src/cmock.c:189:22: warning: function might be candidate for attribute ‘pure’ [-Wsuggest-attribute=pure]
  189 | CMOCK_MEM_INDEX_TYPE CMock_Guts_MemBytesUsed(void)
      |                      ^~~~~~~~~~~~~~~~~~~~~~~

[1] https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html

Signed-off-by: André Draszik <git@andred.net>
2020-05-25 15:39:21 +01:00
André Draszik 2568a3657f return_thru_ptr: fix Wsign-conversion warning
Compiling a source base / test with Wsign-conversion enabled, gives
the following warning:

build/test/mocks/mock_logMessages.c: In function ‘countLogMessages’:
build/test/mocks/mock_logMessages.c:749:26: warning: conversion to ‘size_t’ {aka ‘long unsigned int’} from ‘int’ may change the sign of the result [-Wsign-conversion]
  749 |       cmock_call_instance->ReturnThruPtr_fileIn_Size);
      |       ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~

The ReturnThruPtr_XXX_Size is used as argument to a call to memcpy(),
which expects size_t (unsigned) for a good reason. The size leading
to this call is being determined using sizeof(), so there appears
no reason to ever convert this to (signed) int.

Stop converting size_t to int, and thereby fix the compiler
warning.

Signed-off-by: André Draszik <git@andred.net>
2020-05-25 07:45:34 +01:00
Mark VanderVoord 150573c742 Latest Unity 2020-05-03 16:13:52 -04:00
Mark VanderVoord 7ec556d209 Bump Version 2020-05-03 16:10:55 -04:00
Mark VanderVoord 6259630f00 Merge pull request #301 from booz-allen-hamilton/cpp-static-min
add support for mocking C++ static class member methods
2020-05-03 13:57:14 -04:00
Mark VanderVoord a262194af8 Submit some style cleanup.
Bump Unity Version.
2020-05-03 09:05:39 -04:00
Mark VanderVoord fb8f48a10d Fix tests that were left behind. 2020-05-03 08:53:51 -04:00
Mark VanderVoord b30c22780e Fixed previous error with extra junk and bumped subproject versions 2020-05-03 08:31:23 -04:00
Mark VanderVoord 0d593c60d3 Merge pull request #305 from pwatt01/master
add <function>_StopIgnore()  function
2020-05-02 14:45:23 -04:00
pwatt01 555b608116 Remove Trailing whitespace 2020-04-27 12:23:29 +09:30
pwatt01 3c3dad1eb2 Remove trailing whitespace 2020-04-27 12:21:41 +09:30
pwatt01 7bfa02cd23 Fix whitespace errors, minimize unnecessary branching 2020-04-24 21:49:16 +09:30
pwatt01 1f16f4b5a3 Fix Ignore declaration missing, fix StopIgnore to handle returns 2020-04-24 14:09:02 +09:30
pwatt01 553dc94b76 Fix typo 2020-04-24 12:08:50 +09:30
pwatt01 b6a6bd0a11 Updated documentation 2020-04-24 09:24:54 +09:30
pwatt01 d0214e4e9d add <function>_StopIgnore() function 2020-04-22 15:34:01 +09:30
Mark VanderVoord ee412d296a Merge pull request #299 from Tuc-an/unnecessary-prototype
drop unnecessary prototype (immediately before definition)
2020-04-09 16:11:51 -04:00
Tuc-An e06540f3d7 add support for mocking C++ static class member methods 2020-04-06 11:20:15 -04:00
Tuc-An 7fbeb40965 drop unnecessary prototype (immediately before definition) 2020-03-27 11:17:14 -04:00
Mark VanderVoord b32e3cd601 Merge pull request #298 from Tuc-an/compact
convert Boolean values from int to char to reduce memory
2020-03-25 10:11:14 -04:00
Tuc-An cfcca2e43e convert Boolean values from int to char to reduce memory 2020-03-25 10:00:05 -04:00
Mark VanderVoord 80d2c3a4e9 Merge pull request #297 from Tuc-an/size_t
change CMOCK_MEM_INDEX_TYPE default type to size_t
2020-03-25 08:01:45 -04:00
Tuc-An aaeae0e217 update doc to match 2020-03-25 07:25:47 -04:00
Tuc-An d78b5e4ab6 change CMOCK_MEM_INDEX_TYPE default type to size_t 2020-03-25 07:19:54 -04:00
Mark VanderVoord 2bbf3ab5e5 Merge pull request #296 from Tuc-an/old-c-style-comments
switch comments to C-style to improve compatibility with pre-C99 and …
2020-03-25 06:39:49 -04:00
Tuc-An 2bd9128689 Trigger notification 2020-03-25 05:53:46 -04:00
Tuc-An 24daea45ab switch comments to C-style to improve compatibility with pre-C99 and match unity 2020-03-25 05:41:14 -04:00
mvandervoord 382c196379 Latest Unity 2020-03-19 11:46:58 -04:00
Mark VanderVoord 586ec41c26 Merge pull request #294 from ThrowTheSwitch/style
Update Testing and Style to match our coding standard
2020-03-19 11:43:26 -04:00
mvandervoord 11a278eebf astyle not on travis, therefore don't test with CI 2020-03-19 11:40:30 -04:00
mvandervoord 69ad84b06b No need to freeze immutable objects 2020-03-19 11:35:22 -04:00
mvandervoord 13ee7c9eec Further cleanup based on server results 2020-03-19 11:29:17 -04:00
mvandervoord 1bdb299566 update gem file to drop old requirements 2020-03-19 10:27:51 -04:00
mvandervoord 4706da4453 another try 2020-03-19 10:17:30 -04:00
mvandervoord 44c8d4718a Further tweaks to testing 2020-03-19 10:09:22 -04:00
mvandervoord 9b393ad4fb Further style changes to match standard.
Pull in latest Unity.
Update testing parameters to include Ruby 2.7
2020-03-19 10:00:12 -04:00
mvandervoord 67858837d1 Update coding style to match our own official coding guidelines 2020-03-18 19:16:58 -04:00
Mark VanderVoord 9f8624a722 Merge pull request #283 from michaelbadcrumble/master
Cleaner implementation of Meson build support
2020-03-18 15:20:07 -04:00
mvandervoord 0f196a52cf Deal with more complex array length expressions. (thanks @jlindgren90 !) 2020-03-18 15:19:23 -04:00
mvandervoord 8885be7e55 Support alternative header file extension support (thanks @Tuc-an) 2020-03-18 15:08:21 -04:00
mvandervoord ae677d6481 Tweak to support test runner generator returning includes with extensions now. 2020-03-18 12:29:52 -04:00
mvandervoord 6aafb8184f Update to latest Unity 2020-03-18 11:55:43 -04:00
Mark VanderVoord bd0a8bfd38 Merge pull request #272 from jlindgren90/master
Some minor optimizations
2020-03-16 13:45:10 -04:00
Mark VanderVoord 300ebb86fd Merge branch 'master' into master 2020-03-16 13:44:41 -04:00
mvandervoord 3cfa437460 Make skeleton path configurable 2020-03-12 17:08:51 -04:00
mvandervoord f5abf20f4b Add ability to generate skeleton from header. woo! 2020-03-12 12:20:33 -04:00
Mark VanderVoord 2eb209b2a8 Merge pull request #286 from andred/for-merge
cmock_generator_plugin_callback: allow usage with Clang scan-build
2020-02-13 22:01:07 -05:00
André Draszik ccfe2690f4 cmock_generator_plugin_callback: allow usage with Clang scan-build
Running a project through Clang's scan-build produces countless
warnings like

build/test/mocks/mock_handleTroubleEvents.c:321:5: warning: Value stored to 'call_instance' is never read
    call_instance = CMOCK_GUTS_NONE;
    ^               ~~~~~~~~~~~~~~~

scan-build correctly determines that in the following snippet

    UNITY_CLR_DETAILS();
    if (Mock.checkForActiveTroubleAfterDebounce_CallbackFunctionPointer != NULL)
      call_instance = CMOCK_GUTS_NONE;
    call_instance = Mock.startStopTimer_CallInstance;

as generated by Ceedling / CMock, the first assignment to
call_instance is completely unused.

The sheer amount of warnings makes it very hard to impossible to
spot real problems in one's code, and creates huge code analysis
reports that just distract from actual problems in one's code.

Without being too invasive, we can instruct scan-build to ignore
this dead store using
    https://clang-analyzer.llvm.org/faq.html#dead_store

Signed-off-by: André Draszik <git@andred.net>
2020-02-14 02:56:21 +00:00
Mark VanderVoord 46db68699c Merge pull request #279 from laurensmiers/fix_bug_pull_request
Fix parsing of inline function declarations/macro's
2020-02-12 13:14:11 -05:00
Michael Brockus 4d0ea1afda Update meson.build 2020-01-27 23:18:39 -08:00
Michael Brockus a1b6da1773 Update meson.build 2020-01-27 23:17:18 -08:00
John Lindgren 3093a440dd expect: Optimize mock_verify() for the successful case.
Remove unconditional UNITY_SET_DETAIL/UNITY_CLEAR_DETAILS pair and
only call UNITY_SET_DETAIL if we are failing.
2020-01-27 15:24:06 -05:00
John Lindgren 574d532df7 callback: mock_verify() has no effect.
callback has a later priority than expect, so setting call_instance
to CMOCK_GUTS_NONE at this point has no effect.  This mock_verify()
has probably been obsolete for a long time.
2020-01-27 15:24:06 -05:00
laurensmiers 87cae74434 Re-use global function declaration regex in inline-function parsing 2020-01-15 00:04:28 +01:00
laurensmiers fda0b13fe5 Remove debug prints 2020-01-14 22:23:31 +01:00
laurensmiers 1c67efc485 Update inline function parsing documentation 2020-01-14 22:18:17 +01:00
laurensmiers 9571c52d70 Replace search for first bracket/semicolon with regex matching first function declaration
The regex matches the function declaration at the start of the
string (post-match).
2020-01-14 22:18:17 +01:00
laurens faceb864b8 Fix deleting of next line in user supplied inline function pattern
If we have a 'empty' macro, f.e.:
\#if <something>
\#define MY_LIBRARY_INLINE
\#endif
and using the user pattern 'MY_LIBRARY_INLINE', we would get the
following effect:
match = 'MY_LIBRARY_INLINE\n' <--- NOTE THAT THE NEWLINE IS PART OF THE MATCH
post-match = '#endif\n' <--- NO BEGINNING NEWLINE SINCE IT IS PART OF
THE MATCH ABOVE

And lead to the new header:
\#if <something>
Which gives a compilation error since the preprocessor-if is not
terminated properly.

The root cause is that we add a any-whitespace-character regex to the
user regex.
This any-whitespace-character regex was added only to cleanup the
 whitespaces after a user regex.

So the next line will be deleted if we check for any whitespace
character (THIS INCLUDES A NEWLINE!) after the user regex.
But this had the side effect that when matching a user regex, the newline was
also seen as part of the match. Which in the case of an empty macro
 would mean that in the cleanup of the post-match, we would delete the
 line immediately after the empty macro (\#endif in the example above).
So instead of matching with every whitespace character (which includes
newlines!), we explicitly only check for whitespaces.

Taking the example above, this has the desired effect:
match = 'MY_LIBRARY_INLINE' <--- NOTE THAT THE NEWLINE IS NO LONGER PART OF THE MATCH
post-match = '\n#endif\n' <--- BEGINNING NEWLINE NOW

Now the cleanup after a define will see the beginning newline in the
post-match and only remove that newline and now the preprocessor-if is
terminated properly
2020-01-14 22:18:17 +01:00
laurensmiers cf0e55b6e4 Fix system test compile error
if there is no semicolon in the file, first_semicolon is nil, so check
it before using it.
2020-01-14 22:18:17 +01:00
laurensmiers cfe1b4ef3d Handle user defined inline macro's
First squash all multiline macro's, it makes parsing easier. Otherwise
the regex to remove the macro would become more comples if we have to
deal with newlines etc.

When we have a match, we check if the last line in the pre_match is
the beginning of a macro declaration.
If it is, we remove the beginning of this macro
declaration (#define<space>) and remove the body of the macro from the
post_match, which is basically everything until the next newline.
There is a possible edge case (pretty unlikely but still):
if there is no newline in the post_match, meaning it is a macro at the
end of the line, we should delete it as well, hence the '[\n]?' in the
post match regex.
2020-01-14 22:18:17 +01:00
laurens 3254aef5e5 Handle headers which only have inline-function-declarations
This means there is NO opening bracket, since there are no struct
declarations or inline function definitions.
2020-01-14 22:18:17 +01:00
laurens 7a5d712d79 Expand inline function declaration test
Add a random struct in between to make sure we are not touching it
+
multiple newlines are allowed in the function declaration before the
semicolon, add a test to make sure we handle this.
2020-01-14 22:18:17 +01:00
laurens 550e141c59 Handle inline function declarations when mocking inline functions
When a inline function was declared in a file, we would find the
declaration and remove the function body. However, since it is a
declaration, there is NO function body, so we were deleting a random
piece of code that was between square brackets in the file.

To properly handle this, we have to detect if we are dealing with a
function declaration or a function definition.
If we are dealing with a function declaration, a semicolon
will come BEFORE the first square bracket.
If we are dealing with a function definition, a square bracket will
come BEFORE the first semicolon (the first semicolon will be in the
inline function body, so between the square brackets).
So we determine the location of the first semicolon and the first
square bracket after the function name and apply the logic described
above to handle function declarations.

If we are dealing with a function declaration, we don't do anything,
we just move to the next match.
This will result in redeclarations of the inline function, but this is
allowed in C and I'd rather not touch the file anymore than necessary.
2020-01-14 22:16:32 +01:00
laurens 972814622f Some more debug info 2020-01-14 22:15:14 +01:00
laurens c7f24da4f7 Some debug info during inline function parsing 2020-01-14 22:15:14 +01:00
laurens f291ed217c Trying to reproduce bug pull request 2020-01-14 22:15:14 +01:00
Mark VanderVoord bd5fbc30eb Merge pull request #271 from jvcdk/maintenance/update-submodules
Update submodule unity to current master.
2019-12-06 06:10:36 -05:00
Jørn Villesen Christensen 81345af180 Update submodule unity to current master. 2019-12-06 10:15:09 +01:00
mvandervoord 649005a917 Verify multiline functions are being parsed properly. 2019-12-05 09:15:47 -05:00
Mark VanderVoord 1e6634ca93 Merge pull request #270 from michaelbadcrumble/meson_support
Keep Meson support back to 0.50.0:
2019-12-04 06:03:07 -05:00
Michael Brockus ddf9030b9a Keep Meson support back to version 0.50.0 2019-12-03 22:49:15 -08:00
Michael Brockus 532ddd2c3d Update root meson.build 2019-12-03 22:45:39 -08:00
mvandervoord 7035578605 Grab the latest vendor tools 2019-12-03 18:48:28 -05:00
mvandervoord 91d5e578d8 Add support for function pointers using the shorthand notation 2019-11-18 09:09:42 -05:00
Mark VanderVoord 2afdebd228 Merge pull request #268 from jlindgren90/master
Allow arbitrary parentheses within length of array arguments.
2019-11-17 13:18:03 -05:00
John Lindgren 615b3874b8 Allow arbitrary parentheses within length of array arguments.
Previously, CMock would fail to parse a function like this one:

    void broken(uint8_t arg[((uint8_t)8)]);
2019-11-15 16:55:05 -05:00
Mark VanderVoord a6ec9f968a Merge pull request #267 from jlindgren90/master
Revert "Add quick pointer check before memory comparisons (#224)"
2019-11-15 13:11:19 -05:00
John Lindgren 03ddcb9bad Revert "Add quick pointer check before memory comparisons (#224)"
It didn't add direct comparisons only for pointer arguments, but
also other types of arguments like structs, which can't be compared
with '==' and cause a compiler error instead.

To reproduce, just enable the :array plugin in
system/test_interactions/expect_and_return_custom_types.yml:

In function ‘foo’:
error: invalid operands to binary != (have ‘EXAMPLE_STRUCT_T’ {aka
‘struct _EXAMPLE_STRUCT_T’} and ‘EXAMPLE_STRUCT_T’ {aka ‘struct
 _EXAMPLE_STRUCT_T’})
   59 |     if (cmock_call_instance->Expected_a != a) {
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^~

This reverts commit 4df532afcc.
2019-11-15 12:46:28 -05:00
Mark VanderVoord 7dcb78c629 Merge pull request #265 from laurensmiers/master
User provided patterns for inline function mocking
2019-11-15 11:56:32 -05:00
laurens c0162e1ea6 Remove double unit test for inline_function_patterns 2019-11-15 16:25:23 +01:00
laurens 02cf882d36 Update documentation of :inline_function_patterns 2019-11-15 09:34:50 +01:00
laurens cb55b73522 Simplify inline function removal during source/function parsing
- If inlines are included, we don't do anything since they are
  disguised already as normal functions
- If inlines are NOT included, we remove anything that has inline in
  it
2019-11-14 13:38:10 +01:00
laurens 0f6e4604ff Remove inline specific keywords before starting function parsing 2019-11-14 13:37:57 +01:00
laurens 31244992db Add test for including mocks for user defined inline functions
- Failing now
2019-11-14 13:15:39 +01:00
laurens 56bad95cf7 Make test default inline_function_patterns the default value
- Tests that test the user provided patterns should define them in the
  test itself and not rely on the global one being set
2019-11-14 13:06:33 +01:00
laurens d5a8fcb6a2 Add documentation on configuring build system for :treat_includes 2019-11-13 16:21:49 +01:00
laurens 27002370dd Add documentation for :inline_function_patterns 2019-11-13 13:33:19 +01:00
laurens 9bc3f25281 Remove internal regex for inline functions and make them fully user-defined
- We set the defaults but the user is free to add his own.
  This will overwrite our defaults but they will be added to the
  documentation as reference for the user
2019-11-13 13:33:16 +01:00
laurens 8a7c45c20b Take into account user-provided inline function patterns 2019-11-13 12:44:40 +01:00
laurens 73fa7a6bb2 Add unit test for inline_function_patterns (failing now) 2019-11-13 12:28:28 +01:00
laurens 21e37780fa Add :inline_function_patterns configuration option 2019-11-13 12:08:52 +01:00
mvandervoord 543c230f33 bump version 2019-11-12 18:27:33 -05:00
Mark VanderVoord 968d3f6ec4 Merge pull request #263 from laurensmiers/master
Inline function mocking refactor
2019-11-12 18:26:32 -05:00
laurens 0c45d26a28 Rename total_levels to total_pairs
- We are counting pairs of braces, not levels of indentation
2019-11-13 00:03:52 +01:00
laurens 811b85e1b1 Use <counter>.times iso until <condition> 2019-11-13 00:03:30 +01:00
laurens 759d1826c8 Add test with no braces in source
- Should return 0 since no braces in source
2019-11-12 20:28:08 +01:00
laurens 60a1829acf Fix comments 2019-11-12 20:04:30 +01:00
laurens 8ba3ed99a1 Extract count_number_of_pairs_of_braces_in_function method 2019-11-12 20:01:09 +01:00
laurens 0af0e20d15 Refactor transform_inline_functions
- Just looking for static|inline in the gsub is a bit too aggressive.
  Instead, look for the "static inline" and parse it:
  - Everything before the match should just be copied, we don't want
    to touch anything but the inline functions.
  - Remove the implementation of the inline function (this is enclosed
    in square brackets) and replace it with ";" to complete the
    transformation to normal/non-inline function.
  - Copy everything after the inline function implementation

Repeat the above step until we can't find "static inline" anymore

- To remove the inline implementation,
  we count the number of square-bracket 'levels' in the inline function
  and remove every pair. This ensures that constructs like:
  inline void func(void) {
      if (...) {
        //NOP
      }
      else
      {
        //NOP
      }
  }
  will not end up leaving the 'else' keyword unremoved:
  inline void func(void);
      else
  If we count the number of levels, we don't end up in this scenario
  since we remove 3 'pairs', the if-one, the else-one and finally the
  main body.
2019-11-12 20:01:04 +01:00
laurens 2def6c4f21 Fix compile warnings on inline.h test header 2019-11-12 12:10:27 +01:00
Mark VanderVoord d403eb88c8 Merge pull request #258 from jlindgren90/master
Fix compile error when :unity_helper_path is relative.
2019-11-11 08:38:14 -05:00
Mark VanderVoord 18b2deca85 Merge pull request #261 from laurensmiers/master
Inline function mocking
2019-11-11 08:36:21 -05:00
laurens bd91eb4cca Refactor calling of transform_inline_functions
- This way, @normalized_source will always be defined, which it should
  because we are referencing it a few lines down, thanks to
  @mvandervoord for the suggestion
2019-11-11 14:26:29 +01:00
laurens fe829f2d8a Expand transform_inline_functions unit test with more usecases 2019-11-11 13:26:40 +01:00
laurens 5650b79dcd Replace NOP with actual operations to test inline.h compilation 2019-11-11 13:22:00 +01:00
laurens 9908930bc5 Fix multi-line each + use gsub! iso gsub 2019-11-11 13:14:18 +01:00
laurens b256013c5e Only normalize source if treat_inlines is enabled 2019-11-11 13:12:15 +01:00
laurens 927ca1bec0 Extract method to remove_nested_pair_of_braces in cmock_header_parser 2019-11-10 20:55:02 +01:00
laurens e1c6851492 Rename normalize_source to transform_inline_functions 2019-11-10 20:13:35 +01:00
laurens e0a61d484e Add unit tests for normalize_source
- Refactor normalize_source to do the minimum amount that is
  necessary.
  For now, this is just removing inline functions.
2019-11-10 20:11:27 +01:00
laurens 431c5c678a Refactor cleanup actions when normalizing source 2019-11-10 19:35:27 +01:00
laurens 3a07201a3f Add treat_inlines to all_plugins_coexist test 2019-11-10 18:44:20 +01:00
laurens 11dfb9c668 osek.h does not need to be executable 2019-11-10 18:39:35 +01:00
laurens 27e89dd05e Rename treat_inline to treat_inlines 2019-11-10 18:39:35 +01:00
laurens 237c02dade Write converted header file (without inline) to separate file
- This prevents changing the original mock file that is generated,
  it thinks it includes the 'original' header file that is being
  mocked,
  but if we place our newly generated header file in the same
  directory as the mock_<header_file>.h, it will include our newly
  generated header file.
2019-11-10 18:39:20 +01:00
laurens 5ee470d7e4 Convert inline functions in header-mock to 'normal' functions
- normalize_source() will convert the header-to-mock.
  It will look for the inline function definitions and transform them
  into function declarations for non-inline functions.
2019-11-10 18:39:20 +01:00
laurensmiers 79ee5b8419 Add documentation 2019-11-10 18:39:20 +01:00
laurensmiers fba3bc22a2 Some more tests for :treat_include: with extern + some comments 2019-11-10 18:39:20 +01:00
laurensmiers 01536c4a67 Better handling of inline functions with declaration in header 2019-11-10 18:39:20 +01:00
laurensmiers 7a32429bd2 Add handling of treat_inline
- treat_externs only has effect on "extern", not "inline" anymore
- when treat_inline = :include, we remove the "inline" so that the inline functions become 'normal' functions
  - they are handled as as usual and will be mocked
- Add tests to check inline functions are not deleted when treat_inline=:include (and thus mocked)
2019-11-10 18:39:20 +01:00
laurensmiers dbb2f4964c Add treat_inline configuration option 2019-11-10 18:39:20 +01:00
John Lindgren 2817da62db Fix compile error when :unity_helper_path is relative.
Including :unity_helper_path directly doesn't work if the path is
relative and :mock_path is not the same as the working directory.
2019-11-05 15:39:32 -05:00
Mark VanderVoord ee3ae84e64 Merge pull request #257 from art-of-dom/ret-var-name-change
make ret variable more unique to prevent collision with with code under test
2019-11-04 23:21:09 -05:00
Dom Postorivo 0cdc742538 make ret variable more unique to prevent collision with with code under test 2019-11-04 11:23:57 -05:00
Mark VanderVoord c1b1ff6350 Merge pull request #255 from jlindgren90/master
Add documentation for :array_size_type and :array_size_name.
2019-10-30 17:02:27 -04:00
John Lindgren 73afa2973b Add documentation for :array_size_type and :array_size_name.
Closes #253.
2019-10-30 16:20:47 -04:00
mvandervoord db98427231 Verify old parsing issue is gone (see issue #195) 2019-10-30 14:30:18 -04:00
mvandervoord 7615806e34 Address issue #196 to better deal with passing pointer types 2019-10-30 14:10:59 -04:00
Mark VanderVoord 9a0bf38c76 Merge pull request #254 from jlindgren90/master
Fix typo (unity_gelper -> unity_helper)
2019-10-30 12:47:40 -04:00
John Lindgren 277dc34fa1 Fix typo (unity_gelper -> unity_helper). 2019-10-30 12:45:19 -04:00
Mark VanderVoord 9327cd7af1 Merge pull request #252 from jlindgren90/master
Documentation fixes
2019-10-30 11:59:41 -04:00
Mark VanderVoord 71b4ec2088 Merge pull request #249 from michaelbadcrumble/meson_support
Upgrade Meson version too 0.52.0
2019-10-30 11:57:32 -04:00
John Lindgren 639d4120d1 Documentation fixes. 2019-10-30 11:56:43 -04:00
Mark VanderVoord 16900b4b7f Merge pull request #251 from jlindgren90/master
Fix minor memory-management bugs
2019-10-30 11:54:45 -04:00
mvandervoord 14d57c2e93 Update to latest Unity 2019-10-30 10:34:37 -04:00
John Lindgren c787042e6d Fix off-by-one error in out-of-memory check.
We should be able to allocate up to CMock_Guts_MemBytesFree() minus
CMOCK_MEM_INDEX_SIZE.  An incorrect less-than-or-equal prevented
allocating the very last byte.
2019-10-30 10:30:25 -04:00
John Lindgren ea71fb0e0e CMock_Guts_MemBytesUsed() should return 0 initially.
Set CMock_Guts_FreePtr to CMOCK_MEM_ALIGN_SIZE initially (the same
value it is reset to by CMock_Guts_MemFreeAll().  This makes sure
that the value returned by CMock_Guts_MemBytesUsed() is 0 initially
and not a negative value.
2019-10-30 10:22:05 -04:00
John Lindgren 74fa13f6a0 CMOCK_MEM_ALIGN should not change depending on #include order.
The value of CMOCK_MEM_ALIGN changed depending on whether unity.h
or cmock.h was included first.  Since cmock_internals.h uses
features from unity.h, it should include unity.h.
2019-10-30 10:14:30 -04:00
mvandervoord bb3e821eb2 Verify that void* is treated as a bytewise array comparison. 2019-10-28 07:30:51 -04:00
mvandervoord 4946aaac37 Update to latest Unity 2019-10-24 15:45:45 -04:00
mvandervoord cda809765e Protect again memory overruns.
Get rid of warnings.
2019-10-23 17:12:18 -04:00
Mark VanderVoord 8f1156dddc latest 2019-10-23 16:38:59 -04:00
Mark VanderVoord a210abdd12 Merge branch 'master' of https://github.com/ThrowTheSwitch/CMock
* 'master' of https://github.com/ThrowTheSwitch/CMock:
  Fixed an error.
2019-10-23 16:37:36 -04:00
Mark VanderVoord 10e8cc27eb Add resetTest to documentation 2019-10-23 16:36:59 -04:00
mvandervoord b2e312e434 Fixed an error. 2019-10-23 16:03:42 -04:00
Mark VanderVoord 741b1067a3 ExpectAnyArgs should not be generated for functions with no arguments (#201) 2019-10-23 15:51:22 -04:00
mvandervoord b37b3cd86b Removing mac testing from Travis because Travis is always breaking it. *sigh* 2019-10-23 08:15:40 -04:00
Mark VanderVoord abec576fdb bump version of ruby run by travis 2019-10-21 11:23:39 -04:00
Mark VanderVoord b90706424a Switching to universal version being in the header file itself. 2019-10-21 10:13:19 -04:00
Michael Brockus 2ff29226e8 Upgrade Meson version too 0.52.0
Simply bumping Meson build support version 0.52.0
2019-10-12 09:22:31 -07:00
Mark VanderVoord bc8e20e88d Merge pull request #246 from michaelbadcrumble/meson_support
Add Meson support in CMock.
2019-09-26 08:50:27 -04:00
Mark VanderVoord c5becef9fd Merge pull request #243 from jlindgren90/expect-any-args-cleanup
Replace IgnoreMode with ExpectAnyArgsBool (no functional change).
2019-09-26 08:31:05 -04:00
Michael Brockus d2c5df2f5e Adding meson.build script at root directory. 2019-09-20 16:51:15 -07:00
Michael Brockus 0e9f8c54bc Created sub meson.build in source directory. 2019-09-20 16:25:04 -07:00
John Lindgren b76d570d4a Replace IgnoreMode with ExpectAnyArgsBool (no functional change).
IgnoreMode was used only for the ExpectAnyArgs plugin, and the
semantics of it were backwards:

  - IgnoreMode = CMOCK_ARG_NONE means to ignore all arguments
  - IgnoreMode = CMOCK_ARG_ALL means to verify all arguments

ExpectAnyArgsBool should make the purpose and semantics of this
field clearer.

Additionally, ExpectAnyArgs doesn't use FinalReturn for anything.
2019-09-16 13:28:14 -04:00
Mark VanderVoord c23c01266a We need function prototypes to comply with strict compiler settings 2019-09-09 16:32:39 -04:00
Mark VanderVoord e17728fe4d Minor tweaks to overcome Ruby style warnings. 2019-09-09 14:46:14 -04:00
Mark VanderVoord 37be90bd96 Add another test for function pointers which should be ignored. 2019-09-09 11:12:27 -04:00
Mark VanderVoord 533ae7a7b1 Merge pull request #236 from jlindgren90/redundant-destroy
callback's mock_destroy() is redundant.
2019-09-09 11:02:06 -04:00
Mark VanderVoord 582e0f87cf Reworked naming of the new divided callback functionality to better reflect what is happening and avoid another use of the word Ignore. 2019-09-09 11:00:09 -04:00
Mark VanderVoord 5e9264f993 Merge pull request #237 from jlindgren90/ignore-with-callback-2
Add CheckWithCallback and IgnoreWithCallback.
2019-09-09 10:44:54 -04:00
Mark VanderVoord 6ae662f2e8 Update documentation for clarity.
Grab latest Unity
2019-09-09 10:32:42 -04:00
Mark VanderVoord e1f7c35f2e Merge pull request #241 from jlindgren90/expect-details
Expect plugin should call UNITY_SET/CLR_DETAILS in pairs.
2019-09-03 11:07:03 -04:00
John Lindgren b895a4575a Expect plugin should call UNITY_SET/CLR_DETAILS in pairs.
The generated _Expect() functions called UNITY_CLR_DETAILS, which was
unnecessary because they did not call UNITY_SET_DETAIL.

The generated _Verify() functions called UNITY_SET_DETAIL but never
called UNITY_CLR_DETAILS to clean up after themselves.
2019-08-30 12:14:11 -04:00
Mark VanderVoord e17180b2ef Merge pull request #240 from edgarholleis/master
Improve comment suppression to cope with '/*xxx*//*yyy*/'.
2019-08-22 06:21:22 -04:00
Edgar J Holleis 23d2341c4c Improve comment suppression to cope with '/*xxx*//*yyy*/'. 2019-08-22 10:58:13 +02:00
John Lindgren 5f2ae0ee0f Update documentation 2019-07-24 13:55:04 -04:00
John Lindgren c70cec0b19 Add CheckWithCallback and IgnoreWithCallback.
StubWithCallback can currently be configured to run the callback
function either before or after argument+ordering checks, based on
:callback_after_arg_check.  Currently, however, you can't use both
behaviors in the same test suite; you have to pick one.

This change makes both behaviors available under two new names:
 - IgnoreWithCallback, as if :callback_after_arg_check = false
 - CheckWithCallback, as if :callback_after_arg_check = true

StubWithCallback simply becomes an alias (#define) for either
IgnoreWithCallback or CheckWithCallback, depending on config.
2019-07-24 13:36:41 -04:00
John Lindgren fbb0828ee0 callback's mock_destroy() is redundant.
create_mock_destroy_function() in cmock_generator.rb already clears
the entire mock to 0 (using memset) before call the plugin's
mock_destroy() function.  So mock_destroy() in the callback plugin
is doing work that was already done.
2019-07-24 12:05:50 -04:00
John Lindgren f8281e456d callback's mock_destroy() is redundant.
create_mock_destroy_function() in cmock_generator.rb already clears
the entire mock to 0 (using memset) before call the plugin's
mock_destroy() function.  So mock_destroy() in the callback plugin
is doing work that was already done.
2019-07-24 11:43:44 -04:00
John Lindgren 8b4deef12b Call UNITY_CLR_DETAILS() before returning from mock 2019-07-23 17:41:28 -04:00
John Lindgren 9e5afe4255 Refactor callback generator a bit (no functional change) 2019-07-23 17:14:33 -04:00
Mark VanderVoord 4df532afcc Add quick pointer check before memory comparisons (#224) 2019-07-09 23:16:02 -04:00
Mark VanderVoord 12c74c0349 Keep function pointers from choking CMock (fixes issues #102, #222, #226) 2019-07-09 22:23:40 -04:00
Mark VanderVoord 4c6fe35bbf Clean up full header list. (Why didn't this get caught in my local tests?) 2019-07-09 11:14:10 -04:00
Mark VanderVoord 4ab728b6d3 Whoops 2019-07-09 10:57:31 -04:00
Mark VanderVoord 7761b3fb3f automatically pull in unity helper into tests when specified in both example and cmock's includes. 2019-07-09 10:50:29 -04:00
Mark VanderVoord 0b6118e410 Merge pull request #186 from jlindgren90/master
mock_Verify functions should ideally not modify the state of the mock.
2019-07-07 15:12:07 -04:00
Mark VanderVoord d5dffde17d Merge pull request #187 from jlindgren90/array-typedefs
Add treat_as_array configuration option.
2019-07-07 15:10:18 -04:00
Mark VanderVoord 347dfc181a Merge branch 'master' into array-typedefs 2019-07-07 15:06:49 -04:00
Mark VanderVoord 4a6ee8680c Merge pull request #190 from achsfy/master
Detect array_data,array_size pattern when generating mock
2019-07-07 14:51:21 -04:00
Mark VanderVoord f909378a1d Clean up example makefile to properly support externally supported paths. (This is a tiny fix to PR 193) 2019-07-07 14:43:20 -04:00
Mark VanderVoord 035141e2ab - Added capacity accessor for easier testing
- Made test size-agnostic for easier boundary checking.
2019-07-07 14:15:35 -04:00
Mark VanderVoord 5eab75a078 Reimplement PR 227 with fixed tests. 2019-07-06 12:11:56 -04:00
Mark VanderVoord 99c2223a1d Back out broken changes. (See issue #210. Thanks @HamboLagos) 2019-07-03 11:09:06 -04:00
Mark VanderVoord 4b35cb2e43 Merge pull request #198 from Xenoamor/master
Fix bug where if folder "mocks" doesn't exist it fails
2019-03-22 05:47:44 -04:00
Mark VanderVoord e417f323fc Merge pull request #211 from merazmus/fix_missing_header
Fix missing framework header in mock header files
2019-03-22 05:41:23 -04:00
merazmus af59c531f7 Update unit tests 2019-03-22 09:11:58 +01:00
merazmus a5616dc2df Fix missing framework header in mock header files 2019-03-22 09:10:16 +01:00
Joshua Booth 5716454e11 Merge branch 'master' of https://github.com/Xenoamor/CMock 2019-03-21 19:08:45 +00:00
Xenoamor 80454dc1f3 Fix bug where if folder mocks doesn't exist it fails 2019-03-21 19:08:26 +00:00
Mark VanderVoord 2b93dfdd1d Merge pull request #208 from art-of-dom/travis-fix
Adjusted travis to use ruby 2.3 to make OSX build pass
2019-03-20 05:56:56 -04:00
Dom Postorivo 727a5cc8a8 adjusted travis to use ruby 2.3 to make OSX build pass 2019-03-20 00:00:41 -04:00
Mark VanderVoord c243b9a7a7 Merge pull request #203 from bmcdonnell/grammar
Grammar fix--"fewer times", not "less times"
2019-03-01 22:27:53 -05:00
Brendan McDonnell b409ba6a1d Grammar fix--"fewer times", not "less times" 2019-03-01 21:52:12 -05:00
Xenoamor b2adf60b2f Fix bug where if folder mocks doesn't exist it fails 2019-01-28 15:53:33 +00:00
John Lindgren cfa46d6440 Prevent undefined behavior due to typedef array usage. 2018-12-04 18:22:53 -05:00
John Lindgren 789c5852b5 Add treat_as_array configuration option. 2018-12-04 18:18:43 -05:00
Mark VanderVoord 99fa519136 Merge pull request #194 from danyeaw/license-detection
Move license for GitHub detection (Thanks @danyeaw !)
2018-11-13 21:13:58 -05:00
Dan Yeaw 0706e8b355 Move license for GitHub detection 2018-11-13 21:11:15 -05:00
Aurelien CHAPPUIS 8d16dca722 Update cmock_header_parser_test.rb tests to include new configuration items array_size_type and array_size_name 2018-09-18 15:06:10 +02:00
Aurelien CHAPPUIS e8c7ad9706 Try to find 'array pair' in parameters following this pattern : <type> * <name>, <@array_size_type> <@array_size_name>
When such a pattern is used, the second parameter is used as the array size in _Expect method.
2018-09-18 12:06:40 +02:00
John Lindgren 63527a3217 mock_Verify functions should ideally not modify the state of the mock.
In typical unit tests, this doesn't matter since the Verify functions
are called only from the end of the test.  However, in longer integration
tests, where a sequence of function calls is to be tested, it's handy
to be able to verify the Expects halfway through the test.  This change
is a first step in making that possible.
2018-08-28 14:51:41 -04:00
Mark VanderVoord 7cc41ddfdd Merge pull request #172 from Vicentra/Issue66
Fix alignment error of CMock_Guts_Buffer (Thanks @jmzeeman !)
2018-08-08 13:37:03 -04:00
Mark VanderVoord 407c2ef3b9 Grab latest unity to test as next release candidate 2018-08-08 13:21:00 -04:00
Mark VanderVoord 5edf07e87c Update travis to use a proper gem version for rubocop 2018-07-18 10:40:48 -04:00
Mark VanderVoord 7c6552bb2f Merge pull request #179 from Xenoamor/master
Add "cd test" to README.md for running rake (Thanks!)
2018-07-18 09:15:17 -04:00
Xenoamor ab339721ae Add "cd test" to README.md for running rake
Running rake from the project root directory generates the error: "No Rakefile found"
2018-07-18 14:05:55 +01:00
Matthijs Zeeman 732556700d Fix alignment error of CMock_Guts_Buffer
Changed allocation to use CMOCK_MEM_INDEX_TYPE instead of unsigned char. This may allocate extra memory if CMOCK_MEM_SIZE  is not a multiple of CMOCK_MEM_INDEX_SIZE. Had to substitute CMock_Guts_Buffer with a define in this case because  pointers are not constants.
2018-06-21 11:33:13 +02:00
Mark VanderVoord c3a95e93be Merge pull request #155 from paulsc/master
Fix for issue #154 (rusty or not, it works! Thanks @paulsc )
2017-12-07 06:41:23 -05:00
Paul 49bc3ebcce fix for mock prefix & suffix filter 2017-12-07 09:08:29 +01:00
Mark VanderVoord cb1ad78b97 Update to latest Unity and Post as release 2017-11-14 16:31:44 -05:00
Mark VanderVoord 2b4f9b43c7 Merge pull request #148 from jlindgren90/master
Fix warnings when running "rake test" -- Thanks @jlindgren90 !
2017-11-01 08:26:00 -04:00
Mark VanderVoord 2a2f19dfae Merge pull request #153 from phonetagger/master
Do not change CMock_Guts_Buffer or CMock_Guts_BufferSize unless
2017-11-01 06:43:43 -04:00
Mark VanderVoord e42996ea67 Let's simplify this testing situation a bit. 2017-10-31 21:49:04 -04:00
Minich b9da6d6def Do not change CMock_Guts_Buffer or CMock_Guts_BufferSize unless
realloc() was successful. Prior to this change, if realloc() failed, the
current test would fail for out-of-memory, but subsequent tests would
continue trying to run with CMock_Guts_Buffer at address 0x00000000 and
thinking that the buffer size was sufficient. Therefore depending on the
system and how it handles (or doesn't handle) null pointer
dereferencing, subsequent tests might pass, fail in strange ways, or
crash the test app.
2017-10-31 12:03:31 -04:00
Mark VanderVoord 0fc09121d7 Merge pull request #152 from metc/bugfix/doc
Bugfix/doc Thanks @metc !
2017-10-06 12:53:34 -04:00
Christopher Métrailler 4df347bf17 Fixed 404 link in documentation. 2017-10-06 18:35:24 +02:00
Christopher Métrailler e765181c8d Remove trailing slashes. 2017-10-06 18:30:49 +02:00
John Lindgren 6d1c0f97f5 Fix Minitest deprecation warnings.
assert_equal() doesn't like to be passed nil any more.
2017-09-14 09:40:48 -04:00
John Lindgren 488c469cdf Fix Ruby warnings (mostly unused variables). 2017-09-14 09:40:48 -04:00
Mark VanderVoord 3df5c035e6 Merge pull request #149 from SteinHeselmans/master
fix #147: Push and Pop pragmas not supported by older GCC
2017-09-14 06:50:11 -04:00
Stein Heselmans 1f87c158da Adapt test cases to new header/footer 2017-09-14 10:43:43 +02:00
Stein Heselmans 76b6231f77 Merge remote-tracking branch 'origin/master' into issue-147 2017-09-14 08:14:58 +02:00
Stein Heselmans ca05fe4285 Fix #147: Push and Pop pragmas not supported by older GCC
Solution: check GCC compiler version to be at least 4.6 before enabling
pragma diagnostic push/pop
2017-09-14 08:13:17 +02:00
Mark VanderVoord 37fcb8535a Merge pull request #146 from jlindgren90/master
Fix handling of pointer-to-constant return values (Thanks @jlindgren90 !)
2017-09-13 06:53:02 -04:00
John Lindgren 526668961a Add an additional test for handling of pointer arguments. 2017-09-12 17:24:35 -04:00
John Lindgren 3b123fb533 Don't assume that pointer-to-constant types have "const" removed.
1. Update treat_as table to include pointer-to-constant types.
2. Remove unnecessary casts in assignments and return statements.
3. Improve logic for adding "const" to types of function arguments.
4. It's no longer necessary to prepend "const" to function return type.
2017-09-12 15:54:47 -04:00
John Lindgren c725e4ddc6 Handle pointer-to-constant types more consistently.
725bfd93a0 fixed handling of pointer-to-constant types in function
arguments but did not apply the same fix to function return types.
Unify the logic in a parse_type_and_name() function that is used
for both arguments and return types.  Update tests.
2017-09-12 13:02:08 -04:00
Mark VanderVoord 6e03886f25 Prepare to publish latest version 2017-09-11 15:51:44 -04:00
Mark VanderVoord 50adf82ed4 Merge pull request #144 from jlindgren90/master
Merge pull request #136 and fix merge conflicts (Thanks @jlindgren90 and @phonetagger !)
2017-09-11 15:05:13 -04:00
Mark VanderVoord f2ea4284a6 Merge pull request #145 from SteinHeselmans/master
Add suffix support to create_makefile (Thanks @SteinHeselmans and @Letme !)
2017-09-11 15:04:00 -04:00
Stein Heselmans fb96bb3033 Try to fix CI 2017-09-11 19:45:42 +02:00
Stein Heselmans 9a44444f8b Revert "Fix path issue in create makefile"
This reverts commit 725641409b.
2017-09-11 14:46:45 +02:00
Stein Heselmans 725641409b Fix path issue in create makefile 2017-09-11 14:25:14 +02:00
Stein Heselmans c4cd7d54a9 create_makefile : add support for suffix 2017-09-11 14:24:40 +02:00
Mark VanderVoord aed11e6d0d Add tests to prove that ignore and expects interoperate quite well. 2017-09-08 17:01:56 -04:00
Mark VanderVoord 51b327042f Merge in latest Unity 2017-09-08 15:49:59 -04:00
John Lindgren ef04f4ab7f Fix recent const changes to account for special (char*) handling. 2017-09-08 15:20:57 -04:00
John Lindgren 27c5a9cff5 Merge remote-tracking branch 'phonetagger/improve-const-ptr-handling' 2017-09-08 15:20:34 -04:00
Mark VanderVoord 43fa31380d - Renamed :strict_mock_calling option to :fail_on_unexpected_calls for clarity. 2017-09-08 14:54:55 -04:00
Mark VanderVoord 413c803543 Merge pull request #120 from shreyasbharath/fix-multi-threading-bug
Fixed race condition that occurs when 'requiring' plugins (Thanks @shreyasbharath !)
2017-09-08 13:12:55 -04:00
Mark VanderVoord ee45a7b1e7 Merge pull request #123 from skelliam/fixoutput
Bugfixes + improvements in makefile-based scripts (Thanks @skelliam !)
2017-09-08 13:08:27 -04:00
Mark VanderVoord 699563e503 Merge pull request #140 from jlindgren90/master
Remove dead code (unity_msg is not used since 647876644b). (Thanks @jlindgren90 )
2017-09-08 13:05:31 -04:00
Mark VanderVoord 454fcfb7a3 Merge pull request #141 from jlindgren90/fix-const-parsing
Fix const determination for pointer-to-pointer types. (Thanks John! (@jlindgren90) )
2017-09-08 13:03:27 -04:00
Mark VanderVoord 4b441eafea Merge pull request #143 from laurensmiers/master
Add 'strict_mock_calling' option (Thanks @laurensmiers for your work, and thanks @snke for your helpful input!)
2017-09-08 09:25:12 -04:00
laurensmiers a04e3f160c Expand docs with 'strict_mock_calling' option 2017-09-07 12:28:18 +02:00
laurensmiers df7c67c445 Fix 'should' text 2017-09-06 14:39:28 +02:00
laurensmiers 9c9f08c48b Add 'strict_mock_calling' option
- By default set to true to maintain the default behaviour of CMock
  - When mocked function is called and no Except/Ignor called,
    test will fail
- When set to false:
  - if test calls mocked function,
    and user did not specify Except/Ignore/...
    test will not fail because of this,
    all calls to mocked functions are ignored
2017-09-06 00:28:37 +02:00
John Lindgren 55462aef40 Fix parsing of declarations like "int const* doStuff(void)".
The "const" in this case was not correctly stripped from the return type,
leading to a double const in generated typedefs, i.e.:

  typedef const int const* (* doStuff_CALLBACK)(int cmock_num_calls);

Add a test for these cases.
2017-09-01 12:30:11 -04:00
John Lindgren 42dab4836d Fix handling of string arguments.
Since 2f0a44d7ce, string arguments were being tested with
UNITY_TEST_ASSERT_EQUAL_PTR, not UNITY_TEST_ASSERT_EQUAL_STRING.
Before that change, we would call divine_ptr(arg_type) where
arg_type had the argument name stripped, i.e. "const char *".
Now we are passing it the name as well, i.e. "const char *str"
and it was not prepared to handle that.
2017-08-31 17:44:08 -04:00
John Lindgren 693c658780 Fix const determination for pointer-to-pointer types.
For example, consider: void function(const int **ret_ptr).
This function stores a (const int *) at the address passed in.
We'd want to test it with function_ReturnThruPtr_ret_ptr, but
CMock was incorrectly considering the (const int **) a constant
argument, and thus did not generate the ReturnThruPtr function.

Add a test to ensure that all permutations of constants and
pointers work as expected.
2017-08-31 16:33:21 -04:00
John Lindgren 7eb7e14fbc Remove trailing whitespace. 2017-08-30 16:03:45 -04:00
John Lindgren 846423768b Fix whitespace checking in tests. 2017-08-30 16:01:11 -04:00
John Lindgren 9e69cfb9b1 Remove an extra newline. 2017-08-30 15:50:20 -04:00
John Lindgren 53d6a7c0e4 Remove a commented-out function (it confuses yard otherwise). 2017-08-30 15:49:14 -04:00
John Lindgren a604fb71a4 Remove dead code (unity_msg is not used since 647876644b). 2017-08-30 10:28:53 -04:00
Mark VanderVoord 46f609efee Merge pull request #139 from snke/master
Minor fixes for the CMock summary (Thanks Simon!)
2017-08-23 06:39:54 -04:00
Simon Kuhnle 5ee669ecc0 Fix minor typos in CMock summary 2017-08-23 09:22:42 +02:00
Simon Kuhnle 02aeab8fef Link to examples directory in CMock summary 2017-08-23 09:21:01 +02:00
Mark VanderVoord 9e33ff32cf Merge pull request #138 from jlindgren90/patch-1
Fix typo (typepdef/typedef) THANKS!
2017-08-22 14:43:31 -04:00
John Lindgren 295fe3be4e Fix typo (typepdef/typedef) 2017-08-22 12:26:45 -04:00
phonetagger 73a6aa003b Oops, removed duplicate line. 2017-08-22 11:28:27 -04:00
phonetagger 725bfd93a0 On some embedded platforms (real or simulated), when RAM and ROM are separate address spaces or RAM pointers are smaller than ROM pointers, the C keyword 'const' may (depending on compiler) be critical for differentiating between assembly code pointer types without having to use compiler-specific attribute flags to pick which address space a pointer refers to. (E.g. the M16C/R8C IAR C/C++ compiler in the Near (default) data model, where 'const char*' is a 3-byte pointer that can point anywhere in ROM or RAM, but 'char*' is a 2-byte pointer that can only point to RAM.)
This change causes CMock to preserve 'const' in argument types so that pointers-to-const continue to point to const data in the mocked code, while still removing the 'const' attribute from the pointers themselves.
2017-08-21 19:12:48 -04:00
Mark VanderVoord 0b303dba29 Support version 1.9.3 again (with slightly less awesome brace matching) 2017-08-18 23:46:15 -04:00
Mark VanderVoord c61a35d2a5 Merge pull request #131 from trond-snekvik/gcc_diags_fix
Push and pop GCC diagnostics to maintain scope for changed warning flags (Awesome! Thanks so much for the fix!)
2017-08-03 06:34:34 -04:00
Trond Einar Snekvik 1ffba4383c Update test header and footer to match updated contents 2017-08-03 10:08:22 +02:00
krsk 08b255868a Push and pop GCC diagnostics to maintain scope for changed warning flags 2017-08-02 13:14:09 +02:00
William Skellenger f0a9b5930e Exclude headers that start with mock_ from analysis 2017-05-04 13:15:54 -04:00
William Skellenger 33dabf8338 Without having 'test' in the results extension we cannot generate junit results,
becuase the unity_to_junit.py script (and others) look for *.result*
2017-05-04 10:07:06 -04:00
William Skellenger 7cd25b07a1 Fix problem of getting .results files with zero length 2017-05-04 09:36:12 -04:00
balaksh b58f15d0be Fixed race condition that occurs when 'requiring' plugins 2017-05-02 10:29:16 +12:00
Mark VanderVoord 58971b15db Merge pull request #117 from skelliam/mods
Leverage TEST_FILE directives when using create_makefile.rb.  Also carry over parent INCLUDE_PATH and LDFLAGS.
2017-05-01 08:57:15 -04:00
William Skellenger 4bda2b21d4 Use TEST_FILE directive in test files if it exists 2017-04-26 14:23:05 -04:00
William Skellenger 14ba424b02 Use LDFLAGS during linking if they exist. I am doing this because I want to link with code coverage options. 2017-04-26 12:54:22 -04:00
William Skellenger 6dff24ecda Use curly braces
Also replace hardcoded -DTEST with TEST_CFLAGS
2017-04-21 14:50:47 -04:00
William Skellenger 4bd12aaaf6 Add INCLUDE_PATH -- for larger projects this is necessary 2017-04-21 14:48:24 -04:00
231 changed files with 11201 additions and 3481 deletions
+13
View File
@@ -0,0 +1,13 @@
github: ThrowTheSwitch
#patreon: # Replace with a single Patreon username
#open_collective: # Replace with a single Open Collective username
#ko_fi: # Replace with a single Ko-fi username
#tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
#community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
#liberapay: # Replace with a single Liberapay username
#issuehunt: # Replace with a single IssueHunt username
#lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
#polar: # Replace with a single Polar username
#buy_me_a_coffee: # Replace with a single Buy Me a Coffee username
#thanks_dev: # Replace with a single thanks.dev username
#custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
+52
View File
@@ -0,0 +1,52 @@
---
# Continuous Integration Workflow: Test case suite run + validation build check
name: CI
# Controls when the action will run.
# Triggers the workflow on push or pull request events but only for the master branch
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
# Job: Unit test suite
unit-tests:
name: "Unit Tests"
runs-on: ubuntu-latest
strategy:
matrix:
ruby: ['3.0', '3.1', '3.2', '3.3']
steps:
# Install Multilib
- name: Install Multilib
run: |
sudo apt-get update -qq
sudo apt-get install --assume-yes --quiet gcc-multilib
# Checks out repository under $GITHUB_WORKSPACE
- name: Checkout Latest Repo
uses: actions/checkout@v2
with:
submodules: recursive
# Setup Ruby Testing Tools to do tests on multiple ruby version
- name: Setup Ruby Testing Tools
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
# Install Ruby Testing Tools
- name: Setup Ruby Testing Tools
run: |
sudo gem install rspec
sudo gem install rubocop -v 1.57.2
sudo gem install bundler
bundle update
bundle install
# Run Tests
- name: Run All Unit Tests
run: |
cd test && rake ci
+2
View File
@@ -1,8 +1,10 @@
test/system/build
test/system/generated
*.sublime-project
*.sublime-workspace
Gemfile.lock
.rake_t_cache
.DS_Store
*.swp
examples/make_example/build
examples/temp_sensor/build
+4 -4
View File
@@ -1,8 +1,8 @@
[submodule "vendor/unity"]
path = vendor/unity
url = https://github.com/throwtheswitch/unity.git
branch = master
[submodule "vendor/c_exception"]
path = vendor/c_exception
url = https://github.com/throwtheswitch/cexception.git
branch = master
[submodule "vendor/unity"]
path = vendor/unity
url = https://github.com/throwtheswitch/unity.git
branch = master
-29
View File
@@ -1,29 +0,0 @@
language: ruby
os:
- osx
- linux
rvm:
- "2.0.0"
- "2.2.2"
before_install:
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then rvm install 2.1 && rvm use 2.1 && ruby -v; fi
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install --assume-yes --quiet gcc-multilib; fi
install:
- bundle install
- gem install rspec
- gem install rubocop
script:
- cd test && rake ci
- cd ..
- cd examples && cd make_example
- make clean
- make setup
- make test
- cd ..
- cd temp_sensor
- rake ci
-8
View File
@@ -1,9 +1 @@
source "http://rubygems.org/"
gem "bundler", "~> 1.1.rc.7"
gem "rake", ">= 0.9.2.2"
gem "minitest"
gem "require_all"
gem "constructor"
gem "diy"
+3 -1
View File
@@ -1,4 +1,6 @@
Copyright (c) 2007-14 Mike Karlesky, Mark VanderVoord, Greg Williams
The MIT License (MIT)
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
+38 -16
View File
@@ -1,32 +1,54 @@
CMock - Mock/stub generator for C
=================================
CMock ![CI](https://github.com/ThrowTheSwitch/CMock/workflows/CI/badge.svg)
=====
[![CMock Build Status](https://api.travis-ci.org/ThrowTheSwitch/CMock.png?branch=master)](https://travis-ci.org/ThrowTheSwitch/CMock)
CMock is a mock and stub generator and runtime for unit testing C. It's been designed
to work smoothly with Unity Test, another of the embedded-software testing tools
developed by ThrowTheSwitch.org. CMock automagically parses your C headers and creates
useful and usable mock interfaces for unit testing. Give it a try!
If you don't care to manage unit testing builds yourself, consider checking out Ceedling,
a test-centered build manager for unit testing C code.
- [Known Issues](docs/CMockKnownIssues.md)
- [Change Log](docs/CMockChangeLog.md)
Getting Started
================
===============
If you're using Ceedling, there is no need to install CMock. It will handle it for you.
For everyone else, the simplest way is to grab it off github. You can also download it
as a zip if you prefer. The Github method looks something like this:
Your first step is to get yourself a copy of CMock. There are a number of ways to do this:
1. If you're using Ceedling, there is no need to install CMock. It will handle it for you.
2. The simplest way is to grab it off github. The Github method looks something like this:
> git clone --recursive https://github.com/throwtheswitch/cmock.git
> cd cmock
> bundle install # Ensures you have all RubyGems needed
3. You can also grab the `zip` file from github. If you do this, you'll also need to grab yourself a
copy of Unity and CException, because github unfortunately doesn't bake dependencies into the zip
files.
Contributing to this Project
============================
If you plan to help with the development of CMock (or just want to verify that it can
perform its self tests on your system) then you can enter the test directory and then
ask it to test:
> rake # Run all CMock self tests
perform its self tests on your system) then you can grab its self-testing dependencies,
then run its self-tests:
> cd cmock
> bundle install # Ensures you have all RubyGems needed
> cd test
> rake # Run all CMock self tests
Before working on this project, you're going to want to read our guidelines on
[contributing](docs/CONTRIBUTING.md).
API Documentation
=================
* Not sure what you're doing?
* [View docs/CMock_Summary.md](docs/CMock_Summary.md)
* Interested in our MIT-style license?
* [View docs/license.txt](docs/license.txt)
* Interested in our MIT license?
* [View docs/license.txt](LICENSE.txt)
* Are there examples?
* They are all in [/examples](examples/)
* Any other resources to check out?
+34
View File
@@ -0,0 +1,34 @@
# -*- encoding: utf-8 -*-
$LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), 'lib'))
require "lib/cmock_version"
require 'date'
Gem::Specification.new do |s|
s.name = "cmock"
s.version = CMockVersion::GEM
s.platform = Gem::Platform::RUBY
s.authors = ["Mark VanderVoord", "Michael Karlesky", "Greg Williams"]
s.email = ["mark@vandervoord.net", "michael@karlesky.net", "barney.williams@gmail.com"]
s.homepage = "http://throwtheswitch.org/cmock"
s.summary = "CMock is a mocking framework for C unit testing. It's a member of the ThrowTheSwitch.org family of tools."
s.description = <<-DESC
CMock is a mocking framework for C unit testing. It accepts header files and generates mocks automagically for you.
DESC
s.licenses = ['MIT']
s.metadata = {
"homepage_uri" => s.homepage,
"bug_tracker_uri" => "https://github.com/ThrowTheSwitch/CMock/issues",
"documentation_uri" => "https://github.com/ThrowTheSwitch/CMock/blob/master/docs/CMock_Summary.md",
"mailing_list_uri" => "https://groups.google.com/forum/#!categories/throwtheswitch/cmock",
"source_code_uri" => "https://github.com/ThrowTheSwitch/CMock"
}
s.required_ruby_version = ">= 3.0.0"
s.files += Dir['**/*']
s.test_files = Dir['test/**/*']
s.executables = ['lib/cmock.rb']
s.require_paths = ["lib"]
end
+10 -11
View File
@@ -1,14 +1,13 @@
# ==========================================
# CMock Project - Automatic Mock Generation for C
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
# [Released under MIT License. Please refer to license.txt for details]
# ==========================================
# =========================================================================
# CMock - Automatic Mock Generation for C
# ThrowTheSwitch.org
# Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
# SPDX-License-Identifier: MIT
# =========================================================================
# Setup our load path:
[
'lib',
[
'lib'
].each do |dir|
$LOAD_PATH.unshift( File.join( File.expand_path(File.dirname(__FILE__)) + '/../', dir) )
$:.unshift(File.join("#{__dir__}//..//", dir))
end
+7 -6
View File
@@ -1,8 +1,9 @@
# ==========================================
# CMock Project - Automatic Mock Generation for C
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
# [Released under MIT License. Please refer to license.txt for details]
# ==========================================
# =========================================================================
# CMock - Automatic Mock Generation for C
# ThrowTheSwitch.org
# Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
# SPDX-License-Identifier: MIT
# =========================================================================
# Setup our load path:
[
@@ -12,5 +13,5 @@
'./vendor/unity/auto/',
'./test/system/'
].each do |dir|
$LOAD_PATH.unshift( File.join( File.expand_path(File.dirname(__FILE__) + "/../"), dir) )
$:.unshift(File.join(File.expand_path("#{File.dirname(__FILE__)}//..//"), dir))
end
+166
View File
@@ -0,0 +1,166 @@
# CMock - Change Log
## A Note
This document captures significant features and fixes to the CMock project core source files
and scripts. More detail can be found in the history on Github.
This project is now tracking changes in more detail. Previous releases get less detailed as
we move back in histroy.
Prior to 2012, the project was hosted on SourceForge.net
Prior to 2008, the project was an internal project and not released to the public.
## Log
### CMock 2.6.0 (January 2025)
New Features:
- Reintroduced option to run CMock without setjmp (slightly limited)
- Significant speed improvements to parsing
Significant Bugfixes:
- Make return-thru-pointer calls const
- Fix handling of static inlines
- Fix some situations where parenthetical statements were misinterpreted as functions
- Fix error in skeleton creation
- Improvements towards making generated code fully C-compliant and warning free
Other:
- Improve error message wording where possible
- Improve documentation
- Updated to Ruby 3.0 - 3.3
- Reintroduce matrix testing across multiple Ruby versions
### CMock 2.5.3 (January 2021)
New Features:
- Support mocks in sub-folders
- Improved handling of static and inline functions
- Stateless Ignore plugin added
Significant Bugfixes:
- Allow setting values to empty at command prompt
- Improvements towards making generated code fully C-compliant and warning free
Other:
- Really basic mocking of cpp files (like C files with extern C)
### CMock 2.5.2 (May 2020)
Significant Bugfixes:
- Fix whitespace errors
- Fix Stop Ignore
### CMock 2.5.1 (April 2020)
New Features:
- Add StopIgnore function to Ignore Plugin
- Add ability to generate skeleton from a header.
- Inline functions now have option to remove and mock (with Ceedling's help)
Significant Bugfixes:
- Convert internal handling of bools to chars from ints for memory savings
- Convert CMOCK_MEM_INDEX_TYPE default type to size_t
- Switch to old-school comments for supporting old C compilers
- Significant improvements to handling array length expressions
- Significant improvements to our "C parser"
- Added brace-pair counting to improve parsing
- Fixed error when `:unity_helper_path` is relative
Other:
- Improve documentation
- Optimize speed for pass case, particularly in `_verify()` functions
- Increased depth of unit and system tests
### CMock 2.5.0 (October 2019)
New Features:
- New memory bounds checking.
- New memory alignment algorithm.
- Add `ExpectAnyArgs` plugin
- Divided `CVallback` from `Stub` functionality so we can do both.
- Improved wording of failure messages.
- Added `:treat_as_array` configuration option
Significant Bugfixes:
- Fixed bug where `CMock_Guts_MemBytesUsed()` didn't always return `0` before usage
- Fixed bug which sometimes got `CMOCK_MEM_ALIGN` wrong
- Fixed bug where `ExpectAnyArgs` was generated for functions without args.
- Better handling of function pointers
Other:
- `void*` now tested as bytewise array comparison.
- Documentation fixes, particularly to examples.
- Added `resetTest` to documentation
- New handling of messaging to greatly reduce memory footprint
### CMock 2.4.6 (November 2017)
Significant Bugfixes:
- Fixed critical bug when running dynamic memory.
### CMock 2.4.5 (September 2017)
New Features:
- Simple threading of mocks introduced.
Significant Bugfixes:
- Improvements to handling pointer const arguments.
- Treat `char*` separately from an array of bytes.
- Fixed handling of string arguments.
- Preserve `const` in all arguments.
- Fixed race condition when `require`ing plugins
Other:
- Expand docs on `strict_mock_calling`
### CMock 2.4.4 (April 2017)
New Features:
- Add `INCLUDE_PATH` option for specifying source
Significant Bugfixes:
- Parsing improvements related to braces, brackets, and parenthesis
- `ReturnThruPtr` checks destination not null before copying data.
- Stub overrides Ignore
- Improvements to guessing memory alignment based on datatypes
Other:
- Reorganize testing into subdirectory to not clutter for new users
- Docs switching to markdown from pdf
### CMock 2.4.3 (October 2016)
New Features:
- Support multiple helper header files.
- Add ability to use `weak` symbols if compiler supports it
- Add mock suffix option in addition to mock prefix.
Significant Bugfixes:
- Improved UNICODE support
+13
View File
@@ -0,0 +1,13 @@
# CMock - Known Issues
## A Note
This project will do its best to keep track of significant bugs that might effect your usage of this
project and its supporting scripts. A more detailed and up-to-date list for cutting edge CMock can
be found on our Github repository.
## Issues
- Able to parse most C header files without preprocessor needs, but when handling headers with significant preprocessor usage (#ifdefs, etc), it can get confused
- Multi-dimensional arrays currently simplified to single dimensional arrays of the full size
- Incomplete support for VarArgs
+274
View File
@@ -0,0 +1,274 @@
CMock: Argument Validation
==========================
Much of the power of CMock comes from its ability to automatically
validate that the arguments passed to mocked functions are the
values that were expected to be passed. CMock puts a lot of effort
into guessing how the user would most like to see those values
compared, and then represented when failures are encountered.
Like Unity, CMock follows a philosophy of making its best guesses,
and then allowing the user to explicity specify any features that
they would like to change or customize.
Option 1: Common Types
----------------------
First, if you're dealing with C's standard types, there is nothing
further you need to do. CMock will choose an appropriate assertion
from Unity's list of assertions and will perform the comparison and
display using that. For example, if you specify a `short`, then it's
very likely CMock will compare using `TEST_ASSERT_EQUAL_INT16`. For
unsigned values, it assumes you'd like them displayed in hex. Are you
interested in comparing a `const char*`? That would be Unity's
string comparison.
What if you have some other type of pointer? If you've instructed
CMock to compare pointers, it'll use `TEST_ASSERT_EQUAL_PTR`.
Otherwise it'll use dereference the value being pointed at and
compare that for you. (Read more about the Array plugin for more
details on how this all works). The TYPE being pointed to follows the
same rules as the those above... so if they're common types, for example
`unsigned char*`, then CMock will choose to compare using the
logical assertion (in this case `TEST_ASSERT_EQUAL_HEX8`).
A quick note about floating point types: we're calling the assertions
`TEST_ASSERT_EQUAL_FLOAT` (for example), but don't worry... these
assertions are actually checking to make sure that the values are
"incredibly close" to the desired value instead of identical. This
is because many numbers can be represented in multiple ways when
using floating point. These differences are out of the control of
the user, for the most part. You can ready more about this in the
Unity documentation if you're interested in the details.
Option 1b: The Fallback Plan
----------------------------
So what happens when CMock doesn't recognize the type being used?
This will happen for any custom types being used. What constitutes
a custom type?
- You've used `#define` to create an alias for a standard type
- You've used `typedef` to create an alias for a standard type
- You've created an `enum` type
- You've created a `union` type
- You've created a `struct` type
- You're working with a function pointer
When CMock doesn't recognize the type as a standard type, (and
assuming you don't have a better option specified, as any of the
options below), it will fall back to performing a memory
comparison using `TEST_ASSERT_EQUAL_MEMORY`. For the most part,
this is effective, but the reported failures are not terribly
descriptive.
**WARNING:** There is one important instance where this fallback method
doesn't work at all. If the custom type is a `struct` and that
struct isn't packed, then it's possible you can get false failures
when the unused bytes between fields differ. For an unpacked struct,
it's important that you either use option 3 or 4 below, or ignore that
particular argument (and possibly test it manually yourself).
Option 2: Treat-As
------------------
CMock maintains a list of non-standard types which are basically
aliases of standard types. For example, a common shorthand for
a single-byte unsigned integer might be `u8` or `U8` or `UNIT8`.
Any of these can simply be mapped to the standard
`TEST_ASSERT_EQUAL_HEX8`.
While CMock has its own list of `:treat_as` mappings, you can
add your own pairings to this list. This works especially well for
the following types:
- aliases of standard types using `#define` or `typedef`
- `enum` types (works well as `INT8` or whatever size your enums are)
- function pointers often work well as `PTR` comparisons
- `union` types sometimes make sense to treat as the largest type...
but this is a judgement call
Option 3: Custom Assertions for Custom Types
--------------------------------------------
CMock has the ability to use custom assertions, if you form them
according to certain specifications. Creating a custom assertion
can be a bit of work, But the reward is that, once you've done so,
you can use those assertions within your own tests AND CMock will
magically use them within its own mocks.
To accomplish this, we're going tackle multiple steps:
1. Write a custom assertion function
2. Wrap it in a `UNITY_TEST_` macro
3. Wrap it in a `TEST_` macro
4. Inform CMock that it exists
Let's look at each of those steps in detail:
### Creating a Custom Assertion
A custom assertion is a function which accepts a standard set of
inputs, and then uses Unity's assertion macros to verify any details
required for the types involved.
The inputs:
- the `expected` value (as a `const` version of type being verified)
- the `actual` value (also as a `const` version of the desired type)
- the `line` this function was called from (as type `UNITY_LINE_TYPE`)
- an optional `message` to be appended (as type `const char*`)
Inside the function, we use the *internal* versions of Unity's assertions
to validate any details that need validating.
Let's look at an example! Let's say we have the following type:
```
typedef struct MyType_t
{
int a;
const char* b;
} MyType;
```
In our application, the length of `b` is supposed to be specified by `a`,
and `b` is therefore allowed to have any value (including `0x00`).
Our custom assertion might look something like this:
```
void AssertEqualMyType(const MyType expected, const MyType actual, UNITY_LINE_TYPE line, const char* message)
{
//It's common to override the default message with our own
(void)message;
// Verify the lengths are the same, or they're clearly not matched
UNITY_TEST_ASSERT_EQUAL_INT(expected.a, actual.a, line, "Data length mismatch");
// Verify we're dealing with actual pointers
UNITY_TEST_ASSERT_NOT_NULL(expected.b, line, "Expected value should not be NULL");
UNITY_TEST_ASSERT_NOT_NULL(actual.b, line, "Actual value should not be NULL");
// Verify the string contents
UNITY_TEST_ASSERT_EQUAL_MEMORY(expected.b, actual.b, expected.a, line, "Data not equal");
}
```
There are a few things to note about this. First, notice we're using the
`UNITY_TEST_ASSERT_` assertions? That's because these allow us to pass
on the specific line number. Second, notice we override the message with our
own more helpful messages? You don't need to do this, but anything you can do
to help a developer find a bug is a good thing.
What if there isn't an assertion that is right for your needs? You can
always do whatever operations are necessary yourself, and use `UNITY_TEST_FAIL()`
directly.
One final note: It's best to only test the things that are hard rules about
how a type is supposed to work in your system. Anything else should be left to
the test code.
For example, let's say that in our example above, there are situations where
it IS valid for the pointers to be `NULL`. Perhaps the pointers are ignored
completely when the `a` field is `0`. In that case, we could drop those
assertions completely, or add logic to only check when necessary.
Similarly, should our assertion check that the length is positive? In this
case, it's dangerous if it's negative, because the memory check wouldn't like it.
Updating for these concerns:
```
void AssertEqualMyType(const MyType expected, const MyType actual, UNITY_LINE_TYPE line, const char* message)
{
//It's common to override the default message with our own
(void)message;
// Verify the lengths are the same, or they're clearly not matched
UNITY_TEST_ASSERT_EQUAL_INT(expected.a, actual.a, line, "Data length mismatch");
// Verify the lengths are non-negative
UNITY_TEST_ASSERT_GREATER_OR_EQUAL_INT(0, expected.a, line, "Data length must be positive");
if (expected.a > 0)
{
// Verify we're dealing with actual pointers
UNITY_TEST_ASSERT_NOT_NULL(expected.b, line, "Expected value should not be NULL");
UNITY_TEST_ASSERT_NOT_NULL(actual.b, line, "Actual value should not be NULL");
// Verify the string contents
UNITY_TEST_ASSERT_EQUAL_MEMORY(expected.b, actual.b, expected.a, line, "Data not equal");
}
}
```
### Wrapping our Assertion in Macros
Once you have a function which does the main work, we *need* to create
one macro, and there are a number of other macros which are useful to
create, in order to treat our assertion just like any other Unity
assertion.
`#define UNITY_TEST_ASSERT_EQUAL_MyType(e,a,l,m) AssertEqualMyType(e,a,l,m)`
The macro above is the one that CMock is looking for. Notice that it
starts with `UNITY_TEST_ASSERT_EQUAL_` followed by the name of our type,
*exactly* the way our type is named. The arguments are, in order:
- `e` - expected value
- `a` - actual value
- `l` - line number to report
- `m` - message to append at the end
If CMock finds a macro that matches this argument list and naming convention,
then it can automatically use this assertion where needed... all we need to
do now is tell CMock where to find our custom assertion.
### Informing CMock about our Assertion
In the CMock configuration file, in the `:cmock` or `:unity` sections,
there can be an option for `unity_helper_path`. Add the location of your
new Unity helper file (file with this assertion) to this list.
Done!
**Bonus:** Once you've created a custom assertion, you can use it
with `:treat_as`, just like any other standard type! This is
particularly useful when there is a custom type which is a pointer
to a custom type.
For example, let's say you have these types:
```
typedef struct MY_STRUCT_T_
{
int a;
const char* b;
} MY_STRUCT_T;
typedef MY_STRUCT_T* MY_STRUCT_POINTER_T;
```
Also, let's assume you've created the following assertion:
```
UNITY_TEST_ASSERT_EQUAL_MY_STRUCT_T(e,a,l,m)
```
You can use `:treat_as` like so:
```
:treat_as:
MY_STRUCT_POINTER_T: MY_STRUCT_T*
```
Option 4: Callback
------------------
Finally, You can choose to avoid the use of `_Expect` calls altogether
for challenging types, and use a `Callback` instead. The advantage is that
you can fill in whichever assertions make sense for that particular test,
instead of needing to rely on reusable assertions as used elsewhere.
Typically, this option is also less work than option 3.
+439 -84
View File
@@ -5,6 +5,9 @@ CMock: A Summary
*This documentation is released under a Creative Commons 3.0 Attribution Share-Alike License*
- [Known Issues](CMockKnownIssues.md)
- [Change Log](CMockChangeLog.md)
- [How Does CMock Validate Arguments](CMock_ArgumentValidation.md)
What Exactly Are We Talking About Here?
---------------------------------------
@@ -61,23 +64,23 @@ call DoesSomething enough, or too much, or with the wrong arguments,
or in the wrong order.
CMock is based on Unity, which it uses for all internal testing.
It uses Ruby to do all the main work (versions 2.0.0 and above).
It uses Ruby to do all the main work (versions 3.0.0 and above).
Installing
==========
The first thing you need to do to install CMock is to get yourself
a copy of Ruby. If you're on linux or osx, you probably already
a copy of Ruby. If you're on linux or osx, you probably already
have it. You can prove it by typing the following:
ruby --version
If it replied in a way that implies ignorance, then you're going to
need to install it. You can go to [ruby-lang](https://ruby-lang.org)
to get the latest version. You're also going to need to do that if it
replied with a version that is older than 2.0.0. Go ahead. We'll wait.
need to install it. You can go to [ruby-lang](https://ruby-lang.org)
to get the latest version. You're also going to need to do that if it
replied with a version that is older than 3.0.0. Go ahead. We'll wait.
Once you have Ruby, you have three options:
@@ -117,32 +120,54 @@ ExpectAnyArgs:
This behaves just like the Expects calls, except that it doesn't really
care what the arguments are that the mock gets called with. It still counts
the number of times the mock is called and it still handles return values
if there are some.
if there are some. Note that an ExpectAnyArgs call is not generated for
functions that have no arguments, because it would act exactly like the existing
Expect and ExpectAndReturn calls.
* `void func(void)` => `void func_ExpectAnyArgs(void)`
* `void func(params)` => `void func_ExpectAnyArgs(void)`
* `retval func(void)` => `void func_ExpectAnyArgsAndReturn(retval_to_return)`
* `retval func(params)` => `void func_ExpectAnyArgsAndReturn(retval_to_return)`
Array:
------
An ExpectWithArray is another variant of Expect. Like expect, it cares about
the number of times a mock is called, the arguments it is called with, and the
values it is to return. This variant has another feature, though. For anything
that resembles a pointer or array, it breaks the argument into TWO arguments.
An ExpectWithArray is another variant of Expect. Like expect, it cares about
the number of times a mock is called, the arguments it is called with, and the
values it is to return. This variant has another feature, though. For anything
that resembles a pointer or array, it breaks the argument into TWO arguments.
The first is the original pointer. The second specify the number of elements
it is to verify of that array. If you specify 1, it'll check one object. If 2,
it is to verify of that array. If you specify 1, it'll check one object. If 2,
it'll assume your pointer is pointing at the first of two elements in an array.
If you specify zero elements, it will check just the pointer if
`:smart` mode is configured or fail if `:compare_data` is set.
If you specify zero elements and `UNITY_COMPARE_PTRS_ON_ZERO_ARRAY` is defined,
then this assertion can also be used to directly compare the pointers to verify
that they are pointing to the same memory address.
* `void func(void)` => (nothing. In fact, an additional function is only generated if the params list contains pointers)
* `void func(ptr * param, other)` => `void func_ExpectWithArray(ptr* param, int param_depth, other)`
* `retval func(void)` => (nothing. In fact, an additional function is only generated if the params list contains pointers)
* `retval func(other, ptr* param)` => `void func_ExpectWithArrayAndReturn(other, ptr* param, int param_depth, retval_to_return)`
When the `:array_size_name` and `:array_size_type` options are configured, CMock
can recognize that a scalar parameter is the size of an adjacent pointer parameter
and pair them together. When a size parameter is paired with a pointer, the `_Expect`
call automatically uses it as the array depth, and `_ExpectWithArray` preserves
the original argument order without adding a separate depth argument.
When performing this type of automatic identification of arguments, CMock will also
generate an additional `_ExpectWithArrayExtended`, which accepts an explicit
depth for every pointer — allowing you to override the inferred depth when the
pairing heuristic guesses wrong:
* `void func(int size, ptr* buf)` =>
* `void func_ExpectWithArray(int size, ptr* buf)` _(depth inferred from `size`)_
* `void func_ExpectWithArrayExtended(int size, ptr* buf, int buf_Depth)` _(explicit override)_
`_ExpectWithArrayExtended` is only generated for functions where at least one
size parameter has been automatically identified. For all other functions the short
`_ExpectWithArray` already gives full depth control. This function can be used to correct
poor assumptions that CMock has made. It can also be used to separately verify a passed
length, but compare the actual contents for a DIFFERENT number of elements.
Ignore:
-------
@@ -151,9 +176,9 @@ Maybe you don't care about the number of times a particular function is called o
the actual arguments it is called with. In that case, you want to use Ignore. Ignore
only needs to be called once per test. It will then ignore any further calls to that
particular mock. The IgnoreAndReturn works similarly, except that it has the added
benefit of knowing what to return when that call happens. If the mock is called more
benefit of knowing what to return when that call happens. If the mock is called more
times than IgnoreAndReturn was called, it will keep returning the last value without
complaint. If it's called less times, it will also ignore that. You SAID you didn't
complaint. If it's called fewer times, it will also ignore that. You SAID you didn't
care how many times it was called, right?
* `void func(void)` => `void func_Ignore(void)`
@@ -161,6 +186,35 @@ care how many times it was called, right?
* `retval func(void)` => `void func_IgnoreAndReturn(retval_to_return)`
* `retval func(params)` => `void func_IgnoreAndReturn(retval_to_return)`
StopIgnore:
-------
Maybe you want to ignore a particular function for part of a test but dont want to
ignore it later on. In that case, you want to use StopIgnore which will cancel the
previously called Ignore or IgnoreAndReturn requiring you to Expect or otherwise
handle the call to a function.
* `void func(void)` => `void func_StopIgnore(void)`
* `void func(params)` => `void func_StopIgnore(void)`
* `retval func(void)` => `void func_StopIgnore(void)`
* `retval func(params)` => `void func_StopIgnore(void)`
IgnoreStateless:
----------------
This plugin is similar to the Ignore plugin, but the IgnoreAndReturn functions are
stateless. So the Ignored function will always return the last specified return value
and does not queue the return values as the IgnoreAndReturn of the default plugin will.
To stop ignoring a function you can call StopIgnore or simply overwrite the Ignore
(resp. IgnoreAndReturn) with an Expect (resp. ExpectAndReturn). Note that calling
Ignore (resp IgnoreAndReturn) will clear your previous called Expect
(resp. ExpectAndReturn), so they are not restored after StopIgnore is called.
You can use this plugin by using `:ignore_stateless` instead of `:ignore` in your
CMock configuration file.
The generated functions are the same as **Ignore** and **StopIgnore** above.
Ignore Arg:
------------
@@ -168,9 +222,11 @@ Ignore Arg:
Maybe you overall want to use Expect and its similar variations, but you don't care
what is passed to a particular argument. This is particularly useful when that argument
is a pointer to a value that is supposed to be filled in by the function. You don't want
to use ExpectAnyArgs, because you still care about the other arguments. Instead, before
any of your Expect calls are made, you can call this function. It tells CMock to ignore
a particular argument for the rest of this test, for this mock function.
to use ExpectAnyArgs, because you still care about the other arguments. Instead, after
an Expect call is made, you can call this function. It tells CMock to ignore
a particular argument for the rest of this test, for this mock function. You may call
multiple instances of this to ignore multiple arguments after each expectation if
desired.
* `void func(params)` => `void func_IgnoreArg_paramName(void)`
@@ -179,40 +235,76 @@ ReturnThruPtr:
--------------
Another option which operates on a particular argument of a function is the ReturnThruPtr
plugin. For every argument that resembles a pointer or reference, CMock generates an
plugin. For every argument that resembles a pointer or reference, CMock generates an
instance of this function. Just as the AndReturn functions support injecting one or more
return values into a queue, this function lets you specify one or more return values which
are queued up and copied into the space being pointed at each time the mock is called.
* `void func(param1)` => `void func_ReturnThruPtr_paramName(val_to_return)`
* => `void func_ReturnArrayThruPtr_paramName(cal_to_return, len)`
* => `void func_ReturnArrayThruPtr_paramName(val_to_return, len)`
* => `void func_ReturnMemThruPtr_paramName(val_to_return, size)`
For example, consider the following function:
`BOOL divide(uint numerator, uint denominator, uint* result){
if (denominator == 0){
return FALSE;
}
*result = numerator/denominator;
return TRUE;
}
`
We might want to mock this function so that regardless of the inputs, it returns TRUE and a result of 23.
We could do so like this:
`uint result_1 = 23;
divide_ExpectAnyArgsAndReturn(TRUE);
divide_ReturnThruPtr_result(&result_1);
`
If we want to expect a numerator of 5 and a denominator of 2 and return a result of 42:
`uint result_1 = 42;
divide_ExpectAndReturn(5,2,NULL,TRUE);
divide_IgnoreArg_result();
divide_ReturnThruPtr_result(&result_1);
`
Callback:
---------
If all those other options don't work, and you really need to do something custom, you
still have a choice. As soon as you stub a callback in a test, it will call the callback
whenever the mock is encountered and return the retval returned from the callback (if any)
instead of performing the usual expect checks. It can be configured to check the arguments
first (like expects) or just jump directly to the callback.
whenever the mock is encountered and return the retval returned from the callback (if any).
* `void func(void)` => `void func_StubWithCallback(CMOCK_func_CALLBACK callback)`
* `void func(void)` => `void func_[AddCallback,Stub](CMOCK_func_CALLBACK callback)`
where `CMOCK_func_CALLBACK` looks like: `void func(int NumCalls)`
* `void func(params)` => `void func_StubWithCallback(CMOCK_func_CALLBACK callback)`
* `void func(params)` => `void func_[AddCallback,Stub](CMOCK_func_CALLBACK callback)`
where `CMOCK_func_CALLBACK` looks like: `void func(params, int NumCalls)`
* `retval func(void)` => `void func_StubWithCallback(CMOCK_func_CALLBACK callback)`
* `retval func(void)` => `void func_[AddCallback,Stub](CMOCK_func_CALLBACK callback)`
where `CMOCK_func_CALLBACK` looks like: `retval func(int NumCalls)`
* `retval func(params)` => `void func_StubWithCallback(CMOCK_func_CALLBACK callback)`
* `retval func(params)` => `void func_[AddCallback,Stub](CMOCK_func_CALLBACK callback)`
where `CMOCK_func_CALLBACK` looks like: `retval func(params, int NumCalls)`
You can choose from two options:
* `func_AddCallback` tells the mock to check its arguments and calling
order (based on any Expects you've set up) before calling the callback.
* `func_Stub` tells the mock to skip all the normal checks and jump directly
to the callback instead. In this case, you are replacing the normal mock calls
with your own custom stub function.
There is also an older name, `func_StubWithCallback`, which is just an alias
for either `func_AddCallback` or `func_Stub` depending on setting of the
`:callback_after_arg_check` toggle. This is deprecated and we recommend using
the two options above.
Cexception:
-----------
Finally, if you are using Cexception for error handling, you can use this to throw errors
from inside mocks. Like Expects, it remembers which call was supposed to throw the error,
Finally, if you are using Cexception for error handling, you can use this to throw errors
from inside mocks. Like Expects, it remembers which call was supposed to throw the error,
and it still checks parameters first.
* `void func(void)` => `void func_ExpectAndThrow(value_to_throw)`
@@ -269,6 +361,39 @@ You may specify the options explicitly:
cmock = Cmock.new(:plugins => [:cexception, :ignore], :mock_path => 'my/mocks/')
Creating Skeletons:
-------------------
Not only is CMock able to generate mock files from a header file, but it is also able
to generate (and update) skeleton C files from headers. It does this by creating a
(mostly) empty implementation for every function that is declared in the header. If you later
add to that header list, just run this feature again and it will add prototypes for the missing
functions!
Like the normal usecase for CMock, this feature can be used from the command line
or from within its ruby API. For example, from the command line, add `--skeleton` to
generate a skeleton instead:
```
ruby cmock.rb --skeleton ../create/c/for/this.h
```
Using CMock Without Ceedling
----------------------------
CMock depends on the Unity test framework, but it does not *require* Ceedling. You can use the
generated mocks directly with the Unity test framework in whatever build system you prefer. One
important thing to remember when doing this is that you will need to call the `_Init` function
for each of your mocks BEFORE the tests and the `_Verify` function for each mock AFTER each test.
This allows CMock to perform all of its internal accounting. If you're running into problems where
some errors aren't getting caught, this is likely what you are missing.
There are many ways to accomplish this. Any is valid:
- These actions can be performed as part of `setUp` and `tearDown` in each test file
- You can hand-write your own RUN_TEST macro. If so, protect `_Verify` calls in `TEST_PROTECT`
- You can use Unity's test runner generator and it will automatically take care of this for you.
- You can use Ceedling and it will automatically take care of this for you.
Config Options:
---------------
@@ -295,8 +420,8 @@ from the defaults. We've tried to specify what the defaults are below.
These are attributes that CMock should ignore for you for testing
purposes. Custom compiler extensions and externs are handy things to
put here. If your compiler is choking on some extended syntax, this
is often a good place to look.
is often a good place to look.
* defaults: ['__ramfunc', '__irq', '__fiq', 'register', 'extern']
* **note:** this option will reinsert these attributes onto the mock's calls.
If that isn't what you are looking for, check out :strippables.
@@ -306,16 +431,16 @@ from the defaults. We've tried to specify what the defaults are below.
might show up in your codebase. If it encounters something it doesn't
recognize, it's not going to mock it. We have the most common covered,
but there are many compilers out there, and therefore many other options.
* defaults: ['__stdcall', '__cdecl', '__fastcall']
* **note:** this option will reinsert these attributes onto the mock's calls.
If that isn't what you are looking for, check out :strippables.
* `:callback_after_arg_check`:
Tell `:callback` plugin to do the normal argument checking **before** it
calls the callback function by setting this to true. WHen false, the
calls the callback function by setting this to true. When false, the
callback function is called **instead** of the argument verification.
* default: false
* `:callback_include_count`:
@@ -323,30 +448,51 @@ from the defaults. We've tried to specify what the defaults are below.
number of times the callback has been called. If set to false, the
callback has the same interface as the mocked function. This can be
handy when you're wanting to use callback as a stub.
* default: true
* `:cexception_include`:
Tell `:cexception` plugin where to find CException.h... You only need to
define this if it's not in your build path already... which it usually
will be for the purpose of your builds.
* default: *nil*
* `:create_error_stubs`:
New users of CMock sometimes struggle with the concept that CMock is
generating differently named interface functions for a mock depending
on whether a function to be mocked has a return value or not (see
description of the plugins `:Expect`, `:ExpectAnyArgs`, `:Array`, `:Ignore`,
`:IgnoreStateless` above). They are looking e.g. for a function `func_Expect()`
while CMock generated the function `func_ExpectAndReturn()` instead.
This has proven to be a significant hurdle, because it is not easy to
spot the slightly different named function within the generated mock.
Therefore CMock (v2.6.0 and newer) is generating *both* functions
per default, although one of them has only a "stub" functionality:
on call it will always fail the test emitting a helpful error message
pointing towards the correct function.
Experienced CMock users on the other hand might prefer the original
behavior, where no additional error stubs are generated - e.g. to
ensure code completion offers only "real" functionality of the mock.
In this case, the option `:create_error_stubs` can be set to false.
* default: true
* `:enforce_strict_ordering`:
CMock always enforces the order that you call a particular function,
so if you expect GrabNabber(int size) to be called three times, it
will verify that the sizes are in the order you specified. You might
*also* want to make sure that all different functions are called in a
particular order. If so, set this to true.
* default: false
* `:framework`:
Currently the only option is `:unity.` Eventually if we support other
unity test frameworks (or if you write one for us), they'll get added
here.
: default: :unity
* `:includes`:
@@ -354,11 +500,11 @@ from the defaults. We've tried to specify what the defaults are below.
mocks. Useful for global types and definitions used in your project.
There are more specific versions if you care WHERE in the mock files
the includes get placed. You can define any or all of these options.
* `:includes`
* `:includes_h_pre_orig_header`
* `:includes_h_post_orig_header`
* `:includes_c_pre_header`
* `:includes_c_pre_header`
* `:includes_c_post_header`
* default: nil #for all 5 options
@@ -368,60 +514,68 @@ from the defaults. We've tried to specify what the defaults are below.
the time (though it tries its best). If it comes across a type it doesn't
recognize, you have a choice on how you want it to handle it. It can either
perform a raw memory comparison and report any differences, or it can fail
with a meaningful message. Either way, this feature will only happen after
with a meaningful message. Either way, this feature will only happen after
all other mechanisms have failed (The thing encountered isn't a standard
type. It isn't in the :treat_as list. It isn't in a custom unity_helper).
* default: true
* `:mock_path`:
The directory where you would like the mock files generated to be
placed.
* default: mocks
* `:mock_prefix`:
The prefix to prepend to your mock files. For example, if it's Mock, a file
The prefix to prepend to your mock files. For example, if it's `Mock`, a file
“USART.h” will get a mock called “MockUSART.c”. This CAN be used with a suffix
at the same time.
* default: Mock
* `:mock_suffix`:
The suffix to append to your mock files. For example, it it's "_Mock", a file
The suffix to append to your mock files. For example, it it's `_Mock`, a file
"USART.h" will get a mock called "USART_Mock.h". This CAN be used with a prefix
at the same time.
* default: ""
* `:plugins`:
An array of which plugins to enable. ':expect' is always active. Also
available currently:
* `:ignore`
* `:ignore_arg`
* `:ignore`
* `:ignore_stateless`
* `:ignore_arg`
* `:expect_any_args`
* `:array`
* `:cexception`
* `:callback`
* `:cexception`
* `:callback`
* `:return_thru_ptr`
* `:strippables`:
An array containing a list of items to remove from the header
before deciding what should be mocked. This can be something simple
like a compiler extension CMock wouldn't recognize, or could be a
regex to reject certain function name patterns. This is a great way to
regex to reject certain function name patterns. This is a great way to
get rid of compiler extensions when your test compiler doesn't support
them. For example, use `:strippables: ['(?:functionName\s*\(+.*?\)+)']`
to prevent a function `functionName` from being mocked. By default, it
is ignoring all gcc attribute extensions.
* default: ['(?:__attribute__\s*\(+.*?\)+)']
* default: `['(?:__attribute__\s*\(+.*?\)+)']`
* `:exclude_setjmp_h`:
Some embedded systems don't have <setjmp.h> available. Setting this to true
removes references to this header file and the ability to use cexception.
* default: false
* `:subdir`:
This is a relative subdirectory for your mocks. Set this to e.g. "sys" in
This is a relative subdirectory for your mocks. Set this to e.g. "sys" in
order to create a mock for `sys/types.h` in `(:mock_path)/sys/`.
* default: ""
* `:treat_as`:
@@ -432,11 +586,11 @@ from the defaults. We've tried to specify what the defaults are below.
did that one for you). Maybe you have a type that is a pointer to an
array of unsigned characters? No problem, just add 'UINT8_T*' =>
'HEX8*'
* NOTE: unlike the other options, your specifications MERGE with the
* NOTE: unlike the other options, your specifications MERGE with the
default list. Therefore, if you want to override something, you must
reassign it to something else (or to *nil* if you don't want it)
* default:
* 'int': 'INT'
* 'char': 'INT8'
@@ -479,20 +633,75 @@ from the defaults. We've tried to specify what the defaults are below.
* 'float': 'FLOAT'
* 'double': 'FLOAT'
* `:treat_as_array`:
A specialized sort of `:treat_as` to be used when you've created a
typedef of an array type, such as `typedef int TenIntegers[10];`. This
is a hash of typedef name to element type. For example:
{ "TenIntegers" => "int",
"ArrayOfFloat" => "float" }
Telling CMock about these typedefs allows it to be more intelligent
about parameters of such types, so that you can use features like
ExpectWithArray and ReturnArrayThruPtr with them.
* `:treat_as_void`:
We've seen "fun" legacy systems typedef 'void' with a custom type,
like MY_VOID. Add any instances of those to this list to help CMock
understand how to deal with your code.
* default: []
* `:treat_externs`:
This specifies how you want CMock to handle functions that have been
marked as extern in the header file. Should it mock them?
* `:include` will mock externed functions
* `:include` will mock externed functions
* `:exclude` will ignore externed functions (default).
* `:treat_inlines`:
This specifies how you want CMock to handle functions that have been
marked as inline in the header file. Should it mock them?
* `:include` will mock inlined functions
* `:exclude` will ignore inlined functions (default).
CMock will look for the following default patterns (simplified from the actual regex):
- "static inline"
- "inline static"
- "inline"
You can override these patterns, check out :inline_function_patterns.
Enabling this feature does require a change in the build system that
is using CMock. To understand why, we need to give some more info
on how we are handling inline functions internally.
Let's say we want to mock a header called example.h. example.h
contains inline functions, we cannot include this header in the
mocks or test code if we want to mock the inline functions simply
because the inline functions contain an implementation that we want
to override in our mocks!
So, to circumvent this, we generate a new header, also named
example.h, in the same directory as mock_example.h/c . This newly
generated header should/is exactly the same as the original header,
only difference is the inline functions are transformed to 'normal'
functions declarations. Placing the new header in the same
directory as mock_example.h/c ensures that they will include the new
header and not the old one.
However, CMock has no control in how the build system is configured
and which include paths the test code is compiled with. In order
for the test code to also see the newly generated header ,and not
the old header with inline functions, the build system has to add
the mock folder to the include paths.
Furthermore, we need to keep the order of include paths in mind. We
have to set the mock folder before the other includes to avoid the
test code including the original header instead of the newly
generated header (without inline functions).
* `:unity_helper_path`:
If you have created a header with your own extensions to unity to
handle your own types, you can set this argument to that path. CMock
@@ -500,23 +709,23 @@ from the defaults. We've tried to specify what the defaults are below.
trick is that you make sure you follow the naming convention:
`UNITY_TEST_ASSERT_EQUAL_YourType`. If it finds macros of the right
shape that match that pattern, it'll use them.
* default: []
* `:verbosity`:
How loud shoudl CMock be?
How loud should CMock be?
* 0 for errors only
* 1 for errors and warnings
* 2 for normal (default)
* 2 for normal (default)
* 3 for verbose
* `:weak`:
When set this to some value, the generated mocks are defined as weak
When set this to some value, the generated mocks are defined as weak
symbols using the configured format. This allows them to be overridden
in particular tests.
* Set to '__attribute ((weak))' for weak mocks when using GCC.
in particular tests.
* Set to '__attribute ((weak))' for weak mocks when using GCC.
* Set to any non-empty string for weak mocks when using IAR.
* default: ""
@@ -525,7 +734,7 @@ from the defaults. We've tried to specify what the defaults are below.
it, it usually contains function prototypes (otherwise what was the
point?). You can control what happens when this isn't true. You can
set this to `:warn,` `:ignore,` or `:error`
* default: :warn
* `:when_ptr`:
@@ -538,15 +747,110 @@ from the defaults. We've tried to specify what the defaults are below.
single element of what is being pointed to. So if you have a pointer
to a struct called ORGAN_T, it will compare one ORGAN_T (whatever that
is).
* default: :smart
* `:array_size_type`:
* `:array_size_name`:
When the `:array` plugin is disabled, these options do nothing.
When the `:array` plugin is enabled, these options allow CMock to recognize
functions with parameters that might refer to an array, like the following,
and treat them more intelligently:
* `void GoBananas(Banana * bananas, int num_bananas)`
* `int write_data(int fd, const uint8_t * data, uint32_t size)`
* `void store_data(int buf_size, uint8_t * buf)`
`:array_size_type` is a list of additional types (besides `int` and `size_t`)
that could be used for an array size parameter. For example, to get CMock to
recognize that `uint32_t size` is an array size, you'd need to say:
cfg[:array_size_type] = ['uint32_t']
`:array_size_name` is a regular expression used to match an array size
parameter by name. By default, it's 'size|len'. To get CMock to recognize a
name like `num_bananas`, you could tell it to also accept names containing
'num_' like this:
cfg[:array_size_name] = 'size|len|num_'
A parameter must match *both* `:array_size_type` and `:array_size_name` to be
treated as an array size.
**Pairing heuristic:** CMock scores each candidate size parameter against each
pointer parameter using name similarity. It strips size-words (e.g. "size",
"len") from the size parameter's name to derive a root, then checks whether
that root matches the pointer's name exactly (score 10), as a prefix or suffix
(score 7), or as a substring (score 5). Adjacency in the argument list adds a
small bonus (score +2). The highest-scoring pairing wins. This means CMock
correctly pairs `buff_size` with `buffer` even when another pointer appears
adjacent to `buff_size`.
Size parameters may appear either **before or after** the pointer they describe.
CMock recognizes both orderings:
* Size after pointer: `void func(uint8_t* buf, int buf_size)` — the `_Expect`
call uses `buf_size` as the depth automatically. `_ExpectWithArray` adds an
explicit `buf_Depth` argument after `buf` for manual override.
* Size before pointer: `void func(int buf_size, uint8_t* buf)` — the `_Expect`
call again uses `buf_size` as the depth automatically, and `_ExpectWithArray`
keeps arguments in their original order with no extra depth argument added.
An additional `_ExpectWithArrayExtended` variant is generated that does accept
an explicit depth, allowing you to override the inferred value when needed.
Once you've told it how to recognize your arrays, CMock will give you `_Expect`
calls that work more like `_ExpectWithArray`, and compare an array of objects
rather than just a single object.
For example, if you write the following, CMock will check that GoBananas is
called and passed an array containing a green banana followed by a yellow
banana:
Banana b[2] = {GreenBanana, YellowBanana};
GoBananas_Expect(b, 2);
In other words, `GoBananas_Expect(b, 2)` now works just the same as:
GoBananas_ExpectWithArray(b, 2, 2);
* `:fail_on_unexpected_calls`:
By default, CMock will fail a test if a mock is called without `_Expect` and `_Ignore`
called first. While this forces test writers to be more explicit in their expectations,
it can clutter tests with `_Expect` or `_Ignore` calls for functions which are not the focus
of the test. While this is a good indicator that this module should be refactored, some
users are not fans of the additional noise.
Therefore, :fail_on_unexpected_calls can be set to false to force all mocks to start with
the assumption that they are operating as `_Ignore` unless otherwise specified.
* default: true
* **note:**
If this option is disabled, the mocked functions will return
a default value (0) when called (and only if they have to return something of course).
* `:inline_function_patterns`:
An array containing a list of strings to detect inline functions.
This option is only taken into account if you enable :treat_inlines.
These strings are interpreted as regex patterns so be sure to escape
certain characters. For example, use `:inline_function_patterns: ['static inline __attribute__ \(\(always_inline\)\)']`
to recognize `static inline __attribute__ ((always_inline)) int my_func(void)`
as an inline function.
The default patterns are are:
* default: ['(static\s+inline|inline\s+static)\s*', '(\bstatic\b|\binline\b)\s*']
* **note:**
The order of patterns is important here!
We go from specific patterns ('static inline') to general patterns ('inline'),
otherwise we would miss functions that use 'static inline' iso 'inline'.
Compiled Options:
-----------------
A number of #defines also exist for customizing the cmock experience.
Feel free to pass these into your compiler or whatever is most
Feel free to pass these into your compiler or whatever is most
convenient. CMock will otherwise do its best to guess what you want
based on other settings, particularly Unity's settings.
@@ -559,7 +863,7 @@ based on other settings, particularly Unity's settings.
* `CMOCK_MEM_SIZE`
In static mode this is the total amount of memory you are allocating
to Cmock. In Dynamic mode this is the size of each chunk allocated
at once (larger numbers grab more memory but require less mallocs).
at once (larger numbers grab more memory but require fewer mallocs).
* `CMOCK_MEM_ALIGN`
The way to align your data to. Not everything is as flexible as
@@ -575,14 +879,65 @@ based on other settings, particularly Unity's settings.
* `CMOCK_MEM_INDEX_TYPE`
This needs to be something big enough to point anywhere in Cmock's
memory space... usually it's an unsigned int.
memory space... usually it's a size_t.
Other Tips
==========
resetTest
---------
While this isn't strictly a CMock feature, often users of CMock are using
either the test runner generator scripts in Unity or using Ceedling. In
either case, there is a handy function called `resetTest` which gets
generated with your runner. You can then use this handy function in your tests
themselves. Call it during a test to have CMock validate everything to this point
and start over clean. This is really useful when wanting to test a function in
an iterative manner with different arguments.
C++ Support
-----------
C++ unit test/mocking frameworks often use a completely different approach (vs.
CMock) that relies on overloading virtual class members and does not support
directly mocking static class member methods or free functions (i.e., functions
in plain C). One workaround is to wrap the non-virtual functions in an object
that exposes them as virtual methods and modify your code to inject mocks at
run-time... but there is another way!
Simply use CMock to mock the static member methods and a C++ mocking framework
to handle the virtual methods. (Yes, you can mix mocks from CMock and a C++
mocking framework together in the same test!)
Keep in mind that since C++ mocking frameworks often link the real object to the
unit test too, we need to resolve multiple definition errors with something like
the following in the source of the real implementation for any functions that
CMock mocks:
#if defined(TEST)
__attribute__((weak))
#endif
To address potential issues with re-using the same function name in different
namespaces/classes, the generated function names include the namespace(s) and
class. For example:
namespace MyNamespace {
class MyClass {
static int DoesSomething(int a, int b);
};
}
Will generate functions like
void MyNamespace_MyClass_DoesSomething_ExpectAndReturn(int a, int b, int toReturn);
Examples
========
You can look in the examples directory for a couple of examples on how
You can look in the [examples directory](/examples/) for a couple of examples on how
you might tool CMock into your build process. You may also want to consider
using [Ceedling](https://throwtheswitch.org/Ceedling). Please note that
these examples are meant to show how the build process works. They have
using [Ceedling](https://throwtheswitch.org/ceedling). Please note that
these examples are meant to show how the build process works. They have
failing tests ON PURPOSE to show what that would look like. Don't be alarmed. ;)
+138
View File
@@ -0,0 +1,138 @@
# ThrowTheSwitch.org Code of Conduct
Thank you for participating in a ThrowTheSwitch.org community project! We want
this to continue to be a warm and inviting place for everyone to share ideas
and get help. To accomplish this goal, we've developed this Code of Conduct.
## Our Pledge
We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, caste, color, religion, or sexual
identity and orientation.
We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.
## Our Standards
Examples of behavior that contributes to a positive environment for our
community include:
* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the overall
community
Examples of unacceptable behavior include:
* The use of sexualized language or imagery, and sexual attention or advances of
any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email address,
without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Enforcement Responsibilities
Community leaders are responsible for clarifying and enforcing our standards of
acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.
Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for moderation
decisions when appropriate.
## Scope
This Code of Conduct applies within all community spaces, and also applies when
an individual is officially representing the community in public spaces.
Examples of representing our community include using an official email address,
posting via an official social media account, or acting as an appointed
representative at an online or offline event.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at
hello@thingamabyte.com.
All complaints will be reviewed and investigated promptly and fairly.
All community leaders are obligated to respect the privacy and security of the
reporter of any incident.
## Enforcement Guidelines
Community leaders will follow these Community Impact Guidelines in determining
the consequences for any action they deem in violation of this Code of Conduct:
### 1. Correction
**Community Impact**: Use of inappropriate language or other behavior deemed
unprofessional or unwelcome in the community.
**Consequence**: A private, written warning from community leaders, providing
clarity around the nature of the violation and an explanation of why the
behavior was inappropriate. A public apology may be requested.
### 2. Warning
**Community Impact**: A violation through a single incident or series of
actions.
**Consequence**: A warning with consequences for continued behavior. No
interaction with the people involved, including unsolicited interaction with
those enforcing the Code of Conduct, for a specified period of time. This
includes avoiding interactions in community spaces as well as external channels
like social media. Violating these terms may lead to a temporary or permanent
ban.
### 3. Temporary Ban
**Community Impact**: A serious violation of community standards, including
sustained inappropriate behavior.
**Consequence**: A temporary ban from any sort of interaction or public
communication with the community for a specified period of time. No public or
private interaction with the people involved, including unsolicited interaction
with those enforcing the Code of Conduct, is allowed during this period.
Violating these terms may lead to a permanent ban.
### 4. Permanent Ban
**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.
**Consequence**: A permanent ban from any sort of public interaction within the
community.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.1, available at
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
Community Impact Guidelines were inspired by
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
For answers to common questions about this code of conduct, see the FAQ at
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
[https://www.contributor-covenant.org/translations][translations].
[homepage]: https://www.contributor-covenant.org
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
[Mozilla CoC]: https://github.com/mozilla/diversity
[FAQ]: https://www.contributor-covenant.org/faq
[translations]: https://www.contributor-covenant.org/translations
+238
View File
@@ -0,0 +1,238 @@
# Contributing to a ThrowTheSwitch.org Project
👍🎉 _First off, thanks for taking the time to contribute!_ 🎉👍
The following is a set of guidelines for contributing to any of ThrowTheSwitch.org's projects or the website itself, hosted at throwtheswitch.org or ThrowTheSwitch's organization on GitHub. These are mostly guidelines, not rules. Use your best judgment, and feel free to propose changes to this document in a pull request.
### Table Of Contents
- [Code of Conduct](#book-code-of-conduct)
- [Asking Questions](#bulb-asking-questions)
- [Opening an Issue](#inbox_tray-opening-an-issue)
- [Feature Requests](#love_letter-feature-requests)
- [Triaging Issues](#mag-triaging-issues)
- [Submitting Pull Requests](#repeat-submitting-pull-requests)
- [Writing Commit Messages](#memo-writing-commit-messages)
- [Code Review](#white_check_mark-code-review)
- [Coding Style](#nail_care-coding-style)
- [Certificate of Origin](#medal_sports-certificate-of-origin)
- [Credits](#pray-credits)
## :book: Code of Conduct
Please review our [Code of Conduct](CODE_OF_CONDUCT.md). It is in effect at all times. We expect it to be honored by everyone who contributes to this project. Be a Good Human!
## :bulb: Asking Questions
> **Note:** Please don't file an issue to ask a question. We have an official forum where the community chimes in with helpful advice if you have questions.
* [ThrowTheSwitch Forums](https://throwtheswitch.org/forums)
### What should I know before I get started?
ThrowTheSwitch hosts a number of open source projects &mdash; Ceedling is the entrypoint for many users. Ceedling is actually built upon the foundation of Unity Test (a flexible C testing framework) and CMock (a mocking tool for C) and it coordinates many other open source and proprietary tools. Please do your best to focus your ideas and questions at the correct tool. We'll do our best to help you find your way, but there will be times where we'll have to direct your attention to another subtool.
Here are some of the main projects hosted by ThrowTheSwitch.org:
- [Ceedling](https://www.github.com/throwtheswitch/ceedling) -- Build coordinator for testing C applications, especially embedded C (and optionally your release build too!)
- [CMock](https://www.github.com/throwtheswitch/cmock) -- Mocking tool for automatically creating stubs, mocks, and skeletons in C
- [Unity](https://www.github.com/throwtheswitch/unity) -- Unit Testing framework for C, specially embedded C.
- [MadScienceLabDocker](https://www.github.com/throwtheswitch/madsciencelabdocker) -- Docker image giving you a shortcut to getting running with Ceedling
- [CException](https://www.github.com/throwtheswitch/cexception) -- An exception framework for using simple exceptions in C.
There are many more, but this list should be a good starting point.
## :inbox_tray: Opening an Issue
Before [creating an issue](https://help.github.com/en/github/managing-your-work-on-github/creating-an-issue), check if you are using the latest version of the project. If you are not up-to-date, see if updating fixes your issue first.
### :beetle: Bug Reports and Other Issues
A great way to contribute to the project is to send a detailed issue when you encounter a problem. We always appreciate a well-written, thorough bug report. :v:
In short, since you are most likely a developer, **provide a ticket that you would like to receive**.
- **Review the documentation** before opening a new issue.
- **Do not open a duplicate issue!** Search through existing issues to see if your issue has previously been reported. If your issue exists, comment with any additional information you have. You may simply note "I have this problem too", which helps prioritize the most common problems and requests.
- **Prefer using [reactions](https://github.blog/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/)**, not comments, if you simply want to "+1" an existing issue.
- **Fully complete the provided issue template.** The bug report template requests all the information we need to quickly and efficiently address your issue. Be clear, concise, and descriptive. Provide as much information as you can, including steps to reproduce, stack traces, compiler errors, library versions, OS versions, and screenshots (if applicable).
- **Use [GitHub-flavored Markdown](https://help.github.com/en/github/writing-on-github/basic-writing-and-formatting-syntax).** Especially put code blocks and console outputs in backticks (```). This improves readability.
## :seedling: Feature Requests
Feature requests are welcome! We don't have all the answers and we truly love the collaborative experience of building software together! That being said, we cannot guarantee your request will be accepted. We want to avoid [feature creep](https://en.wikipedia.org/wiki/Feature_creep). Your idea may be great, but also out-of-scope for the project. If accepted, we'll do our best to tackle it in a timely manner, but cannot make any commitments regarding the timeline for implementation and release. However, you are welcome to submit a pull request to help!
- **Please don't open a duplicate feature request.** Search for existing feature requests first. If you find your feature (or one very similar) previously requested, comment on that issue.
- **Fully complete the provided issue template.** The feature request template asks for all necessary information for us to begin a productive conversation.
- Be precise about the proposed outcome of the feature and how it relates to existing features. Include implementation details if possible.
## :mag: Triaging Issues
You can triage issues which may include reproducing bug reports or asking for additional information, such as version numbers or reproduction instructions. Any help you can provide to quickly resolve an issue is very much appreciated!
## :repeat: Submitting Pull Requests
We **love** pull requests! Before [forking the repo](https://help.github.com/en/github/getting-started-with-github/fork-a-repo) and [creating a pull request](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/proposing-changes-to-your-work-with-pull-requests) for non-trivial changes, it is usually best to first open an issue to discuss the changes, or discuss your intended approach for solving the problem in the comments for an existing issue.
For most contributions, after your first pull request is accepted and merged, you will be [invited to the project](https://help.github.com/en/github/setting-up-and-managing-your-github-user-account/inviting-collaborators-to-a-personal-repository) and given **push access**. :tada:
*Note: All contributions will be licensed under the project's license.*
- **Smaller is better.** Submit **one** pull request per bug fix or feature. A pull request should contain isolated changes pertaining to a single bug fix or feature implementation. **Do not** refactor or reformat code that is unrelated to your change. It is better to **submit many small pull requests** rather than a single large one. Enormous pull requests will take enormous amounts of time to review, or may be rejected altogether.
- **Coordinate bigger changes.** For large and non-trivial changes, open an issue to discuss a strategy with the maintainers. Otherwise, you risk doing a lot of work for nothing!
- **Prioritize understanding over cleverness.** Write code clearly and concisely. Remember that source code usually gets written once and read often. Ensure the code is clear to the reader. The purpose and logic should be obvious to a reasonably skilled developer, otherwise you should add a comment that explains it.
- **Follow existing coding style and conventions.** Keep your code consistent with the style, formatting, and conventions in the rest of the code base. When possible, these will be enforced with a linter. Consistency makes it easier to review and modify in the future.
- **Include test coverage.** Add unit tests when possible. Follow existing patterns for implementing tests.
- **Update the example project** if one exists to exercise any new functionality you have added.
- **Add documentation.** Document your changes with code doc comments or in existing guides.
- **Update the CHANGELOG** for all enhancements and bug fixes. Include the corresponding issue number if one exists, and your GitHub username. (example: "- Fixed crash in profile view. #123 @jessesquires")
- **Use the repo's default branch.** Branch from and [submit your pull request](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request-from-a-fork) to the repo's default branch. Usually this is `main`, but it could be `dev`, `develop`, or `master`.
- **[Resolve any merge conflicts](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/resolving-a-merge-conflict-on-github)** that occur.
- **Promptly address any CI failures**. If your pull request fails to build or pass tests, please push another commit to fix it.
- When writing comments, use properly constructed sentences, including punctuation.
- Use spaces, not tabs.
## :memo: Writing Commit Messages
Please [write a great commit message](https://chris.beams.io/posts/git-commit/).
1. Separate subject from body with a blank line
1. Limit the subject line to 50 characters
1. Capitalize the subject line
1. Do not end the subject line with a period
1. Wrap the body at _about_ 72 characters
1. Use the body to explain **why**, *not what and how* (the code shows that!)
1. If applicable, prefix the title with the relevant component name or emoji (see below. examples: "[Docs] Fix typo", "[Profile] Fix missing avatar")
```
:palm_tree: Summary of Amazing Feature Here
Add a more detailed explanation here, if necessary. Possibly give
some background about the issue being fixed, etc. The body of the
commit message can be several paragraphs. Further paragraphs come
after blank lines and please do proper word-wrap.
Wrap it to about 72 characters or so. In some contexts,
the first line is treated as the subject of the commit and the
rest of the text as the body. The blank line separating the summary
from the body is critical (unless you omit the body entirely);
various tools like `log`, `shortlog` and `rebase` can get confused
if you run the two together.
Explain the problem that this commit is solving. Focus on why you
are making this change as opposed to how or what. The code explains
how or what. Reviewers and your future self can read the patch,
but might not understand why a particular solution was implemented.
Are there side effects or other unintuitive consequences of this
change? Here's the place to explain them.
- Bullet points are awesome, too
- A hyphen should be used for the bullet, preceded
by a single space, with blank lines in between
Note the fixed or relevant GitHub issues at the end:
Resolves: #123
See also: #456, #789
```
## :heart: Who Loves Emoji?
Commit comments, Issues, Feature Requests... they can all use a little sprucing up, right? Consider using the following emoji for a mix of function and :sparkles: dazzle!
- actions
- :seedling: `:seedling:` (or other plants) when growing new features. Choose your fav! :cactus: :herb: :evergreen_tree: :palm_tree: :deciduous_tree: :blossom:
- :art: `:art:` when improving the format/structure of the code
- :racehorse: `:racehorse:` when improving performance
- :non-potable_water: `:non-potable_water:` when plugging memory leaks
- :memo: `:memo:` when writing docs
- :bug: `:bug:` (or other insects) when fixing a bug. Maybe :beetle: :ant: or :honeybee: ?
- :fire: `:fire:` when removing code or files
- :green_heart: `:green_heart:` when fixing the CI build
- :white_check_mark: `:white_check_mark:` when adding tests
- :lock: `:lock:` when dealing with security
- :arrow_up: `:arrow_up:` when upgrading dependencies
- :arrow_down: `:arrow_down:` when downgrading dependencies
- :shirt: `:shirt:` when removing linter warnings
- platforms
- :penguin: `:penguin:` when fixing something on Linux
- :apple: `:apple:` when fixing something on macOS
- :checkered_flag: `:checkered_flag:` when fixing something on Windows
## :white_check_mark: Code Review
- **Review the code, not the author.** Look for and suggest improvements without disparaging or insulting the author. Provide actionable feedback and explain your reasoning.
- **You are not your code.** When your code is critiqued, questioned, or constructively criticized, remember that you are not your code. Do not take code review personally.
- **Always do your best.** No one writes bugs on purpose. Do your best, and learn from your mistakes.
- Kindly note any violations to the guidelines specified in this document.
## :violin: Coding Style
Consistency is the most important. Following the existing style, formatting, and naming conventions of the file you are modifying and of the overall project. Failure to do so will result in a prolonged review process that has to focus on updating the superficial aspects of your code, rather than improving its functionality and performance.
For example, if all private properties are prefixed with an underscore `_`, then new ones you add should be prefixed in the same way. Or, if methods are named using camelcase, like `thisIsMyNewMethod`, then do not diverge from that by writing `this_is_my_new_method`. You get the idea. If in doubt, please ask or search the codebase for something similar.
When possible, style and format will be enforced with a linter.
### C Styleguide
C code is linted with [AStyle](https://astyle.sourceforge.net/).
### Ruby Styleguide
Ruby code is linted with [Rubocop](https://github.com/rubocop/rubocop)
## :medal_sports: Certificate of Origin
*Developer's Certificate of Origin 1.1*
By making a contribution to this project, I certify that:
> 1. The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or
> 1. The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or
> 1. The contribution was provided directly to me by some other person who certified (1), (2) or (3) and I have not modified it.
> 1. I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved.
## [No Brown M&M's](https://en.wikipedia.org/wiki/Van_Halen#Contract_riders)
If you are reading this, bravo dear user and (hopefully) contributor for making it this far! You are awesome. :100:
To confirm that you have read this guide and are following it as best as possible, **include this emoji at the top** of your issue or pull request: :pineapple: `:pineapple:`
## :pray: Credits
Written by [@jessesquires](https://github.com/jessesquires). Lovingly adapted to ThrowTheSwitch.org by [@mvandervoord](https://github.com/mvandervoord).
**Please feel free to adopt this guide in your own projects. Fork it wholesale or remix it for your needs.**
*Many of the ideas and prose for the statements in this document were based on or inspired by work from the following communities:*
- [Alamofire](https://github.com/Alamofire/Alamofire/blob/master/CONTRIBUTING.md)
- [CocoaPods](https://github.com/CocoaPods/CocoaPods/blob/master/CONTRIBUTING.md)
- [Docker](https://github.com/moby/moby/blob/master/CONTRIBUTING.md)
- [Linux](https://elinux.org/Developer_Certificate_Of_Origin)
*We commend them for their efforts to facilitate collaboration in their projects.*
+6 -6
View File
@@ -1,8 +1,8 @@
CC ?= gcc
BUILD_DIR ?= ./build
SRC_DIR ?= ./src
TEST_DIR ?= ./test
TEST_BUILD_DIR ?= ${BUILD_DIR}/test
export BUILD_DIR ?= ./build
export SRC_DIR ?= ./src
export TEST_DIR ?= ./test
export TEST_BUILD_DIR ?= ${BUILD_DIR}/test
TEST_MAKEFILE = ${TEST_BUILD_DIR}/MakefileTestSupport
OBJ ?= ${BUILD_DIR}/obj
OBJ_DIR = ${OBJ}
@@ -14,7 +14,7 @@ all: setup test ${BUILD_DIR}/main run
setup:
mkdir -p ${BUILD_DIR}
mkdir -p ${OBJ}
ruby ../../scripts/create_makefile.rb --silent
ruby ../../scripts/create_makefile.rb
clean:
rm -rf ${BUILD_DIR}
@@ -23,7 +23,7 @@ ${BUILD_DIR}/main: ${SRC_DIR}/main.c ${SRC_DIR}/foo.c
${CC} $< -o $@
run:
./build/main || true
./build/main
test: setup
+7
View File
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "foo.h"
void foo_init(void)
+7
View File
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#ifndef _foo_h
void foo_init(void);
+7
View File
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include <stdio.h>
#include "foo.h"
+8 -1
View File
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "unity.h"
#include "foo.h"
@@ -13,5 +20,5 @@ void test_foo_init_should_initialize_multiplier()
{
foo_init();
TEST_ASSERT_FALSE(1);
TEST_ASSERT_FALSE(0);
}
+8 -1
View File
@@ -1,5 +1,12 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "unity.h"
#include "mock_foo.h"
#include "Mockfoo.h"
void setUp(void)
{
-44
View File
@@ -1,44 +0,0 @@
compiler:
path: gcc
source_path: 'src/'
unit_tests_path: &unit_tests_path 'test/'
build_path: &build_path 'build/'
options:
- -c
includes:
prefix: '-I'
items:
- 'src/'
- '../../src/'
- '../../vendor/unity/src/'
- '../../vendor/unity/examples/example_3/helper/'
- './build/mocks/'
- *unit_tests_path
defines:
prefix: '-D'
items:
- __monitor
object_files:
prefix: '-o'
extension: '.o'
destination: *build_path
linker:
path: gcc
options:
- -lm
includes:
prefix: '-I'
object_files:
path: *build_path
extension: '.o'
bin_files:
prefix: '-o'
extension: '.exe'
destination: *build_path
:cmock:
:plugins: []
:includes:
- Types.h
:mock_path: ./build/mocks
colour: true
-92
View File
@@ -1,92 +0,0 @@
tools_root: &tools_root 'C:\Program Files\IAR Systems\Embedded Workbench 4.0 Kickstart\'
compiler:
path: [*tools_root, 'arm\bin\iccarm.exe']
source_path: 'src\'
unit_tests_path: &unit_tests_path 'test\'
build_path: &build_path 'build\'
options:
- --dlib_config
- [*tools_root, 'arm\lib\dl4tptinl8n.h']
- -z3
- --no_cse
- --no_unroll
- --no_inline
- --no_code_motion
- --no_tbaa
- --no_clustering
- --no_scheduling
- --debug
- --cpu_mode thumb
- --endian little
- --cpu ARM7TDMI
- --stack_align 4
- --interwork
- -e
- --silent
- --warnings_are_errors
- --fpu None
- --diag_suppress Pa050
includes:
prefix: '-I'
items:
- 'src/'
- '../../src/'
- '../../vendor/unity/src/'
- '../../vendor/unity/examples/example_3/helper/'
- './build/mocks/'
- [*tools_root, 'arm\inc\']
- *unit_tests_path
defines:
prefix: '-D'
items:
object_files:
prefix: '-o'
extension: '.r79'
destination: *build_path
linker:
path: [*tools_root, 'common\bin\xlink.exe']
options:
- -rt
- [*tools_root, 'arm\lib\dl4tptinl8n.r79']
- -D_L_EXTMEM_START=0
- -D_L_EXTMEM_SIZE=0
- -D_L_HEAP_SIZE=120
- -D_L_STACK_SIZE=32
- -e_small_write=_formatted_write
- -s
- __program_start
- -f
- [*tools_root, '\arm\config\lnkarm.xcl']
includes:
prefix: '-I'
items:
- [*tools_root, 'arm\config\']
- [*tools_root, 'arm\lib\']
object_files:
path: *build_path
extension: '.r79'
bin_files:
prefix: '-o'
extension: '.d79'
destination: *build_path
simulator:
path: [*tools_root, 'common\bin\CSpyBat.exe']
pre_support:
- --silent
- [*tools_root, 'arm\bin\armproc.dll']
- [*tools_root, 'arm\bin\armsim.dll']
post_support:
- --plugin
- [*tools_root, 'arm\bin\armbat.dll']
- --backend
- -B
- -p
- [*tools_root, 'arm\config\ioat91sam7X256.ddf']
- -d
- sim
:cmock:
:plugins: []
:includes:
- Types.h
:mock_path: ./build/mocks
-81
View File
@@ -1,81 +0,0 @@
tools_root: &tools_root 'C:\Program Files\IAR Systems\Embedded Workbench 5.3\'
compiler:
path: [*tools_root, 'arm\bin\iccarm.exe']
source_path: 'src\'
unit_tests_path: &unit_tests_path 'test\'
build_path: &build_path 'build\'
options:
- --dlib_config
- [*tools_root, 'arm\inc\DLib_Config_Normal.h']
- --no_cse
- --no_unroll
- --no_inline
- --no_code_motion
- --no_tbaa
- --no_clustering
- --no_scheduling
- --debug
- --cpu_mode thumb
- --endian=little
- --cpu=ARM7TDMI
- --interwork
- --warnings_are_errors
- --fpu=None
- --diag_suppress=Pa050
- --diag_suppress=Pe111
- -e
- -On
includes:
prefix: '-I'
items:
- 'src/'
- '../../src/'
- '../../vendor/unity/src/'
- '../../vendor/unity/examples/example_3/helper/'
- './build/mocks/'
- [*tools_root, 'arm\inc\']
- *unit_tests_path
defines:
prefix: '-D'
items:
object_files:
prefix: '-o'
extension: '.r79'
destination: *build_path
linker:
path: [*tools_root, 'arm\bin\ilinkarm.exe']
options:
- --redirect _Printf=_PrintfLarge
- --redirect _Scanf=_ScanfSmall
- --semihosting
- --entry __iar_program_start
- --config
- [*tools_root, 'arm\config\generic.icf']
object_files:
path: *build_path
extension: '.o'
bin_files:
prefix: '-o'
extension: '.out'
destination: *build_path
simulator:
path: [*tools_root, 'common\bin\CSpyBat.exe']
pre_support:
- --silent
- [*tools_root, 'arm\bin\armproc.dll']
- [*tools_root, 'arm\bin\armsim.dll']
post_support:
- --plugin
- [*tools_root, 'arm\bin\armbat.dll']
- --backend
- -B
- -p
- [*tools_root, 'arm\config\debugger\atmel\ioat91sam7X256.ddf']
- -d
- sim
:cmock:
:plugins: []
:includes:
- Types.h
:mock_path: ./build/mocks
+75
View File
@@ -0,0 +1,75 @@
# =========================================================================
# CMock - Automatic Mock Generation for C
# ThrowTheSwitch.org
# Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
# SPDX-License-Identifier: MIT
# =========================================================================
:project:
:build_root: 'build/'
:colour: true
:paths:
:source:
- 'src/'
:include:
- 'src/'
- '../../src/'
- '../../vendor/unity/src/'
- '../../vendor/unity/examples/example_3/helper/'
- 'build/mocks/'
- 'test/'
:test: 'test/'
:build: 'build/'
:mocks: 'build/mocks/'
:extension:
:object: '.o'
:executable: '.exe'
:defines:
:test:
- __monitor
- UNITY_SUPPORT_64
:cmock:
# Core configuration
:plugins: []
:verbosity: 2
:when_no_prototypes: :warn
# File configuration
:mock_path: 'build/mocks'
:skeleton_path: ''
:mock_prefix: 'Mock'
:mock_suffix: ''
# Parser configuration
:strippables:
- '(?:__attribute__\s*\([ (]*.*?[ )]*\)+)'
:attributes:
- __ramfunc
- __irq
- __fiq
- register
- extern
:c_calling_conventions:
- __stdcall
- __cdecl
- __fastcall
:treat_externs: :exclude
:treat_inlines: :exclude
# Type handling configuration
:memcmp_if_unknown: true
:when_ptr: :compare_data
# Mock generation configuration
:weak: ''
:enforce_strict_ordering: false
:fail_on_unexpected_calls: true
:callback_include_count: true
:callback_after_arg_check: false
:includes:
- Types.h
:exclude_setjmp_h: false
+19 -12
View File
@@ -1,4 +1,11 @@
HERE = File.expand_path(File.dirname(__FILE__)) + '/'
# =========================================================================
# CMock - Automatic Mock Generation for C
# ThrowTheSwitch.org
# Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
# SPDX-License-Identifier: MIT
# =========================================================================
HERE = "#{__dir__}//".freeze
require 'rake'
require 'rake/clean'
@@ -7,36 +14,36 @@ require './rakefile_helper'
include RakefileHelpers
REQUIRED_DIRS = [ './build', './build/mocks' ]
REQUIRED_DIRS = ['./build', './build/mocks'].freeze
REQUIRED_DIRS.each do |v|
directory v
end
# Load default configuration, for now
DEFAULT_CONFIG_FILE = 'gcc.yml'
DEFAULT_CONFIG_FILE = 'gcc_64.yml'.freeze
configure_toolchain(DEFAULT_CONFIG_FILE)
task :unit do
run_tests(get_unit_test_files)
run_tests(unit_test_files)
end
desc "Generate test summary"
desc 'Generate test summary'
task :summary do
report_summary
end
desc "Build and test Unity"
task :all => [:clean, :unit, :summary]
task :default => REQUIRED_DIRS + [:clobber, :all]
desc 'Build and test Unity'
task :all => %i[clean unit summary]
task :default => REQUIRED_DIRS + %i[clobber all]
task :ci => [:default]
task :cruise => [:default]
desc "Load configuration"
task :config, :config_file do |t, args|
configure_toolchain(args[:config_file])
desc 'Load configuration'
task :config, [:config_file, :cmock_overlay] do |_t, args|
configure_toolchain(args[:config_file], args[:cmock_overlay])
end
desc "Return error on Failures"
desc 'Return error on Failures'
task :strict do
$return_error_on_failures = true
end
+216 -164
View File
@@ -1,3 +1,10 @@
# =========================================================================
# CMock - Automatic Mock Generation for C
# ThrowTheSwitch.org
# Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
# SPDX-License-Identifier: MIT
# =========================================================================
require 'yaml'
require 'fileutils'
require '../../vendor/unity/auto/unity_test_summary'
@@ -5,268 +12,313 @@ require '../../vendor/unity/auto/generate_test_runner'
require '../../vendor/unity/auto/colour_reporter'
module RakefileHelpers
$return_error_on_failures = false
C_EXTENSION = '.c'
C_EXTENSION = '.c'.freeze
def load_configuration(config_file)
def load_yaml(yaml_string)
YAML.load(yaml_string, aliases: true)
rescue ArgumentError
YAML.load(yaml_string)
end
def find_cmock_target(targets_dir, config_file)
return config_file if File.exist?("#{targets_dir}/#{config_file}")
basename = File.basename(config_file, '.yml')
while basename.include?('_')
basename = basename.rpartition('_').first
candidate = "#{basename}.yml"
return candidate if File.exist?("#{targets_dir}/#{candidate}")
end
nil
end
def load_configuration(config_file, cmock_overlay = nil)
$cfg_file = config_file
$cfg = YAML.load(File.read($cfg_file))
$colour_output = false unless $cfg['colour']
$proj = load_yaml(File.read('./project.yml'))
unity_targets_dir = '../../vendor/unity/test/targets'
cmock_targets_dir = '../../test/targets'
config_basename = File.basename(config_file)
path_specified = File.dirname(config_file) != '.'
# Resolve the target file location:
# - path specified → use only that location
# - no path → check current directory first, then vendor unity targets
unity_target = if path_specified
config_file
elsif File.exist?("./#{config_file}")
"./#{config_file}"
else
"#{unity_targets_dir}/#{config_file}"
end
if File.exist?(unity_target)
puts "Loading Unity target: #{unity_target}"
$unity_cfg = load_yaml(File.read(unity_target))
cmock_file = cmock_overlay || find_cmock_target(cmock_targets_dir, config_basename)
if cmock_file
puts "Loading CMock overlay: #{cmock_targets_dir}/#{cmock_file}"
$cmock_cfg = load_yaml(File.read("#{cmock_targets_dir}/#{cmock_file}"))
else
puts "No CMock overlay found for #{config_file}"
$cmock_cfg = {}
end
else
# CMock-only target (no Unity equivalent); it uses Unity format directly
puts "Loading CMock-only target: #{cmock_targets_dir}/#{config_basename}"
$unity_cfg = load_yaml(File.read("#{cmock_targets_dir}/#{config_basename}"))
$cmock_cfg = {}
end
$colour_output = $proj[:project][:colour]
end
def configure_clean
CLEAN.include($cfg['compiler']['build_path'] + '*.*') unless $cfg['compiler']['build_path'].nil?
CLEAN.include("#{$proj[:project][:build_root]}*.*")
end
def configure_toolchain(config_file=DEFAULT_CONFIG_FILE)
config_file += '.yml' unless config_file =~ /\.yml$/
load_configuration(config_file)
def configure_toolchain(config_file = DEFAULT_CONFIG_FILE, cmock_overlay = nil)
config_file ||= DEFAULT_CONFIG_FILE
config_file += '.yml' unless config_file =~ /\.yml$/i
cmock_overlay += '.yml' if cmock_overlay && cmock_overlay !~ /\.yml$/i
load_configuration(config_file, cmock_overlay)
configure_clean
end
def get_unit_test_files
path = $cfg['compiler']['unit_tests_path'] + 'Test*' + C_EXTENSION
path.gsub!(/\\/, '/')
def unit_test_files
path = $proj[:paths][:test] + "Test*#{C_EXTENSION}"
path.tr!('\\', '/')
FileList.new(path)
end
def get_local_include_dirs
include_dirs = $cfg['compiler']['includes']['items'].dup
include_dirs.delete_if {|dir| dir.is_a?(Array)}
return include_dirs
def local_include_dirs
$proj[:paths][:include].reject { |dir| dir.is_a?(Array) }
end
def extract_headers(filename)
includes = []
lines = File.readlines(filename)
lines.each do |line|
m = line.match(/^\s*#include\s+\"\s*(.+\.[hH])\s*\"/)
if not m.nil?
includes << m[1]
end
m = line.match(/^\s*#include\s+"\s*(.+\.[hH])\s*"/)
includes << m[1] unless m.nil?
end
return includes
includes
end
def find_source_file(header, paths)
paths.each do |dir|
src_file = dir + header.ext(C_EXTENSION)
if (File.exists?(src_file))
return src_file
end
return src_file if File.exist?(src_file)
end
return nil
nil
end
def tackit(strings)
case(strings)
when Array
"\"#{strings.join}\""
when /^-/
strings
when /\s/
"\"#{strings}\""
case strings
when Array
"\"#{strings.join}\""
when /^-/
strings
when /\s/
"\"#{strings}\""
else
strings
end
end
# All defines: project common + Unity target + CMock overlay + any extras
def all_defines(extra = [])
(($proj[:defines][:test] || []) +
($unity_cfg[:defines][:test] || []) +
(($cmock_cfg[:defines] || {})[:test] || []) +
extra).uniq
end
# Toolchain-specific include paths: Array items in Unity's :paths: :test:
def toolchain_include_paths
if $unity_cfg[:paths] && $unity_cfg[:paths][:test]
$unity_cfg[:paths][:test]
else
[]
end
end
# Resolve argument template tokens into a flat argument string.
# Supports Ceedling-style positional tokens and legacy Unity COLLECTION_* tokens.
# ${5} → expands to one arg per include path (toolchain paths + project paths combined)
# ${6} → expands to one arg per define
# ${1} → input file(s)
# ${2} → output file
def build_argument_list(raw_args, toolchain_paths, project_paths, defines, input, output)
result = []
raw_args.each do |arg|
if arg.is_a?(Array)
result << arg.join
elsif arg.include?('${5}')
(toolchain_paths + project_paths).each do |p|
result << arg.gsub('${5}', p.is_a?(Array) ? p.join : p.to_s)
end
elsif arg.include?('${6}')
defines.each { |d| result << arg.gsub('${6}', d) }
elsif arg.include?('COLLECTION_PATHS_TEST_TOOLCHAIN_INCLUDE')
toolchain_paths.each { |p| result << "-I\"#{p.is_a?(Array) ? p.join : p}\"" }
elsif arg.include?('COLLECTION_PATHS_TEST_SUPPORT_SOURCE_INCLUDE_VENDOR')
project_paths.each { |p| result << "-I\"#{p}\"" }
elsif arg.include?('COLLECTION_DEFINES_TEST_AND_VENDOR')
defines.each { |d| result << "-D#{d}" }
else
strings
result << arg.gsub('${1}', input.to_s).gsub('${2}', output.to_s)
end
end
result.join(' ')
end
def squash(prefix, items)
result = ''
items.each { |item| result += " #{prefix}#{tackit(item)}" }
return result
end
def compile(file, extra_defines = [])
tool = $unity_cfg[:tools][:test_compiler]
ext = $unity_cfg[:extension][:object] || '.o'
build_root = $proj[:project][:build_root] || 'build/'
obj_file = build_root + File.basename(file, C_EXTENSION) + ext
def build_compiler_fields
command = tackit($cfg['compiler']['path'])
if $cfg['compiler']['defines']['items'].nil?
defines = ''
else
defines = squash($cfg['compiler']['defines']['prefix'], $cfg['compiler']['defines']['items'])
end
options = squash('', $cfg['compiler']['options'])
includes = squash($cfg['compiler']['includes']['prefix'], $cfg['compiler']['includes']['items'])
includes = includes.gsub(/\\ /, ' ').gsub(/\\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR)
return {:command => command, :defines => defines, :options => options, :includes => includes}
end
def compile(file, defines=[])
compiler = build_compiler_fields
cmd_str = "#{compiler[:command]}#{compiler[:defines]}#{compiler[:options]}#{compiler[:includes]} #{file} " +
"#{$cfg['compiler']['object_files']['prefix']}#{$cfg['compiler']['object_files']['destination']}"
obj_file = "#{File.basename(file, C_EXTENSION)}#{$cfg['compiler']['object_files']['extension']}"
execute(cmd_str + obj_file)
return obj_file
end
def build_linker_fields
command = tackit($cfg['linker']['path'])
if $cfg['linker']['options'].nil?
options = ''
else
options = squash('', $cfg['linker']['options'])
end
if ($cfg['linker']['includes'].nil? || $cfg['linker']['includes']['items'].nil?)
includes = ''
else
includes = squash($cfg['linker']['includes']['prefix'], $cfg['linker']['includes']['items'])
end
includes = includes.gsub(/\\ /, ' ').gsub(/\\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR)
return {:command => command, :options => options, :includes => includes}
cmd_str = "#{tackit(tool[:executable])} #{
build_argument_list(tool[:arguments],
toolchain_include_paths,
$proj[:paths][:include],
all_defines(extra_defines),
file, obj_file)}"
execute(cmd_str)
File.basename(obj_file)
end
def link_it(exe_name, obj_list)
linker = build_linker_fields
cmd_str = "#{linker[:command]}#{linker[:includes]} " +
(obj_list.map{|obj|"#{$cfg['linker']['object_files']['path']}#{obj} "}).join +
$cfg['linker']['bin_files']['prefix'] + ' ' +
$cfg['linker']['bin_files']['destination'] +
exe_name + $cfg['linker']['bin_files']['extension'] + " #{linker[:options]}"
tool = $unity_cfg[:tools][:test_linker]
ext = $unity_cfg[:extension][:executable] || ''
build_root = $proj[:project][:build_root] || 'build/'
input_files = obj_list.uniq.map { |obj| build_root + obj }.join(' ')
output_file = build_root + exe_name + ext
cmd_str = "#{tackit(tool[:executable])} #{build_argument_list(tool[:arguments], [], [], [], input_files, output_file)}"
execute(cmd_str)
end
def build_simulator_fields
return nil if $cfg['simulator'].nil?
if $cfg['simulator']['path'].nil?
command = ''
return nil unless $unity_cfg[:tools][:test_fixture]
tool = $unity_cfg[:tools][:test_fixture]
executable = tackit(tool[:executable])
raw_args = tool[:arguments] || []
idx = raw_args.index('${1}')
if idx
pre = raw_args[0...idx].map { |a| a.is_a?(Array) ? a.join : a }.join(' ')
post = raw_args[(idx + 1)..].map { |a| a.is_a?(Array) ? a.join : a }.join(' ')
else
command = (tackit($cfg['simulator']['path']) + ' ')
pre = ''
post = raw_args.map { |a| a.is_a?(Array) ? a.join : a }.join(' ')
end
if $cfg['simulator']['pre_support'].nil?
pre_support = ''
else
pre_support = squash('', $cfg['simulator']['pre_support'])
end
if $cfg['simulator']['post_support'].nil?
post_support = ''
else
post_support = squash('', $cfg['simulator']['post_support'])
end
return {:command => command, :pre_support => pre_support, :post_support => post_support}
{ command: "#{executable} ", pre_support: pre, post_support: post }
end
def execute(command_string, verbose=true, ok_to_fail=false)
def execute(command_string, verbose = true, ok_to_fail = false)
report command_string
output = `#{command_string}`.chomp
report(output) if (verbose && !output.nil? && (output.length > 0))
unless $?.exitstatus.zero? || ok_to_fail
report(output) if verbose && !output.nil? && !output.empty?
unless (!$?.nil? && $?.exitstatus.zero?) || ok_to_fail
raise "Command failed. (Returned #{$?.exitstatus})"
end
return output
output
end
def report_summary
summary = UnityTestSummary.new
summary.root = HERE
results_glob = "#{$cfg['compiler']['build_path']}*.test*"
results_glob.gsub!(/\\/, '/')
results_glob = "#{$proj[:project][:build_root]}*.test*"
results_glob.tr!('\\', '/')
results = Dir[results_glob]
summary.targets = results
report summary.run
raise "There were failures" if (summary.failures > 0) && $return_error_on_failures
raise 'There were failures' if (summary.failures > 0) && $return_error_on_failures
end
def run_tests(test_files)
report 'Running system tests...'
# Tack on TEST define for compiling unit tests
load_configuration($cfg_file)
test_defines = ['TEST']
$cfg['compiler']['defines']['items'] = [] if $cfg['compiler']['defines']['items'].nil?
$cfg['compiler']['defines']['items'] << 'TEST'
include_dirs = get_local_include_dirs
include_dirs = local_include_dirs
# Build and execute each unit test
test_files.each do |test|
# Detect dependencies and build required modules
header_list = (extract_headers(test) + ['cmock.h'] + [($proj[:cmock] || {})[:unity_helper_path]]).compact.uniq
header_list.each do |header|
# create mocks if needed
next unless header =~ /Mock/
require '../../lib/cmock'
@cmock ||= CMock.new($proj[:cmock])
@cmock.setup_mocks([$proj[:paths][:source].first + header.gsub('Mock', '')])
end
# compile all mocks and dependencies
obj_list = []
# Detect dependencies and build required required modules
header_list = extract_headers(test) + ['cmock.h']
header_list.each do |header|
#create mocks if needed
if (header =~ /Mock/)
require "../../lib/cmock.rb"
@cmock ||= CMock.new($cfg_file)
@cmock.setup_mocks([$cfg['compiler']['source_path']+header.gsub('Mock','')])
end
end
#compile all mocks
header_list.each do |header|
#compile source file header if it exists
src_file = find_source_file(header, include_dirs)
if !src_file.nil?
obj_list << compile(src_file, test_defines)
end
obj_list << compile(src_file, ['TEST']) unless src_file.nil?
end
# Build the test runner (generate if configured to do so)
test_base = File.basename(test, C_EXTENSION)
runner_name = test_base + '_Runner.c'
if $cfg['compiler']['runner_path'].nil?
runner_path = $cfg['compiler']['build_path'] + runner_name
test_gen = UnityTestRunnerGenerator.new($cfg_file)
test_gen.run(test, runner_path)
else
runner_path = $cfg['compiler']['runner_path'] + runner_name
end
# Build the test runner
test_base = File.basename(test, C_EXTENSION)
runner_name = "#{test_base}_Runner.c"
runner_path = "#{$proj[:project][:build_root]}#{runner_name}"
UnityTestRunnerGenerator.new({}).run(test, runner_path)
obj_list << compile(runner_path, test_defines)
obj_list << compile(runner_path, ['TEST'])
# Build the test module
obj_list << compile(test, test_defines)
obj_list << compile(test, ['TEST'])
# Link the test executable
link_it(test_base, obj_list)
# Execute unit test and generate results file
simulator = build_simulator_fields
executable = $cfg['linker']['bin_files']['destination'] + test_base + $cfg['linker']['bin_files']['extension']
if simulator.nil?
cmd_str = executable
else
cmd_str = "#{simulator[:command]} #{simulator[:pre_support]} #{executable} #{simulator[:post_support]}"
end
output = execute(cmd_str, true, true)
test_results = $cfg['compiler']['build_path'] + test_base
if output.match(/OK$/m).nil?
test_results += '.testfail'
else
test_results += '.testpass'
end
simulator = build_simulator_fields
build_root = $proj[:project][:build_root]
executable = build_root + test_base + ($unity_cfg[:extension][:executable] || '')
cmd_str = if simulator.nil?
executable
else
"#{simulator[:command]} #{simulator[:pre_support]} #{executable} #{simulator[:post_support]}"
end
output = execute(cmd_str, true)
test_results = build_root + test_base
test_results += output.match(/OK$/m).nil? ? '.testfail' : '.testpass'
File.open(test_results, 'w') { |f| f.print output }
end
end
def build_application(main)
report "Building application..."
report 'Building application...'
obj_list = []
load_configuration($cfg_file)
main_path = $cfg['compiler']['source_path'] + main + C_EXTENSION
main_path = $proj[:paths][:source].first + main + C_EXTENSION
# Detect dependencies and build required required modules
include_dirs = get_local_include_dirs
# Detect dependencies and build required modules
include_dirs = local_include_dirs
extract_headers(main_path).each do |header|
src_file = find_source_file(header, include_dirs)
if !src_file.nil?
obj_list << compile(src_file)
end
obj_list << compile(src_file) unless src_file.nil?
end
# Build the main source file
main_base = File.basename(main_path, C_EXTENSION)
obj_list << compile(main_path)
# Create the executable
link_it(main_base, obj_list)
link_it(File.basename(main_path, C_EXTENSION), obj_list)
end
end
+20 -12
View File
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
// ----------------------------------------------------------------------------
// ATMEL Microcontroller Software Support - ROUSSET -
// ----------------------------------------------------------------------------
@@ -45,15 +52,16 @@
#define AT91SAM7X256_H
typedef volatile unsigned int AT91_REG;// Hardware register definition
typedef volatile void* AT91_PTR;// Hardware register pointer
// *****************************************************************************
// SOFTWARE API DEFINITION FOR System Peripherals
// *****************************************************************************
typedef struct _AT91S_SYS {
AT91_REG AIC_SMR[32]; // Source Mode Register
AT91_REG AIC_SVR[32]; // Source Vector Register
AT91_REG AIC_IVR; // IRQ Vector Register
AT91_REG AIC_FVR; // FIQ Vector Register
AT91_PTR AIC_SVR[32]; // Source Vector Register
AT91_PTR AIC_IVR; // IRQ Vector Register
AT91_PTR AIC_FVR; // FIQ Vector Register
AT91_REG AIC_ISR; // Interrupt Status Register
AT91_REG AIC_IPR; // Interrupt Pending Register
AT91_REG AIC_IMR; // Interrupt Mask Register
@@ -64,7 +72,7 @@ typedef struct _AT91S_SYS {
AT91_REG AIC_ICCR; // Interrupt Clear Command Register
AT91_REG AIC_ISCR; // Interrupt Set Command Register
AT91_REG AIC_EOICR; // End of Interrupt Command Register
AT91_REG AIC_SPU; // Spurious Vector Register
AT91_PTR AIC_SPU; // Spurious Vector Register
AT91_REG AIC_DCR; // Debug Control Register (Protect)
AT91_REG Reserved1[1]; //
AT91_REG AIC_FFER; // Fast Forcing Enable Register
@@ -214,9 +222,9 @@ typedef struct _AT91S_SYS {
// *****************************************************************************
typedef struct _AT91S_AIC {
AT91_REG AIC_SMR[32]; // Source Mode Register
AT91_REG AIC_SVR[32]; // Source Vector Register
AT91_REG AIC_IVR; // IRQ Vector Register
AT91_REG AIC_FVR; // FIQ Vector Register
AT91_PTR AIC_SVR[32]; // Source Vector Register
AT91_PTR AIC_IVR; // IRQ Vector Register
AT91_PTR AIC_FVR; // FIQ Vector Register
AT91_REG AIC_ISR; // Interrupt Status Register
AT91_REG AIC_IPR; // Interrupt Pending Register
AT91_REG AIC_IMR; // Interrupt Mask Register
@@ -227,7 +235,7 @@ typedef struct _AT91S_AIC {
AT91_REG AIC_ICCR; // Interrupt Clear Command Register
AT91_REG AIC_ISCR; // Interrupt Set Command Register
AT91_REG AIC_EOICR; // End of Interrupt Command Register
AT91_REG AIC_SPU; // Spurious Vector Register
AT91_PTR AIC_SPU; // Spurious Vector Register
AT91_REG AIC_DCR; // Debug Control Register (Protect)
AT91_REG Reserved1[1]; //
AT91_REG AIC_FFER; // Fast Forcing Enable Register
@@ -1727,14 +1735,14 @@ typedef struct _AT91S_ADC {
#define AT91C_AIC_EOICR ((AT91_REG *) 0xFFFFF130) // (AIC) End of Interrupt Command Register
#define AT91C_AIC_DCR ((AT91_REG *) 0xFFFFF138) // (AIC) Debug Control Register (Protect)
#define AT91C_AIC_FFER ((AT91_REG *) 0xFFFFF140) // (AIC) Fast Forcing Enable Register
#define AT91C_AIC_SVR ((AT91_REG *) 0xFFFFF080) // (AIC) Source Vector Register
#define AT91C_AIC_SPU ((AT91_REG *) 0xFFFFF134) // (AIC) Spurious Vector Register
#define AT91C_AIC_SVR ((AT91_PTR *) 0xFFFFF080) // (AIC) Source Vector Register
#define AT91C_AIC_SPU ((AT91_PTR *) 0xFFFFF134) // (AIC) Spurious Vector Register
#define AT91C_AIC_FFDR ((AT91_REG *) 0xFFFFF144) // (AIC) Fast Forcing Disable Register
#define AT91C_AIC_FVR ((AT91_REG *) 0xFFFFF104) // (AIC) FIQ Vector Register
#define AT91C_AIC_FVR ((AT91_PTR *) 0xFFFFF104) // (AIC) FIQ Vector Register
#define AT91C_AIC_FFSR ((AT91_REG *) 0xFFFFF148) // (AIC) Fast Forcing Status Register
#define AT91C_AIC_IMR ((AT91_REG *) 0xFFFFF110) // (AIC) Interrupt Mask Register
#define AT91C_AIC_ISR ((AT91_REG *) 0xFFFFF108) // (AIC) Interrupt Status Register
#define AT91C_AIC_IVR ((AT91_REG *) 0xFFFFF100) // (AIC) IRQ Vector Register
#define AT91C_AIC_IVR ((AT91_PTR *) 0xFFFFF100) // (AIC) IRQ Vector Register
#define AT91C_AIC_IDCR ((AT91_REG *) 0xFFFFF124) // (AIC) Interrupt Disable Command Register
#define AT91C_AIC_CISR ((AT91_REG *) 0xFFFFF114) // (AIC) Core Interrupt Status Register
#define AT91C_AIC_IPR ((AT91_REG *) 0xFFFFF10C) // (AIC) Interrupt Pending Register
+7
View File
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "Types.h"
#include "AdcConductor.h"
#include "AdcModel.h"
+7
View File
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#ifndef _ADCCONDUCTOR_H
#define _ADCCONDUCTOR_H
+7
View File
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "Types.h"
#include "AdcHardware.h"
#include "AdcHardwareConfigurator.h"
+7
View File
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#ifndef _ADCHARDWARE_H
#define _ADCHARDWARE_H
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "Types.h"
#include "AdcHardwareConfigurator.h"
#include "ModelConfig.h"
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#ifndef _ADCHARDWARECONFIGURATOR_H
#define _ADCHARDWARECONFIGURATOR_H
+7
View File
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "AdcModel.h"
#include "TaskScheduler.h"
#include "TemperatureCalculator.h"
+7
View File
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#ifndef _ADCMODEL_H
#define _ADCMODEL_H
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "Types.h"
#include "AdcTemperatureSensor.h"
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#ifndef _ADCTEMPERATURESENSOR_H
#define _ADCTEMPERATURESENSOR_H
+7
View File
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "Types.h"
#include "Executor.h"
#include "Model.h"
+7
View File
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#ifndef _EXECUTOR_H
#define _EXECUTOR_H
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "IntrinsicsWrapper.h"
#ifdef __ICCARM__
#include <intrinsics.h>
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#ifndef _INTRINSICS_WRAPPER_H
#define _INTRINSICS_WRAPPER_H
+7
View File
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "Types.h"
#include "IntrinsicsWrapper.h"
+7
View File
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#ifndef _MAIN_H_
#define _MAIN_H_
+7
View File
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "Model.h"
#include "TaskScheduler.h"
#include "TemperatureFilter.h"
+7
View File
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#ifndef _MODEL_H
#define _MODEL_H
+7
View File
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#ifndef _MODELCONFIG_H
#define _MODELCONFIG_H
+7
View File
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "Types.h"
#include "TaskScheduler.h"
+7
View File
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#ifndef _TASKSCHEDULER_H
#define _TASKSCHEDULER_H
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "Types.h"
#include "TemperatureCalculator.h"
#include <math.h>
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#ifndef _TEMPERATURECALCULATOR_H
#define _TEMPERATURECALCULATOR_H
+15 -5
View File
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "Types.h"
#include "TemperatureFilter.h"
#include <math.h>
@@ -27,13 +34,16 @@ void TemperatureFilter_ProcessInput(float temperature)
{
if (temperature == +INFINITY ||
temperature == -INFINITY ||
temperature == +NAN ||
temperature == -NAN)
temperature != temperature)
{
/* Check if +/- Infinity or NaN... reset to -Inf in this instance. */
initialized = FALSE;
temperature = -INFINITY;
temperatureInCelcius = -INFINITY;
}
else
{
/* Otherwise apply our low-pass filter to smooth the values */
temperatureInCelcius = (temperatureInCelcius * 0.75f) + (temperature * 0.25);
}
temperatureInCelcius = (temperatureInCelcius * 0.75f) + (temperature * 0.25);
}
}
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#ifndef _TEMPERATUREFILTER_H
#define _TEMPERATUREFILTER_H
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "Types.h"
#include "TimerConductor.h"
#include "TimerModel.h"
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#ifndef _TIMERCONDUCTOR_H
#define _TIMERCONDUCTOR_H
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "Types.h"
#include "TimerConfigurator.h"
#include "TimerInterruptConfigurator.h"
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#ifndef _TIMERCONFIGURATOR_H
#define _TIMERCONFIGURATOR_H
+7
View File
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "Types.h"
#include "TimerHardware.h"
#include "TimerConfigurator.h"
+7
View File
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#ifndef _TIMERHARDWARE_H
#define _TIMERHARDWARE_H
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "Types.h"
#include "TimerInterruptConfigurator.h"
#include "TimerInterruptHandler.h"
@@ -36,7 +43,7 @@ void Timer_EnableInterrupt(void)
static inline void SetInterruptHandler(void)
{
AT91C_BASE_AIC->AIC_SVR[AT91C_ID_TC0] = (uint32)Timer_InterruptHandler;
AT91C_BASE_AIC->AIC_SVR[AT91C_ID_TC0] = Timer_InterruptHandler;
}
static inline void ConfigureInterruptSourceModeRegister(void)
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#ifndef _TIMERINTERRUPTCONFIGURATOR_H
#define _TIMERINTERRUPTCONFIGURATOR_H
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "Types.h"
#include "TimerInterruptHandler.h"
#include "TimerInterruptConfigurator.h"
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#ifndef _TIMERINTERRUPTHANDLER_H
#define _TIMERINTERRUPTHANDLER_H
+7
View File
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "Types.h"
#include "TimerModel.h"
#include "TaskScheduler.h"
+7
View File
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#ifndef _TIMERMODEL_H
#define _TIMERMODEL_H
+7
View File
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#ifndef _MYTYPES_H_
#define _MYTYPES_H_
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "Types.h"
#include "UsartBaudRateRegisterCalculator.h"
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#ifndef _USARTBAUDRATEREGISTERCALCULATOR_H
#define _USARTBAUDRATEREGISTERCALCULATOR_H
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "Types.h"
#include "UsartConductor.h"
#include "UsartHardware.h"
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#ifndef _USARTCONDUCTOR_H
#define _USARTCONDUCTOR_H
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "Types.h"
#include "UsartConfigurator.h"
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#ifndef _USARTCONFIGURATOR_H
#define _USARTCONFIGURATOR_H
+7
View File
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "Types.h"
#include "UsartHardware.h"
#include "UsartConfigurator.h"
+7
View File
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#ifndef _USARTHARDWARE_H
#define _USARTHARDWARE_H
+7
View File
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "Types.h"
#include "UsartModel.h"
#include "ModelConfig.h"
+7
View File
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#ifndef _USARTMODEL_H
#define _USARTMODEL_H
+7
View File
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "Types.h"
#include "UsartPutChar.h"
#include "UsartTransmitBufferStatus.h"
+7
View File
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#ifndef _USARTPUT_HAR_H
#define _USARTPUT_HAR_H
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "Types.h"
#include "UsartTransmitBufferStatus.h"
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#ifndef _USARTTRANSMITBUFFERSTATUS_H
#define _USARTTRANSMITBUFFERSTATUS_H
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "unity.h"
#include "UnityHelper.h"
#include "Types.h"
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "unity.h"
#include "Types.h"
#include "AdcHardware.h"
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "unity.h"
#include "Types.h"
#include "AdcHardwareConfigurator.h"
+7
View File
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "unity.h"
#include "Types.h"
#include "AdcModel.h"
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "unity.h"
#include "Types.h"
#include "AdcTemperatureSensor.h"
+7
View File
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "unity.h"
#include "Types.h"
#include "Executor.h"
+7
View File
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "unity.h"
#include "Types.h"
#include "MockExecutor.h"
+7
View File
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "unity.h"
#include "Types.h"
#include "Model.h"
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "unity.h"
#include "Types.h"
#include "TaskScheduler.h"
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "unity.h"
#include "Types.h"
#include "TemperatureCalculator.h"
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "unity.h"
#include "Types.h"
#include "TemperatureFilter.h"
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "unity.h"
#include "Types.h"
#include "TimerConductor.h"
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "unity.h"
#include "Types.h"
#include "TimerConfigurator.h"
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "unity.h"
#include "Types.h"
#include "TimerHardware.h"
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "unity.h"
#include "Types.h"
#include "TimerInterruptConfigurator.h"
@@ -35,9 +42,9 @@ void testResetSystemTimeDelegatesTo_Timer_SetSystemTime_Appropriately(void)
void testConfigureInterruptShouldSetInterruptHandlerAppropriately(void)
{
AT91C_BASE_AIC->AIC_SVR[AT91C_ID_TC0] = (uint32)NULL;
AT91C_BASE_AIC->AIC_SVR[AT91C_ID_TC0] = 0;
Timer_ConfigureInterrupt();
TEST_ASSERT_EQUAL((uint32)Timer_InterruptHandler, AT91C_BASE_AIC->AIC_SVR[AT91C_ID_TC0]);
TEST_ASSERT_EQUAL_PTR(Timer_InterruptHandler, AT91C_BASE_AIC->AIC_SVR[AT91C_ID_TC0]);
}
void testConfigureInterruptShouldSetInterruptLevelInSourceModeRegisterAppropriately(void)
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "unity.h"
#include "Types.h"
#include "TimerInterruptHandler.h"
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "unity.h"
#include "Types.h"
#include "TimerModel.h"
@@ -1,3 +1,10 @@
/* =========================================================================
CMock - Automatic Mock Generation for C
ThrowTheSwitch.org
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "unity.h"
#include "Types.h"
#include "UsartBaudRateRegisterCalculator.h"

Some files were not shown because too many files have changed in this diff Show More