aboutsummaryrefslogtreecommitdiff
path: root/test/testclnt.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/testclnt.lua')
-rw-r--r--test/testclnt.lua28
1 files changed, 15 insertions, 13 deletions
diff --git a/test/testclnt.lua b/test/testclnt.lua
index 348439a..1b64abd 100644
--- a/test/testclnt.lua
+++ b/test/testclnt.lua
@@ -3,18 +3,18 @@ port = port or "8080"
3 3
4function pass(...) 4function pass(...)
5 local s = string.format(unpack(arg)) 5 local s = string.format(unpack(arg))
6 io.write(s, "\n") 6 io.stderr:write(s, "\n")
7end 7end
8 8
9function fail(...) 9function fail(...)
10 local s = string.format(unpack(arg)) 10 local s = string.format(unpack(arg))
11 io.write("ERROR: ", s, "!\n") 11 io.stderr:write("ERROR: ", s, "!\n")
12 os.exit() 12 os.exit()
13end 13end
14 14
15function warn(...) 15function warn(...)
16 local s = string.format(unpack(arg)) 16 local s = string.format(unpack(arg))
17 io.write("WARNING: ", s, "\n") 17 io.stderr:write("WARNING: ", s, "\n")
18end 18end
19 19
20pad = string.rep(" ", 8192) 20pad = string.rep(" ", 8192)
@@ -29,7 +29,7 @@ function remote(...)
29end 29end
30 30
31function test(test) 31function test(test)
32 io.write("----------------------------------------------\n", 32 io.stderr:write("----------------------------------------------\n",
33 "testing: ", test, "\n", 33 "testing: ", test, "\n",
34 "----------------------------------------------\n") 34 "----------------------------------------------\n")
35end 35end
@@ -72,14 +72,14 @@ if not socket.debug then
72 fail("Please define LUASOCKET_DEBUG and recompile LuaSocket") 72 fail("Please define LUASOCKET_DEBUG and recompile LuaSocket")
73end 73end
74 74
75io.write("----------------------------------------------\n", 75io.stderr:write("----------------------------------------------\n",
76"LuaSocket Test Procedures\n", 76"LuaSocket Test Procedures\n",
77"----------------------------------------------\n") 77"----------------------------------------------\n")
78 78
79start = socket.time() 79start = socket.time()
80 80
81function reconnect() 81function reconnect()
82 io.write("attempting data connection... ") 82 io.stderr:write("attempting data connection... ")
83 if data then data:close() end 83 if data then data:close() end
84 remote [[ 84 remote [[
85 if data then data:close() data = nil end 85 if data then data:close() data = nil end
@@ -348,7 +348,7 @@ end
348 348
349------------------------------------------------------------------------ 349------------------------------------------------------------------------
350function accept_timeout() 350function accept_timeout()
351 io.write("accept with timeout (if it hangs, it failed): ") 351 io.stderr:write("accept with timeout (if it hangs, it failed): ")
352 local s, e = socket.bind("*", 0, 0) 352 local s, e = socket.bind("*", 0, 0)
353 assert(s, e) 353 assert(s, e)
354 local t = socket.time() 354 local t = socket.time()
@@ -364,7 +364,8 @@ end
364 364
365------------------------------------------------------------------------ 365------------------------------------------------------------------------
366function connect_timeout() 366function connect_timeout()
367 io.write("connect with timeout (if it hangs, it failed): ") 367 io.stderr:write("connect with timeout (if it hangs, it failed): ")
368 local t = socket.time()
368 local c, e = socket.tcp() 369 local c, e = socket.tcp()
369 assert(c, e) 370 assert(c, e)
370 c:settimeout(0.1) 371 c:settimeout(0.1)
@@ -380,16 +381,17 @@ end
380 381
381------------------------------------------------------------------------ 382------------------------------------------------------------------------
382function accept_errors() 383function accept_errors()
383 io.write("not listening: ") 384 io.stderr:write("not listening: ")
384 local d, e = socket.bind("*", 0) 385 local d, e = socket.bind("*", 0)
385 assert(d, e); 386 assert(d, e);
386 local c, e = socket.tcp(); 387 local c, e = socket.tcp();
387 assert(c, e); 388 assert(c, e);
388 d:setfd(c:getfd()) 389 d:setfd(c:getfd())
390 d:settimeout(2)
389 local r, e = d:accept() 391 local r, e = d:accept()
390 assert(not r and e == "not listening", e) 392 assert(not r and e == "not listening", e)
391 print("ok") 393 print("ok")
392 io.write("not supported: ") 394 io.stderr:write("not supported: ")
393 local c, e = socket.udp() 395 local c, e = socket.udp()
394 assert(c, e); 396 assert(c, e);
395 d:setfd(c:getfd()) 397 d:setfd(c:getfd())
@@ -400,11 +402,11 @@ end
400 402
401------------------------------------------------------------------------ 403------------------------------------------------------------------------
402function connect_errors() 404function connect_errors()
403 io.write("connection refused: ") 405 io.stderr:write("connection refused: ")
404 local c, e = socket.connect("localhost", 1); 406 local c, e = socket.connect("localhost", 1);
405 assert(not c and e == "connection refused", e) 407 assert(not c and e == "connection refused", e)
406 print("ok") 408 print("ok")
407 io.write("host not found: ") 409 io.stderr:write("host not found: ")
408 local c, e = socket.connect("not.exist.com", 1); 410 local c, e = socket.connect("not.exist.com", 1);
409 assert(not c and e == "host not found", e) 411 assert(not c and e == "host not found", e)
410 print("ok") 412 print("ok")
@@ -534,7 +536,7 @@ test_raw(1)
534test("non-blocking transfer") 536test("non-blocking transfer")
535reconnect() 537reconnect()
536-- the value is not important, we only want 538-- the value is not important, we only want
537-- to test non-blockin I/O anyways 539-- to test non-blocking I/O anyways
538data:settimeout(200) 540data:settimeout(200)
539test_raw(1) 541test_raw(1)
540test_raw(17) 542test_raw(17)