summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2012-07-21 16:32:07 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2012-07-21 16:32:07 +0100
commitb5460017f1e88baf283ebfaad341cd094f5041ff (patch)
tree445386ab7dbce5dbd3e97078225bb9be3e939960 /test
parentb4d2d633cd88308487aa6e2b689a4328ce6023c1 (diff)
downloadsupple-b5460017f1e88baf283ebfaad341cd094f5041ff.tar.gz
Lots of stuff
Diffstat (limited to 'test')
-rw-r--r--test/test-supple.capi.lua134
-rw-r--r--test/test-supple.lua14
-rw-r--r--test/test-supple.objects.lua69
-rw-r--r--test/test-supple.request.lua54
4 files changed, 269 insertions, 2 deletions
diff --git a/test/test-supple.capi.lua b/test/test-supple.capi.lua
index 30dbf81..7438874 100644
--- a/test/test-supple.capi.lua
+++ b/test/test-supple.capi.lua
@@ -1,4 +1,4 @@
--- test/test-supple.lua
+-- test/test-supple.capi.lua
--
-- Supple - Tests for the capi module
--
@@ -38,6 +38,138 @@ function suite.capi_has_abi()
assert(capi._ABI, "No _ABI found in the CAPI")
end
+function suite.capi_explain_non_table_etc()
+ local ok = pcall(capi.explain, nil, "");
+ assert(ok == false, "Explained nil unexpectedly")
+ ok = pcall(capi.explain, true, "");
+ assert(ok == false, "Explained true unexpectedly")
+ ok = pcall(capi.explain, false, "");
+ assert(ok == false, "Explained false unexpectedly")
+ ok = pcall(capi.explain, 123, "");
+ assert(ok == false, "Explained number unexpectedly")
+ ok = pcall(capi.explain, "", "");
+ assert(ok == false, "Explained string unexpectedly")
+ ok = pcall(capi.explain, coroutine.create(function()end), "");
+ assert(ok == false, "Explained coroutine unexpectedly")
+end
+
+function suite.capi_explain_bad_tag()
+ local ok = pcall(capi.explain, {}, nil)
+ assert(ok == false, "Explained with nil tag unexpectedly")
+ ok = pcall(capi.explain, {}, 1233)
+ assert(ok == false, "Explained with number tag unexpectedly")
+ ok = pcall(capi.explain, {}, true)
+ assert(ok == false, "Explained with true tag unexpectedly")
+ ok = pcall(capi.explain, {}, false)
+ assert(ok == false, "Explained with false tag unexpectedly")
+ ok = pcall(capi.explain, {}, {})
+ assert(ok == false, "Explained with table tag unexpectedly")
+ ok = pcall(capi.explain, {}, function()end)
+ assert(ok == false, "Explained with function tag unexpectedly")
+ ok = pcall(capi.explain, {}, coroutine.create(function()end))
+ assert(ok == false, "Explained with coroutine tag unexpectedly")
+end
+
+function suite.capi_explain_simple_table()
+ local expn = capi.explain({}, "fish")
+ assert(type(expn) == "table", "Explanation wasn't a table")
+ assert(type(expn.tag) == "string", "Tag not a string")
+ assert(expn.tag == "fish", "Tag wasn't as passed in")
+ assert(type(expn.type) == "string", "Type wasn't a string")
+ assert(expn.type == "table", "Type didn't declare it is a table")
+ assert(expn.methods == nil, "Methods table was present in some form")
+end
+
+function suite.capi_explain_table_with_mode()
+ local tab = setmetatable({}, { __mode="k"})
+ local expn = capi.explain(tab, "fish")
+ assert(type(expn) == "table", "Explanation wasn't a table")
+ assert(type(expn.tag) == "string", "Tag not a string")
+ assert(expn.tag == "fish", "Tag wasn't as passed in")
+ assert(type(expn.type) == "string", "Type wasn't a string")
+ assert(expn.type == "table", "Type didn't declare it is a table")
+ assert(type(expn.methods) == "table", "Methods were not present")
+ assert(next(expn.methods) == nil, "Methods had something in")
+end
+
+function suite.capi_explain_table_with_index()
+ local tab = setmetatable({}, { __index = {} })
+ local expn = capi.explain(tab, "fish")
+ assert(type(expn) == "table", "Explanation wasn't a table")
+ assert(type(expn.tag) == "string", "Tag not a string")
+ assert(expn.tag == "fish", "Tag wasn't as passed in")
+ assert(type(expn.type) == "string", "Type wasn't a string")
+ assert(expn.type == "table", "Type didn't declare it is a table")
+ assert(type(expn.methods) == "table", "Methods were not present")
+ assert(expn.methods[1] == "__index", "Missing __index")
+ assert(expn.methods[2] == nil, "Something other than __index")
+end
+
+function suite.capi_explain_function()
+ local expn = capi.explain(function()end, "fish")
+ assert(type(expn) == "table", "Explanation wasn't a table")
+ assert(type(expn.tag) == "string", "Tag not a string")
+ assert(expn.tag == "fish", "Tag wasn't as passed in")
+ assert(type(expn.type) == "string", "Type wasn't a string")
+ assert(expn.type == "function", "Type didn't declare it is a table")
+ assert(expn.methods == nil, "Methods table was present in some form")
+end
+
+function suite.capi_type_chains()
+ assert(capi.type({}) == "table", "Plain table wasn't a table")
+ local t = setmetatable({}, { __type = function() return "jeff" end })
+ assert(capi.type(t) == "jeff", "Chained table wasn't jeff")
+end
+
+function suite.capi_rawtype()
+ assert(capi.rawtype() == "nil", "nil was't nil")
+ assert(capi.rawtype({}) == "table", "table wasn't")
+ assert(capi.rawtype("") == "string", "string wasn't")
+ assert(capi.rawtype(false) == "boolean", "boolean wasn't")
+ assert(capi.rawtype(function()end) == "function", "function wasn't")
+ assert(capi.rawtype(coroutine.create(function()end)) == "thread",
+ "coroutine wasn't")
+ assert(capi.rawtype(capi.new_proxy("table")) == "userdata",
+ "userdata wasn't")
+end
+
+function suite.capi_new_proxy_fails()
+ local ok = pcall(capi.new_proxy)
+ assert(ok == false, "Made a new proxy with a nil type string")
+ ok = pcall(capi.new_proxy, {})
+ assert(ok == false, "Made a new proxy with a table type string")
+end
+
+function suite.capi_new_proxy_function()
+ local proxy, mt = capi.new_proxy("function")
+ local sparetype = mt.__type
+ mt.__type = nil
+ assert(capi.type(proxy) == "userdata", "Proxy wasn't userdata")
+ mt.__type = sparetype
+ assert(capi.type(proxy) == "function", "Proxy did not override type")
+ assert(tostring(proxy):match("^function: "), "Proxy didn't tostring nicely")
+end
+
+function suite.capi_new_proxy_table()
+ local proxy, mt = capi.new_proxy("table")
+ local sparetype = mt.__type
+ mt.__type = nil
+ assert(type(proxy) == "userdata", "Proxy wasn't userdata")
+ mt.__type = sparetype
+ assert(capi.type(proxy) == "table", "Proxy did not override type")
+ assert(tostring(proxy):match("^table: "), "Proxy didn't tostring nicely")
+end
+
+function suite.capi_new_proxy_table()
+ local proxy, mt = capi.new_proxy("userdata")
+ local sparetype = mt.__type
+ mt.__type = nil
+ assert(type(proxy) == "userdata", "Proxy wasn't userdata")
+ mt.__type = sparetype
+ assert(capi.type(proxy) == "userdata", "Proxy did not override type")
+ assert(tostring(proxy):match("^userdata: "), "Proxy didn't tostring nicely")
+end
+
local count_ok = 0
for _, testname in ipairs(testnames) do
-- print("Run: " .. testname)
diff --git a/test/test-supple.lua b/test/test-supple.lua
index 1053b87..fdd08e4 100644
--- a/test/test-supple.lua
+++ b/test/test-supple.lua
@@ -11,8 +11,10 @@
local luacov = require 'luacov'
-local supple = require 'supple'
local capi = require 'supple.capi'
+local request = require 'supple.request'
+local objects = require 'supple.objects'
+local supple = require 'supple'
local testnames = {}
@@ -35,6 +37,16 @@ function suite.capi_passed()
assert(supple.capi == capi, "Supple's capi entry is not supple.capi")
end
+function suite.request_passed()
+ assert(supple.request == request,
+ "Supple's request entry is not supple.request")
+end
+
+function suite.objects_passed()
+ assert(supple.objects == objects,
+ "Supple's objects entry is not supple.objects")
+end
+
local count_ok = 0
for _, testname in ipairs(testnames) do
-- print("Run: " .. testname)
diff --git a/test/test-supple.objects.lua b/test/test-supple.objects.lua
new file mode 100644
index 0000000..cb81420
--- /dev/null
+++ b/test/test-supple.objects.lua
@@ -0,0 +1,69 @@
+-- test/test-supple.lua
+--
+-- Supple - Tests for the core module
+--
+-- Copyright 2012 Daniel Silverstone <dsilvers@digital-scurf.org>
+--
+-- For Licence terms, see COPYING
+--
+
+-- Step one, start coverage
+
+local luacov = require 'luacov'
+
+local objects = require 'supple.objects'
+
+local testnames = {}
+
+local real_assert = assert
+local total_asserts = 0
+local function assert(...)
+ local retval = real_assert(...)
+ total_asserts = total_asserts + 1
+ return retval
+end
+
+local function add_test(suite, name, value)
+ rawset(suite, name, value)
+ testnames[#testnames+1] = name
+end
+
+local suite = setmetatable({}, {__newindex = add_test})
+
+function suite.give_integral_types()
+ assert(objects.give(nil) == nil, "Nil didn't pass through")
+ assert(objects.give(true) == true, "True didn't pass through")
+ assert(objects.give(false) == false, "False didn't pass through")
+ assert(objects.give(123) == 123, "Number didn't pass through")
+ assert(objects.give("") == "", "String didn't pass through")
+end
+
+function suite.set_name_works()
+ local unique_name = tostring({})
+ objects.set_name(unique_name)
+ local expn = objects.give({})
+ assert(expn.tag:find(unique_name), "set_name not passing through")
+end
+
+function suite.give_table()
+ local tab = {}
+ local expn = objects.give(tab)
+ assert(tab ~= expn, "Table passed through")
+
+end
+
+local count_ok = 0
+for _, testname in ipairs(testnames) do
+-- print("Run: " .. testname)
+ local ok, err = xpcall(suite[testname], debug.traceback)
+ if not ok then
+ print(err)
+ print()
+ else
+ count_ok = count_ok + 1
+ end
+end
+
+print(tostring(count_ok) .. "/" .. tostring(#testnames) .. " [" .. tostring(total_asserts) .. "] OK")
+
+os.exit(count_ok == #testnames and 0 or 1)
diff --git a/test/test-supple.request.lua b/test/test-supple.request.lua
new file mode 100644
index 0000000..5413cd8
--- /dev/null
+++ b/test/test-supple.request.lua
@@ -0,0 +1,54 @@
+-- test/test-supple.request.lua
+--
+-- Supple - Tests for the capi module
+--
+-- Copyright 2012 Daniel Silverstone <dsilvers@digital-scurf.org>
+--
+-- For Licence terms, see COPYING
+--
+
+-- Step one, start coverage
+
+local luacov = require 'luacov'
+
+local request = require 'supple.request'
+
+local testnames = {}
+
+local real_assert = assert
+local total_asserts = 0
+local function assert(...)
+ local retval = real_assert(...)
+ total_asserts = total_asserts + 1
+ return retval
+end
+
+local function add_test(suite, name, value)
+ rawset(suite, name, value)
+ testnames[#testnames+1] = name
+end
+
+local suite = setmetatable({}, {__newindex = add_test})
+
+function suite.serialise_error()
+ local err = request.error("m","tb")
+ assert(err == [[error=true,message="m",traceback="tb"]],
+ "Error did not serialise properly")
+
+end
+
+local count_ok = 0
+for _, testname in ipairs(testnames) do
+-- print("Run: " .. testname)
+ local ok, err = xpcall(suite[testname], debug.traceback)
+ if not ok then
+ print(err)
+ print()
+ else
+ count_ok = count_ok + 1
+ end
+end
+
+print(tostring(count_ok) .. "/" .. tostring(#testnames) .. " [" .. tostring(total_asserts) .. "] OK")
+
+os.exit(count_ok == #testnames and 0 or 1)