Commit Graph

323 Commits

Author SHA1 Message Date
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 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
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
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 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 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 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
Dom Postorivo 0cdc742538 make ret variable more unique to prevent collision with with code under test 2019-11-04 11:23:57 -05:00
mvandervoord 7615806e34 Address issue #196 to better deal with passing pointer types 2019-10-30 14:10:59 -04:00
John Lindgren 277dc34fa1 Fix typo (unity_gelper -> unity_helper). 2019-10-30 12:45:19 -04:00
mvandervoord cda809765e Protect again memory overruns.
Get rid of warnings.
2019-10-23 17:12:18 -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
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 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
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
Edgar J Holleis 23d2341c4c Improve comment suppression to cope with '/*xxx*//*yyy*/'. 2019-08-22 10:58:13 +02: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 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 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 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 5eab75a078 Reimplement PR 227 with fixed tests. 2019-07-06 12:11:56 -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
merazmus a5616dc2df Fix missing framework header in mock header files 2019-03-22 09:10:16 +01:00
Xenoamor 80454dc1f3 Fix bug where if folder mocks doesn't exist it fails 2019-03-21 19:08:26 +00:00
John Lindgren cfa46d6440 Prevent undefined behavior due to typedef array usage. 2018-12-04 18:22:53 -05:00