Merge pull request #60 from moteus/master

Add. Appveyor test building.
This commit is contained in:
Alexey Melnichuk 2015-06-15 12:00:48 +03:00
commit d3a4dd9bdd
6 changed files with 1485 additions and 1139 deletions

215
.appveyor/install.bat Normal file
View File

@ -0,0 +1,215 @@
@echo off
cd %APPVEYOR_BUILD_FOLDER%
:: =========================================================
:: Set some defaults. Infer some variables.
::
:: These are set globally
if not "%LUA_VER%"=="" (
set LUA=lua
set LUA_SHORTV=%LUA_VER:~0,3%
) else if not "%LJ_VER%"=="" (
set LUA=luajit
set LJ_SHORTV=%LJ_VER:~0,3%
set LUA_SHORTV=5.1
) else (
echo Can not recognize needed Lua version
echo Please set LUA_VER or LJ_VER
exit /B 3
)
:: Now we declare a scope
Setlocal EnableDelayedExpansion EnableExtensions
set LUAROCKS_SHORTV=%LUAROCKS_VER:~0,3%
if not defined LUAROCKS_URL set LUAROCKS_URL=http://keplerproject.github.io/luarocks/releases
if not defined LUAROCKS_REPO set LUAROCKS_REPO=http://rocks.moonscript.org
if not defined LUA_URL set LUA_URL=http://www.lua.org/ftp
if not defined LUAJIT_GIT_REPO set LUAJIT_GIT_REPO=http://luajit.org/git/luajit-2.0.git
if not defined LUAJIT_URL set LUAJIT_URL=http://luajit.org/download
if not defined LR_EXTERNAL set LR_EXTERNAL=c:\external
if not defined LUAROCKS_INSTALL set LUAROCKS_INSTALL=%ProgramFiles(x86)%\LuaRocks
if not defined LR_ROOT set LR_ROOT=%LUAROCKS_INSTALL%\%LUAROCKS_SHORTV%
if not defined LR_SYSTREE set LR_SYSTREE=%LUAROCKS_INSTALL%\systree
if /I "%platform%"=="x64" set LR_SYSTREE=%ProgramFiles%\LuaRocks\systree
if not defined SEVENZIP set SEVENZIP=7z
::
:: =========================================================
:: first create some necessary directories:
mkdir downloads 2>NUL
:: defines LUA_DIR so Cmake can find this Lua install
if "%LUA%"=="luajit" (
set LUA_DIR=c:\lua\lj%LJ_SHORTV%
) else (
set LUA_DIR=c:\lua\%LUA_VER%
)
:: Download and compile Lua (or LuaJIT)
if "%LUA%"=="luajit" (
if not exist %LUA_DIR% (
if "%LJ_SHORTV%"=="2.1" (
:: Clone repository and checkout 2.1 branch
set lj_source_folder=%APPVEYOR_BUILD_FOLDER%\downloads\luajit-%LJ_VER%
if not exist !lj_source_folder! (
echo Cloning git repo %LUAJIT_GIT_REPO% !lj_source_folder!
git clone %LUAJIT_GIT_REPO% !lj_source_folder! || call :die "Failed to clone repository"
)
cd !lj_source_folder!\src
git checkout v2.1 || call :die
) else (
set lj_source_folder=%APPVEYOR_BUILD_FOLDER%\downloads\luajit-%LJ_VER%
if not exist !lj_source_folder! (
echo Downloading... %LUAJIT_URL%/LuaJIT-%LJ_VER%.tar.gz
curl --silent --fail --max-time 120 --connect-timeout 30 %LUAJIT_URL%/LuaJIT-%LJ_VER%.tar.gz | %SEVENZIP% x -si -so -tgzip | %SEVENZIP% x -si -ttar -aoa -odownloads
)
cd !lj_source_folder!\src
)
:: Compiles LuaJIT
call msvcbuild.bat
mkdir %LUA_DIR% 2> NUL
for %%a in (bin include lib) do ( mkdir "%LUA_DIR%\%%a" )
for %%a in (luajit.exe lua51.dll) do ( move "!lj_source_folder!\src\%%a" "%LUA_DIR%\bin" )
move "!lj_source_folder!\src\lua51.lib" "%LUA_DIR%\lib"
for %%a in (lauxlib.h lua.h lua.hpp luaconf.h lualib.h luajit.h) do (
copy "!lj_source_folder!\src\%%a" "%LUA_DIR%\include"
)
) else (
echo LuaJIT %LJ_VER% already installed at %LUA_DIR%
)
) else (
if not exist %LUA_DIR% (
:: Download and compile Lua
if not exist downloads\lua-%LUA_VER% (
curl --silent --fail --max-time 120 --connect-timeout 30 %LUA_URL%/lua-%LUA_VER%.tar.gz | %SEVENZIP% x -si -so -tgzip | %SEVENZIP% x -si -ttar -aoa -odownloads
)
mkdir downloads\lua-%LUA_VER%\etc 2> NUL
if not exist downloads\lua-%LUA_VER%\etc\winmake.bat (
curl --silent --location --insecure --fail --max-time 120 --connect-timeout 30 https://github.com/Tieske/luawinmake/archive/master.tar.gz | %SEVENZIP% x -si -so -tgzip | %SEVENZIP% e -si -ttar -aoa -odownloads\lua-%LUA_VER%\etc luawinmake-master\etc\winmake.bat
)
cd downloads\lua-%LUA_VER%
call etc\winmake
call etc\winmake install %LUA_DIR%
) else (
echo Lua %LUA_VER% already installed at %LUA_DIR%
)
)
if not exist %LUA_DIR%\bin\%LUA%.exe (
echo Missing Lua interpreter
exit /B 1
)
set PATH=%LUA_DIR%\bin;%PATH%
call %LUA% -v
:: =========================================================
:: LuaRocks
:: =========================================================
if not exist "%LR_ROOT%" (
:: Downloads and installs LuaRocks
cd %APPVEYOR_BUILD_FOLDER%
if not exist downloads\luarocks-%LUAROCKS_VER%-win32.zip (
echo Downloading LuaRocks...
curl --silent --fail --max-time 120 --connect-timeout 30 --output downloads\luarocks-%LUAROCKS_VER%-win32.zip %LUAROCKS_URL%/luarocks-%LUAROCKS_VER%-win32.zip
%SEVENZIP% x -aoa -odownloads downloads\luarocks-%LUAROCKS_VER%-win32.zip
)
cd downloads\luarocks-%LUAROCKS_VER%-win32
call install.bat /LUA %LUA_DIR% /Q /LV %LUA_SHORTV% /P "%LUAROCKS_INSTALL%"
)
if not exist "%LR_ROOT%" (
echo LuaRocks installation failed.
exit /B 2
)
set PATH=%LR_ROOT%;%LR_SYSTREE%\bin;%PATH%
:: Lua will use just the system rocks
set LUA_PATH=%LR_ROOT%\lua\?.lua;%LR_ROOT%\lua\?\init.lua
set LUA_PATH=%LUA_PATH%;%LR_SYSTREE%\share\lua\%LUA_SHORTV%\?.lua
set LUA_PATH=%LUA_PATH%;%LR_SYSTREE%\share\lua\%LUA_SHORTV%\?\init.lua
set LUA_CPATH=%LR_SYSTREE%\lib\lua\%LUA_SHORTV%\?.dll
call luarocks --version || call :die "Error with LuaRocks installation"
call luarocks list
if not exist "%LR_EXTERNAL%" (
mkdir "%LR_EXTERNAL%"
mkdir "%LR_EXTERNAL%\lib"
mkdir "%LR_EXTERNAL%\include"
)
set PATH=%LR_EXTERNAL%;%PATH%
:: Exports the following variables:
:: (beware of whitespace between & and ^ below)
endlocal & set PATH=%PATH%&^
set LUA_DIR=%LUA_DIR%&^
set LR_SYSTREE=%LR_SYSTREE%&^
set LUA_PATH=%LUA_PATH%&^
set LUA_CPATH=%LUA_CPATH%&^
set LR_EXTERNAL=%LR_EXTERNAL%
echo ======================================================
if "%LUA%"=="luajit" (
echo Installation of LuaJIT %LJ_VER% and LuaRocks %LUAROCKS_VER% done.
) else (
echo Installation of Lua %LUA_VER% and LuaRocks %LUAROCKS_VER% done.
)
echo Platform - %platform%
echo LUA - %LUA%
echo LUA_SHORTV - %LUA_SHORTV%
echo LJ_SHORTV - %LJ_SHORTV%
echo LUA_PATH - %LUA_PATH%
echo LUA_CPATH - %LUA_CPATH%
echo
echo LR_EXTERNAL - %LR_EXTERNAL%
echo ======================================================
goto :eof
:: This blank space is intentional. If you see errors like "The system cannot find the batch label specified 'foo'"
:: then try adding or removing blank lines lines above.
:: Yes, really.
:: http://stackoverflow.com/questions/232651/why-the-system-cannot-find-the-batch-label-specified-is-thrown-even-if-label-e
:: helper functions:
:: for bailing out when an error occurred
:die %1
echo %1
exit 1
goto :eof

