From a5efe5373e9567b2cceec15e21d653af9419ee81 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sun, 29 Jul 2012 18:20:05 +0100 Subject: TEST: Test framework for comms and host modules --- test/test-supple.host.lua | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 test/test-supple.host.lua (limited to 'test/test-supple.host.lua') diff --git a/test/test-supple.host.lua b/test/test-supple.host.lua new file mode 100644 index 0000000..bc5943a --- /dev/null +++ b/test/test-supple.host.lua @@ -0,0 +1,50 @@ +-- test/test-supple.lua +-- +-- Supple - Tests for the host module +-- +-- Copyright 2012 Daniel Silverstone +-- +-- For Licence terms, see COPYING +-- + +-- Step one, start coverage + +local luacov = require 'luacov' + +local host = require 'supple.host' + +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.always_works() +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) -- cgit v1.2.1