Skip to content

Commit d6802c2

Browse files
committed
Update tests for network code refactoring
Drop coverage stats for sources outside of technic directory (technic_cnc, technic_worldgen) Update technic API functions for tests (were exported just for tests, now part of API) Move CNC tests, use shared fixtures for tests
1 parent 1e87fd7 commit d6802c2

16 files changed

+149
-57
lines changed

technic/spec/api_spec.lua

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require("mineunit")
66

77
-- Load fixtures required by tests
88
fixture("technic")
9+
sourcefile("init")
910

1011
describe("Technic API", function()
1112

technic/spec/building_spec.lua

+10-10
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe("Power network building", function()
3232
assert.equals(1, #net.PR_nodes)
3333
assert.equals(3, count(net.all_nodes))
3434
world.set_node(build_pos, {name="technic:hv_cable", param2=0})
35-
technic.network_node_on_placenode(build_pos, {"HV"}, "technic:hv_cable")
35+
technic.place_network_node(build_pos, {"HV"}, "technic:hv_cable")
3636
end)
3737

3838
it("is added to network", function()
@@ -72,7 +72,7 @@ describe("Power network building", function()
7272
assert.equals(1, #net.PR_nodes)
7373
assert.equals(4, count(net.all_nodes))
7474
world.set_node(build_pos, {name="technic:hv_cable", param2=0})
75-
technic.network_node_on_placenode(build_pos, {"HV"}, "technic:hv_cable")
75+
technic.place_network_node(build_pos, {"HV"}, "technic:hv_cable")
7676
end)
7777

7878
it("is added to network", function()
@@ -94,7 +94,7 @@ describe("Power network building", function()
9494

9595
it("does not duplicate already added machine", function()
9696
world.set_node(build_pos2, {name="technic:hv_cable", param2=0})
97-
technic.network_node_on_placenode(build_pos2, {"HV"}, "technic:hv_cable")
97+
technic.place_network_node(build_pos2, {"HV"}, "technic:hv_cable")
9898
assert.equals(2, #net.PR_nodes)
9999
assert.equals(7, count(net.all_nodes))
100100
end)
@@ -129,7 +129,7 @@ describe("Power network building", function()
129129
assert.equals(2, #net.PR_nodes)
130130
assert.equals(6, count(net.all_nodes))
131131
world.set_node(build_pos, {name="technic:hv_generator",param2=0})
132-
technic.network_node_on_placenode(build_pos, {"HV"}, "technic:hv_generator")
132+
technic.place_network_node(build_pos, {"HV"}, "technic:hv_generator")
133133
end)
134134

135135
it("is added to network without duplicates", function()
@@ -156,7 +156,7 @@ describe("Power network building", function()
156156

157157
it("overloads network", function()
158158
world.set_node(build_pos2, {name="technic:hv_generator",param2=0})
159-
technic.network_node_on_placenode(build_pos2, {"HV"}, "technic:hv_generator")
159+
technic.place_network_node(build_pos2, {"HV"}, "technic:hv_generator")
160160
assert.not_nil(technic.is_overloaded(net.id))
161161
assert.not_nil(technic.is_overloaded(net2.id))
162162
end)
@@ -182,7 +182,7 @@ describe("Power network building", function()
182182
assert.equals(1, count(net.all_nodes))
183183
assert.equals(1, count(net2.all_nodes))
184184
world.set_node(build_pos, {name="technic:hv_cable", param2=0})
185-
technic.network_node_on_placenode(build_pos, {"HV"}, "technic:hv_cable")
185+
technic.place_network_node(build_pos, {"HV"}, "technic:hv_cable")
186186
end)
187187

188188
it("removes network", function()
@@ -211,7 +211,7 @@ describe("Power network building", function()
211211
assert.equals(2, #net.PR_nodes)
212212
assert.equals(6, count(net.all_nodes))
213213
world.set_node(build_pos, {name="air",param2=0})
214-
technic.network_node_on_dignode(build_pos, {"HV"}, "technic:hv_cable")
214+
technic.remove_network_node(build_pos, {"HV"}, "technic:hv_cable")
215215
end)
216216

217217
--[[ NOTE: Whole network is currently removed when cutting cables
@@ -260,7 +260,7 @@ describe("Power network building", function()
260260
assert.equals(2, #net.PR_nodes)
261261
assert.equals(8, count(net.all_nodes))
262262
world.set_node(build_pos, {name="air",param2=0})
263-
technic.network_node_on_dignode(build_pos, {"HV"}, "technic:hv_cable")
263+
technic.remove_network_node(build_pos, {"HV"}, "technic:hv_cable")
264264
end)
265265

266266
it("is removed from network", function()
@@ -279,7 +279,7 @@ describe("Power network building", function()
279279

280280
it("keeps connected machines in network", function()
281281
world.set_node(build_pos2, {name="air",param2=0})
282-
technic.network_node_on_dignode(build_pos2, {"HV"}, "technic:hv_cable")
282+
technic.remove_network_node(build_pos2, {"HV"}, "technic:hv_cable")
283283
assert.same({x=101,y=911,z=100}, net.all_nodes[minetest.hash_node_position({x=101,y=911,z=100})])
284284
assert.equals(1, #net.PR_nodes)
285285
assert.equals(5, count(net.all_nodes))
@@ -307,7 +307,7 @@ describe("Power network building", function()
307307
assert.equals(3, #net.PR_nodes)
308308
assert.equals(7, count(net.all_nodes))
309309
world.set_node(build_pos, {name="air",param2=0})
310-
technic.network_node_on_dignode(build_pos, {"HV"}, "technic:hv_generator")
310+
technic.remove_network_node(build_pos, {"HV"}, "technic:hv_generator")
311311
end)
312312

313313
it("is removed from network", function()

technic/spec/fixtures/default.lua

+18-11
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11

2-
local function register_node(name)
3-
minetest.register_node(":default:"..name, {
2+
mineunit:set_modpath("default", "spec/fixtures")
3+
4+
local function register_node(name, groups, additional_definition)
5+
local definition = {
46
description = name.." description",
57
tiles = { "default_"..name },
6-
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2},
7-
})
8+
groups = groups,
9+
}
10+
for k,v in pairs(additional_definition or {}) do definition[k] = v end
11+
minetest.register_node(":default:"..name, definition)
812
end
913

1014
local function register_item(name)
@@ -13,12 +17,15 @@ local function register_item(name)
1317
})
1418
end
1519

16-
register_node("furnace")
17-
register_node("stone")
18-
register_node("cobble")
19-
register_node("sand")
20-
register_node("sandstone")
21-
register_node("wood")
22-
register_node("steelblock")
20+
-- Register some basic nodes for cutting, grinding, digging, registering recipes etc.
21+
register_node("stone", {cracky = 3, stone = 1}, {is_ground_content = true, drop = "default:cobble"})
22+
register_node("cobble", {cracky=3, stone = 2})
23+
register_node("sand", {snappy=2, choppy=2, oddly_breakable_by_hand=2})
24+
register_node("wood", {tree=1, choppy=2, oddly_breakable_by_hand=2})
25+
register_node("dirt", {crumbly = 3, soil = 1})
26+
register_node("sandstone", {crumbly = 1, cracky = 3})
27+
register_node("steelblock", {cracky = 1, level = 2})
28+
register_node("furnace", {cracky=2})
29+
register_node("furnace_active", {cracky=2, not_in_creative_inventory=1}, {drop = "default:furnace"})
2330

2431
register_item("steel_ingot")

technic_cnc/spec/fixtures/digilines.lua renamed to technic/spec/fixtures/digilines.lua

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11

2+
-- Simple digilines mod fixture that logs sent messages, works with some simple digiline mods
3+
24
mineunit:set_modpath("digilines", "spec/fixtures")
35

4-
_G.digilines = {
6+
digilines = {
57
_msg_log = {},
68
receptor_send = function(pos, rules, channel, msg)
7-
table.insert(_G.digilines._msg_log, {
9+
table.insert(digilines._msg_log, {
810
pos = pos,
911
rules = rules,
1012
channel = channel,
@@ -28,3 +30,8 @@ _G.digilines = {
2830
}
2931
}
3032
}
33+
34+
digilines = setmetatable(digilines, {
35+
__call = function(self,...) return self end,
36+
__index = function(...) return function(...)end end,
37+
})

technic/spec/fixtures/network.lua

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ technic.register_tier("MV", "Busted MV")
3737
technic.register_tier("HV", "Busted HV")
3838

3939
sourcefile("machines/network")
40+
sourcefile("machines/overload")
4041

4142
sourcefile("machines/register/cables")
4243
sourcefile("machines/LV/cables")

technic/spec/fixtures/technic.lua

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ mineunit("voxelmanip")
1313
-- Load fixtures required by tests
1414
fixture("default")
1515
fixture("mesecons")
16+
fixture("digilines")
1617
fixture("pipeworks")
1718
fixture("technic_worldgen")
18-
19-
-- Load mod
20-
sourcefile("init")

technic/spec/fixtures/technic_cnc.lua

-8
This file was deleted.

technic/spec/hv_network_spec.lua

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require("mineunit")
66

77
-- Load complete technic mod
88
fixture("technic")
9+
sourcefile("init")
910

1011
describe("HV machine network", function()
1112

technic/spec/lv_network_spec.lua

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require("mineunit")
66

77
-- Load complete technic mod
88
fixture("technic")
9+
sourcefile("init")
910

1011
describe("LV machine network", function()
1112

technic/spec/mineunit.conf

+2
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ exclude = {
55
-- These are commented out, not part of mod without manually editing code
66
"machines/MV/lighting",
77
"machines/MV/power_radiator",
8+
-- Exclude everything outside of technic directory, some are tested but we do not want stats for these
9+
"^../"
810
}

technic/spec/nodes_spec.lua

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require("mineunit")
66

77
-- Load complete technic mod
88
fixture("technic")
9+
sourcefile("init")
910

1011
describe("Technic node placement", function()
1112

technic/spec/supply_converter_spec.lua

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe("Supply converter", function()
4545
assert.equals(0, #net2.RE_nodes)
4646
assert.equals(1, count(net2.all_nodes))
4747
world.set_node(build_pos, {name="technic:supply_converter",param2=0})
48-
technic.network_node_on_placenode(build_pos, {"HV"}, "technic:supply_converter")
48+
technic.place_network_node(build_pos, {"HV"}, "technic:supply_converter")
4949
end)
5050

5151
it("is added to network without duplicates", function()
@@ -77,7 +77,7 @@ describe("Supply converter", function()
7777
it("overloads network", function()
7878
pending("overload does not work with supply converter")
7979
world.set_node(build_pos2, {name="technic:supply_converter",param2=0})
80-
technic.network_node_on_placenode(build_pos2, {"HV"}, "technic:supply_converter")
80+
technic.place_network_node(build_pos2, {"HV"}, "technic:supply_converter")
8181
assert.not_nil(technic.is_overloaded(net.id))
8282
assert.is_nil(technic.is_overloaded(net2.id))
8383
assert.not_nil(technic.is_overloaded(net3.id))
@@ -104,7 +104,7 @@ describe("Supply converter", function()
104104
assert.equals(1, #net.RE_nodes)
105105
assert.equals(4, count(net.all_nodes))
106106
world.set_node(build_pos, {name="air",param2=0})
107-
technic.network_node_on_dignode(build_pos, {"HV"}, "technic:supply_converter")
107+
technic.remove_network_node(build_pos, {"HV"}, "technic:supply_converter")
108108
end)
109109

110110
it("is removed from network", function()

technic_cnc/spec/digilines_spec.lua

+43-4
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,38 @@ describe("CNC digiline API", function()
5555
assert.equals(1, meta:get_int("size"))
5656
end)
5757

58-
it("disables machine", function()
59-
action(pos, table.copy(node), "ch1", "disable")
58+
it("sets size", function()
59+
action(pos, table.copy(node), "ch1", { size = 2 })
6060
local meta = minetest.get_meta(pos)
61+
assert.equals("cylinder", meta:get("program"))
62+
assert.equals(2, meta:get_int("size"))
63+
end)
64+
65+
it("table disables machine", function()
66+
local meta = minetest.get_meta(pos)
67+
assert.is_true(technic_cnc.is_enabled(meta))
68+
action(pos, table.copy(node), "ch1", { enabled = false })
6169
assert.is_false(technic_cnc.is_enabled(meta))
6270
end)
6371

64-
it("enables machine", function()
65-
action(pos, table.copy(node), "ch1", "enable")
72+
it("table enables machine", function()
73+
local meta = minetest.get_meta(pos)
74+
assert.is_false(technic_cnc.is_enabled(meta))
75+
action(pos, table.copy(node), "ch1", { enabled = true })
76+
assert.is_true(technic_cnc.is_enabled(meta))
77+
end)
78+
79+
it("string disables machine", function()
80+
local meta = minetest.get_meta(pos)
81+
assert.is_true(technic_cnc.is_enabled(meta))
82+
action(pos, table.copy(node), "ch1", "disable")
83+
assert.is_false(technic_cnc.is_enabled(meta))
84+
end)
85+
86+
it("string enables machine", function()
6687
local meta = minetest.get_meta(pos)
88+
assert.is_false(technic_cnc.is_enabled(meta))
89+
action(pos, table.copy(node), "ch1", "enable")
6790
assert.is_true(technic_cnc.is_enabled(meta))
6891
end)
6992

@@ -78,4 +101,20 @@ describe("CNC digiline API", function()
78101
assert.not_nil(response.msg.sphere)
79102
end)
80103

104+
it("returns status", function()
105+
local count = #digilines._msg_log
106+
action(pos, table.copy(node), "ch1", "status")
107+
assert.equals(count + 1, #digilines._msg_log)
108+
local response = digilines._msg_log[#digilines._msg_log]
109+
assert.is_table(response)
110+
assert.is_table(response.msg)
111+
assert.equals("ch1", response.channel)
112+
assert.is_boolean(response.msg.enabled)
113+
assert.is_number(response.msg.time)
114+
assert.is_number(response.msg.size)
115+
assert.is_string(response.msg.program)
116+
assert.is_string(response.msg.user)
117+
assert.is_table(response.msg.material)
118+
end)
119+
81120
end)

technic_cnc/spec/fixtures/default.lua

-10
This file was deleted.

technic_cnc/spec/mineunit.conf

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
time_step = 100
12
exclude = {
2-
"../technic/",
3+
"^../"
4+
}
5+
-- Using helper at technic/spec/fixtures/technic.lua for loading technic mod
6+
fixture_paths = {
7+
"../technic/spec/fixtures",
38
}

0 commit comments

Comments
 (0)