/
ihtiandr9
/
gc_learn
Обзор
Документация
Войти
/
ihtiandr9
/
gc_learn
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
test_all.lua
95 строк
3 KB
user@krolik-note
replace malloc with local-heap allocator; port tests to Lua; add third_party/lua
10 июн 2026, 15:50
10 июн 2026, 15:50
9638131
Код
Авторство
О чём код?
#!/usr/bin/env lua --[[ Comprehensive functional test for gc_basic interpreter. ]] local BASE = arg[0]:match("^(.+)/") or "." local BINARY = BASE .. "/build/gc_basic" local function run(cmds) local tmp = os.tmpname() local f = io.open(tmp, "w") f:write(table.concat(cmds, "\n")) f:close() local p = io.popen(BINARY .. " < " .. tmp .. " 2>&1", "r") local out = p:read("*a") p:close() os.remove(tmp) return out end local function check(desc, cmds, expected) local out = run(cmds) local ok = out:find(expected, 1, true) ~= nil local status = ok and "PASS" or "FAIL" io.write(string.format(" [%s] %s\n", status, desc)) if not ok then io.write(string.format(" expected: %q\n", expected)) io.write(string.format(" got: %s\n", out:sub(1, 200))) end return ok end local function main() print("=== Building ===") os.execute("cmake -S " .. BASE .. " -B " .. BASE .. "/build >/dev/null 2>&1") os.execute("cmake --build " .. BASE .. "/build -j 2>&1") print() local all_ok = true print("--- Numbers ---") all_ok = check("assign & print number", {"LET A = 42", "PRINT A", "QUIT"}, "42") and all_ok all_ok = check("assign & print negative", {"LET A = -3.5", "PRINT A", "QUIT"}, "-3.5") and all_ok print("--- Strings ---") all_ok = check("string literal", {"LET A$ = \"HELLO\"", "PRINT A$", "QUIT"}, "\"HELLO\"") and all_ok all_ok = check("string concat", {"LET A$ = \"HELLO\"", "LET B$ = \"WORLD\"", "LET C$ = A$ + B$", "PRINT C$", "QUIT"}, "\"HELLOWORLD\"") and all_ok all_ok = check("uninitialized string concat (no crash)", {"LET A$ = \"HELLO\"", "LET A$ = A$ + C$", "QUIT"}, "not initialized") and all_ok print("--- Arrays ---") all_ok = check("DIM and LETARR", {"DIM X(5)", "LETARR X(0) = 1.5", "LETARR X(1) = 2.5", "PRINT X", "QUIT"}, "[1.5, 2.5") and all_ok all_ok = check("out of bounds", {"DIM X(3)", "LETARR X(10) = 1", "QUIT"}, "Index out of bounds") and all_ok print("--- LIST ---") all_ok = check("LIST shows all vars", {"LET A = 1", "LET B$ = \"X\"", "LIST", "QUIT"}, "B$ = \"X\"") and all_ok print("--- GC ---") all_ok = check("GC status", {"STATUS", "GC", "STATUS", "QUIT"}, "GC runs") and all_ok print("--- CLEAR ---") all_ok = check("CLEAR frees memory", {"LET A = 42", "CLEAR", "PRINT A", "QUIT"}, "0") and all_ok print() if all_ok then print("ALL TESTS PASSED") return 0 else print("SOME TESTS FAILED") return 1 end end os.exit(main())