The C function tries to match
I don't know where it originated. Now I've scribbled one C function try matching tool . It can probably match the C function definition from the pure C source file that can be compiled -- that is, the matching C function definition factor
Modifier return value type function name parameter list
Free combination mode. It can be used to support some less important lazy behaviors:
- statement
- Full coverage of unit test function
For the matching of free combination patterns of C function definition factors, there are probably the following two difficulties:
- C function can cause great interference, and the processing strategy is to skip the function body.
- Comments and quotation marks will cause interference. The processing strategy is to delete them.
with ln_co.c Try it for the target.
Make a declaration
1.1 definition of matching function
$ awk -f tryfun ln_co.c try=declare results in cfnof... done. $ cat cfnof static bool _put_unit_ci(ci_s *ci, int nr); static bool inline _put_cc(cc_s *cc); /* Save space and omit multiple lines */ void * co_send(ci_s *ci); int co_yield(ci_s *ci); void * co_yield_from(cc_s *cc, ci_s *self, char *id, void *co, void *arg); /* ... */
1.2 matching global function definitions
$ awk -f tryfun ln_co.c try=declare decorate=extern cfnof=_clear results in cfnof... done. $ cat cfnof /* ... */ void * co_send(ci_s *ci); int co_yield(ci_s *ci); void * co_yield_from(cc_s *cc, ci_s *self, char *id, void *co, void *arg); /* ... */
1.3 matching static function definitions
$ awk -f tryfun ln_co.c try=declare decorate=static cfnof=_clear results in cfnof... done. $ cat cfnof static bool _put_unit_ci(ci_s *ci, int nr); static bool inline _put_cc(cc_s *cc); /* ... */
2 unit test - full function coverage
Some consideration should be given to the processing of C function type parameters. The processing method here is to directly transfer the function type parameters to NULL.
2.1 random call
$ awk -f tryfun ln_co.c try=randcall cfnof=_clear results in cfnof... done. $ cat cfnof ci_s *ci = NULL; int nr; _put_unit_ci(ci, nr); /* ... */ cc_s *cc = NULL; ci_s *self = NULL; char *id = NULL; void *co = NULL; void *arg = NULL; co_yield_from(cc,self,id,co,arg); /* ... */
2.2 random call output to google test unit test framework
The function under this heading is the default behavior of the tool, which is suspected of being lazy and utilitarian.
$ awk -f tryfun ln_co.c cfnof=_clear results in cfnof... done. $ cat cfnof TEST(_put_unit_ci_t, case0) { ci_s *ci = NULL; int nr; _put_unit_ci(ci, nr); } /* ... */ TEST(co_yield_t, case0) { ci_s *ci = NULL; co_yield(ci); } TEST(co_yield_from_t, case0) { cc_s *cc = NULL; ci_s *self = NULL; char *id = NULL; void *co = NULL; void *arg = NULL; co_yield_from(cc,self,id,co,arg); } /* ... */
The combination of try, decorate and cfnof should not be shown one by one.
3 add a little challenge
It seems that the average sophomore in China can handle the above contents. It's better to increase the difficulty to reach the average sophomore level in China - randomly remove LN_ Some line breaks in co.c make it look like the following:
int co_yield(ci_s *ci){/*Save column omits multiple characters*/return rv;}/*Follow definition*/void * co_yield_from(cc_s *cc, ci_s *self, char *id, void *co, void *arg){int ret;ci_s *ci = NULL; /*...*/return rv;}/*...*/
Try matching again:
$ awk -f tryfun ln_co.c cfnof=_clear results in cfnof... done. $ cat cfnof /* ... */ TEST(co_yield_t, case0) { ci_s *ci = NULL; co_yield(ci); } TEST(co_yield_from_t, case0) { cc_s *cc = NULL; ci_s *self = NULL; char *id = NULL; void *co = NULL; void *arg = NULL; co_yield_from(cc,self,id,co,arg); } /* ... */
4. Short protection
Although the C function try matching tool can handle a little challenge, it can't handle all the challenges, which is normal. If you encounter a challenge that cannot be completed by repairing the tool, or return to the manual mode to complete the corresponding functions, the manual mode should be the most natural.