Permalink
Browse files

test: assert that readdir on file raises UV_ENOTDIR

  • Loading branch information...
bnoordhuis committed Oct 12, 2011
1 parent 197f591 commit 25a177a2e5760b41c3cc75ad354ef41fafbc26a5
Showing with 35 additions and 0 deletions.
  1. 0 test/fixtures/empty_file
  2. +33 −0 test/test-fs.c
  3. +2 −0 test/test-list.h
View
No changes.
View
@@ -364,6 +364,17 @@ static void empty_readdir_cb(uv_fs_t* req) {
}
+static void file_readdir_cb(uv_fs_t* req) {
+ ASSERT(req == &readdir_req);
+ ASSERT(req->fs_type == UV_FS_READDIR);
+ ASSERT(req->result == -1);
+ ASSERT(req->ptr == NULL);
+ ASSERT(uv_last_error(req->loop).code == UV_ENOTDIR);
+ uv_fs_req_cleanup(req);
+ readdir_cb_count++;
+}
+
+
static void stat_cb(uv_fs_t* req) {
ASSERT(req == &stat_req);
ASSERT(req->fs_type == UV_FS_STAT || req->fs_type == UV_FS_LSTAT);
@@ -1333,3 +1344,25 @@ TEST_IMPL(fs_readdir_empty_dir) {
return 0;
}
+
+
+TEST_IMPL(fs_readdir_file) {
+ const char* path;
+ int r;
+
+ path = "test/fixtures/empty_file";
+ loop = uv_default_loop();
+
+ r = uv_fs_readdir(loop, &readdir_req, path, 0, NULL);
+ ASSERT(r == -1);
+ ASSERT(uv_last_error(loop).code == UV_ENOTDIR);
+
+ r = uv_fs_readdir(loop, &readdir_req, path, 0, file_readdir_cb);
+ ASSERT(r == 0);
+
+ ASSERT(readdir_cb_count == 0);
+ uv_run(loop);
+ ASSERT(readdir_cb_count == 1);
+
+ return 0;
+}
View
@@ -102,6 +102,7 @@ TEST_DECLARE (fs_event_watch_dir)
TEST_DECLARE (fs_event_watch_file)
TEST_DECLARE (fs_event_watch_file_current_dir)
TEST_DECLARE (fs_readdir_empty_dir)
+TEST_DECLARE (fs_readdir_file)
TEST_DECLARE (threadpool_queue_work_simple)
#ifdef _WIN32
TEST_DECLARE (spawn_detect_pipe_name_collisions_on_windows)
@@ -238,6 +239,7 @@ TASK_LIST_START
TEST_ENTRY (fs_event_watch_file)
TEST_ENTRY (fs_event_watch_file_current_dir)
TEST_ENTRY (fs_readdir_empty_dir)
+ TEST_ENTRY (fs_readdir_file)
TEST_ENTRY (threadpool_queue_work_simple)

0 comments on commit 25a177a

Please sign in to comment.