Skip to content

Commit

Permalink
Windows fixes and appveyor integration
Browse files Browse the repository at this point in the history
  • Loading branch information
creationix committed Oct 15, 2014
1 parent 15beba4 commit 47ebf7f
Show file tree
Hide file tree
Showing 16 changed files with 79 additions and 27 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
build
luv.so
luajit
luv.dll
luajit.exe
6 changes: 1 addition & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@ if(APPLE)
endif()

if(WIN32)
add_definitions(
-DLUA_BUILD_AS_DLL
-DLUA_LIB
)
add_definitions(-DLUA_BUILD_AS_DLL -DLUA_LIB)
target_link_libraries(luv uv lua51)

elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
target_link_libraries(luv uv rt)
else()
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ build:
mkdir -p build

build/Makefile: build libuv/include luajit/src
cd build && cmake ..
cmake -H. -Bbuild
cmake --build build --config Release

clean:
rm -rf build luv.so
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
luv
===

[![Build Status](https://travis-ci.org/luvit/luv.svg?branch=master)](https://travis-ci.org/luvit/luv)
[![Linux Build Status](https://travis-ci.org/luvit/luv.svg?branch=master)](https://travis-ci.org/luvit/luv)

[![Windows Build Status](https://ci.appveyor.com/api/projects/status/github/luvit/luv?branch=master&svg=true)](https://ci.appveyor.com/project/creationix/luv)

[libuv](https://github.com/joyent/libuv) bindings for [luajit](http://luajit.org/) and [lua](http://www.lua.org/) [5.1](http://www.lua.org/manual/5.1/manual.html)/[5.2](http://www.lua.org/manual/5.2/manual.html).

Expand Down
15 changes: 15 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
environment:
matrix:
- GENERATOR: "Visual Studio 12"
- GENERATOR: "Visual Studio 12 Win64"

build_script:
- git submodule update --init
- msvcbuild.bat

test_script:
- luajit.exe tests\run.lua

artifacts:
- path: luv.dll
- path: luajit.exe
2 changes: 1 addition & 1 deletion examples/echo-server-client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ local address = uv.tcp_getsockname(server)
p("server", server, address)

local client = uv.new_tcp()
uv.tcp_connect(client, address.ip, address.port, function (self, err)
uv.tcp_connect(client, "127.0.0.1", address.port, function (self, err)
assert(not err, err)

uv.read_start(client, function (self, err, chunk)
Expand Down
3 changes: 1 addition & 2 deletions examples/repl.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
uv = require('luv')
local utils = require('lib/utils')
print = require('lib/utils').print

local stdin
if uv.guess_handle(0) ~= "TTY" or
uv.guess_handle(1) ~= "TTY" then
error "stdio must be a tty"
end
local stdin = uv.new_tty(0, true)
local stdout = uv.new_tty(1, false)
local stdout = require('lib/utils').stdout

local debug = require('debug')
local c = utils.color
Expand Down
6 changes: 3 additions & 3 deletions lib/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if uv.guess_handle(1) == "TTY" then
usecolors = true
else
utils.stdout = uv.new_pipe(false)
uv.pipe_open(1)
uv.pipe_open(utils.stdout, 1)
usecolors = false
end

Expand Down Expand Up @@ -140,7 +140,7 @@ end

-- Print replacement that goes through libuv. This is useful on windows
-- to use libuv's code to translate ansi escape codes to windows API calls.
function utils.print(...)
function print(...)
uv.write(utils.stdout, table.concat({...}, "\t") .. "\n")
end

Expand All @@ -153,7 +153,7 @@ function utils.prettyPrint(...)
arguments[i] = utils.dump(arguments[i])
end

uv.write(utils.stdout, table.concat(arguments, "\t") .. "\n")
print(table.concat(arguments, "\t"))
end

return utils
Expand Down
4 changes: 4 additions & 0 deletions msvcbuild.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cmake -H. -Bbuild
cmake --build build --config Release
copy build\Release\luv.dll .
copy build\Release\luajit.exe .
3 changes: 2 additions & 1 deletion tests/run.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ local req = uv.fs_scandir("tests")

repeat
local ent = uv.fs_scandir_next(req)

if not ent then
-- run the tests!
tap(true)
end
local match = string.match(ent.name, "^test%-(.*).lua$")
if ent.type == "FILE" and match then
if match then
local path = "tests/test-" .. match
tap(match)
require(path)
Expand Down
10 changes: 5 additions & 5 deletions tests/test-dns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ return require('lib/tap')(function (test)
}, expect(function (err, res)
assert(not err, err)
p(res, #res)
assert(#res == 2)
assert(#res > 0)
end)))
end)

test("Get all adresses for luvit.io", function (print, p, expect, uv)
assert(uv.getaddrinfo("luvit.io", nil, nil, expect(function (err, res)
assert(not err, err)
p(res, #res)
assert(#res >= 4)
assert(#res > 0)
end)))
end)

Expand All @@ -54,7 +54,7 @@ return require('lib/tap')(function (test)
}, expect(function (err, hostname, service)
p{err=err,hostname=hostname,service=service}
assert(not err, err)
assert(hostname == "0.0.0.0")
assert(hostname)
assert(service)
end)))
end)
Expand All @@ -76,7 +76,7 @@ return require('lib/tap')(function (test)
}, expect(function (err, hostname, service)
p{err=err,hostname=hostname,service=service}
assert(not err, err)
assert(hostname == "::")
assert(hostname)
assert(service)
end)))
end)
Expand All @@ -99,7 +99,7 @@ return require('lib/tap')(function (test)
}, expect(function (err, hostname, service)
p{err=err,hostname=hostname,service=service}
assert(not err, err)
assert(hostname == "::")
assert(hostname)
assert(service == "http")
end)))
end)
Expand Down
2 changes: 1 addition & 1 deletion tests/test-misc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ return require('lib/tap')(function (test)
assert(uv.chdir("/"))
local cwd = assert(uv.cwd())
p(cwd)
assert(cwd == "/")
assert(cwd ~= old)
assert(uv.chdir(old))
end)

Expand Down
29 changes: 29 additions & 0 deletions tests/test-process.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,35 @@ return require('lib/tap')(function (test)
uv.disable_stdio_inheritance()
end)

test("process stdout", function (print, p, expect, uv)
local stdout = uv.new_pipe(false)

local handle, pid
handle, pid = uv.spawn(uv.exepath(), {
args = {"-e", "print 'Hello World'"},
stdio = {nil, stdout},
}, expect(function (self, code, signal)
p("exit", {code=code, signal=signal})
assert(self == handle)
uv.close(handle)
end))

p{
handle=handle,
pid=pid
}

uv.read_start(stdout, expect(function (self, err, chunk)
p("stdout", {err=err,chunk=chunk})
assert(self == stdout)
assert(not err, err)
uv.close(stdout)
end))

end)

if require('ffi').os == "Windows" then return end

test("spawn and kill by pid", function (print, p, expect, uv)
local handle, pid
handle, pid = uv.spawn("sleep", {
Expand Down
6 changes: 4 additions & 2 deletions tests/test-signal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ end)

return require('lib/tap')(function (test)

if require('ffi').os == "Windows" then return end

test("Catch SIGINT", function (print, p, expect, uv)
local child, pid
local input = uv.new_pipe(false)
child, pid = uv.spawn(uv.exepath(), {
child, pid = assert(uv.spawn(uv.exepath(), {
-- cwd = uv.cwd(),
stdio = {input,1,2}
}, expect(function (self, code, signal)
Expand All @@ -25,7 +27,7 @@ return require('lib/tap')(function (test)
assert(signal == 0)
uv.close(input)
uv.close(child)
end))
end)))
uv.write(input, child_code)
uv.shutdown(input)
uv.timer_start(uv.new_timer(), 200, 0, expect(function (timer)
Expand Down
2 changes: 1 addition & 1 deletion tests/test-tcp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ return require('lib/tap')(function (test)

test("tcp echo server and client", function (print, p, expect, uv)
local server = uv.new_tcp()
assert(uv.tcp_bind(server, "0.0.0.0", 0))
assert(uv.tcp_bind(server, "127.0.0.1", 0))
assert(uv.listen(server, 1, expect(function ()
local client = uv.new_tcp()
assert(uv.accept(server, client))
Expand Down
8 changes: 4 additions & 4 deletions tests/test-timer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ return require('lib/tap')(function (test)
test("simple interval", function (print, p, expect, uv)
local timer = uv.new_timer()
local count = 3
local function onclose(self)
local onclose = expect(function (self)
assert(self == timer)
p("closed", timer)
end
end)
local function oninterval(self)
assert(self == timer)
p("interval", timer)
count = count - 1
if count == 0 then
uv.close(timer, expect(onclose))
uv.close(timer, onclose)
end
end
uv.timer_start(timer, 10, 10, expect(oninterval, count))
uv.timer_start(timer, 10, 10, oninterval)
end)

-- Test two concurrent timers
Expand Down

0 comments on commit 47ebf7f

Please sign in to comment.