View File

@ -0,0 +1,48 @@
SETLOCAL
set PLAT_NAME=Win32
set CURL_PLAT=Win32
set CURL_URL=http://curl.haxx.se/download
set CURL_CFG=DLL Release - DLL Windows SSPI
if /I "%platform%" == "x64" (
set PLAT_NAME=Win64
set CURL_PLAT=x64
)
cd %APPVEYOR_BUILD_FOLDER%
echo =========================================
echo External library path: %LR_EXTERNAL%
echo =========================================
if not exist %LR_EXTERNAL%\libcurl.dll (
@echo Download %CURL_URL%/curl-%CURL_VER%.zip ...
appveyor DownloadFile %CURL_URL%/curl-%CURL_VER%.zip
7z x curl-%CURL_VER%.zip
cd curl-%CURL_VER%
@echo Build curl %CURL_CFG% / %PLAT_NAME% ...
if exist projects\Windows\VC12\curl.sln (
msbuild projects\Windows\VC12\curl.sln /p:Configuration="%CURL_CFG%" /p:Platform=%CURL_PLAT%
) else (
msbuild projects\Windows\VC12\curl-all.sln /p:Configuration="%CURL_CFG%" /p:Platform=%CURL_PLAT%
)
@echo Build curl done
if not exist %LR_EXTERNAL%\include\curl mkdir %LR_EXTERNAL%\include\curl
copy "include\curl\*.h" %LR_EXTERNAL%\include\curl
copy "build\%PLAT_NAME%\VC12\%CURL_CFG%\libcurl.lib" %LR_EXTERNAL%\lib\libcurl.lib
copy "build\%PLAT_NAME%\VC12\%CURL_CFG%\libcurl.dll" %LR_EXTERNAL%\libcurl.dll
)
if not exist %LR_EXTERNAL%\libcurl.dll (
exit /B 1
)
appveyor PushArtifact %LR_EXTERNAL%\libcurl.dll -DeploymentName ext-deps
cd %APPVEYOR_BUILD_FOLDER%

