]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-lua: test_io_lua() - Ensure a read error is handled correctly
authorKarl Fleischmann <karl.fleischmann@open-xchange.com>
Wed, 21 May 2025 09:48:21 +0000 (11:48 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Thu, 22 May 2025 11:24:01 +0000 (11:24 +0000)
src/lib-lua/test-io-lua.c
src/lib-lua/test-io-lua.lua

index 7ceb3f9104bce9311ba4f70fdedecf0ed5849add..88580f7817b430ea2025c7903405b364e45dfa16 100644 (file)
@@ -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();
 }
index cdee94f78081ca980efa281d65f337a817b44791..4129848daabdebe6b4ad8d724707a5d6a958c947 100644 (file)
@@ -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