From b7d88070d80e14ce922e9b991d48737076da6b08 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 6 Sep 2011 00:16:41 +0200 Subject: [PATCH] fs: add UV_ENOENT error code, add test --- include/uv.h | 1 + src/unix/error.c | 1 + src/uv-common.c | 1 + test/test-fs.c | 35 +++++++++++++++++++++++++++++++++++ test/test-list.h | 2 ++ 5 files changed, 40 insertions(+) diff --git a/include/uv.h b/include/uv.h index bceb432d..5b1144ef 100644 --- a/include/uv.h +++ b/include/uv.h @@ -172,6 +172,7 @@ typedef enum { UV_ENOTCONN, UV_ENOTSOCK, UV_ENOTSUP, + UV_ENOENT, UV_EPIPE, UV_EPROTO, UV_EPROTONOSUPPORT, diff --git a/src/unix/error.c b/src/unix/error.c index 45fcb35c..96615f36 100644 --- a/src/unix/error.c +++ b/src/unix/error.c @@ -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; diff --git a/src/uv-common.c b/src/uv-common.c index 8e85db27..ec31688f 100644 --- a/src/uv-common.c +++ b/src/uv-common.c @@ -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"; diff --git a/test/test-fs.c b/test/test-fs.c index ef3b3b9e..c3712def 100644 --- a/test/test-fs.c +++ b/test/test-fs.c @@ -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; diff --git a/test/test-list.h b/test/test-list.h index fe8f1ed0..9d4a57f6 100644 --- a/test/test-list.h +++ b/test/test-list.h @@ -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)