Add automated test framework and 21 regression tests
- tests/runner.gd: lightweight headless test runner (TAP format output) - tests/weapons.gd: 6 tests for weapon registry and stats - tests/team.gd: 5 tests for team assignment and balancing - tests/economy.gd: 6 tests for economy constants and loss streaks - tests/bootstrapper.gd: 4 tests for LAN bootstrapper input parsing Run with: godot --headless -s tests/runner.gd --path . All 21 tests pass on Linux and Windows.
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
extends RefCounted
|
||||
|
||||
## Weapon registry tests — no framework dependencies, no class_name types.
|
||||
## Each test_* method returns "" on pass or an error message on fail.
|
||||
##
|
||||
## Uses direct integer enum values to avoid class_name loading order issues:
|
||||
## FireMode: SEMI=0, AUTO=1, MELEE=2
|
||||
|
||||
const Registry := preload("res://examples/multiplayer-fps/scripts/data/weapon_registry.gd")
|
||||
|
||||
const KNIFE := 1
|
||||
const GLOCK := 2
|
||||
const USP := 3
|
||||
const AK47 := 4
|
||||
const M4A1 := 5
|
||||
const AWP := 6
|
||||
|
||||
func _check_field(w, field: String, expected) -> String:
|
||||
var actual = w.get(field)
|
||||
if actual != expected:
|
||||
return " %s: got %s, expected %s" % [field, str(actual), str(expected)]
|
||||
return ""
|
||||
|
||||
func test_all_weapons_registered() -> String:
|
||||
var ids := [KNIFE, GLOCK, USP, AK47, M4A1, AWP]
|
||||
for id in ids:
|
||||
var w := Registry.get_weapon(id)
|
||||
if w == null:
|
||||
return "Weapon ID %d not registered" % id
|
||||
return ""
|
||||
|
||||
func test_unknown_id_returns_null() -> String:
|
||||
if Registry.get_weapon(0) != null: return "ID 0 should return null"
|
||||
if Registry.get_weapon(99) != null: return "ID 99 should return null"
|
||||
if Registry.get_weapon(-1) != null: return "ID -1 should return null"
|
||||
return ""
|
||||
|
||||
func test_ak47_stats() -> String:
|
||||
var w := Registry.get_weapon(AK47)
|
||||
if w == null: return "AK47 not found"
|
||||
var e := ""
|
||||
e += _check_field(w, "weapon_name", "AK-47")
|
||||
e += _check_field(w, "damage", 36)
|
||||
e += _check_field(w, "fire_mode", 1) # AUTO=1
|
||||
e += _check_field(w, "team", 0) # T=0
|
||||
e += _check_field(w, "price", 2500)
|
||||
e += _check_field(w, "slot", 2)
|
||||
return e
|
||||
|
||||
func test_awp_stats() -> String:
|
||||
var w := Registry.get_weapon(AWP)
|
||||
if w == null: return "AWP not found"
|
||||
var e := ""
|
||||
e += _check_field(w, "weapon_name", "AWP")
|
||||
e += _check_field(w, "damage", 110)
|
||||
e += _check_field(w, "fire_mode", 0) # SEMI=0
|
||||
e += _check_field(w, "price", 4750)
|
||||
return e
|
||||
|
||||
func test_knife_stats() -> String:
|
||||
var w := Registry.get_weapon(KNIFE)
|
||||
if w == null: return "Knife not found"
|
||||
var e := ""
|
||||
e += _check_field(w, "weapon_name", "Knife")
|
||||
e += _check_field(w, "damage", 50)
|
||||
e += _check_field(w, "fire_mode", 2) # MELEE=2
|
||||
e += _check_field(w, "price", 0)
|
||||
return e
|
||||
|
||||
func test_default_pistol() -> String:
|
||||
var e := ""
|
||||
var t := Registry.get_default_pistol(0)
|
||||
if t != GLOCK: e += " T side should get Glock, got %d" % t
|
||||
var ct := Registry.get_default_pistol(1)
|
||||
if ct != USP: e += " CT side should get USP, got %d" % ct
|
||||
return e
|
||||
Reference in New Issue
Block a user