Skip to content

Commit

Permalink
Add Tests (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mctalian committed Aug 27, 2024
1 parent c1df0ac commit da4bae5
Show file tree
Hide file tree
Showing 28 changed files with 765 additions and 45 deletions.
25 changes: 23 additions & 2 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: PR Translation Check
name: PR Checks

on:
pull_request:
Expand All @@ -11,7 +11,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
Expand All @@ -26,3 +26,24 @@ jobs:

- name: Check for Hard-coded strings
run: python .scripts/hardcode_string_check.py

run_tests:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- uses: leafo/gh-actions-lua@v10
- uses: leafo/gh-actions-luarocks@v4

- name: Install luarock dependencies
run: luarocks make --local rpglootfeed-1-1.rockspec

- name: Run Tests
run: make test-ci

- uses: actions/upload-artifact@v4
with:
name: luacov-html
path: luacov-html/
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,4 @@ luac.out

.venv

/luarocks
/lua
/lua_modules
/.luarocks
luacov-html
9 changes: 9 additions & 0 deletions .luacov
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
statsfile = "luacov.stats.out"
reporter = "html"
exclude = {"spec", "Icons", "locale", ".release"}
include = {
"^BlizzOverrides/", -- Include all files in BlizzOverrides/
"^config/", -- Include all files in config/
"^Features/", -- Include all files in Features/
"^[^/]+$" -- Include all Lua files in the repo root
}
4 changes: 1 addition & 3 deletions .pkgmeta
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ externals:
enable-nolib-creation: yes

ignore:
- lua_modules/
- *_spec.lua
- *.ps1
- *.md
- *.rockspec
- lua
- luarocks
- requirements.txt

7 changes: 6 additions & 1 deletion DynamicPropertyTable.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ function DynamicPropertyTable(globalTable, defaultsTable)
__index = function(_, key)
-- Check if the key exists in defaults, handle dynamically
if defaultsTable[key] ~= nil then
return globalTable[key] or defaultsTable[key]
local globalValue = globalTable[key]
if globalValue ~= nil then
return globalValue
else
return defaultsTable[key]
end
else
return rawget(_, key)
end
Expand Down
4 changes: 2 additions & 2 deletions Features/Currency.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function Currency:OnUpdate(...)
return
end

if currencyType == nil or quantityChange <= 0 then
if currencyType == nil or not quantityChange or quantityChange <= 0 then
return
end

Expand All @@ -16,7 +16,7 @@ function Currency:OnUpdate(...)
return
end

G_RLF.LootDisplay:ShowLoot(info.currencyID, G_RLF:GetCurrencyLink(info.currencyID, info.name), info.iconFileID,
G_RLF.LootDisplay:ShowLoot(info.currencyID, C_CurrencyInfo.GetCurrencyLink(currencyType), info.iconFileID,
quantityChange)
end

Expand Down
69 changes: 37 additions & 32 deletions Features/Reputation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,24 @@ function Rep:RefreshRepData()
local count = 0
for i = 1, numFactions do
local factionData = C_Reputation.GetFactionDataByIndex(i)
if not factionData.isHeader or factionData.isHeaderWithRep then
if C_Reputation.IsFactionParagon(factionData.factionID) then
-- Need to support Paragon factions
local value, max = C_Reputation.GetFactionParagonInfo(factionData.factionID)
paragonRepData[factionData.factionID] = value
elseif C_Reputation.IsMajorFaction(factionData.factionID) then
-- Need to support Major factions
local majorFactionData = C_MajorFactions.GetMajorFactionData(factionData.factionID)
local level = majorFactionData.renownLevel
local rep = majorFactionData.renownReputationEarned
local max = majorFactionData.renownLevelThreshold
majorRepData[factionData.factionID] = {level, rep, max}
else
repData[factionData.factionID] = factionData.currentStanding
if factionData ~= nil then
if not factionData.isHeader or factionData.isHeaderWithRep then
if C_Reputation.IsFactionParagon(factionData.factionID) then
-- Need to support Paragon factions
local value, max = C_Reputation.GetFactionParagonInfo(factionData.factionID)
paragonRepData[factionData.factionID] = value
elseif C_Reputation.IsMajorFaction(factionData.factionID) then
-- Need to support Major factions
local majorFactionData = C_MajorFactions.GetMajorFactionData(factionData.factionID)
local level = majorFactionData.renownLevel
local rep = majorFactionData.renownReputationEarned
local max = majorFactionData.renownLevelThreshold
majorRepData[factionData.factionID] = {level, rep, max}
else
repData[factionData.factionID] = factionData.currentStanding
end
count = count + 1
end
count = count + 1
end
end

Expand All @@ -46,23 +48,26 @@ function Rep:AddAnyNewFactions()

for i = 1, numFactions do
local factionData = C_Reputation.GetFactionDataByIndex(i)
if not factionData.isHeader or factionData.isHeaderWithRep then
local factionData = C_Reputation.GetFactionDataByIndex(i)
local fId = factionData.factionID
if C_Reputation.IsFactionParagon(fId) then
if not paragonRepData[fId] then
paragonRepData[fId] = 0
end
elseif C_Reputation.IsMajorFaction(fId) then
if not majorRepData[fId] then
local mfd = C_MajorFactions.GetMajorFactionData(fId)
local level = mfd.renownLevel
local max = mfd.renownLevelThreshold
majorRepData[fId] = {level, 0, max}
end
else
if not repData[fId] then
repData[fId] = 0
if factionData ~= nil then

if not factionData.isHeader or factionData.isHeaderWithRep then
local factionData = C_Reputation.GetFactionDataByIndex(i)
local fId = factionData.factionID
if C_Reputation.IsFactionParagon(fId) then
if not paragonRepData[fId] then
paragonRepData[fId] = 0
end
elseif C_Reputation.IsMajorFaction(fId) then
if not majorRepData[fId] then
local mfd = C_MajorFactions.GetMajorFactionData(fId)
local level = mfd.renownLevel
local max = mfd.renownLevelThreshold
majorRepData[fId] = {level, 0, max}
end
else
if not repData[fId] then
repData[fId] = 0
end
end
end
end
Expand Down
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
.PHONY: all_checks venv_up hardcode_string_check missing_translation_check
.PHONY: all_checks venv_up hardcode_string_check missing_translation_check test test-ci

all_checks: venv_up hardcode_string_check missing_translation_check

# Variables
PYTHON := python3
ROCKSBIN := $(HOME)/.luarocks/bin

# Target for running the hardcoded string checker
hardcode_string_check:
Expand All @@ -15,3 +16,9 @@ missing_translation_check:

venv_up:
@if [ ! -d ".venv" ]; then $(PYTHON) -m venv ./.venv; fi

test:
@rm -rf luacov-html && rm -rf luacov.*out && $(ROCKSBIN)/busted --coverage && $(ROCKSBIN)/luacov

test-ci:
@rm -rf luacov-html && rm -rf luacov.*out && $(ROCKSBIN)/busted --coverage -o=TAP && $(ROCKSBIN)/luacov
15 changes: 15 additions & 0 deletions rpglootfeed-1-1.rockspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package = "rpglootfeed"
version = "1-1"
source = {
url = "https://github.com/Mctalian/RPGLootFeed.git"
}
dependencies = {
"lua >= 5.3",
"busted >= 2.2",
"luacov >= 0.15",
"luacov-html >= 1.0"
}
build = {
type = "builtin",
modules = {}
}
17 changes: 17 additions & 0 deletions spec/AddonScope_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
describe("AddonScope module", function()

before_each(function()
_G.LibStub = function()
return {
NewAddon = function()
end
}
end
-- Load the list module before each test
dofile("AddonScope.lua")
end)

it("TODO", function()
assert.are.equal(true, true)
end)
end)
15 changes: 15 additions & 0 deletions spec/BlizzOverrides/BossBanner_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
describe("BossBanner module", function()

before_each(function()
-- Define the global G_RLF
_G.G_RLF = {
RLF = {}
}
-- Load the list module before each test
dofile("BlizzOverrides/BossBanner.lua")
end)

it("TODO", function()
assert.are.equal(true, true)
end)
end)
15 changes: 15 additions & 0 deletions spec/BlizzOverrides/LootToasts_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
describe("LootToasts module", function()

before_each(function()
-- Define the global G_RLF
_G.G_RLF = {
RLF = {}
}
-- Load the list module before each test
dofile("BlizzOverrides/LootToasts.lua")
end)

it("TODO", function()
assert.are.equal(true, true)
end)
end)
Loading

0 comments on commit da4bae5

Please sign in to comment.