Repository navigation
adding Serial.prinf(const char* format, ...) - #84
arek-jamanskiy wants to merge 1 commit into
Conversation
|
|
||
|
|
||
| size_t Print::printf(const char *format, ...) { | ||
| va_list arg; |
There was a problem hiding this comment.
This should be a call to the fake instance not a concrete implementation.
This might help : https://github.com/FabioBatSilva/ArduinoFake/blob/master/CONTRIBUTING.md
There was a problem hiding this comment.
I tried - maybe not very hard - but mocking method with ... did not work for me at all.
There was a problem hiding this comment.
But I will try one more time. thanks for fast feedback!
| if (this->Instances) { | ||
| delete this->Instances; | ||
| } | ||
| this->Instances = new ArduinoFakeInstances(); |
There was a problem hiding this comment.
this is necessary to fix unit test ArduinoContextTest::test_reset. It failed on my pc all the time no matter what.
It failed because CRT, used in g++ compiler shipped with msys64 installed on Windows, reuses very same memory address (value of this->Instances) when re-creating object just after deleting it. So I created new object first and then deleted the old one
|
@arek-jamanskiy Hi, Thanks for the PR! I've just bumped into the same issue - missing |
|
@FabioBatSilva Hi, The fix for:
should be pretty straigtforward (like the one below): size_t Print::printf(const char *format, ...) {
va_list args;
va_start(args, format);
const size_t result = ArduinoFakeInstance(Print, this)->printf(format, args);
va_end(args);
return result;
}but to be honest, not sure how to test such function, seems like fakeit doesn't recognize a C-style variadic method signatures. The following doesn't compile: void test_printf(void)
{
const char * format = "format %d %s";
int int_var = 123;
const char * char_array_var = "char_array_var";
When(OverloadedMethod(ArduinoFake(Print), printf, size_t(const char*, va_list))).AlwaysReturn();
Print* print = ArduinoFakeMock(Print);
print->printf(format, int_var, char_array_var);
Verify(OverloadedMethod(ArduinoFake(Print), printf, size_t(const char*, va_list)).Using(format, int_var, char_array_var)).Once();
}error: error: cannot convert 'size_t (PrintFake::*)(const char*, ...)' {aka 'long long unsigned int (PrintFake::*)(const char*, ...)'} to 'fakeit::Prototype<long long unsigned int(const char*, char*)>::MemberType<PrintFake>::Type' {aka 'long long unsigned int (PrintFake::*)(const char*, char*)'}Any suggestions? |
|
I tried it the right way, and it didn’t work for me - was not able to make
it compile in tests.
Then I was eager to use it and made PR like it is.
If you can figure it out - you are welcome to fix that.
Hope compiler or unit test library or people trying to fix (or AI agents)
will become smarter after couple of years and fix will be possible:)
…On Fri, Oct 2, 2026 at 01:27 Pavel Sapehin ***@***.***> wrote:
*psxvoid* left a comment (FabioBatSilva/ArduinoFake#84)
<#84 (comment)>
@FabioBatSilva <https://github.com/FabioBatSilva> Hi,
The fix for:
This should be a call to the fake instance not a concrete implementation.
should be pretty straigtforward (like the one below):
size_t Print::printf(const char *format, ...) {
va_list args;
va_start(args, format);
const size_t result = ArduinoFakeInstance(Print, this)->printf(format, args);
va_end(args);
return result;
}
but to be honest, not sure how to test such function, seems like fakeit
doesn't recognize a C-style variadic method signatures. The following
doesn't compiles:
void test_printf(void)
{
const char * format = "format %d %s";
int int_var = 123;
const char * char_array_var = "char_array_var";
When(OverloadedMethod(ArduinoFake(Print), printf, size_t(const char*, va_list))).AlwaysReturn();
Print* print = ArduinoFakeMock(Print);
print->printf(format, int_var, char_array_var);
Verify(OverloadedMethod(ArduinoFake(Print), printf, size_t(const char*, va_list)).Using(format, int_var, char_array_var)).Once();
}
error:
error: cannot convert 'size_t (PrintFake::*)(const char*, ...)' {aka 'long long unsigned int (PrintFake::*)(const char*, ...)'} to 'fakeit::Prototype<long long unsigned int(const char*, char*)>::MemberType<PrintFake>::Type' {aka 'long long unsigned int (PrintFake::*)(const char*, char*)'}
Any suggestions?
—
Reply to this email directly, view it on GitHub
<#84?email_source=notifications&email_token=ADLOV3LQ3MPI3I6NT7SWKFL5R44EFA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKOJUGYYTGMBUGEYKM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLDGN5XXIZLSL5RWY2LDNM#issuecomment-5946130410>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADLOV3LXG2LP57DYS7MYEYL5R44EFAVCNFSNUABEKJSXA33TNF2G64TZHM4TGNJXGY2TGNB3JFZXG5LFHM2DAMBWGAZDCMZQGCQXMAQ>
.
Triage notifications, keep track of coding agent tasks and review pull
requests on the go with GitHub Mobile for iOS
<https://github.com/notifications/mobile/ios/ADLOV3M5YUCFE55HUFLJURL5R44EFA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKOJUGYYTGMBUGEYKM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJKTGN5XXIZLSL5UW64Y>
and Android
<https://github.com/notifications/mobile/android/ADLOV3PEGPODY7QDOUHYPBL5R44EFA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKOJUGYYTGMBUGEYKM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLTGN5XXIZLSL5QW4ZDSN5UWI>.
Download it today!
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
adding Serial.printf(const char* format, ...)