tests: Refactor testlib to simplify and fix Cygwin build Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>