Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
fs: add UV_ENOENT error code, add test
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Sep 5, 2011
1 parent efcd273 commit b7d8807
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/uv.h
Expand Up @@ -172,6 +172,7 @@ typedef enum {
UV_ENOTCONN,
UV_ENOTSOCK,
UV_ENOTSUP,
UV_ENOENT,
UV_EPIPE,
UV_EPROTO,
UV_EPROTONOSUPPORT,
Expand Down
1 change: 1 addition & 0 deletions src/unix/error.c
Expand Up @@ -69,6 +69,7 @@ char* uv_strerror(uv_err_t err) {
uv_err_code uv_translate_sys_error(int sys_errno) {
switch (sys_errno) {
case 0: return UV_OK;
case ENOENT: return UV_ENOENT;
case EACCES: return UV_EACCESS;
case EBADF: return UV_EBADF;
case EPIPE: return UV_EPIPE;
Expand Down
1 change: 1 addition & 0 deletions src/uv-common.c
Expand Up @@ -81,6 +81,7 @@ const char* uv_err_name(uv_err_t err) {
case UV_ENOTCONN: return "ENOTCONN";
case UV_ENOTSOCK: return "ENOTSOCK";
case UV_ENOTSUP: return "ENOTSUP";
case UV_ENOENT: return "ENOENT";
case UV_EPIPE: return "EPIPE";
case UV_EPROTO: return "EPROTO";
case UV_EPROTONOSUPPORT: return "EPROTONOSUPPORT";
Expand Down
35 changes: 35 additions & 0 deletions test/test-fs.c
Expand Up @@ -360,6 +360,41 @@ static void sendfile_cb(uv_fs_t* req) {
}


static void open_noent_cb(uv_fs_t* req) {
ASSERT(req->fs_type == UV_FS_OPEN);
ASSERT(req->errorno == UV_ENOENT);
ASSERT(req->result == -1);
open_cb_count++;
uv_fs_req_cleanup(req);
}


TEST_IMPL(fs_file_noent) {
uv_fs_t req;
int r;

uv_init();
loop = uv_default_loop();

r = uv_fs_open(loop, &req, "does_not_exist", O_RDONLY, 0, NULL);
ASSERT(r == -1);
ASSERT(req.result == -1);
ASSERT(uv_last_error(loop).code == UV_ENOENT);
uv_fs_req_cleanup(&req);

r = uv_fs_open(loop, &req, "does_not_exist", O_RDONLY, 0, open_noent_cb);
ASSERT(r == 0);

ASSERT(open_cb_count == 0);
uv_run(loop);
ASSERT(open_cb_count == 1);

/* TODO add EACCES test */

return 0;
}


TEST_IMPL(fs_file_async) {
int r;

Expand Down
2 changes: 2 additions & 0 deletions test/test-list.h
Expand Up @@ -72,6 +72,7 @@ TEST_DECLARE (spawn_exit_code)
TEST_DECLARE (spawn_stdout)
TEST_DECLARE (spawn_stdin)
TEST_DECLARE (spawn_and_kill)
TEST_DECLARE (fs_file_noent)
TEST_DECLARE (fs_file_async)
TEST_DECLARE (fs_file_sync)
TEST_DECLARE (fs_async_dir)
Expand Down Expand Up @@ -180,6 +181,7 @@ TASK_LIST_START
TEST_ENTRY (environment_creation)
#endif

TEST_ENTRY (fs_file_noent)
TEST_ENTRY (fs_file_async)
TEST_ENTRY (fs_file_sync)
TEST_ENTRY (fs_async_dir)
Expand Down

0 comments on commit b7d8807

Please sign in to comment.