TableTower/tests/test_demos.gd
RobinFiredrake d41a6e40aa Tests: 15 s budget, shared Godot workers; a freed Main cancels its roll
tools/run_tests.sh stops every run at 15 s and lists what was not run.
Suites are nodes run by tests/run_suites.gd, several per Godot process;
TestBase no longer compiles the app (AppTestBase does). Audit: fewer
repeats and less setup; 51 suites in about 12 s (was 45 s).

Fix a crash when a roll was still animating as its Main was freed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 16:19:30 -06:00

46 lines
1.9 KiB
GDScript

extends AppTestBase
## Help's demo spreads: every demo builds and rolls cleanly, Help links to
## them, and opening one shows it unsaved with a way back.
## Run: tools/run_tests.sh demos
func run() -> void:
if not require_sample():
return
_test_builds()
if not await start_main():
return
await _test_open()
finish()
func _test_builds() -> void:
var rng := RandomNumberGenerator.new()
for key: String in DemoSpreads.TITLES:
var b := DemoSpreads.build(key)
_check(not b.tables.is_empty() and b.id == "demo-" + key, "demo %s builds" % key)
var start := b.tables[0] if b.tables[0].kind != RollTable.KIND_VARIABLE else b.tables[1]
var tree := Roller.roll(b, start.id, rng)
var bad := Roller.flatten(tree, []).filter(func(s: Dictionary) -> bool: return s.get("stop", false) and not s.get("deck_empty", false))
_check(bad.is_empty(), "demo %s rolls cleanly: %s" % [key, str(bad.map(func(s: Dictionary) -> String: return str(s.get("text", ""))))])
var book := DemoSpreads.build("book")
_check(book.page_uses("p_sword") == 2, "the Book demo links two results to its page")
var linked := book.get_table("goblin").entries[1]
book.sync_page("p_sword")
_check(linked.text.contains("Holy Light"), "and they show the page's text")
var help := FileAccess.get_file_as_string("res://help/topics.txt")
var re := RegEx.create_from_string("\\[demo\\]([a-z_]+)\\[/demo\\]")
for m in re.search_all(help):
_check(DemoSpreads.has(m.get_string(1)), "help's demo link %s exists" % m.get_string(1))
_check(HelpDialog._inline("[demo]deck[/demo]").contains("url=demo:deck"), "a demo marker becomes a link")
func _test_open() -> void:
var before := main.data.id
main.demo.open("deck")
await _frames(3)
_check(main.data.id == "demo-deck" and main.demo.active() and not main._saving_enabled, "a demo opens unsaved, with its bar")
main.demo.back()
await _frames(3)
_check(not main.demo.active() and main.data.id == before, "Back to my spread returns")