Hi All
You may find my script helpful if you need to add tests to legacy C and C++. It generates exploding fakes from C and C++ linker errors. An exploding fake is a test stub, that if executed, fails the test run. It is helpful to quickly resolve linker errors so you can incrementally write more meaningful tests.
https://github.com/jwgrenning/gen-xfakes
If any of you could try it, I'd appreciate any feedback. Right now it only supports gcc/g++. I plan on adding clang and VS.
Cheers, James
/* File: piop-c.c From: build-output.txt Generated file to help to quickly stub C-linkage unresolved external references * When EXPLODING_FAKE_FOR is executed, a message is printed and the test run is existed * You could customize EXPLODING_FAKE_FOR to only fail the test * Add this file to your test build. * Do not include the header files for the referenced functions. The C-linker does not care. Note: a EXPLODING_FAKE_FOR() is generated for global variables too. * They will explode upon write :-) * You might want to resolve these a different way. */ #include <stdio.h> #include <stdlib.h> #define BOOM_MESSAGE printf("BOOM! time to write a better fake for %s\n", __func__) #define EXPLODING_FAKE_FOR(f) void f(void); void f(void) { BOOM_MESSAGE; exit(1); } #define NULL_VOID_FAKE_FOR(f) void f(void); void f(void) {} #define NULL_VALUE_FAKE_FOR(value_type, f, result) value_type f(void); value_type f(void) { return result; } EXPLODING_FAKE_FOR(c:\MyProducts\SAM4S\firmware\test\CppUTest/../../dev/code/device/devd/piod.c:189: undefined reference to `piop_read) EXPLODING_FAKE_FOR(c:\MyProducts\SAM4S\firmware\test\CppUTest/../../dev/code/device/devd/piod.c:244: undefined reference to `piop_write) EXPLODING_FAKE_FOR(c:\MyProducts\SAM4S\firmware\test\CppUTest/../../dev/code/device/devd/piod.c:251: undefined reference to `piop_write) EXPLODING_FAKE_FOR(c:\MyProducts\SAM4S\firmware\test\CppUTest/../../dev/code/device/devd/piod.c:252: undefined reference to `piop_write)
The prototypes for piop_read and piop_write are as follows:
ssize_t piop_read (void *pPort, uint32_t *Value, bool_t bReadPins);
ssize_t piop_write (void *pPort, uint32_t Value, bool_t bSetPins);
/* File: piop-c.c From: build-output.txt Generated file to help to quickly stub C-linkage unresolved external references * When EXPLODING_FAKE_FOR is executed, a message is printed and the test run is existed * You could customize EXPLODING_FAKE_FOR to only fail the test * Add this file to your test build. * Do not include the header files for the referenced functions. The C-linker does not care. Note: a EXPLODING_FAKE_FOR() is generated for global variables too. * They will explode upon write :-) * You might want to resolve these a different way. */ #include <stdio.h> #include <stdlib.h> #define BOOM_MESSAGE printf("BOOM! time to write a better fake for %s\n", __func__) #define EXPLODING_FAKE_FOR(f) ssize_t f(void *, uint32_t *, bool_t); ssize_t f(void *p1, uint32_t *p2, bool_t p3) { BOOM_MESSAGE; exit(1); } #define EXPLODING_FAKE2_FOR(f) ssize_t f(void *, uint32_t, bool_t); ssize_t f(void *p1, uint32_t p2, bool_t p3) { BOOM_MESSAGE; exit(1); } #define NULL_VOID_FAKE_FOR(f) void f(void); void f(void) {} #define NULL_VALUE_FAKE_FOR(value_type, f, result) value_type f(void); value_type f(void) { return result; } EXPLODING_FAKE_FOR(piop_read) EXPLODING_FAKE2_FOR(piop_write)
Hi Dean
Thanks for the report. Look like I need to modify the regex to handle that linker output. Thanks for the details!
James
James Grenning - Author of TDD for Embedded C - wingman-sw.com/tddec
wingman-sw.com
wingman-sw.com/blog
twitter.com/jwgrenning
facebook.com/wingman.sw

--
You received this message because you are subscribed to the Google Groups "cpputest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cpputest+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cpputest/4481c30e-1e0a-441e-a04c-dce2fb3b2c54%40googlegroups.com.