Files
ReSkate/contrib/plugins/reskate-test/plugin/checks/package.lua
T
AyeZeeBB a3e75ba10e Plugins: the reskate-test and reskate-hostile plugins, and trick reading and a facing teleport in the core
- 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.
2026-10-19 12:08:26 -05:00

28 lines
1.2 KiB
Lua

local h = require("harness")
local t = h.module("package")
t.check("read returns a file's text", function()
local text = reskate.package.read("data/sample.txt")
assert(text and text:sub(1, 12) == "ptest sample", tostring(text))
end)
t.check("read returns nil for a file that is not there", function()
assert(reskate.package.read("data/missing.txt") == nil)
end)
t.check("read_json returns the file as tables", function()
local data = reskate.package.read_json("data/sample.json")
assert(data.name == "sample" and data.list[3] == 3 and data.nested.yes == true)
end)
t.check("list names a folder's files, sorted", function()
local names = table.concat(reskate.package.list("data"), ",")
assert(names == "sample.json,sample.txt", names)
end)
t.check("list with no folder is the package, folders ending in /", function()
local names = table.concat(reskate.package.list(), ",")
assert(names:find("plugin/", 1, true) and names:find("reskate-plugin.json", 1, true), names)
end)
t.check("paths out of the package are refused", function()
for _, path in {"../x", "/x", "C:/Windows/win.ini", "data\\sample.txt", "data/../../x", "data/./sample.txt"} do
h.refused(reskate.package.read, path)
end
end)