Commit Graph

387 Commits

Author SHA1 Message Date
Mark VanderVoord dcde998087 cleanup style 2021-01-16 22:20:16 -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
ollehu 70d5750659 Merge branch 'master' into master 2020-11-12 16:01:43 +01: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
Hannes Bachl 22a7228bbc add optional folder argument to create_mock() 2020-09-01 10:17:54 +02: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
cloudsftp d304ff273a add StopIgnore to new plugin 2020-08-19 11:25:27 +02:00
cloudsftp 61ed5cc7f8 add more tests for the new plugin 2020-08-19 10:17:05 +02:00
cloudsftp 94ca645061 add first simple test and remove warning "unused parameter" 2020-08-18 16:31:45 +02:00
cloudsftp b735d09603 add plugin :ignore_stateless that solves ThrowTheSwitch/CMock#307 2020-08-18 15:25:55 +02:00
laurens 541e7034ad Remove comments before start of inline-function-parsing 2020-06-13 12:49:33 +02: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 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 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
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 d0214e4e9d add <function>_StopIgnore() function 2020-04-22 15:34:01 +09:30
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
Tuc-An cfcca2e43e convert Boolean values from int to char to reduce memory 2020-03-25 10:00:05 -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 13ee7c9eec Further cleanup based on server results 2020-03-19 11:29:17 -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
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
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
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
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