ThrowTheSwitch / CMock

CMock - Mock/stub generator for C
http://throwtheswitch.org
MIT License
671 stars 273 forks source link

Additional option to be able to mock global variables #474

Open cabbott9 opened 5 months ago

cabbott9 commented 5 months ago

Unfortunately I have to work in a lot of legacy code which contains 100s of global variables. If cmock could define these things would be much easier, also preventing the case where a data type changes such that an old test (declaring variable as old type) still seems to pass. Suggestion; when cmock reads the header file any "Extern" or "Extern const" parameters get included as real parameters into the mock_file.c (both cases would be a normal changeable variable, const is ignored). This would be a feature normally turned off, but could be enabled through the configuration. NOTE: Only extern in the header file are to be processed in this way (i.e. if header includes another header (which is bad) that header is ignored for this process)

Header file example: extern U8 myParameter[PARAM_ARRAY_SIZE]; extern const uint8 whatEver;

mock_.c: U8 myParameter[PARAM_ARRAY_SIZE]; uint8 whatEver;