mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-01-30 04:30:58 +02:00
test discovery
This commit is contained in:
parent
b4fa00ccdf
commit
7f659cbe58
@ -169,7 +169,9 @@ if _DUMP_ENV then
|
||||
require 'utils.dump_env'
|
||||
end
|
||||
|
||||
require 'utils.test.main'
|
||||
if _DEBUG then
|
||||
require 'utils.test.main'
|
||||
end
|
||||
|
||||
-- Needs to be at bottom so tokens are registered last.
|
||||
if _DEBUG then
|
||||
|
51
tests.lua
51
tests.lua
@ -1,51 +0,0 @@
|
||||
local Declare = require 'utils.test.declare'
|
||||
local EventFactory = require 'utils.test.event_factory'
|
||||
local Gui = require 'utils.gui'
|
||||
local Assert = require 'utils.test.assert'
|
||||
|
||||
require 'features.landfill_remover_test'
|
||||
|
||||
Declare.module(
|
||||
'Gui top buttons',
|
||||
function()
|
||||
local function count_gui_elements(gui)
|
||||
return #gui.top.children + #gui.left.children + #gui.center.children
|
||||
end
|
||||
|
||||
for _, name in pairs(Gui._top_elements) do
|
||||
Declare.test(
|
||||
'can toggle - ' .. Gui.names[name],
|
||||
function(context)
|
||||
local player = context.player
|
||||
local element = player.gui.top[name]
|
||||
local event = EventFactory.on_gui_click(element, player.index)
|
||||
local click_action = function()
|
||||
EventFactory.raise(event)
|
||||
end
|
||||
|
||||
local before_count = count_gui_elements(player.gui)
|
||||
|
||||
-- Open
|
||||
click_action()
|
||||
local after_open_count = count_gui_elements(player.gui)
|
||||
Assert.is_true(
|
||||
after_open_count > before_count,
|
||||
'after open count should be greater than before count.'
|
||||
)
|
||||
|
||||
-- Close
|
||||
context:next(click_action):next(
|
||||
function()
|
||||
local after_close_count = count_gui_elements(player.gui)
|
||||
Assert.equal(
|
||||
before_count,
|
||||
after_close_count,
|
||||
'after close count should be equal to before count.'
|
||||
)
|
||||
end
|
||||
)
|
||||
end
|
||||
)
|
||||
end
|
||||
end
|
||||
)
|
59
utils/gui_tests.lua
Normal file
59
utils/gui_tests.lua
Normal file
@ -0,0 +1,59 @@
|
||||
local Declare = require 'utils.test.declare'
|
||||
local EventFactory = require 'utils.test.event_factory'
|
||||
local Gui = require 'utils.gui'
|
||||
local Assert = require 'utils.test.assert'
|
||||
|
||||
Declare.module(
|
||||
'Gui',
|
||||
function()
|
||||
Declare.module(
|
||||
'can toggle top buttons',
|
||||
function()
|
||||
local function count_gui_elements(gui)
|
||||
return #gui.top.children + #gui.left.children + #gui.center.children
|
||||
end
|
||||
|
||||
for _, name in pairs(Gui._top_elements) do
|
||||
Declare.test(
|
||||
Gui.names[name],
|
||||
function(context)
|
||||
local player = context.player
|
||||
local element = player.gui.top[name]
|
||||
|
||||
if not element.enabled then
|
||||
return
|
||||
end
|
||||
|
||||
local event = EventFactory.on_gui_click(element, player.index)
|
||||
local click_action = function()
|
||||
EventFactory.raise(event)
|
||||
end
|
||||
|
||||
local before_count = count_gui_elements(player.gui)
|
||||
|
||||
-- Open
|
||||
click_action()
|
||||
local after_open_count = count_gui_elements(player.gui)
|
||||
Assert.is_true(
|
||||
after_open_count > before_count,
|
||||
'after open count should be greater than before count.'
|
||||
)
|
||||
|
||||
-- Close
|
||||
context:next(click_action):next(
|
||||
function()
|
||||
local after_close_count = count_gui_elements(player.gui)
|
||||
Assert.equal(
|
||||
before_count,
|
||||
after_close_count,
|
||||
'after close count should be equal to before count.'
|
||||
)
|
||||
end
|
||||
)
|
||||
end
|
||||
)
|
||||
end
|
||||
end
|
||||
)
|
||||
end
|
||||
)
|
13
utils/test/discovery.lua
Normal file
13
utils/test/discovery.lua
Normal file
@ -0,0 +1,13 @@
|
||||
local require = require
|
||||
local pcall = pcall
|
||||
|
||||
function find_all_tests()
|
||||
local loaded = _G.package.loaded
|
||||
|
||||
for name in pairs(loaded) do
|
||||
pcall(require, name .. '_test')
|
||||
pcall(require, name .. '_tests')
|
||||
end
|
||||
end
|
||||
|
||||
find_all_tests()
|
@ -73,6 +73,7 @@ function Public.startup_test_surface(context, options)
|
||||
local player = context.player
|
||||
local old_surface = player.surface
|
||||
local old_position = player.position
|
||||
local old_character = player.character
|
||||
|
||||
local surface =
|
||||
game.create_surface(
|
||||
@ -97,12 +98,19 @@ function Public.startup_test_surface(context, options)
|
||||
|
||||
surface.destroy_decoratives {area = {{-32, -32}, {32, 32}}}
|
||||
|
||||
player.character = nil
|
||||
player.teleport({0, 0}, surface)
|
||||
player.create_character()
|
||||
end
|
||||
)
|
||||
|
||||
return function()
|
||||
player.teleport(old_position, old_surface)
|
||||
|
||||
if old_character and old_character.valid then
|
||||
player.character = old_character
|
||||
end
|
||||
|
||||
game.delete_surface(surface)
|
||||
end
|
||||
end
|
||||
|
@ -1,4 +1,4 @@
|
||||
require 'tests'
|
||||
require 'utils.test.runner'
|
||||
require 'utils.test.viewer'
|
||||
require 'utils.test.command'
|
||||
require 'utils.test.discovery'
|
||||
|
Loading…
x
Reference in New Issue
Block a user