Rewrite tests and testing infrastructure

Uses [tape](https://github.com/substack/tape) and [testling](https://ci.testling.com).