Skip to content

Commit 1856ae4

Browse files
committed
Added some unit testing.
1 parent f0eddee commit 1856ae4

File tree

7 files changed

+282
-3
lines changed

7 files changed

+282
-3
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "tests/wowmock"]
2+
path = tests/wowmock
3+
url = https://github.com/Adirelle/wowmock

.pkgmeta

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
package-as: LibPlayerSpells-1.0
2+
3+
ignore:
4+
- tests/*

.travis.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
language: erlang
2+
3+
env:
4+
- LUA="lua5.1" LUAC="luac5.1"
5+
6+
install:
7+
- sudo apt-get install $LUA luarocks
8+
- sudo luarocks install luaunit
9+
- sudo luarocks install mockagne
10+
- sudo luarocks install luabitop
11+
12+
script:
13+
- $LUAC -p $(find . -name "*.lua")
14+
- cd tests
15+
- $LUA core.lua
16+
- $LUA databases.lua
17+
18+
notifications:
19+
email:
20+
on_failure: always
21+
on_success: change

LibPlayerSpells-1.0.lua

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ You should have received a copy of the GNU General Public License
1818
along with LibPlayerSpells-1.0. If not, see <http://www.gnu.org/licenses/>.
1919
--]]
2020

21-
local MAJOR, MINOR = "LibPlayerSpells-1.0", 3
22-
local lib = LibStub:NewLibrary(MAJOR, MINOR)
23-
if not lib then return end
21+
local MAJOR, MINOR, lib = "LibPlayerSpells-1.0", 3
22+
if LibStub then
23+
lib = LibStub:NewLibrary(MAJOR, MINOR)
24+
if not lib then return end
25+
else
26+
lib = {}
27+
end
2428

2529
local _G = _G
2630
local ceil = _G.ceil
@@ -386,6 +390,7 @@ function lib:__RegisterSpells(category, interface, minor, newSpells, newProvider
386390
FlattenSpellData(newSpells, defs, "", 2)
387391

388392
-- Useful constants
393+
local rshift = bit.rshift
389394
local RAIDBUFF = constants.RAIDBUFF
390395
local TYPE = masks.TYPE
391396
local RAIDBUFF_TYPE = masks.RAIDBUFF_TYPE
@@ -433,3 +438,5 @@ function lib:__RegisterSpells(category, interface, minor, newSpells, newProvider
433438
end
434439

435440
end
441+
442+
return lib

tests/core.lua

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
--[[
2+
LibPlayerSpells-1.0 - Additional information about player spells.
3+
(c) 2013-2014 Adirelle ([email protected])
4+
5+
This file is part of LibPlayerSpells-1.0.
6+
7+
LibPlayerSpells-1.0 is free software: you can redistribute it and/or modify
8+
it under the terms of the GNU General Public License as published by
9+
the Free Software Foundation, either version 3 of the License, or
10+
(at your option) any later version.
11+
12+
LibPlayerSpells-1.0 is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
GNU General Public License for more details.
16+
17+
You should have received a copy of the GNU General Public License
18+
along with LibPlayerSpells-1.0. If not, see <http://www.gnu.org/licenses/>.
19+
--]]
20+
21+
package.path = package.path .. ";./wowmock/?.lua"
22+
local LuaUnit = require('luaunit')
23+
local mockagne = require('mockagne')
24+
local wowmock = require('wowmock')
25+
local bit = require('bit')
26+
27+
local when, any, verify = mockagne.when, mockagne.any, mockagne.verify
28+
29+
local lib, G
30+
31+
LibStub = false
32+
33+
local function setup()
34+
G = mockagne:getMock()
35+
lib = wowmock("../LibPlayerSpells-1.0.lua", G)
36+
end
37+
38+
testRegisterSpells = { setup = setup }
39+
40+
-- lib:__RegisterSpells(category, interface, minor, newSpells, newProviders, newModifiers)
41+
42+
function testRegisterSpells:test_unknown_category()
43+
assertEquals(pcall(lib.__RegisterSpells, lib, "foobar", 0, 0, {}), false)
44+
end
45+
46+
function testRegisterSpells:test_new_data()
47+
lib:__RegisterSpells("HUNTER", 50000, 1, {})
48+
local _, patch, rev = lib:GetVersionInfo("HUNTER")
49+
assertEquals(patch, 50000)
50+
assertEquals(rev, 1)
51+
end
52+
53+
function testRegisterSpells:test_newer_revision()
54+
lib:__RegisterSpells("HUNTER", 50000, 1, {})
55+
lib:__RegisterSpells("HUNTER", 50000, 2, {})
56+
local _, patch, rev = lib:GetVersionInfo("HUNTER")
57+
assertEquals(patch, 50000)
58+
assertEquals(rev, 2)
59+
end
60+
61+
function testRegisterSpells:test_newer_patch()
62+
lib:__RegisterSpells("HUNTER", 50000, 1, {})
63+
lib:__RegisterSpells("HUNTER", 60000, 1, {})
64+
local _, patch, rev = lib:GetVersionInfo("HUNTER")
65+
assertEquals(patch, 60000)
66+
assertEquals(rev, 1)
67+
end
68+
69+
function testRegisterSpells:test_older_patch()
70+
lib:__RegisterSpells("HUNTER", 60000, 1, {})
71+
lib:__RegisterSpells("HUNTER", 50000, 2, {})
72+
local _, patch, rev = lib:GetVersionInfo("HUNTER")
73+
assertEquals(patch, 60000)
74+
assertEquals(rev, 1)
75+
end
76+
77+
function testRegisterSpells:test_older_revision()
78+
lib:__RegisterSpells("HUNTER", 50000, 2, {})
79+
lib:__RegisterSpells("HUNTER", 50000, 1, {})
80+
local _, patch, rev = lib:GetVersionInfo("HUNTER")
81+
assertEquals(patch, 50000)
82+
assertEquals(rev, 2)
83+
end
84+
85+
function testRegisterSpells:test_provider_inconsistency()
86+
local success, msg = pcall(lib.__RegisterSpells, lib, "HUNTER", 1, 1, {}, {[5] = 6})
87+
assertEquals(success, false)
88+
end
89+
90+
function testRegisterSpells:test_modifier_inconsistency()
91+
local success, msg = pcall(lib.__RegisterSpells, lib, "HUNTER", 1, 1, {}, {}, {[5] = 6})
92+
assertEquals(success, false)
93+
end
94+
95+
function testRegisterSpells:test_consistent_data()
96+
when(G.GetSpellLink(any())).thenAnswer("link")
97+
lib:__RegisterSpells("HUNTER", 1, 1, {[4] = "AURA", [5] = "AURA"}, {[4] = 8}, {[5] = 6})
98+
end
99+
100+
function testRegisterSpells:test_unknown_flag()
101+
local success, msg = pcall(lib.__RegisterSpells, lib, "HUNTER", 1, 1, {[4] = "FOO"})
102+
assertEquals(success, false)
103+
end
104+
105+
function testRegisterSpells:test_unknown_spell()
106+
when(G.GetSpellLink(4)).thenAnswer(false)
107+
local success, msg = pcall(lib.__RegisterSpells, lib, "HUNTER", 1, 1, { [4] = "AURA" })
108+
assertEquals(success, false)
109+
verify(G.GetSpellLink(4))
110+
end
111+
112+
function testRegisterSpells:test_known_spell()
113+
when(G.GetSpellLink(4)).thenAnswer("link")
114+
lib:__RegisterSpells("HUNTER", 1, 1, { [4] = "AURA" })
115+
verify(G.GetSpellLink(4))
116+
end
117+
118+
function testRegisterSpells:test_key_id_value_flag()
119+
when(G.GetSpellLink(4)).thenAnswer("link")
120+
lib:__RegisterSpells("HUNTER", 1, 1, { [4] = "AURA" })
121+
assertEquals(lib.__categories.HUNTER[4], bit.bor(lib.constants.AURA, lib.constants.HUNTER))
122+
end
123+
124+
function testRegisterSpells:test_spell_list()
125+
when(G.GetSpellLink(any())).thenAnswer("link")
126+
lib:__RegisterSpells("HUNTER", 1, 1, { AURA = { 4, 5 } })
127+
local db, c, bor = lib.__categories.HUNTER, lib.constants, bit.bor
128+
assertEquals(db[4], bor(c.AURA, c.HUNTER))
129+
assertEquals(db[5], bor(c.AURA, c.HUNTER))
130+
end
131+
132+
function testRegisterSpells:test_nested()
133+
when(G.GetSpellLink(any())).thenAnswer("link")
134+
lib:__RegisterSpells("HUNTER", 1, 1, {
135+
AURA = {
136+
4,
137+
[5] = "HARMFUL",
138+
HELPFUL = {
139+
6,
140+
[7] = "COOLDOWN"
141+
}
142+
}
143+
})
144+
local db, c, bor = lib.__categories.HUNTER, lib.constants, bit.bor
145+
assertEquals(db[4], bor(c.AURA, c.HUNTER))
146+
assertEquals(db[5], bor(c.AURA, c.HUNTER, c.HARMFUL))
147+
assertEquals(db[6], bor(c.AURA, c.HUNTER, c.HELPFUL))
148+
assertEquals(db[7], bor(c.AURA, c.HUNTER, c.HELPFUL, c.COOLDOWN))
149+
end
150+
151+
function testRegisterSpells:test_multipart_string()
152+
when(G.GetSpellLink(4)).thenAnswer("link")
153+
lib:__RegisterSpells("HUNTER", 1, 1, { [4] = "HELPFUL AURA" })
154+
local db, c, bor = lib.__categories.HUNTER, lib.constants, bit.bor
155+
assertEquals(db[4], bor(c.AURA, c.HELPFUL, c.HUNTER))
156+
end
157+
158+
function testRegisterSpells:test_invalid_data()
159+
local success, msg = pcall(lib.__RegisterSpells, lib, "HUNTER", 1, 1, { [4] = function() end })
160+
assertEquals(success, false)
161+
end
162+
163+
function testRegisterSpells:test_database_conflict()
164+
when(G.GetSpellLink(4)).thenAnswer("link")
165+
lib:__RegisterSpells("HUNTER", 1, 1, { [4] = "AURA" })
166+
local success, msg = pcall(lib.__RegisterSpells, lib, "SHAMAN", 1, 1, { [4] = "HELPFUL" })
167+
assertEquals(success, false)
168+
end
169+
170+
--[[ Ignored until I figure out how to workaround the luabitop issue with 0x8000000
171+
function testRegisterSpells:test_raidbuff()
172+
when(G.GetSpellLink(any())).thenAnswer("link")
173+
lib:__RegisterSpells("HUNTER", 1, 1, { [4] = "RAIDBUFF STAMINA" })
174+
local c, bor = lib.constants, bit.bor
175+
assertEquals(lib.__specials.RAIDBUFF[4], c.STAMINA)
176+
assertEquals(lib.__categories.HUNTER[4], bor(c.HELPFUL, c.UNIQUE_AURA, c.AURA, c.HUNTER))
177+
end
178+
]]
179+
180+
os.exit(LuaUnit:Run())

tests/databases.lua

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
--[[
2+
LibPlayerSpells-1.0 - Additional information about player spells.
3+
(c) 2013-2014 Adirelle ([email protected])
4+
5+
This file is part of LibPlayerSpells-1.0.
6+
7+
LibPlayerSpells-1.0 is free software: you can redistribute it and/or modify
8+
it under the terms of the GNU General Public License as published by
9+
the Free Software Foundation, either version 3 of the License, or
10+
(at your option) any later version.
11+
12+
LibPlayerSpells-1.0 is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
GNU General Public License for more details.
16+
17+
You should have received a copy of the GNU General Public License
18+
along with LibPlayerSpells-1.0. If not, see <http://www.gnu.org/licenses/>.
19+
--]]
20+
21+
package.path = package.path .. ";./wowmock/?.lua"
22+
local LuaUnit = require('luaunit')
23+
local mockagne = require('mockagne')
24+
local wowmock = require('wowmock')
25+
26+
local when, any = mockagne.when, mockagne.any
27+
28+
local lib, G
29+
30+
testDatabases = {}
31+
32+
function testDatabases:setup()
33+
G = mockagne:getMock()
34+
G.LibStub = false
35+
lib = wowmock("../LibPlayerSpells-1.0.lua", G)
36+
G.LibStub = nil
37+
when(G.LibStub("LibPlayerSpells-1.0")).thenAnswer(lib)
38+
when(G.GetSpellLink(any())).thenAnswer(true)
39+
end
40+
41+
local sources = {
42+
"Deathknight",
43+
"Druid",
44+
"Hunter",
45+
"Mage",
46+
"Monk",
47+
"Paladin",
48+
"Priest",
49+
"Racials",
50+
"Rogue",
51+
"Shaman",
52+
"Tradeskills",
53+
"Warlock",
54+
"Warrior",
55+
}
56+
57+
for i, source in ipairs(sources) do
58+
local source = source
59+
testDatabases["test_"..source] = function()
60+
wowmock("../data/"..source..".lua", G)
61+
end
62+
end
63+
64+
os.exit(LuaUnit:Run())

tests/wowmock

Submodule wowmock added at 9534285

0 commit comments

Comments
 (0)