Append record stub gen code instead of prepending

The difficulty was to make sure incomplete code doesn't trigger code generation.

I've added a function to simplify new test case additions (in the case where the code generation is supposed to have no effect).