Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase test coverage #33

Merged
merged 19 commits into from
Nov 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@
# build
*.so
*.o

# gcov
*.gcda
*.gcno
*.gcov
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ script:
- export LD_PRELOAD=/lib/x86_64-linux-gnu/libpthread.so.0
- busted
- if [[ "$LUA" != *"luajit"* ]]; then bash .travis/valgrind_test.sh; fi
- luarocks make CFLAGS="-O0 -fPIC -ftest-coverage -fprofile-arcs" LIBFLAG="-shared --coverage"
- luarocks make CFLAGS="-O0 -g -fPIC -ftest-coverage -fprofile-arcs" LIBFLAG="-shared --coverage"
- busted

after_success:
Expand Down
1 change: 1 addition & 0 deletions luawt-dev-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ build = {
"src/luawt/WWidget.cpp",
"src/luawt/init.cpp",
"src/luawt/shared.cpp",
"src/luawt/test.cpp",
},
libraries = {
"wt",
Expand Down
111 changes: 85 additions & 26 deletions spec/luawt_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,100 @@
-- Copyright (c) 2015 Pavel Dolgov and Boris Nagaev
-- See the LICENSE file for terms of use.

local function socketRequest(port)
os.execute("sleep 2")
local socket = require 'socket.http'
local data = socket.request('http://127.0.0.1:' .. port)
return data
end

local function baseConfig()
local wt_config = os.tmpname()
local file = io.open(wt_config, 'w')
local config = [=[
<server>
<application-settings location="*">
<progressive-bootstrap>
true
</progressive-bootstrap>
</application-settings>
</server> ]=]
file:write(config)
file:close()
return wt_config
end

local function createServer(code, port, wt_config)
local luawt = require 'luawt'
local server = luawt.WServer({
code = code,
port = port,
wt_config = wt_config,
})
return server
end

describe("luawt", function()

it("requires main module", function()
local luawt = require 'luawt'
end)

it("uses wrap with unknown exceptions", function()
local luawt = require 'luawt'
local code = [[
local luawt = require 'luawt'
luawt.Test.unknownException()
]]
local port = 56789
local wt_config = baseConfig()
local server = createServer(code, port, wt_config)
assert.has_no_error(function()
server:start()
local data = socketRequest(port)
server:stop(true)
end)
end)

it("can stop the server forcibly", function()
local luawt = require 'luawt'
local code = ''
local port = 56789
local wt_config = baseConfig()
local server = createServer(code, port, wt_config)
server:start()
local data = socketRequest(port)
server:stop(true)
end)

it("doesn't throw on bad syntax in lua code", function()
local luawt = require 'luawt'
local code = "(;(;(;)))))"
local port = 56789
local wt_config = baseConfig()
local server = createServer(code, port, wt_config)
assert.has_no_error(function()
server:start()
local data = socketRequest(port)
server:stop(true)
end)
os.remove(wt_config)
end)

it("creates simple application", function()
local luawt = require 'luawt'
local wt_config = os.tmpname()
local file = io.open(wt_config, 'w')
local config = [=[
<server>
<application-settings location="*">
<progressive-bootstrap>
true
</progressive-bootstrap>
</application-settings>
</server> ]=]
file:write(config)
file:close()
local server = luawt.WServer({
code = [[
local app, env = ...
local luawt = require 'luawt'
local text = "IP: " .. env:clientAddress()
local button = luawt.WPushButton(app:root())
button:setText(text)
]],
port = 56789,
wt_config = wt_config,
})
local code = [[
local app, env = ...
local luawt = require 'luawt'
local text = "IP: " .. env:clientAddress()
local button = luawt.WPushButton(app:root())
button:setText(text)
]]
local port = 56789
local wt_config = baseConfig()
local server = createServer(code, port, wt_config)
server:start()
os.execute("sleep 2")
local socket = require 'socket.http'
local data = socket.request('http://127.0.0.1:56789/')
local data = socketRequest(port)
assert.truthy(data:match('IP:'))
server:stop()
os.remove(wt_config)
Expand Down
1 change: 1 addition & 0 deletions src/luawt/WPushButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ static const luaL_Reg methods[] = {

void luawtWPushButton(lua_State* L) {
const char* base = luawt_typeToStr<WWidget>();
assert(base);
DECLARE_CLASS(
WPushButton,
L,
Expand Down
2 changes: 1 addition & 1 deletion src/luawt/WServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void luawtWServer(lua_State* L) {
lua_pop(L, 1); // mt
// put make to luawt
luaL_getmetatable(L, "luawt");
lua_pushcfunction(L, luawt_WServer_make);
lua_pushcfunction(L, wrap<luawt_WServer_make>::func);
lua_setfield(L, -2, "WServer");
lua_pop(L, 1); // luawt
}
1 change: 1 addition & 0 deletions src/luawt/globals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ class LuaDeclareType {

/* This functions are called from luaopen() */
void luawtShared(lua_State* L);
void luawtTest(lua_State* L);
void luawtWApplication(lua_State* L);
void luawtWContainerWidget(lua_State* L);
void luawtWEnvironment(lua_State* L);
Expand Down
1 change: 1 addition & 0 deletions src/luawt/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ typedef struct LuawtReg {
static const LuawtReg luawt_modules[] = {
// Base must be before child
MODULE(Shared),
MODULE(Test),
MODULE(WApplication),
MODULE(WEnvironment),
MODULE(WServer),
Expand Down
26 changes: 26 additions & 0 deletions src/luawt/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* luawt, Lua bindings for Wt
* Copyright (c) 2015 Pavel Dolgov and Boris Nagaev
*
* See the LICENSE file for terms of use.
*/

#include "globals.hpp"

int luawt_Test_unknownException(lua_State* L) {
int error;
throw error;
}

static const luaL_Reg Test_functions[] = {
METHOD(Test, unknownException),
{NULL, NULL},
};

void luawtTest(lua_State* L) {
luaL_getmetatable(L, "luawt");
assert(lua_type(L, -1) == LUA_TTABLE);
lua_newtable(L); // Test table
my_setfuncs(L, Test_functions);
lua_setfield(L, -2, "Test");
lua_pop(L, 1); // luawt
}