mirror of
https://github.com/Dingo-Shenanigans/ReSkate.git
synced 2026-10-24 18:16:27 +02:00
- contrib/plugins/reskate-test calls every plugin API and says what worked: ptest all, ptest <module>, ptest list. Its 45 checks cover the base set, timers, the level, package files, JSON, require, the console, storage and the sandbox. It is the example to copy for a plugin. - contrib/plugins/reskate-hostile attacks the sandbox, one attack per command (hostile list): loops, memory and buffer bombs, caught errors, error and log floods, timers, recursion, an unload that never ends, and 17 ways out. Each must end stopped or refused. - dingosdk_plugin_tests runs both from the repository: every reskate-test check passes, and every hostile attack is stopped or refused with nothing escaping. - Taken from Domination (PR 279) for the plugin API to use: the trick watch (when a trick starts, lands and what it scored, or a slam breaks it; Domination's spots left out) in Extension/Skater/trick_watch.h with its tests, the score HUD reader in score_hud.h, and teleport_local_skater_heading, whose hunks are the PR's own. Neither is wired to anything yet.
50 lines
1.8 KiB
Lua
50 lines
1.8 KiB
Lua
local h = require("harness")
|
|
local t = h.module("storage")
|
|
|
|
-- Its keys start with ptest. and are removed after each check.
|
|
local function clean()
|
|
for _, key in reskate.storage.keys() do
|
|
if key:sub(1, 6) == "ptest." then reskate.storage.set(key, nil) end
|
|
end
|
|
end
|
|
|
|
t.check("set and get keep tables, lists, text and numbers", function()
|
|
reskate.storage.set("ptest.table", {a = 1, list = {1, 2, 3}, name = "x", yes = true})
|
|
local back = reskate.storage.get("ptest.table")
|
|
clean()
|
|
assert(back.a == 1 and back.list[3] == 3 and back.name == "x" and back.yes == true)
|
|
end)
|
|
t.check("add counts, from nothing", function()
|
|
assert(reskate.storage.add("ptest.count") == 1)
|
|
assert(reskate.storage.add("ptest.count", 4) == 5)
|
|
reskate.storage.set("ptest.text", "x")
|
|
local why = h.refused(reskate.storage.add, "ptest.text")
|
|
clean()
|
|
assert(why:find("number", 1, true), why)
|
|
end)
|
|
t.check("nil removes a key", function()
|
|
reskate.storage.set("ptest.gone", 1)
|
|
reskate.storage.set("ptest.gone", nil)
|
|
assert(reskate.storage.get("ptest.gone") == nil)
|
|
end)
|
|
t.check("keys lists them", function()
|
|
reskate.storage.set("ptest.listed", 1)
|
|
local found = table.find(reskate.storage.keys(), "ptest.listed")
|
|
clean()
|
|
assert(found)
|
|
end)
|
|
t.check("a plugin has 1 MB", function()
|
|
local why = h.refused(reskate.storage.set, "ptest.big", string.rep("x", 2000000))
|
|
assert(why:find("full", 1, true), why)
|
|
assert(reskate.storage.get("ptest.big") == nil, "the failed write was kept")
|
|
end)
|
|
t.check("bad keys and values are refused", function()
|
|
h.refused(reskate.storage.set, "", 1)
|
|
h.refused(reskate.storage.set, string.rep("k", 200), 1)
|
|
h.refused(reskate.storage.set, "ptest.f", print)
|
|
local cycle = {}
|
|
cycle.me = cycle
|
|
h.refused(reskate.storage.set, "ptest.c", cycle)
|
|
clean()
|
|
end)
|