diff --git a/tests/test_actions.gd b/tests/test_actions.gd index 16fe17a..d6c23dd 100644 --- a/tests/test_actions.gd +++ b/tests/test_actions.gd @@ -1,25 +1,16 @@ -extends SceneTree +extends TestBase ## The shared action menus (Actions): what the card, thread, group and spread ## menus offer in Play and Build, the ☰ menu, running an action, and placing ## a new card where the spread was right-clicked. ## Run: godot --headless --path . -s res://tests/test_actions.gd -- --sample -var _failures := 0 -var main: Main - func _init() -> void: - if not OS.get_cmdline_user_args().has("--sample"): - print("Run with -- --sample so the test can't touch saved data.") - quit(2) + if not await start_main(): return - main = load("res://ui/main.tscn").instantiate() - root.add_child(main) - await _frames(5) await _test_lists() await _test_popup_and_run() - print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) - quit(1 if _failures else 0) + finish() func _texts(list: Array) -> Array[String]: @@ -76,13 +67,3 @@ func _test_popup_and_run() -> void: bar_pm.about_to_popup.emit() _check(bar_pm.item_count > 4, "the ☰ menu fills with the spread's actions") - -func _frames(n: int = 2) -> void: - for i in n: - await process_frame - - -func _check(ok: bool, what: String) -> void: - if not ok: - _failures += 1 - print("FAIL ", what) diff --git a/tests/test_board_tester.gd b/tests/test_board_tester.gd index c8a737f..968bcc1 100644 --- a/tests/test_board_tester.gd +++ b/tests/test_board_tester.gd @@ -1,10 +1,9 @@ -extends SceneTree +extends TestBase ## BoardTester: static checks, simulated runs, isolation from the caller's ## variables and decks, batches, start-table detection, and the Test board ## dialog driven through its methods. ## Run: godot --headless --path . -s res://tests/test_board_tester.gd -var _failures := 0 ## Stands in for Main: just enough for the dialog. @@ -120,8 +119,7 @@ func _init() -> void: frames += 1 _check(not d2.running and d2.summary.text.begins_with("Cancelled after"), "cancelled run reports it: %s" % d2.summary.text) - print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) - quit(1 if _failures else 0) + finish() func _board() -> TowerBoard: @@ -202,12 +200,3 @@ func _text_has(probs: Array, s: String) -> bool: return true return false - -func _eq(got: Variant, want: Variant, what: String) -> void: - _check(str(got) == str(want), "%s\n got: %s\n want: %s" % [what, str(got), str(want)]) - - -func _check(ok: bool, what: String) -> void: - if not ok: - _failures += 1 - print(" ✗ ", what) diff --git a/tests/test_book.gd b/tests/test_book.gd index d298944..3056bf0 100644 --- a/tests/test_book.gd +++ b/tests/test_book.gd @@ -1,26 +1,17 @@ -extends SceneTree +extends TestBase ## The Book: pages saved from results, linked results following a page's edits, ## dropping a page onto a result or a card, unlinking, saving and undo. ## Run: godot --headless --path . -s res://tests/test_book.gd -- --sample -var _failures := 0 -var main: Main - func _init() -> void: - if not OS.get_cmdline_user_args().has("--sample"): - print("Run with -- --sample so the test can't touch saved data.") - quit(2) + if not await start_main(): return - main = load("res://ui/main.tscn").instantiate() - root.add_child(main) - await _frames(5) main.set_mode(Main.Mode.BUILD) await _frames() await _test_book() _test_pictures() - print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) - quit(1 if _failures else 0) + finish() func _test_book() -> void: @@ -117,13 +108,3 @@ func _test_pictures() -> void: _check(e3.combine_for("loot") == "max" and e3.pipe_pause.has("loot") and e3.pipe_color.get("loot") == "#c04a86", "thread options import") _check(b2.get_group(g2.id).parent == g.id and b2.book.size() == main.data.book.size() and b2.images.has(r["id"]), "nesting, the Book and pictures import") - -func _frames(n: int = 2) -> void: - for i in n: - await process_frame - - -func _check(ok: bool, what: String) -> void: - if not ok: - _failures += 1 - print("FAIL ", what) diff --git a/tests/test_builder.gd b/tests/test_builder.gd index cf6631a..5016723 100644 --- a/tests/test_builder.gd +++ b/tests/test_builder.gd @@ -1,11 +1,9 @@ -extends SceneTree +extends TestBase ## Headless checks for Builder (docs/PLAIN.md §2): effect and condition models ## that round-trip exactly with the stored text, the cases that don't fit a ## builder (ok: false), and known_values(). ## Run: godot --headless --path . -s res://tests/test_builder.gd -var _failures := 0 - func _init() -> void: _test_parse_effect() @@ -15,21 +13,9 @@ func _init() -> void: _test_condition_round_trips() _test_condition_not_ok() _test_known_values() - print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) - quit(1 if _failures else 0) + finish() -func _eq(got: Variant, want: Variant, what: String) -> void: - if typeof(got) != typeof(want) or got != want: - _failures += 1 - print(" ✗ %s: got %s, want %s" % [what, JSON.stringify(got), JSON.stringify(want)]) - - -func _check(ok: bool, what: String) -> void: - if not ok: - _failures += 1 - print(" ✗ ", what) - # ---------------------------------------------------------------- effects diff --git a/tests/test_card_size.gd b/tests/test_card_size.gd index 189a19e..cdcafb4 100644 --- a/tests/test_card_size.gd +++ b/tests/test_card_size.gd @@ -1,25 +1,16 @@ -extends SceneTree +extends TestBase ## Resizable cards: the grip's corner hit area, a dragged width and list ## height (the list scrolls), saving them, and double-click back to automatic. ## Run: godot --headless --path . -s res://tests/test_card_size.gd -- --sample -var _failures := 0 -var main: Main - func _init() -> void: - if not OS.get_cmdline_user_args().has("--sample"): - print("Run with -- --sample so the test can't touch saved data.") - quit(2) + if not await start_main(): return - main = load("res://ui/main.tscn").instantiate() - root.add_child(main) - await _frames(5) await _test_resize() await _test_compact() await _test_play_drag_selects() - print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) - quit(1 if _failures else 0) + finish() func _test_resize() -> void: @@ -95,13 +86,3 @@ func _test_play_drag_selects() -> void: _check(main.selection.has("road"), "it selects what the box touches") main.clear_selection() - -func _frames(n: int = 2) -> void: - for i in n: - await process_frame - - -func _check(ok: bool, what: String) -> void: - if not ok: - _failures += 1 - print("FAIL ", what) diff --git a/tests/test_check_inputs.gd b/tests/test_check_inputs.gd index 797d3b4..0a7bd73 100644 --- a/tests/test_check_inputs.gd +++ b/tests/test_check_inputs.gd @@ -1,11 +1,9 @@ -extends SceneTree +extends TestBase ## Headless checks for the new engine features of docs/PLAIN.md §3–§4: check ## cards, card inputs (pipe "with" values), collections, "nat" on roll tables, ## the why facts they record, the file format and the lint. ## Run: godot --headless --path . -s res://tests/test_check_inputs.gd -var _failures := 0 - func _init() -> void: _test_check_success_failure() @@ -24,22 +22,11 @@ func _init() -> void: _test_nat() _test_json() _test_lint() - print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) - quit(1 if _failures else 0) + finish() # ---------------------------------------------------------------- helpers -func _eq(got: Variant, want: Variant, what: String) -> void: - if typeof(got) != typeof(want) or got != want: - _failures += 1 - print(" ✗ %s: got %s, want %s" % [what, JSON.stringify(got), JSON.stringify(want)]) - - -func _check(ok: bool, what: String) -> void: - if not ok: - _failures += 1 - print(" ✗ ", what) func _rng(seed_value: int = 1) -> RandomNumberGenerator: diff --git a/tests/test_choice_dialog.gd b/tests/test_choice_dialog.gd index ad43c5c..e963ba2 100644 --- a/tests/test_choice_dialog.gd +++ b/tests/test_choice_dialog.gd @@ -1,24 +1,10 @@ -extends SceneTree +extends TestBase ## The choice pop-up's minimize pill and hover preview, and TablePreview. ## Run: godot --headless --path . -s res://tests/test_choice_dialog.gd -- --sample -var _failures := 0 -var main: Main - func _init() -> void: - if not OS.get_cmdline_user_args().has("--sample"): - print("Run with -- --sample so the test can't touch saved data.") - quit(2) - return - - main = load("res://ui/main.tscn").instantiate() - root.add_child(main) - for i in 5: - await process_frame - if main._saving_enabled: - print("Saving is enabled; refusing to roll.") - quit(2) + if not await start_main(): return # Headless windows are tiny; give the app a real size. main.set_anchors_preset(Control.PRESET_TOP_LEFT) @@ -36,8 +22,7 @@ func _init() -> void: await _test_cancel_from_pill() await _test_state_kept() - print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) - quit(1 if _failures else 0) + finish() func _add_tables() -> void: @@ -284,9 +269,3 @@ func _test_state_kept() -> void: _check(not d.minimized and int(d._spin.value) == 9, "the typed value survives minimize and restore") d.answer(null) await process_frame - - -func _check(ok: bool, what: String) -> void: - if not ok: - _failures += 1 - print(" ✗ ", what) diff --git a/tests/test_demos.gd b/tests/test_demos.gd index cef2e4d..77b2f2d 100644 --- a/tests/test_demos.gd +++ b/tests/test_demos.gd @@ -1,24 +1,17 @@ -extends SceneTree +extends TestBase ## 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: godot --headless --path . -s res://tests/test_demos.gd -- --sample -var _failures := 0 -var main: Main - func _init() -> void: - if not OS.get_cmdline_user_args().has("--sample"): - print("Run with -- --sample so the test can't touch saved data.") - quit(2) + if not require_sample(): return _test_builds() - main = load("res://ui/main.tscn").instantiate() - root.add_child(main) - await _frames(5) + if not await start_main(): + return await _test_open() - print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) - quit(1 if _failures else 0) + finish() func _test_builds() -> void: @@ -51,13 +44,3 @@ func _test_open() -> void: await _frames(3) _check(not main.demo.active() and main.data.id == before, "Back to my spread returns") - -func _frames(n: int = 2) -> void: - for i in n: - await process_frame - - -func _check(ok: bool, what: String) -> void: - if not ok: - _failures += 1 - print("FAIL ", what) diff --git a/tests/test_describe.gd b/tests/test_describe.gd index 3647c37..ee4d86a 100644 --- a/tests/test_describe.gd +++ b/tests/test_describe.gd @@ -1,12 +1,10 @@ -extends SceneTree +extends TestBase ## Headless checks for Describe (docs/PLAIN.md §1 and §3): plain phrases for ## every effect op, the condition forms, dice, dynamic options, pipes, check ## cards and why facts, with labels from variable cards, collections and card ## inputs, and the fallbacks to the original text. ## Run: godot --headless --path . -s res://tests/test_describe.gd -var _failures := 0 - func _init() -> void: _test_labels() @@ -20,22 +18,11 @@ func _init() -> void: _test_why_from_rolls() _test_fallbacks() _test_rules_view() - print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) - quit(1 if _failures else 0) + finish() # ---------------------------------------------------------------- helpers -func _eq(got: Variant, want: Variant, what: String) -> void: - if typeof(got) != typeof(want) or got != want: - _failures += 1 - print(" ✗ %s: got %s, want %s" % [what, JSON.stringify(got), JSON.stringify(want)]) - - -func _check(ok: bool, what: String) -> void: - if not ok: - _failures += 1 - print(" ✗ ", what) func _var_card(id: String, name: String, var_name: String, type: String = "number") -> RollTable: diff --git a/tests/test_expr_if.gd b/tests/test_expr_if.gd index 15d15c3..281ac28 100644 --- a/tests/test_expr_if.gd +++ b/tests/test_expr_if.gd @@ -1,9 +1,7 @@ -extends SceneTree +extends TestBase ## if(condition, then, else) in expressions, and the refused inline ternary. ## Run: godot --headless --path . -s res://tests/test_expr_if.gd -- --sample -var _failures := 0 - func _init() -> void: _value("if(1 > 2, 10, 20)", 20) @@ -16,16 +14,9 @@ func _init() -> void: _check(str(r.get("error", "")).contains("if(condition"), "\"%s\" is refused with a hint (got %s)" % [src, r]) _check(Expr.check(src) != "", "Expr.check flags \"%s\"" % src) _check(Expr.check("if(@str > 8, 1, 0)") == "", "if() with a variable passes the check") - print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) - quit(1 if _failures else 0) + finish() func _value(src: String, want: Variant) -> void: var r := Expr.evaluate(src, null) _check(str(r.get("error", "")) == "" and r.get("value") == want, "%s = %s (got %s)" % [src, want, r]) - - -func _check(ok: bool, what: String) -> void: - if not ok: - _failures += 1 - print(" ✗ ", what) diff --git a/tests/test_fast_roll.gd b/tests/test_fast_roll.gd index ef5a9a5..fd227a8 100644 --- a/tests/test_fast_roll.gd +++ b/tests/test_fast_roll.gd @@ -1,23 +1,11 @@ -extends SceneTree +extends TestBase ## Fast roll (Shift-click): the whole result shows at once, with no animation. ## Run: godot --headless --path . -s res://tests/test_fast_roll.gd -- --sample ## (--sample keeps the app from reading or writing saved collections.) -var _failures := 0 - func _init() -> void: - if not OS.get_cmdline_user_args().has("--sample"): - print("Run with -- --sample so the test can't touch saved data.") - quit(2) - return - var main: Main = load("res://ui/main.tscn").instantiate() - root.add_child(main) - for i in 5: - await process_frame - if main._saving_enabled: - print("Saving is enabled; refusing to roll.") - quit(2) + if not await start_main(): return main.rng.seed = 7 @@ -51,11 +39,4 @@ func _init() -> void: await process_frame _check(main.current.get("done", false) and main.current.get("fast", false), "the interrupted roll doesn't overwrite the fast result") - print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) - quit(1 if _failures else 0) - - -func _check(ok: bool, what: String) -> void: - if not ok: - _failures += 1 - print(" ✗ ", what) + finish() diff --git a/tests/test_groups.gd b/tests/test_groups.gd index 629ede0..e270a3b 100644 --- a/tests/test_groups.gd +++ b/tests/test_groups.gd @@ -1,28 +1,17 @@ -extends SceneTree +extends TestBase ## Group cards: the model and file format, membership, and in the app the ## frame, collapsing (hidden members, re-routed pipes, lit results, choice ## pop-ups), moving, dropping cards in and out, ungroup and delete. ## Run: godot --headless --path . -s res://tests/test_groups.gd -- --sample -var _failures := 0 -var main: Main - func _init() -> void: - if not OS.get_cmdline_user_args().has("--sample"): - print("Run with -- --sample so the test can't touch saved data.") - quit(2) + if not require_sample(): return _test_model() _test_json() _test_import() - main = load("res://ui/main.tscn").instantiate() - root.add_child(main) - for i in 5: - await process_frame - if main._saving_enabled: - print("Saving is enabled; refusing to run.") - quit(2) + if not await start_main(): return main.rng.seed = 5 await _load(_board_dict()) @@ -35,8 +24,7 @@ func _init() -> void: await _test_drop_in_and_out() await _test_collapse_all_and_fit() await _test_ungroup_and_delete() - print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) - quit(1 if _failures else 0) + finish() ## start -> a (in G) -> b (choice, in G) -> out @@ -403,17 +391,6 @@ func _test_nested() -> void: _check(back.groups.size() == main.data.groups.size(), "groups survive saving") -func _frames(n: int = 2) -> void: - for i in n: - await process_frame - - func _shown(tid: String) -> bool: var c := main.card_for(tid) return c != null and c.visible - - -func _check(ok: bool, what: String) -> void: - if not ok: - _failures += 1 - print("FAIL ", what) diff --git a/tests/test_inspector.gd b/tests/test_inspector.gd index 625c76f..6db5c08 100644 --- a/tests/test_inspector.gd +++ b/tests/test_inspector.gd @@ -1,27 +1,15 @@ -extends SceneTree +extends TestBase ## The Build inspector (docs/PLAIN.md §6): selection, the effects and ## condition builders, Otherwise, pipe inputs, check fields and the modifier ## picker, collection members, options source, the value picker, the ## Plain/Text switch, undo, and dirty/save. ## Run: godot --headless --path . -s res://tests/test_inspector.gd -- --sample -var _failures := 0 -var main: Main var insp: Inspector func _init() -> void: - if not OS.get_cmdline_user_args().has("--sample"): - print("Run with -- --sample so the test can't touch saved data.") - quit(2) - return - main = load("res://ui/main.tscn").instantiate() - root.add_child(main) - for i in 5: - await process_frame - if main._saving_enabled: - print("Saving is enabled; refusing to run.") - quit(2) + if not await start_main(): return main.set_anchors_and_offsets_preset(Control.PRESET_TOP_LEFT) main.size = Vector2(1440, 900) @@ -43,25 +31,9 @@ func _init() -> void: await _test_dirty_and_save() await _test_other_cards() await _test_add_kinds() - print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) - quit(1 if _failures else 0) + finish() -func _check(ok: bool, what: String) -> void: - if ok: - print(" ok %s" % what) - else: - _failures += 1 - print(" FAIL %s" % what) - - -func _eq(a: Variant, b: Variant, what: String) -> void: - _check(a == b, "%s (got %s, want %s)" % [what, JSON.stringify(a), JSON.stringify(b)]) - - -func _frames(n: int = 2) -> void: - for i in n: - await process_frame func _board_dict() -> Dictionary: diff --git a/tests/test_integration.gd b/tests/test_integration.gd index d08d1ec..f48a823 100644 --- a/tests/test_integration.gd +++ b/tests/test_integration.gd @@ -1,10 +1,8 @@ -extends SceneTree +extends TestBase ## Headless checks for the roller working with RollContext, TextExpander, ## pipes that save variables, card decks and StateStore. ## Run: godot --headless --path . -s res://tests/test_integration.gd -var _failures := 0 - func _init() -> void: _test_refs_and_vars() @@ -14,8 +12,7 @@ func _init() -> void: _test_missing_and_unset() _test_decks_through_state() _test_lit_and_steps() - print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) - quit(1 if _failures else 0) + finish() func _entry(id: String, text: String, weight: int = 1) -> TableEntry: @@ -224,12 +221,3 @@ func _test_lit_and_steps() -> void: var back: Variant = JSON.parse_string(JSON.stringify(steps)) _check(back is Array and (back as Array).size() == steps.size() and back[0]["text"] == steps[0]["text"], "steps round-trip through JSON") - -func _eq(got: Variant, want: Variant, what: String) -> void: - _check(got == want, "%s\n got: %s\n want: %s" % [what, str(got), str(want)]) - - -func _check(ok: bool, what: String) -> void: - if not ok: - _failures += 1 - print(" ✗ ", what) diff --git a/tests/test_io.gd b/tests/test_io.gd index 9c1138a..b592e15 100644 --- a/tests/test_io.gd +++ b/tests/test_io.gd @@ -1,11 +1,9 @@ -extends SceneTree +extends TestBase ## Headless checks for the import/export converters. ## Run: godot --headless --path . -s res://tests/test_io.gd const TMP_DIR := "user://test_io_tmp/" -var _failures := 0 - func _init() -> void: DirAccess.make_dir_recursive_absolute(TMP_DIR) @@ -15,8 +13,7 @@ func _init() -> void: _test_mermaid_dot() _test_graphml() _cleanup() - print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) - quit(1 if _failures else 0) + finish() ## Two tables with weights, ranges, count/save_as pipes, an inline reference, a @@ -281,9 +278,3 @@ func _plain_tables(tables: Array, sample: Dictionary) -> Array: if not logic: plain[t["id"]] = true return tables.filter(func(t: Dictionary) -> bool: return plain.has(t["id"])) - - -func _check(ok: bool, what: String) -> void: - if not ok: - _failures += 1 - print(" ✗ ", what) diff --git a/tests/test_list_view.gd b/tests/test_list_view.gd index e063cef..a276da8 100644 --- a/tests/test_list_view.gd +++ b/tests/test_list_view.gd @@ -1,24 +1,15 @@ -extends SceneTree +extends TestBase ## List view: rows for every card with thread counts and Roll, search, new ## folders, and drag-and-drop moves (reorder, into a folder, folder in folder). ## Run: godot --headless --path . -s res://tests/test_list_view.gd -- --sample -var _failures := 0 -var main: Main - func _init() -> void: - if not OS.get_cmdline_user_args().has("--sample"): - print("Run with -- --sample so the test can't touch saved data.") - quit(2) + if not await start_main(): return - main = load("res://ui/main.tscn").instantiate() - root.add_child(main) - await _frames(5) await _test_rows() await _test_moves() - print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) - quit(1 if _failures else 0) + finish() func _rows(it: TreeItem, out: Array) -> Array: @@ -77,13 +68,3 @@ func _test_moves() -> void: main.undo_redo.undo() _check(main.data.tables[0].id == ids[0], "and undo puts it back") - -func _frames(n: int = 2) -> void: - for i in n: - await process_frame - - -func _check(ok: bool, what: String) -> void: - if not ok: - _failures += 1 - print("FAIL ", what) diff --git a/tests/test_logic.gd b/tests/test_logic.gd index f305005..ab829b3 100644 --- a/tests/test_logic.gd +++ b/tests/test_logic.gd @@ -1,11 +1,9 @@ -extends SceneTree +extends TestBase ## Headless checks for logic cards (docs/LOGIC.md): expressions, effects, ## variables, choice / loop / variable / sheet cards, the action limit, long ## chains and the file format. ## Run: godot --headless --path . -s res://tests/test_logic.gd -var _failures := 0 - func _init() -> void: _test_expressions() @@ -20,8 +18,7 @@ func _init() -> void: _test_sheet() _test_json() await _test_character() - print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) - quit(1 if _failures else 0) + finish() # ---------------------------------------------------------------- helpers @@ -720,11 +717,3 @@ func _test_character() -> void: # ---------------------------------------------------------------- checks -func _eq(got: Variant, want: Variant, what: String) -> void: - _check(typeof(got) == typeof(want) and got == want or (got is Array and want is Array and str(got) == str(want)), "%s\n got: %s\n want: %s" % [what, str(got), str(want)]) - - -func _check(ok: bool, what: String) -> void: - if not ok: - _failures += 1 - print(" ✗ ", what) diff --git a/tests/test_logic_ui.gd b/tests/test_logic_ui.gd index 8ee9143..ae458d8 100644 --- a/tests/test_logic_ui.gd +++ b/tests/test_logic_ui.gd @@ -1,4 +1,4 @@ -extends SceneTree +extends TestBase ## Logic cards in the app: the choice pop-up, progress while it's open, ## cancelling, a new roll replacing an open question, live variable and sheet ## cards, the long-chain tray and the Build-mode settings rules. @@ -7,22 +7,9 @@ extends SceneTree const DEMO := "res://examples/logic_demo.json" -var _failures := 0 -var main: Main - func _init() -> void: - if not OS.get_cmdline_user_args().has("--sample"): - print("Run with -- --sample so the test can't touch saved data.") - quit(2) - return - main = load("res://ui/main.tscn").instantiate() - root.add_child(main) - for i in 5: - await process_frame - if main._saving_enabled: - print("Saving is enabled; refusing to roll.") - quit(2) + if not await start_main(): return main.rng.seed = 11 @@ -40,8 +27,7 @@ func _init() -> void: await _test_long_chain() await _test_action_limit() - print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) - quit(1 if _failures else 0) + finish() func _load_demo() -> void: @@ -443,13 +429,3 @@ func _test_action_limit() -> void: # ---------------------------------------------------------------- checks -func _eq(got: Variant, want: Variant, what: String) -> void: - if typeof(got) != typeof(want) or got != want: - _failures += 1 - print(" ✗ %s (got %s, want %s)" % [what, str(got), str(want)]) - - -func _check(ok: bool, what: String) -> void: - if not ok: - _failures += 1 - print(" ✗ ", what) diff --git a/tests/test_mobile.gd b/tests/test_mobile.gd index b209099..93984c4 100644 --- a/tests/test_mobile.gd +++ b/tests/test_mobile.gd @@ -1,25 +1,16 @@ -extends SceneTree +extends TestBase ## The phone layout (List fills the screen, Spread/List swap, slim bar and ## tray, View/Help/Play-Build in ☰) and touch gestures (pinch zoom, a long ## press timing out into a right-click). ## Run: godot --headless --path . -s res://tests/test_mobile.gd -- --sample -var _failures := 0 -var main: Main - func _init() -> void: - if not OS.get_cmdline_user_args().has("--sample"): - print("Run with -- --sample so the test can't touch saved data.") - quit(2) + if not await start_main(): return - main = load("res://ui/main.tscn").instantiate() - root.add_child(main) - await _frames(5) await _test_layout() await _test_touch() - print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) - quit(1 if _failures else 0) + finish() func _test_layout() -> void: @@ -67,13 +58,3 @@ func _tap(i: int, at: Vector2, down: bool) -> InputEventScreenTouch: t.pressed = down return t - -func _frames(n: int = 2) -> void: - for i in n: - await process_frame - - -func _check(ok: bool, what: String) -> void: - if not ok: - _failures += 1 - print("FAIL ", what) diff --git a/tests/test_model.gd b/tests/test_model.gd index 6daf201..8d00ca7 100644 --- a/tests/test_model.gd +++ b/tests/test_model.gd @@ -1,9 +1,7 @@ -extends SceneTree +extends TestBase ## Headless checks for dice, weights, pipe options, card mode and JSON. ## Run: godot --headless --path . -s res://tests/test_model.gd -var _failures := 0 - func _init() -> void: _test_dice() @@ -15,8 +13,7 @@ func _init() -> void: _test_seed() _test_json() _test_sample() - print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) - quit(1 if _failures else 0) + finish() func _entry(id: String, text: String, weight: int = 1) -> TableEntry: @@ -375,9 +372,3 @@ func _test_sample() -> void: _check(ruins.dice_mod == "@luck" and ruins.range_problems() == "", "Search the Ruins is 1d6 + Luck with clean ranges") var reach: Array = ruins.entries.map(func(e: TableEntry) -> bool: return RollRange.natural_reach(ruins, e)) _check(reach == [false, true, true, true, false], "only a modifier reaches its first and last results: %s" % str(reach)) - - -func _check(ok: bool, what: String) -> void: - if not ok: - _failures += 1 - print(" ✗ ", what) diff --git a/tests/test_modifier.gd b/tests/test_modifier.gd index c39922a..a7afcfe 100644 --- a/tests/test_modifier.gd +++ b/tests/test_modifier.gd @@ -1,12 +1,10 @@ -extends SceneTree +extends TestBase ## Headless checks for the roll modifier on ranged roll tables (dice_mod, ## RollRange): results past the dice, using the nearest result past the ends, ## chances with a modifier, the file format, plain words and the Why line, ## and the ModifierEditor's plain forms. ## Run: godot --headless --path . -s res://tests/test_modifier.gd -var _failures := 0 - func _init() -> void: _test_model() @@ -16,21 +14,9 @@ func _init() -> void: _test_words() _test_problems() _test_editor_forms() - print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) - quit(1 if _failures else 0) + finish() -func _eq(got: Variant, want: Variant, what: String) -> void: - if typeof(got) != typeof(want) or got != want: - _failures += 1 - print(" ✗ %s: got %s, want %s" % [what, JSON.stringify(got), JSON.stringify(want)]) - - -func _check(ok: bool, what: String) -> void: - if not ok: - _failures += 1 - print(" ✗ ", what) - ## A 1d20 + @luck event table with results from -3 to 24: ## -3 Disaster · -2–5 Bad · 6–15 Quiet · 16–23 Good · 24 Windfall. diff --git a/tests/test_navigation.gd b/tests/test_navigation.gd index 4fa65d2..d1f4cd0 100644 --- a/tests/test_navigation.gd +++ b/tests/test_navigation.gd @@ -1,27 +1,16 @@ -extends SceneTree +extends TestBase ## Navigation on big boards: search (BoardSearch and the panel), focus_table, ## the minimap, Pack collapsed groups (and making room when a packed group ## expands), lazily built cards for collapsed groups, and the resizable tray ## and inspector. ## Run: godot --headless --path . -s res://tests/test_navigation.gd -- --sample -var _failures := 0 -var main: Main - func _init() -> void: - if not OS.get_cmdline_user_args().has("--sample"): - print("Run with -- --sample so the test can't touch saved data.") - quit(2) + if not require_sample(): return _test_fold_and_layout() - main = load("res://ui/main.tscn").instantiate() - root.add_child(main) - for i in 5: - await process_frame - if main._saving_enabled: - print("Saving is enabled; refusing to run.") - quit(2) + if not await start_main(): return # The headless window is tiny; give the app a real screen's worth of room. main.set_anchors_and_offsets_preset(Control.PRESET_TOP_LEFT) @@ -36,8 +25,7 @@ func _init() -> void: await _test_pack() await _test_zoom_range() await _test_panels() - print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) - quit(1 if _failures else 0) + finish() ## start -> agent (in Careers, 30 results); careers and skills groups @@ -339,12 +327,6 @@ func _overlaps(rects: Array) -> bool: return false -func _check(ok: bool, what: String) -> void: - if not ok: - _failures += 1 - print("FAIL ", what) - - func _test_panels() -> void: print("Resizable tray and inspector") var foot: PanelSplitter = null @@ -393,11 +375,3 @@ func _test_panels() -> void: _check(not side.visible, "no handle in Play mode") main.history.clear() - -func _eq(got: Variant, want: Variant, what: String) -> void: - _check(typeof(got) == typeof(want) and got == want, "%s: got %s, want %s" % [what, str(got), str(want)]) - - -func _frames(n: int = 4) -> void: - for i in n: - await process_frame diff --git a/tests/test_options.gd b/tests/test_options.gd index e0e00c7..6237128 100644 --- a/tests/test_options.gd +++ b/tests/test_options.gd @@ -1,4 +1,4 @@ -extends SceneTree +extends TestBase ## Headless checks for dynamic pick options (options_from / options_where), ## conditional options (show_if) and indirect variable names (@[expr]), as in ## docs/LOGIC.md §2a: candidates, labels and values, fixed extras, Random, @@ -6,13 +6,9 @@ extends SceneTree ## already have" board and the choice pop-up's rendering. ## Run: godot --headless --path . -s res://tests/test_options.gd -- --sample -var _failures := 0 - func _init() -> void: - if not OS.get_cmdline_user_args().has("--sample"): - print("Run with -- --sample so the test can't touch saved data.") - quit(2) + if not require_sample(): return _test_prefix_options() _test_list_options() @@ -28,8 +24,7 @@ func _init() -> void: await _test_dialog() _test_settings() await _test_card() - print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) - quit(1 if _failures else 0) + finish() # ---------------------------------------------------------------- helpers @@ -617,9 +612,3 @@ func _has(n: Node, needle: String) -> bool: if s.contains(needle): return true return false - - -func _check(ok: bool, what: String) -> void: - if not ok: - _failures += 1 - print(" ✗ ", what) diff --git a/tests/test_plain_display.gd b/tests/test_plain_display.gd index 35319c2..3a25091 100644 --- a/tests/test_plain_display.gd +++ b/tests/test_plain_display.gd @@ -1,4 +1,4 @@ -extends SceneTree +extends TestBase ## The display side of Plain Build (docs/PLAIN.md §6): plain chips and lines ## on cards and their text-mode twins, the switch refreshing them, pipe ## labels, check / collection / inputs visuals, "Why this?" sentences and the @@ -9,8 +9,6 @@ extends SceneTree ## (rules_plain(), rules_view_changed, select_result(), select_card()), so the ## display can be tested on its own. -var _failures := 0 -var main: Main const FAKE_MAIN := """extends Main %s @@ -56,19 +54,11 @@ const BOARD := { func _init() -> void: - if not OS.get_cmdline_user_args().has("--sample"): - print("Run with -- --sample so the test can't touch saved data.") - quit(2) + if not require_sample(): return _test_why_sentences() _test_rules_view_helpers() - main = _make_main() - root.add_child(main) - for i in 5: - await process_frame - if main._saving_enabled: - print("Saving is enabled; refusing to roll.") - quit(2) + if not await start_main(): return main.rng.seed = 7 main.data.load_json(JSON.stringify(BOARD)) @@ -88,13 +78,12 @@ func _init() -> void: await _test_roll_why() await _test_build_rows() - print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) - quit(1 if _failures else 0) + finish() ## Main with the inspector's hooks (only the signal is skipped when Main ## already declares it). -func _make_main() -> Main: +func _create_main() -> Main: var has_signal := false for s: Dictionary in (load("res://ui/main.gd") as Script).get_script_signal_list(): if str(s["name"]) == "rules_view_changed": @@ -150,17 +139,6 @@ func _chips(card: TableCard) -> PackedStringArray: return out -func _check(ok: bool, what: String) -> void: - if not ok: - _failures += 1 - print(" ✗ ", what) - - -func _eq(got: Variant, want: Variant, what: String) -> void: - if got != want: - _failures += 1 - print(" ✗ %s: got %s, want %s" % [what, var_to_str(got), var_to_str(want)]) - # ---------------------------------------------------------------- pure parts diff --git a/tests/test_roll_features.gd b/tests/test_roll_features.gd index ebb02ce..1e19508 100644 --- a/tests/test_roll_features.gd +++ b/tests/test_roll_features.gd @@ -1,11 +1,9 @@ -extends SceneTree +extends TestBase ## Roll features in the engine: combining a thread's repeated rolls (add, ## highest, lowest, choose), saving the combined value, and only the kept roll ## following its threads. ## Run: godot --headless --path . -s res://tests/test_roll_features.gd -var _failures := 0 - func _init() -> void: _test_combine() @@ -13,8 +11,7 @@ func _init() -> void: await _test_pause() await _test_costs() _test_limits() - print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) - quit(1 if _failures else 0) + finish() ## Start → Gold ×3; Gold's results are numbers, and each pipes on to Note. @@ -186,9 +183,3 @@ func _test_limits() -> void: _check(why.contains("raised to 7"), "Why says it was raised: " + why) var back := RollTable.from_dict(atmo.to_dict()) _check(back.roll_floor == "@atmo_min", "the floor is saved") - - -func _check(ok: bool, what: String) -> void: - if not ok: - _failures += 1 - print("FAIL ", what) diff --git a/tests/test_roller.gd b/tests/test_roller.gd index 97792bf..97a21d9 100644 --- a/tests/test_roller.gd +++ b/tests/test_roller.gd @@ -1,9 +1,7 @@ -extends SceneTree +extends TestBase ## Headless checks for the data model and roller. ## Run: godot --headless --path . -s res://tests/test_roller.gd -var _failures := 0 - func _init() -> void: var board := SampleBoard.create() @@ -93,11 +91,4 @@ func _init() -> void: dangling = true _check(not dangling and copy.get_table("loot") == null, "removing a table removes threads into it") - print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) - quit(1 if _failures else 0) - - -func _check(ok: bool, what: String) -> void: - if not ok: - _failures += 1 - print(" ✗ ", what) + finish() diff --git a/tests/test_router.gd b/tests/test_router.gd index 640afdc..8a73059 100644 --- a/tests/test_router.gd +++ b/tests/test_router.gd @@ -1,12 +1,10 @@ -extends SceneTree +extends TestBase ## Headless checks for conditional pipes and router cards (docs/LOGIC.md §3a ## and §3b): when / otherwise selection, the snapshot rule, expression errors, ## first-match routing, "No case matched", the file format, lint_pipes() and a ## small board where a router replaces a chain-variable workaround. ## Run: godot --headless --path . -s res://tests/test_router.gd -var _failures := 0 - func _init() -> void: _test_when_otherwise() @@ -19,8 +17,7 @@ func _init() -> void: _test_cycles() await _test_mini_board() _test_ui_helpers() - print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) - quit(1 if _failures else 0) + finish() # ---------------------------------------------------------------- helpers @@ -414,11 +411,3 @@ func _test_ui_helpers() -> void: # ---------------------------------------------------------------- checks -func _eq(got: Variant, want: Variant, what: String) -> void: - _check(typeof(got) == typeof(want) and got == want or (got is Array and want is Array and str(got) == str(want)), "%s\n got: %s\n want: %s" % [what, str(got), str(want)]) - - -func _check(ok: bool, what: String) -> void: - if not ok: - _failures += 1 - print(" ✗ ", what) diff --git a/tests/test_shell.gd b/tests/test_shell.gd index 2fc6397..6cd0abb 100644 --- a/tests/test_shell.gd +++ b/tests/test_shell.gd @@ -1,11 +1,9 @@ -extends SceneTree +extends TestBase ## Headless checks for the app-shell logic: table settings, collections, import. ## Run: godot --headless --path . -s res://tests/test_shell.gd const ROOT := "user://test_shell_tmp" -var _failures := 0 - func _init() -> void: _wipe(ROOT) @@ -16,8 +14,7 @@ func _init() -> void: _test_import() _test_export() _wipe(ROOT) - print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) - quit(1 if _failures else 0) + finish() func _plain_table(n: int = 4) -> RollTable: @@ -166,9 +163,3 @@ func _wipe(path: String) -> void: for f in d.get_files(): DirAccess.remove_absolute(abs.path_join(f)) DirAccess.remove_absolute(abs) - - -func _check(cond: bool, msg: String) -> void: - if not cond: - _failures += 1 - print("FAIL: ", msg) diff --git a/tests/test_simulate.gd b/tests/test_simulate.gd index 164d84a..f7ca2d2 100644 --- a/tests/test_simulate.gd +++ b/tests/test_simulate.gd @@ -1,10 +1,8 @@ -extends SceneTree +extends TestBase ## Keeps the simulator (BoardTester, and its CLI tools/simulate_board.gd) working: runs it on a small inline board with ## a choice, a loop, a check, a bad effect, an unreachable table and a sheet. ## Run: godot --headless --path . -s res://tests/test_simulate.gd -var _failures := 0 - func _init() -> void: var b := _board() @@ -42,8 +40,7 @@ func _init() -> void: _eq((r3["halted"] as Dictionary).get("Action limit", 0), 5, "the action limit is a halt reason") var text := BoardTester.format_report(r) _check(text.contains("Runs: 60") and text.contains("Tables never reached: 1") and text.contains("Sample final sheet") and text.contains("@gold: min"), "the report prints:\n%s" % text) - print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) - quit(1 if _failures else 0) + finish() func _board() -> TowerBoard: @@ -87,12 +84,3 @@ func _board() -> TowerBoard: b.tables.append(t) return b - -func _eq(got: Variant, want: Variant, what: String) -> void: - _check(str(got) == str(want), "%s\n got: %s\n want: %s" % [what, str(got), str(want)]) - - -func _check(ok: bool, what: String) -> void: - if not ok: - _failures += 1 - print(" ✗ ", what) diff --git a/tests/test_small_ui.gd b/tests/test_small_ui.gd index 7a73e5d..9d17340 100644 --- a/tests/test_small_ui.gd +++ b/tests/test_small_ui.gd @@ -1,21 +1,13 @@ -extends SceneTree +extends TestBase ## Small UI items: backwards ranges warn and block rolling (no auto-swap), the ## inspector's thread lists, replacing a template, the tray chip's bold source ## name, and the export menu's Other formats. ## Run: godot --headless --path . -s res://tests/test_small_ui.gd -- --sample -var _failures := 0 -var main: Main - func _init() -> void: - if not OS.get_cmdline_user_args().has("--sample"): - print("Run with -- --sample so the test can't touch saved data.") - quit(2) + if not await start_main(): return - main = load("res://ui/main.tscn").instantiate() - root.add_child(main) - await _frames(5) await _test_backwards_range() await _test_thread_lists() _test_template_replace() @@ -24,8 +16,7 @@ func _init() -> void: await _test_batch() await _test_pause_aside() _test_sheet_export() - print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) - quit(1 if _failures else 0) + finish() func _test_backwards_range() -> void: @@ -169,13 +160,3 @@ func _test_sheet_export() -> void: main.rolling.start_roll("road", true) _check(SheetExport.document(main, "txt").contains("Road Encounter"), "the current roll becomes a document") - -func _frames(n: int = 2) -> void: - for i in n: - await process_frame - - -func _check(ok: bool, what: String) -> void: - if not ok: - _failures += 1 - print("FAIL ", what) diff --git a/tests/test_storage.gd b/tests/test_storage.gd index 838cfbd..8bfea8b 100644 --- a/tests/test_storage.gd +++ b/tests/test_storage.gd @@ -1,11 +1,9 @@ -extends SceneTree +extends TestBase ## Headless checks for collections, LibraryStore and StateStore. ## Run: godot --headless --path . -s res://tests/test_storage.gd const ROOT := "user://test_storage_tmp" -var _failures := 0 - func _init() -> void: _wipe(ROOT) @@ -15,8 +13,7 @@ func _init() -> void: _test_corrupt() _test_state() _wipe(ROOT) - print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) - quit(1 if _failures else 0) + finish() func _test_versions() -> void: @@ -196,9 +193,3 @@ func _wipe(path: String) -> void: for f in DirAccess.get_files_at(path): DirAccess.remove_absolute(path.path_join(f)) DirAccess.remove_absolute(path) - - -func _check(ok: bool, what: String) -> void: - if not ok: - _failures += 1 - print(" ✗ ", what) diff --git a/tests/test_templates.gd b/tests/test_templates.gd index 6730f4e..ae024f5 100644 --- a/tests/test_templates.gd +++ b/tests/test_templates.gd @@ -1,4 +1,4 @@ -extends SceneTree +extends TestBase ## Templates: saving (placeholder detection, relative positions, pipes kept or ## recorded by name), inserting (substitution, fresh ids, internal pipes kept, ## outside pipes relinked or reported), the library and the built-in @@ -7,14 +7,9 @@ extends SceneTree const TMP_ROOT := "user://test_templates_tmp" -var _failures := 0 -var main: Main - func _init() -> void: - if not OS.get_cmdline_user_args().has("--sample"): - print("Run with -- --sample so the test can't touch saved data.") - quit(2) + if not require_sample(): return _test_make() _test_insert() @@ -22,17 +17,10 @@ func _init() -> void: _test_library_memory() _test_library_files() _test_builtins() - main = load("res://ui/main.tscn").instantiate() - root.add_child(main) - for i in 5: - await process_frame - if main._saving_enabled: - print("Saving is enabled; refusing to run.") - quit(2) + if not await start_main(): return await _test_app() - print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) - quit(1 if _failures else 0) + finish() ## A check table and its outcome table, piping to "Wounds" outside. @@ -327,9 +315,3 @@ func _wipe(dir: String) -> void: DirAccess.remove_absolute(tdir) if DirAccess.dir_exists_absolute(dir): DirAccess.remove_absolute(dir) - - -func _check(ok: bool, what: String) -> void: - if not ok: - _failures += 1 - print("FAIL ", what) diff --git a/tests/test_text.gd b/tests/test_text.gd index 8d8931b..5a55297 100644 --- a/tests/test_text.gd +++ b/tests/test_text.gd @@ -1,4 +1,4 @@ -extends SceneTree +extends TestBase ## Headless checks for RollContext, TextExpander and Formatter. ## Run: godot --headless --path . -s res://tests/test_text.gd @@ -17,7 +17,6 @@ const RESULTS := { "bold": ["[b]heavy"], } -var _failures := 0 var _ctx: RollContext var _rolls: Dictionary = {} @@ -25,8 +24,7 @@ var _rolls: Dictionary = {} func _init() -> void: _test_expander() _test_formatter() - print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) - quit(1 if _failures else 0) + finish() func _new_ctx(persistent: Dictionary = {}) -> RollContext: @@ -208,12 +206,3 @@ func _test_formatter() -> void: _eq(RollContext.normalize_name(" [b]Gems[/b] "), "gems", "normalize_name") - -func _eq(got: Variant, want: Variant, what: String) -> void: - _check(got == want, "%s\n got: %s\n want: %s" % [what, got, want]) - - -func _check(ok: bool, what: String) -> void: - if not ok: - _failures += 1 - print(" ✗ ", what) diff --git a/tests/test_theme.gd b/tests/test_theme.gd index 1d79790..9768340 100644 --- a/tests/test_theme.gd +++ b/tests/test_theme.gd @@ -1,28 +1,21 @@ -extends SceneTree +extends TestBase ## Theme sets: applying built-ins sets Style tokens and fills, saving and ## deleting a user set, and the Theme dialog building its editors. ## Run: godot --headless --path . -s res://tests/test_theme.gd -- --sample -var _failures := 0 -var main: Main - func _init() -> void: - if not OS.get_cmdline_user_args().has("--sample"): - print("Run with -- --sample so the test can't touch saved data.") - quit(2) + if not require_sample(): return ThemeStore.DIR = OS.get_temp_dir().path_join("tt_theme_test_%d/" % OS.get_process_id()) - main = load("res://ui/main.tscn").instantiate() - root.add_child(main) - await _frames(5) + if not await start_main(): + return _test_apply() _test_save_delete() await _test_dialog() _test_own_colours() await _test_sparkles() - print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) - quit(1 if _failures else 0) + finish() func _test_apply() -> void: @@ -105,13 +98,3 @@ func _test_sparkles() -> void: await _frames() _check(not pipes._trail.emitting, "the trail stops with the pulse") - -func _frames(n: int = 2) -> void: - for i in n: - await process_frame - - -func _check(ok: bool, what: String) -> void: - if not ok: - _failures += 1 - print("FAIL ", what) diff --git a/tests/test_top_bar.gd b/tests/test_top_bar.gd index f49b989..7fc064c 100644 --- a/tests/test_top_bar.gd +++ b/tests/test_top_bar.gd @@ -1,24 +1,12 @@ -extends SceneTree +extends TestBase ## The top bar's menus (View ▾, the zoom control, Board ▾ with Pack, Help ▾), ## striped result rows, the Build card's ⋯ menu and the row × that shows on ## hover or selection, and the Help window's topics and links. ## Run: godot --headless --path . -s res://tests/test_top_bar.gd -- --sample -var _failures := 0 -var main: Main - func _init() -> void: - if not OS.get_cmdline_user_args().has("--sample"): - print("Run with -- --sample so the test can't touch saved data.") - quit(2) - return - main = load("res://ui/main.tscn").instantiate() - root.add_child(main) - await _frames(5) - if main._saving_enabled: - print("Saving is enabled; refusing to run.") - quit(2) + if not await start_main(): return main.set_anchors_and_offsets_preset(Control.PRESET_TOP_LEFT) main.size = Vector2(1440, 900) @@ -28,8 +16,7 @@ func _init() -> void: await _test_stripes() await _test_card_menu() await _test_help() - print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) - quit(1 if _failures else 0) + finish() func _test_bar() -> void: @@ -149,18 +136,3 @@ func _test_help() -> void: _check(d.text.get_parsed_text().contains("Luck"), "and shows its text") d.close() await _frames() - - -func _frames(n: int = 2) -> void: - for i in n: - await process_frame - - -func _check(ok: bool, what: String) -> void: - if not ok: - _failures += 1 - print("FAIL ", what) - - -func _eq(got: Variant, want: Variant, what: String) -> void: - _check(got == want, "%s: got %s, want %s" % [what, str(got), str(want)]) diff --git a/tests/test_undo.gd b/tests/test_undo.gd index bbffd85..685fca2 100644 --- a/tests/test_undo.gd +++ b/tests/test_undo.gd @@ -1,4 +1,4 @@ -extends SceneTree +extends TestBase ## Undo and redo of Build edits (EditHistory and Main's "Undo and redo"): ## every kind of edit, coalescing, redo being cleared, the cap, per-collection ## histories, labels, view and lit state, the toast's Undo, lazily built cards, @@ -7,23 +7,12 @@ extends SceneTree ## [--big-board=] times a real board instead of a made-up ## 800-card one. -var _failures := 0 -var main: Main - func _init() -> void: - if not OS.get_cmdline_user_args().has("--sample"): - print("Run with -- --sample so the test can't touch saved data.") - quit(2) + if not require_sample(): return _test_history_unit() - main = load("res://ui/main.tscn").instantiate() - root.add_child(main) - for i in 5: - await process_frame - if main._saving_enabled: - print("Saving is enabled; refusing to run.") - quit(2) + if not await start_main(): return main.set_anchors_and_offsets_preset(Control.PRESET_TOP_LEFT) main.size = Vector2(1440, 900) @@ -46,16 +35,7 @@ func _init() -> void: await _test_play_mode() await _test_collections() await _test_big_board() - print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) - quit(1 if _failures else 0) - - -func _check(ok: bool, what: String) -> void: - if ok: - print(" ok %s" % what) - else: - _failures += 1 - print(" FAIL %s" % what) + finish() ## Loot (two results, one piping to Gems), Gems, Weapons and Armor in the @@ -83,11 +63,6 @@ func _load(d: Dictionary = {}) -> void: await process_frame -func _frames(n: int = 2) -> void: - for i in n: - await process_frame - - func _t(id: String) -> RollTable: return main.data.get_table(id) diff --git a/tests/testbase.gd b/tests/testbase.gd new file mode 100644 index 0000000..7dcdfcb --- /dev/null +++ b/tests/testbase.gd @@ -0,0 +1,63 @@ +class_name TestBase +extends SceneTree +## Shared boilerplate for the headless suites: the --sample guard, loading the +## app, frame waiting, the check helpers and the PASS/FAIL summary the runner +## (tools/run_tests.sh) looks for. A suite extends this and calls +## `if not await start_main(): return` first when it needs the app. + +var _failures := 0 +var main: Main + + +## Returns false (after quitting with 2) unless the suite was started with +## `-- --sample`, so a test can't touch saved data. +func require_sample() -> bool: + if OS.get_cmdline_user_args().has("--sample"): + return true + print("Run with -- --sample so the test can't touch saved data.") + quit(2) + return false + + +## Hook: suites that need a customised Main override this. +func _create_main() -> Main: + return load("res://ui/main.tscn").instantiate() + + +## Guard, then loads the app under root and waits for it. Returns false (after +## quitting) if the guard fails or the app would save. +func start_main() -> bool: + if not require_sample(): + return false + main = _create_main() + root.add_child(main) + await _frames(5) + if main._saving_enabled: + print("Saving is enabled; refusing to run.") + quit(2) + return false + return true + + +func _frames(n: int = 2) -> void: + for i in n: + await process_frame + + +func _check(ok: bool, what: String) -> void: + if not ok: + _failures += 1 + print("FAIL ", what) + + +func _eq(got: Variant, want: Variant, what: String) -> void: + var same: bool = typeof(got) == typeof(want) and got == want + if not same and got is Array and want is Array: + same = str(got) == str(want) + _check(same, "%s\n got: %s\n want: %s" % [what, str(got), str(want)]) + + +## Prints the summary line the runner greps for, then quits. +func finish() -> void: + print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) + quit(1 if _failures else 0) diff --git a/tests/testbase.gd.uid b/tests/testbase.gd.uid new file mode 100644 index 0000000..c601090 --- /dev/null +++ b/tests/testbase.gd.uid @@ -0,0 +1 @@ +uid://qgpdvh5r3t5i