Unit tests for each way of assigning an action to an event handler

This commit is contained in:
Celtic Minstrel 2021-04-11 01:33:55 -04:00 committed by Celtic Minstrel
parent d03116f829
commit 245cd57d24
2 changed files with 104 additions and 0 deletions

View File

@ -0,0 +1,99 @@
# This is kinda a duplicate of a basic unit test system sanity test, but... it seems to fit here as well...
{GENERIC_UNIT_TEST "event_test_action_wml" (
[event]
name=start
{SUCCEED}
[/event]
)}
# Test that dynamically adding an event from Lua works
# There's two different ways of calling game_events.add, so test both
{GENERIC_UNIT_TEST "event_test_lua" (
[event]
name=preload
[lua]
code=<<
wesnoth.game_events.add('new turn', function()
unit_test.succeed()
end)
>>
[/lua]
[/event]
)}
{GENERIC_UNIT_TEST "event_test_lua_advanced" (
[event]
name=preload
[lua]
code=<<
wesnoth.game_events.add{
name = 'new turn',
action = function()
unit_test.succeed()
end
}
>>
[/lua]
[/event]
)}
# Test that first_time_only works correctly in Lua events
{GENERIC_UNIT_TEST "event_test_lua_repeat" (
[event]
name=preload
[lua]
code=<<
wml.variables.only_once = 0
wml.variables.should_repeat = 0
wesnoth.game_events.add{
name = 'new turn',
first_time_only = true,
action = function()
wml.variables.only_once = wml.variables.only_once + 1
end
}
wesnoth.game_events.add{
name = 'new turn',
first_time_only = false,
action = function()
wml.variables.should_repeat = wml.variables.should_repeat + 1
end
}
>>
[/lua]
[/event]
[event]
name=side 1 turn 1
[end_turn][/end_turn]
[/event]
[event]
name=side 2 turn 1
[end_turn][/end_turn]
[/event]
[event]
name=side 1 turn 2
[end_turn][/end_turn]
[/event]
[event]
name=side 2 turn 2
{ASSERT ({VARIABLE_CONDITIONAL only_once equals 1})}
{ASSERT ({VARIABLE_CONDITIONAL should_repeat equals 2})}
{SUCCEED}
[/event]
)}
# Verify that a warning is produced if adding an event that would break saved games
{GENERIC_UNIT_TEST "event_test_lua_break_save" (
[event]
name=start
[lua]
code=<<
wesnoth.game_events.add{
name = 'new turn',
action = function() end
}
unit_test.succeed()
>>
[/lua]
[/event]
)}

View File

@ -139,6 +139,11 @@
0 test_ability_id_active
0 test_ability_id_not_active
0 event_test_filter_attack
0 event_test_action_wml
0 event_test_lua
0 event_test_lua_advanced
0 event_test_lua_repeat
9 event_test_lua_break_save
0 test_lua_name
0 filter_vision
0 test_shroud_init