shellcheck does not do deep inspection and so does not see that
we use the EXPECTED variable. Let's help it understand this is
valid. This doesn't really cost us something, but it helps us
enforce useful policies (in many other cases this may be a valid
error indication).
changes some of the test commands to use bash functions
includes some small bug fixes to tests where bugs were
previously not seen due to different plumbing.