-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use new $(lua.c.lib.dir) make variable provided by make-common, and m…
…ove the tests under the test directory. Also added more IO tests that depend on luasocket. These test exemplify the need for using coroutine yields to wrap read/write operations.
- Loading branch information
Brian Maher
committed
Jul 10, 2009
1 parent
db8f10d
commit 44b07b2
Showing
10 changed files
with
116 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
-- This test relies on socket support: | ||
local has_socket, socket = pcall(require, "socket") | ||
if not has_socket then | ||
print '1..0' | ||
print '# No socket library available' | ||
os.exit(0) | ||
end | ||
print '1..??' | ||
|
||
local tap = require("tap") | ||
local ev = require("ev") | ||
local help = require("help") | ||
local ok = tap.ok | ||
local dump = require("dumper").dump | ||
|
||
local noleaks = help.collect_and_assert_no_watchers | ||
local loop = ev.Loop.default | ||
|
||
local function test_stdin() | ||
local io1 = ev.IO.new( | ||
function(loop, io, revents) | ||
ok(true, 'STDIN is writable') | ||
io:stop(loop) | ||
end, 1, ev.WRITE) | ||
io1:start(loop) | ||
loop:loop() | ||
end | ||
|
||
local function newtry() | ||
local try = {} | ||
setmetatable(try, try) | ||
function try:__call(body) | ||
local is_err, err = pcall(body) | ||
for finalizer in ipairs(self) do | ||
-- ignore errors in finalizers: | ||
pcall(finalizer) | ||
end | ||
assert(is_err, err) | ||
end | ||
function try:finally(finalizer) | ||
self[#self + 1] = finalizer | ||
end | ||
return try | ||
end | ||
|
||
local function test_echo() | ||
local got_response | ||
local try = newtry() | ||
try(function() | ||
local server = assert(socket.bind("*", 0)) | ||
try:finally(function() server:close() end) | ||
server:settimeout(0) | ||
ev.IO.new( | ||
function(loop, timer) | ||
timer:stop(loop) | ||
local client = assert(server:accept()) | ||
client:settimeout(0) | ||
ev.IO.new( | ||
function(loop, timer) | ||
timer:stop(loop) | ||
local buff = assert(client:receive('*a')) | ||
ev.IO.new( | ||
function(loop, timer) | ||
timer:stop(loop) | ||
assert(client:send(buff)) | ||
assert(client:shutdown("send")) | ||
end, | ||
client:getfd(), | ||
ev.WRITE):start(loop) | ||
end, | ||
client:getfd(), | ||
ev.READ):start(loop) | ||
end, | ||
server:getfd(), | ||
ev.READ):start(loop) | ||
local port = select(2, server:getsockname()) | ||
local client = assert(socket.connect("127.0.0.1", port)) | ||
try:finally(function() client:close() end) | ||
client:settimeout(0) | ||
ev.IO.new( | ||
function(loop, timer) | ||
timer:stop(loop) | ||
local str = "Hello World" | ||
assert(client:send(str)) | ||
assert(client:shutdown("send")) | ||
ev.IO.new( | ||
function(loop, timer) | ||
timer:stop(loop) | ||
local response = assert(client:receive("*a")) | ||
ok(response == str, | ||
tostring(response) .. " == " .. tostring(str)) | ||
got_response = true | ||
end, | ||
client:getfd(), | ||
ev.READ):start(loop) | ||
end, | ||
client:getfd(), | ||
ev.WRITE):start(loop) | ||
loop:loop() | ||
end) | ||
ok(got_response, "echo") | ||
end | ||
|
||
noleaks(test_stdin, "test_stdin") | ||
noleaks(test_echo, "test_echo") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.