Skip to content

Commit 713409b

Browse files
committed
Tests for chest registration API
1 parent 7bcb0d1 commit 713409b

File tree

5 files changed

+185
-2
lines changed

5 files changed

+185
-2
lines changed

.github/workflows/mineunit.yml

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ jobs:
99

1010
steps:
1111
- uses: actions/checkout@v2
12-
with:
13-
submodules: true
1412

1513
- id: mineunit
1614
uses: mt-mods/mineunit-actions@master
@@ -43,6 +41,13 @@ jobs:
4341
COLOR: "${{ steps.mineunit-cnc.outputs.badge-color }}"
4442
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4543

44+
- id: mineunit-chests
45+
uses: mt-mods/mineunit-actions@master
46+
with:
47+
working-directory: ./technic_chests
48+
badge-name: coverage-chests
49+
badge-label: Test coverage
50+
4651
- uses: KeisukeYamashita/create-comment@v1
4752
if: success() && github.event_name == 'pull_request'
4853
with:
@@ -56,17 +61,30 @@ jobs:
5661
-----------------------------------------------------
5762
${{ steps.mineunit-cnc.outputs.mineunit-report }}
5863
```
64+
65+
### Test coverage report for technic chests ${{ steps.mineunit-chests.outputs.coverage-total }} in ${{ steps.mineunit-chests.outputs.coverage-files }} files:
66+
```
67+
File Hits Missed Coverage
68+
----------------------------------
69+
${{ steps.mineunit-chests.outputs.mineunit-report }}
70+
```
71+
5972
### Test coverage report for technic ${{ steps.mineunit.outputs.coverage-total }} in ${{ steps.mineunit.outputs.coverage-files }} files:
6073
```
6174
File Hits Missed Coverage
6275
--------------------------------------------------------------
6376
${{ steps.mineunit.outputs.mineunit-report }}
6477
```
78+
6579
### Raw test runner output for geeks:
6680
CNC:
6781
```
6882
${{ steps.mineunit-cnc.outputs.mineunit-stdout }}
6983
```
84+
Chests:
85+
```
86+
${{ steps.mineunit-chests.outputs.mineunit-stdout }}
87+
```
7088
Technic:
7189
```
7290
${{ steps.mineunit.outputs.mineunit-stdout }}
@@ -84,6 +102,12 @@ jobs:
84102
```
85103
${{ steps.mineunit-cnc.outputs.mineunit-stdout }}
86104
```
105+
106+
### Regression test log for Technic Chests:
107+
```
108+
${{ steps.mineunit-chests.outputs.mineunit-stdout }}
109+
```
110+
87111
### Regression test log for Technic:
88112
```
89113
${{ steps.mineunit.outputs.mineunit-stdout }}

technic_chests/spec/api_spec.lua

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
require("mineunit")
2+
3+
mineunit("core")
4+
mineunit("player")
5+
mineunit("server")
6+
7+
describe("Chests API", function()
8+
9+
fixture("default")
10+
fixture("digilines")
11+
--fixture("pipeworks")
12+
13+
sourcefile("init")
14+
15+
-- Our player Sam will be helping, he promised to place some nodes
16+
local Sam = Player("Sam")
17+
18+
-- Construct test world with CNC machines
19+
setup(function()
20+
world.clear()
21+
mineunit:set_current_modname("my_mod_name")
22+
mineunit:execute_on_joinplayer(Sam)
23+
end)
24+
25+
teardown(function()
26+
mineunit:restore_current_modname()
27+
end)
28+
29+
it("registered builtin chests", function()
30+
local materials = {"iron", "copper", "silver", "gold", "mithril"}
31+
local types = {"", "_locked", "_protected"}
32+
local failed = {}
33+
for _,m in ipairs(materials) do
34+
for _,t in ipairs(types) do
35+
local name = "technic:"..m..t.."_chest"
36+
if type(minetest.registered_nodes[name]) ~= "table" then
37+
table.insert(failed, name)
38+
end
39+
end
40+
end
41+
if #failed > 0 then
42+
error("Builtin chest(s) not registered: "..table.concat(failed,", "))
43+
end
44+
end)
45+
46+
it("default builtin descriptions", function()
47+
local materials = {"iron", "copper", "silver", "gold", "mithril"}
48+
local types = {"", "_locked", "_protected"}
49+
local failed = {}
50+
for _,m in ipairs(materials) do
51+
for _,t in ipairs(types) do
52+
local name = "technic:"..m..t.."_chest"
53+
local description
54+
if t == "_locked" then
55+
description = ("%s Locked Chest"):format(m:sub(1,1):upper() .. m:sub(2))
56+
elseif t == "_protected" then
57+
description = ("%s Protected Chest"):format(m:sub(1,1):upper() .. m:sub(2))
58+
else
59+
description = ("%s Chest"):format(m:sub(1,1):upper() .. m:sub(2))
60+
end
61+
assert.equals(description, minetest.registered_nodes[name].description)
62+
end
63+
end
64+
end)
65+
66+
it("registers chest", function()
67+
technic.chests.register_chest("my_mod_name:my_special", {
68+
description = "My Special",
69+
texture_prefix = "my_mod_name_my_special",
70+
width = 15,
71+
height = 6,
72+
sort = true,
73+
infotext = true,
74+
autosort = true,
75+
quickmove = true,
76+
digilines = true,
77+
})
78+
-- Verify node registration
79+
assert.is_table(minetest.registered_nodes["my_mod_name:my_special"])
80+
-- Try to place it
81+
world.place_node({x=-99,y=-999,z=-9999}, {name = "my_mod_name:my_special", param2 = 0}, Sam)
82+
end)
83+
84+
it("registers locked chest", function()
85+
technic.chests.register_chest("my_mod_name:my_locked_special", {
86+
description = "My Special",
87+
texture_prefix = "my_mod_name_my_special",
88+
width = 15,
89+
height = 6,
90+
sort = true,
91+
infotext = true,
92+
autosort = true,
93+
quickmove = true,
94+
digilines = true,
95+
locked = true
96+
})
97+
-- Verify node registration
98+
assert.is_table(minetest.registered_nodes["my_mod_name:my_locked_special"])
99+
-- Try to place it
100+
world.place_node({x=-99,y=-999,z=-9998}, {name = "my_mod_name:my_locked_special", param2 = 0}, Sam)
101+
end)
102+
103+
it("registers protected chest", function()
104+
technic.chests.register_chest("my_mod_name:my_protected_special", {
105+
description = "My Special",
106+
texture_prefix = "my_mod_name_my_special",
107+
width = 15,
108+
height = 6,
109+
sort = true,
110+
infotext = true,
111+
autosort = true,
112+
quickmove = true,
113+
digilines = true,
114+
protected = true
115+
})
116+
-- Verify node registration
117+
assert.is_table(minetest.registered_nodes["my_mod_name:my_protected_special"])
118+
-- Try to place it
119+
world.place_node({x=-99,y=-999,z=-9997}, {name = "my_mod_name:my_protected_special", param2 = 0}, Sam)
120+
end)
121+
122+
end)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function default.get_hotbar_bg(...)
2+
return "dummy"
3+
end
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
mineunit:set_modpath("digilines", "fixtures")
3+
4+
_G.digilines = {
5+
_msg_log = {},
6+
receptor_send = function(pos, rules, channel, msg)
7+
table.insert(_G.digilines._msg_log, {
8+
pos = pos,
9+
rules = rules,
10+
channel = channel,
11+
msg = msg,
12+
})
13+
end,
14+
rules = {
15+
default = {
16+
{x=0, y=0, z=-1},
17+
{x=1, y=0, z=0},
18+
{x=-1, y=0, z=0},
19+
{x=0, y=0, z=1},
20+
{x=1, y=1, z=0},
21+
{x=1, y=-1, z=0},
22+
{x=-1, y=1, z=0},
23+
{x=-1, y=-1, z=0},
24+
{x=0, y=1, z=1},
25+
{x=0, y=-1, z=1},
26+
{x=0, y=1, z=-1},
27+
{x=0, y=-1, z=-1}
28+
}
29+
}
30+
}

technic_chests/spec/mineunit.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
validate_textures = true
2+
exclude_textures = {
3+
"^my_mod_name"
4+
}

0 commit comments

Comments
 (0)