Fix some intermittent test failures

The byte-compilation was causing errors because some macros were defined
after they were used. Putting them at the top of the file prevents that
from happening.