TableTower/tests/app_testbase.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

63 lines
1.8 KiB
GDScript

class_name AppTestBase
extends TestBase
## For suites that load the app. Call `if not await start_main(): return` first.
## Long demo tables are cut to this many rows: rebuilding them costs up to a
## second per mode switch. test_roller checks the demo's full tables.
const MAX_DEMO_ROWS := 12
var main: Main
## Hook: suites that need a customised Main override this.
func _create_main() -> Main:
return load("res://ui/main.tscn").instantiate()
## The app's demo spread with short tables.
func _short_demo() -> TowerBoard:
var board := SampleBoard.create()
board.id = "fantasy-loot"
board.name = "Fantasy Loot"
for table in board.tables:
if not table.is_ranged() and table.entries.size() > MAX_DEMO_ROWS:
table.entries.resize(MAX_DEMO_ROWS)
return board
func _empty_spread() -> TowerBoard:
var board := TowerBoard.new()
board.id = "fantasy-loot"
board.name = "Fantasy Loot"
return board
## A suite that loads its own board first should pass `with_demo` false: the
## demo's cards take about half a second to build. Guard, then loads the app under root and waits for it. Returns false (after
## aborting) if the guard fails or the app would save.
func start_main(with_demo: bool = true) -> bool:
if not require_sample():
return false
main = _create_main()
if main.data == null:
main.data = _short_demo() if with_demo else _empty_spread()
root.add_child(main)
await _frames(5)
if main._saving_enabled:
abort("Saving is enabled; refusing to run.")
return false
return true
## Back to the default theme, window and shared UI state.
func clean_up() -> void:
if main != null:
main.queue_free()
ThemeStore.DIR = "user://themes/"
ThemeStore.carry_board = null
ThemeStore.current = {}
ThemeAssets._cache.clear()
Spellcheck.ignored.clear()
TestBoardDialog.last = {}
RulesView.fallback_plain = true
SpreadLinks.loader = Callable()