Add. Travis files

master
Alexey Melnichuk 2014-08-26 12:14:01 +05:00
parent d4b1b76de7
commit ea7a282218
8 changed files with 238 additions and 4 deletions

41
.travis.yml Normal file
View File

@ -0,0 +1,41 @@
language: c
env:
global:
- LUAROCKS=2.2.0
matrix:
- LUA=lua5.1
- LUA=lua5.2
- LUA=luajit
branches:
only:
- master
before_install:
- sudo apt-get update
- bash .travis/setup_lua.sh
- sudo luarocks install lunitx
- wget http://curl.haxx.se/download/curl-7.37.0.tar.gz
- tar -xzf curl-7.37.0.tar.gz
- cd curl-7.37.0/
- ./configure
- make
- sudo make install
- cd ..
- sudo pip install cpp-coveralls
install:
- sudo luarocks make rockspecs/lcurl-scm-0.rockspec CFLAGS="-O2 -fPIC -ftest-coverage -fprofile-arcs" LIBFLAG="-shared --coverage"
script:
- cd test
- lunit.sh run.lua
after_success:
- coveralls -b .. -r ..
notifications:
email:
on_success: change
on_failure: always

15
.travis/platform.sh Normal file
View File

@ -0,0 +1,15 @@
if [ -z "$PLATFORM" ]; then
PLATFORM=$TRAVIS_OS_NAME;
fi
if [ "$PLATFORM" == "osx" ]; then
PLATFORM="macosx";
fi
if [ -z "$PLATFORM" ]; then
if [ "$(uname)" == "Linux" ]; then
PLATFORM="linux";
else
PLATFORM="macosx";
fi;
fi

96
.travis/setup_lua.sh Normal file
View File

@ -0,0 +1,96 @@
#! /bin/bash
# A script for setting up environment for travis-ci testing.
# Sets up Lua and Luarocks.
# LUA must be "lua5.1", "lua5.2" or "luajit".
# luajit2.0 - master v2.0
# luajit2.1 - master v2.1
LUAJIT_BASE="LuaJIT-2.0.3"
source .travis/platform.sh
LUAJIT="no"
if [ "$PLATFORM" == "macosx" ]; then
if [ "$LUA" == "luajit" ]; then
LUAJIT="yes";
fi
if [ "$LUA" == "luajit2.0" ]; then
LUAJIT="yes";
fi
if [ "$LUA" == "luajit2.1" ]; then
LUAJIT="yes";
fi;
elif [ "$(expr substr $LUA 1 6)" == "luajit" ]; then
LUAJIT="yes";
fi
if [ "$LUAJIT" == "yes" ]; then
if [ "$LUA" == "luajit" ]; then
curl http://luajit.org/download/$LUAJIT_BASE.tar.gz | tar xz;
else
git clone http://luajit.org/git/luajit-2.0.git $LUAJIT_BASE;
fi
cd $LUAJIT_BASE
if [ "$LUA" == "luajit2.1" ]; then
git checkout v2.1;
fi
make && sudo make install
if [ "$LUA" == "luajit2.1" ]; then
sudo ln -s /usr/local/bin/luajit-2.1.0-alpha /usr/local/bin/luajit
sudo ln -s /usr/local/bin/luajit /usr/local/bin/lua;
else
sudo ln -s /usr/local/bin/luajit /usr/local/bin/lua;
fi;
else
if [ "$LUA" == "lua5.1" ]; then
curl http://www.lua.org/ftp/lua-5.1.5.tar.gz | tar xz
cd lua-5.1.5;
elif [ "$LUA" == "lua5.2" ]; then
curl http://www.lua.org/ftp/lua-5.2.3.tar.gz | tar xz
cd lua-5.2.3;
fi
sudo make $PLATFORM install;
fi
cd $TRAVIS_BUILD_DIR;
LUAROCKS_BASE=luarocks-$LUAROCKS
# curl http://luarocks.org/releases/$LUAROCKS_BASE.tar.gz | tar xz
git clone https://github.com/keplerproject/luarocks.git $LUAROCKS_BASE
cd $LUAROCKS_BASE
git checkout v$LUAROCKS
if [ "$LUA" == "luajit" ]; then
./configure --lua-suffix=jit --with-lua-include=/usr/local/include/luajit-2.0;
elif [ "$LUA" == "luajit2.0" ]; then
./configure --lua-suffix=jit --with-lua-include=/usr/local/include/luajit-2.0;
elif [ "$LUA" == "luajit2.1" ]; then
./configure --lua-suffix=jit --with-lua-include=/usr/local/include/luajit-2.1;
else
./configure;
fi
make build && sudo make install
cd $TRAVIS_BUILD_DIR
rm -rf $LUAROCKS_BASE
if [ "$LUAJIT" == "yes" ]; then
rm -rf $LUAJIT_BASE;
elif [ "$LUA" == "lua5.1" ]; then
rm -rf lua-5.1.5;
elif [ "$LUA" == "lua5.2" ]; then
rm -rf lua-5.2.3;
fi

