Support TESTFLAGS

Fixes #3021.