This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH 3/9] selftest.h: add temp_override fixture
On Thu, Sep 08, 2016 at 08:30:47PM -0400, David Malcolm wrote:
> We have a lot of global state in our code. Ideally we'd reduce the
> amount of such global state, but a prerequisite for sane refactoring
> is having automated testing in place to ensure that the refactoring
> doesn't break anything.
>
> However, the global state itself makes it hard to write such automated
> testing.
>
> To break this Catch-22, this patch introduces a class temp_override,
> for temporarily assigning a value to a global variable, saving the old
> value, and then restoring that old value in a dtor.
I expect there are uses for this outside of selftests, so I'd suggest
making it more general. I guess the name is good enough, I would have
done auto_restore, but this is fine. You just need to put it somewhere
generally accessible though I'm not sure what that would be.
Trev