View File

@ -7,6 +7,11 @@
-- @treturn[1] httppost new curl HTTP Post object context
function httppost() end
--- Create Easy object
--
-- @treturn[1] easy new curl easy object
function easy() end
--- Returns libcurl version as human readable string
--
function version() end

View File

@ -5,7 +5,7 @@ source = {
dir = "lua-lcurl-master",
}
description = {
summary = "Lua module binding CURL",
summary = "Lua binding to libcurl",
detailed = [[
]],
homepage = "https://github.com/moteus/lua-lcurl",

View File

@ -164,7 +164,10 @@ static int lcurl_opt_set_long_(lua_State *L, int opt){
long val; CURLcode code;
if(lua_isboolean(L, 2)) val = lua_toboolean(L, 2);
else val = luaL_checklong(L, 2);
else{
luaL_argcheck(L, lua_type(L, 2) == LUA_TNUMBER, 2, "number or boolean expected");
val = luaL_checklong(L, 2);
}
code = curl_easy_setopt(p->curl, opt, val);
if(code != CURLE_OK){
@ -176,12 +179,17 @@ static int lcurl_opt_set_long_(lua_State *L, int opt){
static int lcurl_opt_set_string_(lua_State *L, int opt, int store){
lcurl_easy_t *p = lcurl_geteasy(L);
const char *val = luaL_checkstring(L, 2);
CURLcode code = curl_easy_setopt(p->curl, opt, val);
CURLcode code;
luaL_argcheck(L, lua_type(L, 2) == LUA_TSTRING, 2, "string expected");
code = curl_easy_setopt(p->curl, opt, lua_tostring(L, 2));
if(code != CURLE_OK){
return lcurl_fail_ex(L, p->err_mode, LCURL_ERROR_EASY, code);
}
if(store)lcurl_storage_preserve_value(L, p->storage, 2);
lua_settop(L, 1);
return 1;
}

1
test/run.lua Normal file
View File

@ -0,0 +1 @@
require "test_safe"

68
test/test_safe.lua Normal file
View File

@ -0,0 +1,68 @@
local HAS_RUNNER = not not lunit
local lunit = require "lunit"
local TEST_CASE = assert(lunit.TEST_CASE)
local skip = lunit.skip or function() end
local _ENV = TEST_CASE'error_mode' do
local c
function teardown()
if c then c:close() end
c = nil
end
function test_safe()
local curl = require "lcurl.safe"
c = assert(curl.easy())
assert_equal(c, c:setopt_url("aaaaa://123"))
assert_nil(c:perform())
end
function test_raise()
local curl = require "lcurl"
c = assert(curl.easy())
assert_equal(c, c:setopt_url("aaaaa://123"))
assert_error(function() c:perform() end)
end
end
local _ENV = TEST_CASE'setopt' do
local c
function setup()
c = assert(require"lcurl.safe".easy())
end
function teardown()
if c then c:close() end
c = nil
end
function test_number()
assert_equal(c, c:setopt_verbose(false))
assert_equal(c, c:setopt_verbose(true))
assert_equal(c, c:setopt_verbose(1))
assert_equal(c, c:setopt_verbose(0))
assert_error(function() c:setopt_verbose("1") end)
assert_error(function() c:setopt_verbose("true") end)
end
function test_string()
assert_error(function() c:setopt_url(true) end)
assert_error(function() c:setopt_url(1) end)
assert_equal(c, c:setopt_url("1"))
end
function test_array()
assert_error(function() c:setopt_httpheader(true) end)
assert_error(function() c:setopt_httpheader(1) end)
assert_error(function() c:setopt_httpheader("k:v")end)
assert_equal(c, c:setopt_httpheader{"k:v"})
end
end
if not HAS_RUNNER then lunit.run() end