From: Karl Fleischmann Date: Wed, 21 May 2025 09:48:21 +0000 (+0200) Subject: lib-lua: test_io_lua() - Ensure a read error is handled correctly X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=79e9c12d78d784cf143c170b50b794ffb7f8a01e;p=thirdparty%2Fdovecot%2Fcore.git lib-lua: test_io_lua() - Ensure a read error is handled correctly --- diff --git a/src/lib-lua/test-io-lua.c b/src/lib-lua/test-io-lua.c index 7ceb3f9104..88580f7817 100644 --- a/src/lib-lua/test-io-lua.c +++ b/src/lib-lua/test-io-lua.c @@ -68,10 +68,17 @@ static void test_io_lua(void) if (dlua_pcall(script->L, "test_read_bytes", 1, 0, &error) < 0) i_fatal("%s", error); + /* Check error handling. */ + is = i_stream_create_error(EINVAL); + dlua_push_istream(script, is); + i_stream_unref(&is); + if (dlua_pcall(script->L, "test_read_error", 1, 0, &error) < 0) + i_fatal("%s", error); + dlua_script_unref(&script); /* ensure all tests were actually ran */ - test_assert_ucmp(assert_count, ==, 19); + test_assert_ucmp(assert_count, ==, 21); test_end(); } diff --git a/src/lib-lua/test-io-lua.lua b/src/lib-lua/test-io-lua.lua index cdee94f780..4129848daa 100644 --- a/src/lib-lua/test-io-lua.lua +++ b/src/lib-lua/test-io-lua.lua @@ -44,3 +44,9 @@ function test_read_bytes(is) test_assert("r == \\0\\1\\2\\3\\4\\5", r == "\0\1\2\3\4\5") test_assert("#r==6", #r == 6) end + +function test_read_error(is) + local _, err, errno = is:read(1) + test_assert("errno == 22", errno == 22) + test_assert("err = (error): Invalid argument", err == "(error): Invalid argument") +end