View File

@ -0,0 +1,12 @@
@setlocal
@for /f "delims=" %%A in ('luarocks pack %1') do @set "rock_name=%%A"
@set rock_name=%rock_name:Packed: =%
@echo make rock file as artifact: %rock_name%
@appveyor PushArtifact %rock_name% -DeploymentName %2
@endlocal

65
appveyor.yml Normal file
View File

@ -0,0 +1,65 @@
version: 0.3.2.{build}
os:
- Windows Server 2012 R2
shallow_clone: true
environment:
LUAROCKS_VER: 2.2.1
CURL_VER: 7.41.0
matrix:
- LUA_VER: 5.1.5
# - LUA_VER: 5.2.4
# - LUA_VER: 5.3.0
# - LJ_VER: 2.0.3
# - LJ_VER: 2.1
platform:
- x64
- x86
cache:
- c:\lua -> appveyor.yml
- c:\external -> appveyor.yml
- C:\Program Files (x86)\LuaRocks -> appveyor.yml
- C:\Program Files\LuaRocks -> appveyor.yml
init:
- call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" %platform%
install:
# Setup Lua development/build environment
- call .appveyor\install.bat
before_build:
# external deps
- call .appveyor\install_curl.bat
build_script:
- set LUA_CURL_VER=scm-0
- if "%APPVEYOR_REPO_TAG%" == "true" set set LUA_CURL_VER=%APPVEYOR_REPO_TAG_NAME:~1%-1
- echo "Making lua-curl-%LUA_CURL_VER% ..."
- luarocks make rockspecs/lua-curl-%LUA_CURL_VER%.rockspec
before_test:
# test deps
- luarocks install lunitx
- luarocks install dkjson
- luarocks install luafilesystem
- if "%LUA_SHORTV%"=="5.1" luarocks install bit32
- luarocks install lua-path
test_script:
- echo "Testing..."
- cd %APPVEYOR_BUILD_FOLDER%\test
- lua test_easy.lua
- lua test_safe.lua
- lua test_form.lua
- lua test_pause02.c.lua
- lua test_curl.lua
after_test:
- cd %APPVEYOR_BUILD_FOLDER%
- .appveyor\pack_artifact.bat lua-curl bin-rock

