Macos test fixes

Fixes for tests on OS X:
 * Set `DYLD_LIBRARY_PATH` when running tests (485e6a7)
 * `close` is a more portable way of checking errno handling than `fdopendir` (945dc91)