Cleanup must run at the end of the scope no matter how the scope exits. In Go there is defer for this; in C++ the same is built by hand: an object remembers the callbacks, and its destructor fires them. Reverse order is essential — what was opened last closes first.
Implement CallAfter — an object that collects functions via operator() and calls them when it is destroyed, in REVERSE registration order. Like defer in Go, built from a destructor.
Store the function pointers in a vector; the destructor walks it from the back.
Make sure nothing is called inside operator() — the test registers callbacks, checks that nothing ran yet, and only then ends the scope.
Hit Submit (or ⌘/Ctrl + ↵) — test results will show up here.