Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

fs: add UV_ENOENT error code, add test

  • Loading branch information...
bnoordhuis committed Sep 5, 2011
1 parent efcd273 commit b7d88070d80e14ce922e9b991d48737076da6b08
Showing with 40 additions and 0 deletions.
  1. +1 −0 include/uv.h
  2. +1 −0 src/unix/error.c
  3. +1 −0 src/uv-common.c
  4. +35 −0 test/test-fs.c
  5. +2 −0 test/test-list.h
@@ -172,6 +172,7 @@ typedef enum {
UV_ENOTCONN,
UV_ENOTSOCK,
UV_ENOTSUP,
UV_ENOENT,
UV_EPIPE,
UV_EPROTO,
UV_EPROTONOSUPPORT,
@@ -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;
@@ -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";
@@ -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;

@@ -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)
@@ -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)

0 comments on commit b7d8807

Please sign in to comment.
You can’t perform that action at this time.