From c8236833a484a7d308e9819e3f89fe525d462893 Mon Sep 17 00:00:00 2001 From: Rainrider Date: Sat, 19 Oct 2024 22:12:55 +0200 Subject: [PATCH] test: drop luaunit in favor of busted --- .github/workflows/ci.yml | 14 +-- tests/core.lua | 243 ------------------------------------ tests/core_spec.lua | 262 +++++++++++++++++++++++++++++++++++++++ tests/databases.lua | 71 ----------- tests/databases_spec.lua | 37 ++++++ 5 files changed, 305 insertions(+), 322 deletions(-) delete mode 100644 tests/core.lua create mode 100644 tests/core_spec.lua delete mode 100644 tests/databases.lua create mode 100644 tests/databases_spec.lua diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ac8a29a..8560b37 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,31 +24,29 @@ jobs: needs: lint steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: submodules: true - name: Install Lua - uses: leafo/gh-actions-lua@v9 + uses: leafo/gh-actions-lua@v10 with: - luaVersion: '5.1' + luaVersion: '5.1.5' - name: Install LuaRocks uses: leafo/gh-actions-luarocks@v4 - name: Install Dependencies run: | - luarocks install luaunit - luarocks install mockagne luarocks install luabitop + luarocks install busted - name: Test run: | cd ./tests - lua core.lua - lua databases.lua + busted -o TAP . release: runs-on: ubuntu-latest needs: test steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 - name: Prepare Packager Arguments diff --git a/tests/core.lua b/tests/core.lua deleted file mode 100644 index e53d071..0000000 --- a/tests/core.lua +++ /dev/null @@ -1,243 +0,0 @@ ---[[ -LibPlayerSpells-1.0 - Additional information about player spells. -(c) 2013-2021 Adirelle (adirelle@gmail.com) - -This file is part of LibPlayerSpells-1.0. - -LibPlayerSpells-1.0 is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -LibPlayerSpells-1.0 is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with LibPlayerSpells-1.0. If not, see . ---]] - -package.path = package.path .. ";./wowmock/?.lua" -local lu = require('luaunit') -local mockagne = require('mockagne') -local wowmock = require('wowmock') -local bit = require('bit') - -local when, any, verify = mockagne.when, mockagne.any, mockagne.verify - -local bor, tohex = bit.bor, bit.tohex - -local lib, G - -LibStub = false -AdiDebug = false - -local function setup() - G = mockagne:getMock() - lib = wowmock("../LibPlayerSpells-1.0.lua", G) -end - -testRegisterSpells = { setup = setup } - -function testRegisterSpells:test_unknown_category() - lu.assertEquals(pcall(lib.__RegisterSpells, lib, "foobar", 0, 0, {}), false) -end - -function testRegisterSpells:test_new_data() - lib:__RegisterSpells("HUNTER", 50000, 1, {}) - local _, patch, rev = lib:GetVersionInfo("HUNTER") - lu.assertEquals(patch, 50000) - lu.assertEquals(rev, 1) -end - -function testRegisterSpells:test_newer_revision() - lib:__RegisterSpells("HUNTER", 50000, 1, {}) - lib:__RegisterSpells("HUNTER", 50000, 2, {}) - local _, patch, rev = lib:GetVersionInfo("HUNTER") - lu.assertEquals(patch, 50000) - lu.assertEquals(rev, 2) -end - -function testRegisterSpells:test_newer_patch() - lib:__RegisterSpells("HUNTER", 50000, 1, {}) - lib:__RegisterSpells("HUNTER", 60000, 1, {}) - local _, patch, rev = lib:GetVersionInfo("HUNTER") - lu.assertEquals(patch, 60000) - lu.assertEquals(rev, 1) -end - -function testRegisterSpells:test_older_patch() - lib:__RegisterSpells("HUNTER", 60000, 1, {}) - lib:__RegisterSpells("HUNTER", 50000, 2, {}) - local _, patch, rev = lib:GetVersionInfo("HUNTER") - lu.assertEquals(patch, 60000) - lu.assertEquals(rev, 1) -end - -function testRegisterSpells:test_older_revision() - lib:__RegisterSpells("HUNTER", 50000, 2, {}) - lib:__RegisterSpells("HUNTER", 50000, 1, {}) - local _, patch, rev = lib:GetVersionInfo("HUNTER") - lu.assertEquals(patch, 50000) - lu.assertEquals(rev, 2) -end - -function testRegisterSpells:test_provider_inconsistency() - local success, msg = pcall(lib.__RegisterSpells, lib, "HUNTER", 1, 1, {}, {[5] = 6}) - lu.assertEquals(success, true) - lu.assertEquals(msg, 1) -end - -function testRegisterSpells:test_modifier_inconsistency() - local success, msg = pcall(lib.__RegisterSpells, lib, "HUNTER", 1, 1, {}, {}, {[5] = 6}) - lu.assertEquals(success, true) - lu.assertEquals(msg, 1) -end - -function testRegisterSpells:test_unknown_flag() - local success, msg = pcall(lib.__RegisterSpells, lib, "HUNTER", 1, 1, {[4] = "FOO"}) - lu.assertEquals(success, true) - lu.assertEquals(msg, 1) -end - -function testRegisterSpells:test_unknown_spell() - when(G.C_Spell.GetSpellInfo(4)).thenAnswer(false) - local success, msg = pcall(lib.__RegisterSpells, lib, "HUNTER", 1, 1, { [4] = "AURA" }) - lu.assertEquals(success, true) - lu.assertEquals(msg, 1) - verify(G.C_Spell.GetSpellInfo(4)) -end - -function testRegisterSpells:test_consistent_data() - when(G.C_Spell.GetSpellInfo(any())).thenAnswer("link") - lib:__RegisterSpells("HUNTER", 1, 1, {[4] = "AURA", [5] = "AURA"}, {[4] = 8}, {[5] = 6}) -end - -function testRegisterSpells:test_known_spell() - when(G.C_Spell.GetSpellInfo(4)).thenAnswer("link") - lib:__RegisterSpells("HUNTER", 1, 1, { [4] = "AURA" }) - verify(G.C_Spell.GetSpellInfo(4)) -end - -function testRegisterSpells:test_key_id_value_flag() - when(G.C_Spell.GetSpellInfo(4)).thenAnswer("link") - lib:__RegisterSpells("HUNTER", 1, 1, { [4] = "AURA" }) - lu.assertEquals(lib.__categories.HUNTER[4], bor(lib.constants.AURA, lib.constants.HUNTER)) -end - -function testRegisterSpells:test_spell_list() - when(G.C_Spell.GetSpellInfo(any())).thenAnswer("link") - lib:__RegisterSpells("HUNTER", 1, 1, { AURA = { 4, 5 } }) - local db, c = lib.__categories.HUNTER, lib.constants - lu.assertEquals(db[4], bor(c.AURA, c.HUNTER)) - lu.assertEquals(db[5], bor(c.AURA, c.HUNTER)) -end - -function testRegisterSpells:test_nested() - when(G.C_Spell.GetSpellInfo(any())).thenAnswer("link") - lib:__RegisterSpells("HUNTER", 1, 1, { - AURA = { - 4, - [5] = "HARMFUL", - HELPFUL = { - 6, - [7] = "COOLDOWN" - } - } - }) - local db, c = lib.__categories.HUNTER, lib.constants - lu.assertEquals(db[4], bor(c.AURA, c.HUNTER)) - lu.assertEquals(db[5], bor(c.AURA, c.HUNTER, c.HARMFUL)) - lu.assertEquals(db[6], bor(c.AURA, c.HUNTER, c.HELPFUL)) - lu.assertEquals(db[7], bor(c.AURA, c.HUNTER, c.HELPFUL, c.COOLDOWN)) -end - -function testRegisterSpells:test_multipart_string() - when(G.C_Spell.GetSpellInfo(4)).thenAnswer("link") - lib:__RegisterSpells("HUNTER", 1, 1, { [4] = "HELPFUL AURA" }) - local db, c = lib.__categories.HUNTER, lib.constants - lu.assertEquals(db[4], bor(c.AURA, c.HELPFUL, c.HUNTER)) -end - -function testRegisterSpells:test_invalid_data() - local success = pcall(lib.__RegisterSpells, lib, "HUNTER", 1, 1, { [4] = function() end }) - lu.assertEquals(success, false) -end - -function testRegisterSpells:test_database_conflict() - when(G.C_Spell.GetSpellInfo(4)).thenAnswer("link") - when(G.GetBuildInfo()).thenAnswer({4,4,4,4}) - lib:__RegisterSpells("HUNTER", 1, 1, { [4] = "AURA" }) - local msg - xpcall( - function() lib:__RegisterSpells("SHAMAN", 1, 1, { [4] = "HELPFUL" }) end, - function(m) msg = m end - ) - lu.assertEquals(msg == nil, true) -end - -function testRegisterSpells:test_crowd_ctrl() - when(G.C_Spell.GetSpellInfo(any())).thenAnswer("link") - lib:__RegisterSpells("HUNTER", 1, 1, { [4] = "AURA HARMFUL CROWD_CTRL STUN" }) - local c = lib.constants - lu.assertEquals(lib.__specials.CROWD_CTRL[4], c.STUN) - lu.assertEquals(lib.__categories.HUNTER[4], bor(c.HARMFUL, c.AURA, c.HUNTER, c.CROWD_CTRL)) -end - -function testRegisterSpells:test_dispel() - when(G.C_Spell.GetSpellInfo(any())).thenAnswer("link") - lib:__RegisterSpells("HUNTER", 1, 1, { [4] = "DISPEL HARMFUL MAGIC" }) - local c = lib.constants - lu.assertEquals(lib.__specials.DISPEL[4], c.MAGIC) - lu.assertEquals(lib.__categories.HUNTER[4], bor(c.DISPEL, c.HARMFUL, c.HUNTER)) -end - -testFilterParsing = { setup = setup } - -function testFilterParsing:test_empty() - lu.assertEquals(lib.__filters[""], 0) -end - -function testFilterParsing:test_single_values() - for name, value in pairs(lib.constants) do - lu.assertEquals(tohex(lib.__filters[name]), tohex(value)) - end -end - -function testFilterParsing:test_combination() - local c = lib.constants - lu.assertEquals(lib.__filters["HUNTER AURA"], bor(c.HUNTER, c.AURA)) - lu.assertEquals(lib.__filters["AURA HUNTER"], bor(c.HUNTER, c.AURA)) -end - -testFlagTester = { setup = setup } - -for i, data in ipairs{ - { "HUNTER", "", "", "HUNTER", true }, - { "HUNTER", "", "", "SHAMAN", false }, - { "HUNTER", "", "", "HUNTER AURA", true }, - { "HUNTER SHAMAN", "", "", "HUNTER", true }, - { "HUNTER SHAMAN", "", "", "SHAMAN", true }, - { "HUNTER SHAMAN", "", "", "DRUID", false }, - { "HUNTER", "AURA", "", "HUNTER AURA", true }, - { "HUNTER", "AURA", "", "HUNTER", false }, - { "HUNTER", "AURA", "", "SHAMAN", false }, - { "HUNTER SHAMAN", "AURA", "", "SHAMAN AURA COOLDOWN", true }, - { "HUNTER", "AURA", "COOLDOWN", "HUNTER AURA", true }, - { "HUNTER", "AURA", "COOLDOWN", "AURA", false }, - { "HUNTER", "AURA", "COOLDOWN", "AURA COOLDOWN", false }, - { "HUNTER", "AURA", "COOLDOWN", "HUNTER COOLDOWN", false }, - { "HUNTER", "", "COOLDOWN", "HUNTER", true }, - { "HUNTER", "", "COOLDOWN", "HUNTER AURA", true }, - { "HUNTER", "", "COOLDOWN", "AURA", false }, - { "HUNTER", "", "COOLDOWN", "AURA COOLDOWN", false }, - { "HUNTER", "", "COOLDOWN", "HUNTER COOLDOWN", false }, -} do - local anyOf, include, exclude, value, expected = unpack(data) - testFlagTester["test_"..i] = function() - lu.assertEquals(lib:GetFlagTester(anyOf, include, exclude)(lib.__filters[value]), expected) - end -end - -os.exit(lu.LuaUnit.run()) diff --git a/tests/core_spec.lua b/tests/core_spec.lua new file mode 100644 index 0000000..b987e72 --- /dev/null +++ b/tests/core_spec.lua @@ -0,0 +1,262 @@ +package.path = package.path .. ';./wowmock/?.lua' + +local wowmock = require('wowmock') + +describe('Core', function () + local G, lib + + before_each(function () + G = mock({ C_Spell = { + GetSpellInfo = function (id) return { spellID = id } end} + }) + lib = wowmock('../LibPlayerSpells-1.0.lua', G) + end) + + it('throws on unsupported spell source', function () + assert.errors(function () lib:__RegisterSpells('foobar', 0, 0, {}) end) + end) + + it('adds new data', function () + local _, patch, rev = lib:GetVersionInfo('HUNTER') + assert.equals(0, patch) + assert.equals(0, rev) + + lib:__RegisterSpells('HUNTER', 50000, 1, {}) + + _, patch, rev = lib:GetVersionInfo('HUNTER') + assert.equals(50000, patch) + assert.equals(1, rev) + end) + + it('adds newer revision', function () + lib:__RegisterSpells('HUNTER', 50000, 1, {}) + lib:__RegisterSpells('HUNTER', 50000, 2, {}) + + local _, patch, rev = lib:GetVersionInfo('HUNTER') + assert.equals(50000, patch) + assert.equals(2, rev) + end) + + it('skips older revision', function () + lib:__RegisterSpells('HUNTER', 50000, 2, {}) + lib:__RegisterSpells('HUNTER', 50000, 1, {}) + + local _, patch, rev = lib:GetVersionInfo('HUNTER') + assert.equals(50000, patch) + assert.equals(2, rev) + end) + + it('adds newer patch', function () + lib:__RegisterSpells('HUNTER', 50000, 1, {}) + lib:__RegisterSpells('HUNTER', 60000, 1, {}) + + local _, patch, rev = lib:GetVersionInfo('HUNTER') + assert.equals(60000, patch) + assert.equals(1, rev) + end) + + it('skips older patch', function () + lib:__RegisterSpells('HUNTER', 60000, 1, {}) + lib:__RegisterSpells('HUNTER', 50000, 2, {}) + + local _, patch, rev = lib:GetVersionInfo('HUNTER') + assert.equals(60000, patch) + assert.equals(1, rev) + end) + + it('ignores provider inconsistency', function () + lib:__RegisterSpells('HUNTER', 1, 1, {}, {[5] = 6}) + + assert.is_nil(lib:GetSpellInfo(5)) + end) + + it('ignores modifier inconsistency', function () + lib:__RegisterSpells('HUNTER', 1, 1, {}, {}, {[5] = 6}) + + assert.is_nil(lib:GetSpellInfo(5)) + end) + + it('throws on invalid filter', function () + assert.errors(function () + lib:__RegisterSpells('HUNTER', 1, 1, {[4] = 'FOO'}) + end) + end) + + it('throws on invalid spell definition', function () + assert.errors(function () + lib:__RegisterSpells('HUNTER', 1, 1, {[4] = function () end}) + end) + end) + + it('ignores unknown spells', function () + G.C_Spell.GetSpellInfo = function (id) return nil end + spy.on(G.C_Spell, 'GetSpellInfo') + lib = wowmock('../LibPlayerSpells-1.0.lua', G) + + lib:__RegisterSpells('HUNTER', 1, 1, {[4] = 'AURA'}) + + assert.spy(G.C_Spell.GetSpellInfo).was_called_with(4) + assert.is_nil(lib:GetSpellInfo(4)) + end) + + it('imports known spell', function () + lib:__RegisterSpells('HUNTER', 1, 1, {[4] = 'AURA'}) + + assert.spy(G.C_Spell.GetSpellInfo).was_called_with(4) + assert.is_not_nil(lib:GetSpellInfo(4)) + end) + + it('spell is implictly its own provider', function () + lib:__RegisterSpells('HUNTER', 1, 1, {[4] = 'AURA'}) + + local _, providers = lib:GetSpellInfo(4) + + assert.equals(4, providers) + end) + + it('explicit spell provider overrides the implicit one', function () + lib:__RegisterSpells('HUNTER', 1, 1, {[4] = 'AURA'}, {[4] = 5}) + + local _, providers = lib:GetSpellInfo(4) + + assert.equals(5, providers) + end) + + it('spell can have multiple spell providers', function () + lib:__RegisterSpells('HUNTER', 1, 1, {[4] = 'AURA'}, {[4] = {5, 6}}) + + local _, providers = lib:GetSpellInfo(4) + + assert.same({5, 6}, providers) + end) + + it('spell is implicitly its own modifier', function () + lib:__RegisterSpells('HUNTER', 1, 1, {[4] = 'AURA'}) + + local _, _, modified = lib:GetSpellInfo(4) + + assert.equals(4, modified) + end) + + it('explicit modified spell overrides the implicit one', function () + lib:__RegisterSpells('HUNTER', 1, 1, {[4] = 'AURA'}, {}, {[4] = 5}) + + local _, _, modified = lib:GetSpellInfo(4) + + assert.equals(5, modified) + end) + + it('spell can modify multiple spells', function () + lib:__RegisterSpells('HUNTER', 1, 1, {[4] = 'AURA'}, {}, {[4] = {5, 6}}) + + local _, _, modified = lib:GetSpellInfo(4) + + assert.same({5, 6}, modified) + end) + + it('spell flag mask contains source and category', function () + lib:__RegisterSpells('HUNTER', 1, 1, {[4] = 'AURA'}) + local hunterAura = bit.bor(lib.constants.AURA, lib.constants.HUNTER) + + assert.equals(hunterAura, lib:GetSpellInfo(4)) + end) + + it('imports multiple spells by category', function () + lib:__RegisterSpells('HUNTER', 1, 1, {AURA = {4, 5}}) + local hunterAura = bit.bor(lib.constants.AURA, lib.constants.HUNTER) + + assert.equals(hunterAura, lib:GetSpellInfo(4)) + assert.equals(hunterAura, lib:GetSpellInfo(5)) + end) + + it('imports spells with nested categories', function () + lib:__RegisterSpells('HUNTER', 1, 1, { + AURA = { + 4, + [5] = 'HARMFUL', + HELPFUL = { + 6, + [7] = 'COOLDOWN', + }, + }, + }) + local c = lib.constants + + -- TODO: maybe lib:GetFlagTester? + assert.equals(bit.bor(c.HUNTER, c.AURA), lib:GetSpellInfo(4)) + assert.equals(bit.bor(c.HUNTER, c.AURA, c.HARMFUL), lib:GetSpellInfo(5)) + assert.equals(bit.bor(c.HUNTER, c.AURA, c.HELPFUL), lib:GetSpellInfo(6)) + assert.equals(bit.bor(c.HUNTER, c.AURA, c.HELPFUL, c.COOLDOWN), lib:GetSpellInfo(7)) + end) + + it('imports spells with multipart categories', function () + lib:__RegisterSpells('HUNTER', 1, 1, {[4] = 'HELPFUL AURA'}) + local c = lib.constants + + assert.equals(bit.bor(c.HUNTER, c.AURA, c.HELPFUL), lib:GetSpellInfo(4)) + end) + + it('imports same spell on different classes', function () + lib:__RegisterSpells('HUNTER', 1, 1, {[4] = 'HELPFUL AURA'}) + lib:__RegisterSpells('SHAMAN', 1, 1, {[4] = 'AURA'}) + local db, c = lib.__categories, lib.constants + + local flags, _, _, _, sources = lib:GetSpellInfo(4) + + assert.equals(bit.bor(c.HUNTER, c.AURA, c.HELPFUL), db.HUNTER[4]) + assert.equals(bit.bor(c.SHAMAN, c.AURA), db.SHAMAN[4]) + assert.equals(bit.bor(c.HUNTER, c.SHAMAN, c.AURA, c.HELPFUL), flags) + assert.equals('HUNTER SHAMAN', sources) + end) + + it('imports crowd control special category', function () + lib:__RegisterSpells('HUNTER', 1, 1, {[4] = 'AURA HARMFUL CROWD_CTRL STUN'}) + local c = lib.constants + + local flags, _, _, cc = lib:GetSpellInfo(4) + + assert.equals(bit.bor(c.HUNTER, c.AURA, c.HARMFUL, c.CROWD_CTRL), flags) + assert.equals(c.STUN, cc) + end) + + it('imports dispel special category', function () + lib:__RegisterSpells('HUNTER', 1, 1, {[4] = 'DISPEL HARMFUL MAGIC'}) + local c = lib.constants + + local flags, _, _, _, _, dispel = lib:GetSpellInfo(4) + + assert.equals(bit.bor(c.HUNTER, c.HARMFUL, c.DISPEL), flags) + assert.equals(c.MAGIC, dispel) + end) + + for i, data in ipairs{ + { 'HUNTER', '', '', 'HUNTER', true }, + { 'HUNTER', '', '', 'SHAMAN', false }, + { 'HUNTER', '', '', 'HUNTER AURA', true }, + { 'HUNTER SHAMAN', '', '', 'HUNTER', true }, + { 'HUNTER SHAMAN', '', '', 'SHAMAN', true }, + { 'HUNTER SHAMAN', '', '', 'DRUID', false }, + { 'HUNTER', 'AURA', '', 'HUNTER AURA', true }, + { 'HUNTER', 'AURA', '', 'HUNTER', false }, + { 'HUNTER', 'AURA', '', 'SHAMAN', false }, + { 'HUNTER SHAMAN', 'AURA', '', 'SHAMAN AURA COOLDOWN', true }, + { 'HUNTER', 'AURA', 'COOLDOWN', 'HUNTER AURA', true }, + { 'HUNTER', 'AURA', 'COOLDOWN', 'AURA', false }, + { 'HUNTER', 'AURA', 'COOLDOWN', 'AURA COOLDOWN', false }, + { 'HUNTER', 'AURA', 'COOLDOWN', 'HUNTER COOLDOWN', false }, + { 'HUNTER', '', 'COOLDOWN', 'HUNTER', true }, + { 'HUNTER', '', 'COOLDOWN', 'HUNTER AURA', true }, + { 'HUNTER', '', 'COOLDOWN', 'AURA', false }, + { 'HUNTER', '', 'COOLDOWN', 'AURA COOLDOWN', false }, + { 'HUNTER', '', 'COOLDOWN', 'HUNTER COOLDOWN', false }, + } do + local anyOf, include, exclude, value, expected = unpack(data) + + it('FlagTester ' .. i, function () + local flagTester = lib:GetFlagTester(anyOf, include, exclude) + local filter = lib.__filters[value] + + assert.equals(expected, flagTester(filter)) + end) + end +end) diff --git a/tests/databases.lua b/tests/databases.lua deleted file mode 100644 index 5f67511..0000000 --- a/tests/databases.lua +++ /dev/null @@ -1,71 +0,0 @@ ---[[ -LibPlayerSpells-1.0 - Additional information about player spells. -(c) 2013-2021 Adirelle (adirelle@gmail.com) - -This file is part of LibPlayerSpells-1.0. - -LibPlayerSpells-1.0 is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -LibPlayerSpells-1.0 is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with LibPlayerSpells-1.0. If not, see . ---]] - -package.path = package.path .. ";./wowmock/?.lua" -local lu = require('luaunit') -local mockagne = require('mockagne') -local wowmock = require('wowmock') - -local when, any = mockagne.when, mockagne.any - -local lib, G - -testDatabases = {} - -function testDatabases:setup() - G = mockagne:getMock() - G.LibStub = false - G.AdiDebug = false - lib = wowmock("../LibPlayerSpells-1.0.lua", G) - G.LibStub = nil - when(G.geterrorhandler()).thenAnswer(error) - when(G.GetBuildInfo()).thenAnswer(0, 0, 0, 0) - when(G.LibStub("LibPlayerSpells-1.0")).thenAnswer(lib) - when(G.GetSpellInfo(any())).thenAnswer(true) -end - -local sources = { - "Deathknight", - "Druid", - "Hunter", - "Mage", - "Monk", - "Paladin", - "Priest", - "Racials", - "Rogue", - "Shaman", - "Warlock", - "Warrior", -} - -for _, source in ipairs(sources) do - testDatabases["test"..source] = function () - wowmock("../data/"..source..".lua", G) - end -end - -function testDatabases:testAllAtOnce() - for _, source in ipairs(sources) do - wowmock("../data/"..source..".lua", G) - end -end - -os.exit(lu.LuaUnit.run()) diff --git a/tests/databases_spec.lua b/tests/databases_spec.lua new file mode 100644 index 0000000..86e8abb --- /dev/null +++ b/tests/databases_spec.lua @@ -0,0 +1,37 @@ +package.path = package.path .. ';./wowmock/?.lua' + +local wowmock = require('wowmock') + +describe('Imports', function () + local G, lib + + before_each(function () + G = mock({ C_Spell = { + GetSpellInfo = function (id) return { spellID = id } end} + }) + lib = wowmock('../LibPlayerSpells-1.0.lua', G) + end) + + for _, source in next, { + 'Deathknight', + 'Demonhunter', + 'Druid', + 'Evoker', + 'Hunter', + 'Mage', + 'Monk', + 'Paladin', + 'Priest', + 'Racials', + 'Rogue', + 'Shaman', + 'Warlock', + 'Warrior', + } do + it(source, function () + G.LibStub = function (what) return lib end + + wowmock('../data/' .. source .. '.lua', G) + end) + end +end)