Files
pogo/Scripts/tests/test_gameplay_blockers.py
T

97 lines
4.2 KiB
Python

"""Fast regression checks for gameplay control-flow blockers.
These tests intentionally inspect the small C++ functions at issue. The Unreal
editor build remains the integration gate for syntax, types, and engine APIs.
"""
from pathlib import Path
import unittest
ROOT = Path(__file__).resolve().parents[2]
def source(relative_path: str) -> str:
return (ROOT / relative_path).read_text(encoding="utf-8")
def function_body(relative_path: str, signature: str) -> str:
text = source(relative_path)
start = text.index(signature)
open_brace = text.index("{", start)
depth = 0
for index in range(open_brace, len(text)):
if text[index] == "{":
depth += 1
elif text[index] == "}":
depth -= 1
if depth == 0:
return text[open_brace + 1:index]
raise AssertionError(f"Unclosed function body for {signature}")
class GameplayBlockerTests(unittest.TestCase):
def test_set_character_speed_finishes_synchronously(self):
body = function_body(
"Source/pogo/Variant_Combat/AI/CombatStateTreeUtility.cpp",
"FStateTreeSetCharacterSpeedTask::EnterState",
)
self.assertIn("return EStateTreeRunStatus::Succeeded;", body)
self.assertNotIn("return EStateTreeRunStatus::Running;", body)
def test_dash_commits_state_only_after_montage_starts(self):
body = function_body(
"Source/pogo/Variant_Platforming/PlatformingCharacter.cpp",
"void APlatformingCharacter::DoDash()",
)
self.assertIn("if (!AnimInstance || !DashMontage)", body)
self.assertIn("MontageLength <= 0.0f", body)
play = body.index("Montage_Play")
success_guard = body.index("MontageLength <= 0.0f")
state_commit = body.index("bIsDashing = true;")
self.assertLess(play, success_guard)
self.assertLess(success_guard, state_commit)
def test_attacks_commit_state_only_after_montage_starts(self):
cases = [
("Source/pogo/Variant_Combat/CombatCharacter.cpp", "void ACombatCharacter::ComboAttack()", False),
("Source/pogo/Variant_Combat/CombatCharacter.cpp", "void ACombatCharacter::ChargedAttack()", False),
("Source/pogo/Variant_Combat/AI/CombatEnemy.cpp", "void ACombatEnemy::DoAIComboAttack()", True),
("Source/pogo/Variant_Combat/AI/CombatEnemy.cpp", "void ACombatEnemy::DoAIChargedAttack()", True),
]
for path, signature, must_finish_state_tree in cases:
with self.subTest(signature=signature):
body = function_body(path, signature)
self.assertIn("MontageLength <= 0.0f", body)
play = body.index("Montage_Play")
success_guard = body.index("MontageLength <= 0.0f")
state_commit = body.index("bIsAttacking = true;")
self.assertLess(play, success_guard)
self.assertLess(success_guard, state_commit)
if must_finish_state_tree:
self.assertGreaterEqual(body.count("OnAttackCompleted.ExecuteIfBound();"), 2)
def test_side_scrolling_landed_calls_base_first(self):
body = function_body(
"Source/pogo/Variant_SideScrolling/SideScrollingCharacter.cpp",
"void ASideScrollingCharacter::Landed(const FHitResult& Hit)",
)
self.assertIn("Super::Landed(Hit);", body)
self.assertLess(body.index("Super::Landed(Hit);"), body.index("bHasDoubleJumped = false;"))
def test_attack_traces_deduplicate_actors(self):
cases = [
("Source/pogo/Variant_Combat/CombatCharacter.cpp", "ACombatCharacter::DoAttackTrace"),
("Source/pogo/Variant_Combat/AI/CombatEnemy.cpp", "ACombatEnemy::DoAttackTrace"),
]
for path, signature in cases:
with self.subTest(signature=signature):
body = function_body(path, signature)
self.assertIn("TSet<AActor*> DamagedActors;", body)
self.assertIn("DamagedActors.Contains(HitActor)", body)
self.assertIn("DamagedActors.Add(HitActor);", body)
self.assertLess(body.index("DamagedActors.Add(HitActor);"), body.index("Damageable->ApplyDamage"))
if __name__ == "__main__":
unittest.main()