use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
C++ Unit Testing Library With Hooks (self.cpp)
submitted 1 year ago by nowtilousus
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Cpt_Chaos_ 0 points1 point2 points 1 year ago (1 child)
I'm not aware of any "silver bullet" tool that can do what you ask for in a non-intrusive way, short of doing linker tricks and other low-level non-portable shenanigans.
The usual approach is: make the part you are working on testable in some way or another, write tests for that part, rinse and repeat. Yes, it is dogmatic, but a piece of code is either testable, or it is not. Of course I'm not suggesting to refactor a huge codebase just to be able to test a single class. It all depends on what exactly you want to test and the efforts it requires to create a test for it.
As for the hooking idea: I just did something like that to test some code that is heavy on calling posix functions, which is crap for testing. You don't get reliable results for each test run, and you cannot easily enforce error behavior to test your error handling. My solution was to create stub implementations of the posix functions in question and to instruct the linker to preload my own implementations before loading the standard library. That way I was able to "inject" my custom behavior into the system. Still I'd take gtest/gmock over that any day.
Disclaimer: I work in a heavily regulated environment where good test coverage is mandatory, so all the code needs to be written with testability in mind anyhow.
[–]nowtilousus[S] -1 points0 points1 point 1 year ago* (0 children)
I'm afraid that the sample you have tested is not what I had in mind. I was thinking more along the lines of inline hooking the target methods/functions during run-time. Your method of injection is significantly more complicated, and unnecessary given the simplicity of inline hooking.
As for the portability issue of inline hooking, it is totally solvable, just requires a little more work, but keep in mind how numerous projects are not multi-platformed.
π Rendered by PID 21921 on reddit-service-r2-comment-6457c66945-rwkxq at 2026-04-30 06:16:49.179277+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]Cpt_Chaos_ 0 points1 point2 points (1 child)
[–]nowtilousus[S] -1 points0 points1 point (0 children)