Skip to content

Conversation

@S-S-X
Copy link

@S-S-X S-S-X commented May 10, 2025

This most likely isn't that useful as is but thought I'd share it now that I've already did it.

Also not exactly unit testing but a bit more like integration testing (or could we even call it interaction testing, smoke testing it is anyway).

So I found this old issue and it was interesting as I've been test driving some formspec utilities for mineunit:

Basically this to execute echo Hello World on modular_computers:computer:

-- Maybe it does something if we'd right click it
player:do_place_from_above({x=1, y=1, z=1})

-- We should have received a formspec, parse it and find input field
local form1 = mineunit:get_player_formspec(player)
assert.is_Form(form1)
local input = form1:one("_in$", "field")
assert.not_nil(input)

-- Try some fancy command and send the form
input:value("echo Hello World")
form1:send(player)

-- Get response form and output field
local form2 = mineunit:get_player_formspec(player)
assert.is_Form(form2)
local output = form2:one("_out$", "textarea")
assert.not_nil(output)

-- Check if output matches expected value which is our command and its output
assert.match("echo Hello World\nHello World", output:value())
Raw workflow/Mineunit output (click on it):
Running tests in /github/workspace
++ Executing suite spec/computer_spec.lua
I:	Mineunit configuration loaded from	spec/mineunit.conf
I:	Mod configuration loaded from	mod.conf
I:	Setting modpath	modular_computers	.
I:	Mineunit initialized, current modname is	modular_computers
I:	File not found:	spec/fixtures/fonts
I:	File not found:	spec/fixtures/fonts
I:	File not found:	spec/fixtures/minetest.conf
I:	File not found:	spec/fixtures/minetest.conf
I:	File not found, creating empty Settings object:	spec/fixtures/minetest.conf
I:	Running custom core.get_us_time with step increment:100
I:	Loading source	init.lua
E:	[modular_computers]:	could not find a crafting recipe
I:	[modular_computers]:	return {{{"default", "basic_materials"}, {{"default:steel_ingot", "basic_materials:copper_wire", "default:steel_ingot"}, {"basic_materials:copper_wire", "basic_materials:ic", "basic_materials:copper_wire"}, {"default:steel_ingot", "basic_materials:copper_wire", "default:steel_ingot"}}}, {{"default", "mesecons"}, {{"default:steel_ingot", "default:copper_ingot", "default:steel_ingot"}, {"default:copper_ingot", "mesecons_luacontroller:luacontroller0000", "default:copper_ingot"}, {"default:steel_ingot", "default:copper_ingot", "default:steel_ingot"}}}, {{"default"}, {{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}, {"default:steel_ingot", "default:mese_crystal", "default:steel_ingot"}, {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}}}, {{"mcl_core"}, {{"mcl_core:iron_ingot", "mcl_copper:copper_ingot", "mcl_core:iron_ingot"}, {"mcl_copper:copper_ingot", "mesecons_torch:redstoneblock", "mcl_copper:copper_ingot"}, {"mcl_core:iron_ingot", "mcl_copper:copper_ingot", "mcl_core:iron_ingot"}}}}
I:	[modular_computers]:	return {"default", "basic_materials"}
I:	[modular_computers]:	return {{"default:steel_ingot", "basic_materials:copper_wire", "default:steel_ingot"}, {"basic_materials:copper_wire", "basic_materials:ic", "basic_materials:copper_wire"}, {"default:steel_ingot", "basic_materials:copper_wire", "default:steel_ingot"}}
I:	[modular_computers]:	return {"default", "mesecons"}
I:	[modular_computers]:	return {{"default:steel_ingot", "default:copper_ingot", "default:steel_ingot"}, {"default:copper_ingot", "mesecons_luacontroller:luacontroller0000", "default:copper_ingot"}, {"default:steel_ingot", "default:copper_ingot", "default:steel_ingot"}}
I:	[modular_computers]:	return {"default"}
I:	[modular_computers]:	return {{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}, {"default:steel_ingot", "default:mese_crystal", "default:steel_ingot"}, {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}}
I:	[modular_computers]:	return {"mcl_core"}
I:	[modular_computers]:	return {{"mcl_core:iron_ingot", "mcl_copper:copper_ingot", "mcl_core:iron_ingot"}, {"mcl_copper:copper_ingot", "mesecons_torch:redstoneblock", "mcl_copper:copper_ingot"}, {"mcl_core:iron_ingot", "mcl_copper:copper_ingot", "mcl_core:iron_ingot"}}
⭆ Starting test set computer_spec.lua:11 ⯈ modular_computers:computer
I:	Executing register_on_mods_loaded functions
🢆 Running tests from computer_spec.lua:32 ▷ modular_computers:computer can be placed
I:	node under is buildable to
I:	facedir: 0
I:	Sam places node modular_computers:computer at (0,0,0)
🢆 Running tests from computer_spec.lua:45 ▷ modular_computers:computer can be placed with aux1
I:	node under is buildable to
I:	facedir: 0
I:	Sam places node modular_computers:computer at (1,1,1)
🢆 Running tests from computer_spec.lua:80 ▷ modular_computers:computer accepts echo command
E:	Form:fields() is experimental and UNSTABLE. Its behavior and interface WILL BE CHANGED.
I:	[modular_computers]:	Player:	SamSubmitted command:	echo Hello World
I: core.close_formspec(Sam, nil) failed, this form is not active

++ Executing suite spec/init_spec.lua
5 successes / 0 failures / 0 errors / 0 pending : 0.063624 seconds
Generating report in /github/workspace

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant