Skip to content

Commit

Permalink
Use new $(lua.c.lib.dir) make variable provided by make-common, and m…
Browse files Browse the repository at this point in the history
…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
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 38 deletions.
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ EVLUA:
timeout to be created, and your thread continues after the timeout
event occurs. To the person writing the code, this appears as
though we "slept", but other threads still got the opportunity to
run.
run. (VAPOR-WARE)

IMPLEMENTATION NOTES:

Expand Down
4 changes: 2 additions & 2 deletions ev.luadoc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!lua

--- EvLua exposes libev functionality to lua.
module "evlua"
--- Lua Ev exposes libev functionality to lua.
module "ev"

--- The version of libev in use as a floating point.
-- @return floating point version number.
Expand Down
8 changes: 4 additions & 4 deletions module.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ include $(make-common.dir)/tool/cc.mk
include $(make-common.dir)/tool/lua.mk
include $(make-common.dir)/layout.mk

_lib := $(lua.lib.dir)/ev.so
_lib := $(lua.c.lib.dir)/ev.so
_objs := $(call cc.c.to.o,$(addprefix $(_pwd)/, \
lua_ev.c \
lua_ev_io.c \
Expand All @@ -24,9 +24,9 @@ $(_lib): $(_objs)
test: | lua_ev.test

lua ?= lua
lua_ev.test: | $(lua.lib.dir)/ev.so
lua_ev.test: lua.path += $(_pwd)
lua_ev.test: $(wildcard $(_pwd)/test*)
lua_ev.test: | $(lua.c.lib.dir)/ev.so
lua_ev.test: lua.path += $(_pwd)/test
lua_ev.test: $(wildcard $(_pwd)/test/test_*.lua)
@mkdir -p $(tmp.dir)
cd $(tmp.dir); for t in $(filter-out %_help.lua,$^); do \
echo "TESTING: $$t"; \
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
106 changes: 106 additions & 0 deletions test/test_ev_io.lua
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")

4 changes: 2 additions & 2 deletions test_ev_loop.lua → test/test_ev_loop.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

local tap = require("tap")
local ev = require("ev")
local help = require("test_help")
local ev = require("ev")
local help = require("help")
local ok = tap.ok

local noleaks = help.collect_and_assert_no_watchers
Expand Down
2 changes: 1 addition & 1 deletion test_ev_timer.lua → test/test_ev_timer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ print '1..17'

local tap = require("tap")
local ev = require("ev")
local help = require("test_help")
local help = require("help")
local dump = require("dumper").dump
local ok = tap.ok

Expand Down
28 changes: 0 additions & 28 deletions test_ev_io.lua

This file was deleted.

0 comments on commit 44b07b2

Please sign in to comment.