local script_dir = (arg and arg[0]) and arg[0]:match("(.*/?)") or "./"
local sdk_root = script_dir .. "../"
package.path = sdk_root .. "?.lua;" .. sdk_root .. "?/init.lua;" .. package.path
local passed = 0
local failed = 0
local skipped = 0
local current_suite = ""
local function suite(name)
current_suite = name
print("\n " .. name)
end
local function test(name, fn)
local ok, err = pcall(fn)
if ok then
passed = passed + 1
print(" [PASS] " .. name)
else
failed = failed + 1
print(" [FAIL] " .. name)
print(" " .. tostring(err))
end
end
local function skip(name, reason)
skipped = skipped + 1
print(" [SKIP] " .. name .. " (" .. (reason or "skipped") .. ")")
end
local function assert_eq(a, b, msg)
if a ~= b then
error((msg or "assertion failed") .. ": expected " .. tostring(b) .. ", got " .. tostring(a), 2)
end
end
local function assert_true(v, msg)
if not v then
error((msg or "expected true, got false/nil"), 2)
end
end
local function assert_nil(v, msg)
if v ~= nil then
error((msg or "expected nil, got") .. ": " .. tostring(v), 2)
end
end
local function assert_not_nil(v, msg)
if v == nil then
error((msg or "expected non-nil value"), 2)
end
end
require("test.test_json")(suite, test, skip, assert_eq, assert_true, assert_nil, assert_not_nil)
require("test.test_discovery")(suite, test, skip, assert_eq, assert_true, assert_nil, assert_not_nil)
require("test.test_client")(suite, test, skip, assert_eq, assert_true, assert_nil, assert_not_nil)
print(string.format(
"\n Results: %d passed, %d failed, %d skipped\n",
passed, failed, skipped
))
if failed > 0 then
os.exit(1)
end