Files
gen1recomp/tools/save-editor/Catalog.lua
T
johnjohto ff90062741 Make the T3 content tier run on Windows (#269)
* Make ROM-free test tiers actually run on Windows

Suite discovery, the extension-point catalog scan, mod test-dir pickup,
and the meta-coverage corpus all shelled out to ls/find/test -d, which do
not exist in cmd.exe. Every listing came back empty on Windows, so tiers
ran 0 suites and still reported ALL TESTS PASSED.

Add portable probes to tests/fs_io.lua (same Unix commands on
Linux/macOS; dir /b and a shell-free rename-self existence check on
Windows) and rewire the four call sites to them. 15/15 engine suites and
2/2 modkit suites now genuinely run and pass on Windows.

Fixes #266

* Make the T3 content tier run on Windows

The content tier had the same Unix-shell assumptions as the tier
discovery fixed in #267, one level down:

- run_tests.lua redirected to /dev/null when chaining tier runners
- mod_runtime_tests.lua called ffi setenv/unsetenv, which msvcrt lacks
  (_putenv with an empty value unsets)
- modkit_tests.lua captured exit codes with POSIX '; echo 0' (cmd
  needs /v:on and !errorlevel!), called python3 (python on Windows),
  and used mkdir -p / rm -rf; cmd mkdir makes parents on its own and
  read -p as a directory name
- the save-editor suites globbed save backups with ls
- tools/save-editor/Catalog.lua scraped mod flags with ls; this one
  affects the real editor on Windows, not just tests

With a ROM imported, run_tests.lua goes from 12 failures to the 3 that
track the missing audio.lua generation (#268), which fails on any OS
and needs a maintainer decision.

---------

Co-authored-by: johnjohto <johnjohto@users.noreply.github.com>
2026-07-27 10:04:35 -04:00

82 lines
1.8 KiB
Lua

local Catalog = {}
local function sortedKeys(t)
local keys = {}
for k in pairs(t) do
table.insert(keys, k)
end
table.sort(keys)
return keys
end
function Catalog.build(data)
return {
species = sortedKeys(data.pokemon),
items = sortedKeys(data.items),
moves = sortedKeys(data.moves),
}
end
-- extraDirs: loaded mods' roots, so MOD_-prefixed flags defined in mod
-- scripts show up beside the vanilla EVENT_ ones
function Catalog.scrapeEvents(scriptDir, headerPath, listFiles, extraDirs)
listFiles = listFiles or function(dir)
local out = {}
if package.config:sub(1, 1) == "\\" then
-- cmd has no ls; dir /b prints bare names, so re-attach the directory
local p = io.popen(string.format('dir /b "%s\\*.lua" 2>nul', dir))
if p then
for line in p:lines() do
if line ~= "" then table.insert(out, dir .. "/" .. line) end
end
p:close()
end
return out
end
local p = io.popen(string.format('ls "%s"/*.lua 2>/dev/null', dir))
if p then
for line in p:lines() do
table.insert(out, line)
end
p:close()
end
return out
end
local found = {}
local function eat(text)
for name in text:gmatch("EVENT_[A-Z0-9_]+") do
found[name] = true
end
for name in text:gmatch("MOD_[A-Z0-9_]+") do
found[name] = true
end
end
local dirs = { scriptDir }
for _, dir in ipairs(extraDirs or {}) do
dirs[#dirs + 1] = dir
end
for _, dir in ipairs(dirs) do
for _, path in ipairs(listFiles(dir)) do
local f = io.open(path, "r")
if f then
eat(f:read("*a"))
f:close()
end
end
end
if headerPath then
local f = io.open(headerPath, "r")
if f then
eat(f:read("*a"))
f:close()
end
end
return sortedKeys(found)
end
return Catalog