Fix assorted bugs, make avocado return codes and functional test more complete

I had noticed a bug when an invalid test was passed to the runner, and ended up discovering a lot more. Here's a bunch of juicy fixes and functional tests.