From c8b4fdf85829d98e185256fba10d50f5b35735a8 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Sat, 28 Mar 2020 15:14:18 -0600 Subject: [PATCH] test/getoptions: guard calls with pcall(); check result of getoption"linger" --- test/tcp-getoptions | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/test/tcp-getoptions b/test/tcp-getoptions index d98b189..fbcc884 100755 --- a/test/tcp-getoptions +++ b/test/tcp-getoptions @@ -4,18 +4,32 @@ local socket = require"socket" port = 8765 +function pcalltest(msg, o, opt) + local a = { pcall(o.getoption, o, opt) } + if a[1] then + print(msg, opt, unpack(a)) + else + print(msg, opt, 'fail: ' .. a[2]) + end +end + function options(o) print("options for", o) for _, opt in ipairs{ "keepalive", "reuseaddr", "tcp-nodelay", "tcp-keepidle", "tcp-keepcnt", "tcp-keepintvl"} do - print("getoption", opt, o:getoption(opt)) + pcalltest("getoption", o, opt) end - print("getoption", "linger", - "on", o:getoption("linger").on, - "timeout", o:getoption("linger").timeout) + r = o:getoption'linger' + if r then + print("getoption", "linger", + "on", r.on, + "timeout", r.timeout) + else + print("getoption", "linger", "no result") + end end local m = socket.tcp()