Try $HOSTNAME first, for OS X

OS X uses `$HOSTNAME` instead of the result of hostname(1). In the test
suite, use `$HOSTNAME` first, falling back to hostname(1).