fixes #307 and adds tests.

I'm not sure the tests are exactly correct. In the shell one would pass and the other fail. In the suite both pass or both fail.