From 2c5560a8308e48b723e69829abae81c6b232337d Mon Sep 17 00:00:00 2001 From: Ryan Liptak Date: Mon, 6 Jun 2022 21:42:51 -0700 Subject: [PATCH] Add tests for fs_scandir errors Follow up to #605 and #603. The sync error test added here was the actual cause of the segfaults in normal usage. --- tests/test-fs.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/test-fs.lua b/tests/test-fs.lua index 1eb55af2..69274943 100644 --- a/tests/test-fs.lua +++ b/tests/test-fs.lua @@ -125,6 +125,29 @@ return require('lib/tap')(function (test) end end) + test("fs.scandir sync error", function (print, p, expect, uv) + local req, err, code = uv.fs_scandir('BAD_FILE!') + p{err=err,code=code,req=req} + assert(not req) + assert(err) + assert(code == "ENOENT") + end) + + test("fs.scandir async error", function (print, p, expect, uv) + local _req, _err = uv.fs_scandir('BAD_FILE!', expect(function(err, req) + p{err=err,req=req} + assert(not req) + assert(err) + end)) + -- Note: when using the async version, the initial return only errors + -- if there is an error when setting up the internal Libuv call + -- (e.g. if there's an out-of-memory error when copying the path). + -- So even though the callback will have an error, the initial call + -- should return a valid uv_fs_t userdata without an error. + assert(_req) + assert(not _err) + end) + test("fs.scandir async", function (print, p, expect, uv) assert(uv.fs_scandir('.', function(err, req) assert(not err)