View File

@ -1,308 +1,308 @@
local lunit, RUN = lunit do
RUN = lunit and function()end or function ()
local res = lunit.run()
if res.errors + res.failed > 0 then
os.exit(-1)
end
return os.exit(0)
end
lunit = require "lunit"
end
local _,luacov = pcall(require, "luacov")
local TEST_CASE = assert(lunit.TEST_CASE)
local skip = lunit.skip or function() end
local curl = require "cURL"
local scurl = require "cURL.safe"
local json = require "dkjson"
local fname = "./test.download"
local ENABLE = true
local _ENV = TEST_CASE'multi_iterator' if ENABLE then
local url = "http://httpbin.org/get"
local c, t, m
local function json_data()
return json.decode(table.concat(t))
end
function setup()
t = {}
m = assert(scurl.multi())
end
function teardown()
if m then m:close() end
if c then c:close() end
m, c, t = nil
end
function test_add_handle()
local base_url = 'http://httpbin.org/get?key='
local urls = {
base_url .. "1",
base_url .. "2",
"###" .. base_url .. "3",
base_url .. "4",
base_url .. "5",
}
local i = 0
local function next_easy()
i = i + 1
local url = urls[i]
if url then
c = assert(scurl.easy{url = url})
t = {}
return c
end
end
m = assert_equal(m, m:add_handle(next_easy()))
for data, type, easy in m:iperform() do
if type == "done" or type == "error" then
assert_equal(urls[i], easy:getinfo_effective_url())
assert_equal(easy, c)
easy:close()
c = nil
if i == 3 then
assert_equal(curl.error(curl.ERROR_EASY, curl.E_UNSUPPORTED_PROTOCOL), data)
else
local data = json_data()
assert_table(data.args)
assert_equal(tostring(i), data.args.key)
end
easy = next_easy()
if easy then m:add_handle(easy) end
end
if type == "data" then table.insert(t, data) end
end
assert_equal(#urls + 1, i)
assert_nil(c)
end
function test_info_read()
local url = 'http://httpbin.org/get?key=1'
c = assert(curl.easy{url=url, writefunction=function() end})
assert_equal(m, m:add_handle(c))
while m:perform() > 0 do m:wait() end
local h, ok, err = m:info_read()
assert_equal(c, h)
local h, ok, err = m:info_read()
assert_equal(0, h)
end
end
local _ENV = TEST_CASE'form' if ENABLE then
local post
function teardown()
if post then post:free() end
post = nil
end
function test_content_01()
post = assert(scurl.form{name01 = 'value01'})
local data = assert_string(post:get())
assert_match("\r\n\r\nvalue01\r\n", data)
assert_match('name="name01"', data)
end
function test_content_02()
post = assert(scurl.form{name02 = {'value02', type = "text/plain"}})
local data = assert_string(post:get())
assert_match("\r\n\r\nvalue02\r\n", data)
assert_match('name="name02"', data)
assert_match('Content%-Type: text/plain\r\n', data)
end
function test_content_03()
post = assert(scurl.form{name03 = {content = 'value03', headers = {"Content-Encoding: gzip"}}})
local data = assert_string(post:get())
assert_match("\r\n\r\nvalue03\r\n", data)
assert_match('name="name03"', data)
assert_match('Content%-Encoding: gzip\r\n', data)
end
function test_content_04()
post = assert(scurl.form{name04 = {'value04', type = "text/plain", headers = {"Content-Encoding: gzip"}}})
local data = assert_string(post:get())
assert_match("\r\n\r\nvalue04\r\n", data)
assert_match('name="name04"', data)
assert_match('Content%-Encoding: gzip\r\n', data)
assert_match('Content%-Type: text/plain\r\n', data)
end
function test_buffer_01()
post = assert(scurl.form{name01 = {
name = 'file01',
data = 'value01',
}})
local data = assert_string(post:get())
assert_match("\r\n\r\nvalue01\r\n", data)
assert_match('name="name01"', data)
assert_match('filename="file01"', data)
assert_match('Content%-Type: application/octet%-stream\r\n', data)
end
function test_buffer_02()
post = assert(scurl.form{name02 = {
name = 'file02',
data = 'value02',
type = "text/plain",
}})
local data = assert_string(post:get())
assert_match("\r\n\r\nvalue02\r\n", data)
assert_match('name="name02"', data)
assert_match('filename="file02"', data)
assert_match('Content%-Type: text/plain\r\n', data)
assert_not_match('Content%-Type: application/octet%-stream\r\n', data)
end
function test_buffer_03()
post = assert(scurl.form{name03 = {
name = 'file03',
data = 'value03',
headers = {"Content-Encoding: gzip"},
}})
local data = assert_string(post:get())
assert_match("\r\n\r\nvalue03\r\n", data)
assert_match('name="name03"', data)
assert_match('filename="file03"', data)
assert_match('Content%-Type: application/octet%-stream\r\n', data)
assert_match('Content%-Encoding: gzip\r\n', data)
end
function test_buffer_04()
post = assert(scurl.form{name04 = {
name = 'file04',
data = 'value04',
type = "text/plain",
headers = {"Content-Encoding: gzip"},
}})
local data = assert_string(post:get())
assert_match("\r\n\r\nvalue04\r\n", data)
assert_match('name="name04"', data)
assert_match('filename="file04"', data)
assert_match('Content%-Type: text/plain\r\n', data)
assert_not_match('Content%-Type: application/octet%-stream\r\n', data)
assert_match('Content%-Encoding: gzip\r\n', data)
end
function test_stream_01()
post = assert(scurl.form{name01 = {
stream = function() end,
length = 128,
}})
local data = assert_string(post:get())
assert_match('name="name01"', data)
assert_not_match('filename', data)
end
function test_stream_02()
post = assert(scurl.form{name02 = {
name = 'file02',
stream = function() end,
length = 128,
}})
local data = assert_string(post:get())
assert_match('name="name02"', data)
assert_match('filename="file02"', data)
end
function test_stream_03()
post = assert(scurl.form{name03 = {
name = 'file03',
stream = function() end,
length = 128,
type = 'text/plain',
}})
local data = assert_string(post:get())
assert_match('name="name03"', data)
assert_match('filename="file03"', data)
assert_match('Content%-Type: text/plain\r\n', data)
end
function test_stream_04()
post = assert(scurl.form{name04 = {
name = 'file04',
stream = function() end,
length = 128,
type = 'text/plain',
headers = {"Content-Encoding: gzip"},
}})
local data = assert_string(post:get())
assert_match('name="name04"', data)
assert_match('filename="file04"', data)
assert_match('Content%-Type: text/plain\r\n', data)
assert_match('Content%-Encoding: gzip\r\n', data)
end
function test_stream_05()
post = assert(scurl.form{name05 = {
stream = {
length = function() return 128 end;
read = function() end;
}
}})
local data = assert_string(post:get())
assert_match('name="name05"', data)
assert_not_match('filename', data)
end
function test_error()
assert_error(function() post = scurl.form{name = {content = 1}} end)
assert_error(function() post = scurl.form{name = {1}} end)
assert_error(function() post = scurl.form{name = {data = {}}} end)
assert_error(function() post = scurl.form{name = {file = true}} end)
assert_error(function() post = scurl.form{name = {stream = function() end}} end)
assert_error(function() post = scurl.form{name = {stream = {}}} end)
assert_error(function() post = scurl.form{name = {stream = {
read=function()end;length=function()end
}}}end)
assert_error(function() post = scurl.form{name = {stream = {
read=function()end;length=function() return "123" end
}}}end)
assert_error(function() post = scurl.form{name = {stream = {
read=function()end;length=function() return "hello" end
}}}end)
end
function test_ignore_unknown()
post = assert(scurl.form{
name01 = {},
name02 = {name = "helo"},
})
local data = assert_string(post:get())
assert_not_match('name="name01"', data)
assert_not_match('name="name02"', data)
end
function test_empty()
post = assert(scurl.form{})
end
end
RUN()
local lunit, RUN = lunit do
RUN = lunit and function()end or function ()
local res = lunit.run()
if res.errors + res.failed > 0 then
os.exit(-1)
end
return os.exit(0)
end
lunit = require "lunit"
end
local _,luacov = pcall(require, "luacov")
local TEST_CASE = assert(lunit.TEST_CASE)
local skip = lunit.skip or function() end
local curl = require "cURL"
local scurl = require "cURL.safe"
local json = require "dkjson"
local fname = "./test.download"
local ENABLE = true
local _ENV = TEST_CASE'multi_iterator' if ENABLE then
local url = "http://httpbin.org/get"
local c, t, m
local function json_data()
return json.decode(table.concat(t))
end
function setup()
t = {}
m = assert(scurl.multi())
end
function teardown()
if m then m:close() end
if c then c:close() end
m, c, t = nil
end
function test_add_handle()
local base_url = 'http://httpbin.org/get?key='
local urls = {
base_url .. "1",
base_url .. "2",
"###" .. base_url .. "3",
base_url .. "4",
base_url .. "5",
}
local i = 0
local function next_easy()
i = i + 1
local url = urls[i]
if url then
c = assert(scurl.easy{url = url})
t = {}
return c
end
end
m = assert_equal(m, m:add_handle(next_easy()))
for data, type, easy in m:iperform() do
if type == "done" or type == "error" then
assert_equal(urls[i], easy:getinfo_effective_url())
assert_equal(easy, c)
easy:close()
c = nil
if i == 3 then
assert_equal(curl.error(curl.ERROR_EASY, curl.E_UNSUPPORTED_PROTOCOL), data)
else
local data = json_data()
assert_table(data.args)
assert_equal(tostring(i), data.args.key)
end
easy = next_easy()
if easy then m:add_handle(easy) end
end
if type == "data" then table.insert(t, data) end
end
assert_equal(#urls + 1, i)
assert_nil(c)
end
function test_info_read()
local url = 'http://httpbin.org/get?key=1'
c = assert(curl.easy{url=url, writefunction=function() end})
assert_equal(m, m:add_handle(c))
while m:perform() > 0 do m:wait() end
local h, ok, err = m:info_read()
assert_equal(c, h)
local h, ok, err = m:info_read()
assert_equal(0, h)
end
end
local _ENV = TEST_CASE'form' if ENABLE then
local post
function teardown()
if post then post:free() end
post = nil
end
function test_content_01()
post = assert(scurl.form{name01 = 'value01'})
local data = assert_string(post:get())
assert_match("\r\n\r\nvalue01\r\n", data)
assert_match('name="name01"', data)
end
function test_content_02()
post = assert(scurl.form{name02 = {'value02', type = "text/plain"}})
local data = assert_string(post:get())
assert_match("\r\n\r\nvalue02\r\n", data)
assert_match('name="name02"', data)
assert_match('Content%-Type: text/plain\r\n', data)
end
function test_content_03()
post = assert(scurl.form{name03 = {content = 'value03', headers = {"Content-Encoding: gzip"}}})
local data = assert_string(post:get())
assert_match("\r\n\r\nvalue03\r\n", data)
assert_match('name="name03"', data)
assert_match('Content%-Encoding: gzip\r\n', data)
end
function test_content_04()
post = assert(scurl.form{name04 = {'value04', type = "text/plain", headers = {"Content-Encoding: gzip"}}})
local data = assert_string(post:get())
assert_match("\r\n\r\nvalue04\r\n", data)
assert_match('name="name04"', data)
assert_match('Content%-Encoding: gzip\r\n', data)
assert_match('Content%-Type: text/plain\r\n', data)
end
function test_buffer_01()
post = assert(scurl.form{name01 = {
name = 'file01',
data = 'value01',
}})
local data = assert_string(post:get())
assert_match("\r\n\r\nvalue01\r\n", data)
assert_match('name="name01"', data)
assert_match('filename="file01"', data)
assert_match('Content%-Type: application/octet%-stream\r\n', data)
end
function test_buffer_02()
post = assert(scurl.form{name02 = {
name = 'file02',
data = 'value02',
type = "text/plain",
}})
local data = assert_string(post:get())
assert_match("\r\n\r\nvalue02\r\n", data)
assert_match('name="name02"', data)
assert_match('filename="file02"', data)
assert_match('Content%-Type: text/plain\r\n', data)
assert_not_match('Content%-Type: application/octet%-stream\r\n', data)
end
function test_buffer_03()
post = assert(scurl.form{name03 = {
name = 'file03',
data = 'value03',
headers = {"Content-Encoding: gzip"},
}})
local data = assert_string(post:get())
assert_match("\r\n\r\nvalue03\r\n", data)
assert_match('name="name03"', data)
assert_match('filename="file03"', data)
assert_match('Content%-Type: application/octet%-stream\r\n', data)
assert_match('Content%-Encoding: gzip\r\n', data)
end
function test_buffer_04()
post = assert(scurl.form{name04 = {
name = 'file04',
data = 'value04',
type = "text/plain",
headers = {"Content-Encoding: gzip"},
}})
local data = assert_string(post:get())
assert_match("\r\n\r\nvalue04\r\n", data)
assert_match('name="name04"', data)
assert_match('filename="file04"', data)
assert_match('Content%-Type: text/plain\r\n', data)
assert_not_match('Content%-Type: application/octet%-stream\r\n', data)
assert_match('Content%-Encoding: gzip\r\n', data)
end
function test_stream_01()
post = assert(scurl.form{name01 = {
stream = function() end,
length = 128,
}})
local data = assert_string(post:get())
assert_match('name="name01"', data)
assert_not_match('filename', data)
end
function test_stream_02()
post = assert(scurl.form{name02 = {
name = 'file02',
stream = function() end,
length = 128,
}})
local data = assert_string(post:get())
assert_match('name="name02"', data)
assert_match('filename="file02"', data)
end
function test_stream_03()
post = assert(scurl.form{name03 = {
name = 'file03',
stream = function() end,
length = 128,
type = 'text/plain',
}})
local data = assert_string(post:get())
assert_match('name="name03"', data)
assert_match('filename="file03"', data)
assert_match('Content%-Type: text/plain\r\n', data)
end
function test_stream_04()
post = assert(scurl.form{name04 = {
name = 'file04',
stream = function() end,
length = 128,
type = 'text/plain',
headers = {"Content-Encoding: gzip"},
}})
local data = assert_string(post:get())
assert_match('name="name04"', data)
assert_match('filename="file04"', data)
assert_match('Content%-Type: text/plain\r\n', data)
assert_match('Content%-Encoding: gzip\r\n', data)
end
function test_stream_05()
post = assert(scurl.form{name05 = {
stream = {
length = function() return 128 end;
read = function() end;
}
}})
local data = assert_string(post:get())
assert_match('name="name05"', data)
assert_not_match('filename', data)
end
function test_error()
assert_error(function() post = scurl.form{name = {content = 1}} end)
assert_error(function() post = scurl.form{name = {1}} end)
assert_error(function() post = scurl.form{name = {data = {}}} end)
assert_error(function() post = scurl.form{name = {file = true}} end)
assert_error(function() post = scurl.form{name = {stream = function() end}} end)
assert_error(function() post = scurl.form{name = {stream = {}}} end)
assert_error(function() post = scurl.form{name = {stream = {
read=function()end;length=function()end
}}}end)
assert_error(function() post = scurl.form{name = {stream = {
read=function()end;length=function() return "123" end
}}}end)
assert_error(function() post = scurl.form{name = {stream = {
read=function()end;length=function() return "hello" end
}}}end)
end
function test_ignore_unknown()
post = assert(scurl.form{
name01 = {},
name02 = {name = "helo"},
})
local data = assert_string(post:get())
assert_not_match('name="name01"', data)
assert_not_match('name="name02"', data)
end
function test_empty()
post = assert(scurl.form{})
end
end
RUN()

File diff suppressed because it is too large Load Diff