Skip to content

Commit

Permalink
Merge pull request #593 from nekomatata/physics-tests-cancel-fix
Browse files Browse the repository at this point in the history
Physics test cases, cancel previous running test properly
  • Loading branch information
aaronfranke authored Mar 9, 2021
2 parents 35687c3 + 7f095a6 commit 5c154da
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 5 deletions.
2 changes: 1 addition & 1 deletion 2d/physics_tests/test.gd
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func cancel_timer():


func is_timer_canceled():
return _timer.paused
return _timer and _timer.paused


func wait_for_physics_ticks(tick_count):
Expand Down
2 changes: 2 additions & 0 deletions 2d/physics_tests/tests/functional/test_character.gd
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ func _on_option_changed(option, checked):


func _start_test():
cancel_timer()

if _moving_body:
_body_parent.remove_child(_moving_body)
_moving_body.queue_free()
Expand Down
4 changes: 4 additions & 0 deletions 2d/physics_tests/tests/functional/test_character_pixels.gd
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,14 @@ func _test_all():

# Test floor detection with no snapping.
yield(_start_test_case(OPTION_TEST_CASE_DETECT_FLOOR_NO_SNAP), "completed")
if is_timer_canceled():
return

# Test floor detection with no snapping.
# In this test case, motion alternates different speeds.
yield(_start_test_case(OPTION_TEST_CASE_DETECT_FLOOR_MOTION_CHANGES), "completed")
if is_timer_canceled():
return

Log.print_log("* Done.")

Expand Down
13 changes: 13 additions & 0 deletions 2d/physics_tests/tests/functional/test_character_tilemap.gd
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,25 @@ func _test_all():

# RigidBody tests.
yield(_start_test_case(OPTION_TEST_CASE_JUMP_ONE_WAY_RIGID), "completed")
if is_timer_canceled():
return

yield(_start_test_case(OPTION_TEST_CASE_JUMP_ONE_WAY_CORNER_RIGID), "completed")
if is_timer_canceled():
return

# KinematicBody tests.
yield(_start_test_case(OPTION_TEST_CASE_JUMP_ONE_WAY_KINEMATIC), "completed")
if is_timer_canceled():
return

yield(_start_test_case(OPTION_TEST_CASE_JUMP_ONE_WAY_CORNER_KINEMATIC), "completed")
if is_timer_canceled():
return

yield(_start_test_case(OPTION_TEST_CASE_FALL_ONE_WAY_KINEMATIC), "completed")
if is_timer_canceled():
return

Log.print_log("* Done.")

Expand Down
55 changes: 51 additions & 4 deletions 2d/physics_tests/tests/functional/test_one_way_collision.gd
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ var _test_step = 0
var _test_all_angles = false
var _lock_controls = false

var _test_canceled = false


func _ready():
if not Engine.editor_hint:
Expand Down Expand Up @@ -225,16 +227,24 @@ func _test_all_rigid_body():
_set_platform_size(64.0, false)
_set_rigidbody_angle(0.0, false)
yield(_start_test_case(OPTION_TEST_CASE_ALL_ANGLES_RIGID), "completed")
if _test_canceled:
return

_set_platform_size(64.0, false)
_set_rigidbody_angle(45.0, false)
yield(_start_test_case(OPTION_TEST_CASE_ALL_ANGLES_RIGID), "completed")
if _test_canceled:
return

_set_platform_size(32.0, false)
_set_rigidbody_angle(45.0, false)
yield(_start_test_case(OPTION_TEST_CASE_ALL_ANGLES_RIGID), "completed")
if _test_canceled:
return

yield(_start_test_case(OPTION_TEST_CASE_MOVING_PLATFORM_RIGID), "completed")
if _test_canceled:
return


func _test_all_kinematic_body():
Expand All @@ -243,16 +253,24 @@ func _test_all_kinematic_body():
_set_platform_size(64.0, false)
_set_rigidbody_angle(0.0, false)
yield(_start_test_case(OPTION_TEST_CASE_ALL_ANGLES_KINEMATIC), "completed")
if _test_canceled:
return

_set_platform_size(64.0, false)
_set_rigidbody_angle(45.0, false)
yield(_start_test_case(OPTION_TEST_CASE_ALL_ANGLES_KINEMATIC), "completed")
if _test_canceled:
return

_set_platform_size(32.0, false)
_set_rigidbody_angle(45.0, false)
yield(_start_test_case(OPTION_TEST_CASE_ALL_ANGLES_KINEMATIC), "completed")
if _test_canceled:
return

yield(_start_test_case(OPTION_TEST_CASE_MOVING_PLATFORM_KINEMATIC), "completed")
if _test_canceled:
return


func _test_moving_platform():
Expand All @@ -265,9 +283,13 @@ func _test_moving_platform():

_set_platform_angle(90.0, false)
yield(_wait_for_test(), "completed")
if _test_canceled:
return

_set_platform_angle(-90.0, false)
yield(_wait_for_test(), "completed")
if _test_canceled:
return

Log.print_log("* Platform moving towards body...")
_set_platform_size(64.0, false)
Expand All @@ -276,9 +298,13 @@ func _test_moving_platform():

_set_platform_angle(90.0, false)
yield(_wait_for_test(), "completed")
if _test_canceled:
return

_set_platform_angle(-90.0, false)
yield(_wait_for_test(), "completed")
if _test_canceled:
return

_platform_speed = 0.0
emit_signal("all_tests_done")
Expand All @@ -288,7 +314,12 @@ func _test_all():
Log.print_log("* TESTING ALL...")

yield(_test_all_rigid_body(), "completed")
if _test_canceled:
return

yield(_test_all_kinematic_body(), "completed")
if _test_canceled:
return

Log.print_log("* Done.")

Expand Down Expand Up @@ -342,7 +373,9 @@ func _start_test():


func _reset_test(cancel_test = true):
$Timer.stop()
_test_canceled = true
_on_timeout()
_test_canceled = false

_test_step = 0

Expand Down Expand Up @@ -415,13 +448,27 @@ func _should_collide():


func _on_timeout():
cancel_timer()

if $Timer.is_stopped():
return

$Timer.stop()

if _test_canceled:
emit_signal("test_done")
emit_signal("all_tests_done")
return

if not _contact_detected and not _target_entered:
Log.print_log("Test TIMEOUT")
_set_result()

$Timer.stop()

yield(get_tree().create_timer(0.5), "timeout")
yield(start_timer(0.5), "timeout")
if _test_canceled:
emit_signal("test_done")
emit_signal("all_tests_done")
return

var was_all_angles = _test_all_angles

Expand Down

0 comments on commit 5c154da

Please sign in to comment.