Commit Graph

681 Commits

Author SHA1 Message Date
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 v2.5.1 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