Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
with:
persist-credentials: false
- name: Install test tools
run: sudo apt-get update && sudo apt-get install -y luajit python3 zip unzip jq
run: sudo apt-get update && sudo apt-get install -y luajit python3 zip unzip jq librsvg2-bin imagemagick fonts-dejavu-core
- name: Set up pinned test libraries
run: bash scripts/setup-test-libs.sh
- name: Check out the matching Blizzard source
Expand All @@ -37,6 +37,28 @@ jobs:
run: python3 -B scripts/spell_catalog.py --fetch --check
- name: Run all tests and addon syntax checks
run: bash scripts/run-tests.sh --times -j
- name: Cache Blizzard interface art for UI proof
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: .proof-art
key: proof-art-d23deaf8f44a7d280dc974a5c9d5321c013db59b-${{ hashFiles('tests/proof/*.lua') }}
restore-keys: proof-art-d23deaf8f44a7d280dc974a5c9d5321c013db59b-
- name: Render UI proof
env:
GITHUB_TOKEN: ${{ github.token }}
run: bash scripts/proof.sh
- name: Save UI proof
if: always()
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: ui-proof
path: |
.proof/*.png
.proof/*.svg
.proof/index.html
include-hidden-files: true
if-no-files-found: error
retention-days: 14
- name: Save spell classification audit
if: always()
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ UnitFrames/Libs/
UnitFrames_Media/Libs/
/.release/
/.build/
/.proof/
/.proof-art/
36 changes: 36 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ in source is needed before tagging.
| `UnitFrames_Onboarding/` | Load-on-demand Getting started guide: preset looks, tweaks, extras and Workbench hand-off |
| `UnitFrames_Media/` | Additional fonts and their licences |
| `tests/` | Mocked client, API snapshot and regression specs |
| `wowproof/` | Standalone UI-proof renderer (no UnitFrames code; see its README) |
| `scripts/` | Library fetching, installation and API snapshot generation |

New runtime files belong in the relevant TOC in dependency order; tests
Expand Down Expand Up @@ -227,6 +228,41 @@ a name ending in `.lua` exactly one file. `-t` and `--tag` narrow further. A run
that selects no tests fails. The runner always checks addon Lua syntax. No
external busted installation is needed. To see where a spec spends its time,
use LuaJIT's profiler: `luajit -jp=F tests/run.lua clickgrid_spec.lua`.
The specs of the `wowproof/` package run with the suite as `wowproof/<file>`.

### UI proof

The mocked client can render frames to images, for visual proof of a change:

```sh
bash scripts/proof.sh # every scenario
bash scripts/proof.sh target clickgrid # scenario names containing the text
```

It writes `.proof/<scenario>.svg`, `.png` and a contact sheet `.proof/index.html`
(ignored by Git; `UF_PROOF_DIR` picks another folder). PNGs need `rsvg-convert`
(librsvg); our own `.tga` textures need ImageMagick. Scenarios live in
`tests/proof/units.lua` and `tests/proof/workbench.lua`: each is a name and a
`build` that loads the addon, feeds sample values and returns the region to
render. `tests/proof/setup.lua` is the only coupling to the renderer: it hands
`wowproof` an adapter for the mock and maps our fonts and textures. A spec can
also call `Helpers.Snapshot(name, region)`, which renders only with
`UF_PROOF=1`. CI uploads the images as the `ui-proof` artifact.

The images show real anchoring, sizes, colours, bar fill, text, clipping,
texture coordinates and paint order. Blizzard textures and icons
(`Interface\...`) are downloaded on demand from the public
[Gethe/wow-ui-textures](https://github.com/Gethe/wow-ui-textures) mirror,
pinned in `tests/proof/setup.lua`, into the ignored `.proof-art/` folder. Only
the files a render uses are fetched, and the cache is reused offline. Never
commit that art. `UF_PROOF_ART` picks another cache folder, and
`UF_PROOF_ART_FETCH=0` stays offline. Set `GH_TOKEN` or `GITHUB_TOKEN` if
GitHub's API rate limit bites.

Still drawn as dashed placeholders:
- art the mirror lacks, listed in `.proof-art/missing-<commit>.txt`
- atlases (`SetAtlas`), which need Blizzard's atlas table
- portrait models

### Pull request checks

Expand Down
13 changes: 13 additions & 0 deletions scripts/proof.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -euo pipefail

repo_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$repo_dir"
if [[ ! -f UnitFrames/Libs/LibStub/LibStub.lua ]]; then
echo 'Test libraries are missing. Run bash scripts/setup-test-libs.sh first.' >&2
exit 1
fi
command -v rsvg-convert >/dev/null || echo 'rsvg-convert not found: writing SVG only.' >&2
command -v magick >/dev/null || command -v convert >/dev/null \
|| echo 'ImageMagick not found: addon textures render as placeholders.' >&2
exec luajit tests/proof/run.lua "$@"
6 changes: 6 additions & 0 deletions tests/fixtures/api_snapshot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,7 @@ return {
[":update"] = "Interface/AddOns/Blizzard_GroupFinder/Mainline/PVEFrame.lua",
API = "Interface/AddOns/Blizzard_ObjectAPI/Mainline/AsyncCallbackSystem.lua",
AddPoint = "Interface/AddOns/Blizzard_LegacySystem/Blizzard_LegacySystem.lua",
BOTTOMRIGHT = "Interface/AddOns/Blizzard_Settings_Shared/Blizzard_ImplementationReadme.lua",
BUTTON = "Interface/AddOns/Blizzard_Settings_Shared/Blizzard_Keybindings.lua",
Chain = "Interface/AddOns/Blizzard_PTRFeedback/Blizzard_Reports.lua",
ClearText = "Interface/AddOns/Blizzard_PlayerSpells/Blizzard_PlayerSpellsFrame.lua",
Expand Down Expand Up @@ -1464,6 +1465,7 @@ return {
SetupTextureCoordinates = "Interface/AddOns/Blizzard_SharedXML/NineSlice.lua",
Show = "Interface/AddOns/Blizzard_EncounterWarnings/EncounterWarningsView.lua",
T = "Interface/AddOns/Blizzard_ProfessionsTemplates/Blizzard_ProfessionsRecipeSchematicForm.lua",
TOPLEFT = "Interface/AddOns/Blizzard_Settings_Shared/Blizzard_ImplementationReadme.lua",
UnitHasIncomingResurrection = "Interface/AddOns/Blizzard_UnitFrame/Shared/CompactUnitFrame.lua",
Warrior = "Interface/AddOns/Blizzard_BoostTutorial/Blizzard_TutorialRacialData.lua",
action = "Interface/AddOns/Blizzard_SharedXML/ScriptedAnimations/ScriptAnimatedModelScene.lua",
Expand All @@ -1488,9 +1490,11 @@ return {
children = "Interface/AddOns/Blizzard_GamepadSmartNavigation/Utility.lua",
click = "Interface/AddOns/Blizzard_GamepadSharedUtility/InputHandlers/InputButtonUtility.lua",
color = "Interface/AddOns/Blizzard_Menu/MenuTemplates.lua",
column = "Interface/AddOns/Blizzard_RestrictedAddOnEnvironment/SecureGroupHeaders.lua",
comparison = "Interface/AddOns/Blizzard_GarrisonUI/Mainline/Blizzard_GarrisonShipyardUI.lua",
condition = "Interface/AddOns/Blizzard_AuctionHouseUI/Shared/Blizzard_AuctionHouseItemList.lua",
content = "Interface/AddOns/Blizzard_NamePlates/Blizzard_NamePlateConstants.lua",
coords = "Interface/AddOns/Blizzard_ArtifactUI/Blizzard_ArtifactPerks.lua",
create = "Interface/AddOns/Blizzard_RestrictedAddOnEnvironment/SecureGroupHeaders.lua",
data = "Interface/AddOns/Blizzard_StaticPopup_Glue/Mainline/GlueDialogDefs.lua",
dataProvider = "Interface/AddOns/Blizzard_SharedXML/TableBuilder.lua",
Expand Down Expand Up @@ -1537,6 +1541,8 @@ return {
order = "Interface/AddOns/Blizzard_RestrictedAddOnEnvironment/SecureAuraHeader.lua",
out = "Interface/AddOns/Blizzard_DeclensionFrame/Mainline/DeclensionFrame.lua",
pass = "Interface/AddOns/Blizzard_SharedXML/MixinUtil.lua",
piece = "Interface/AddOns/Blizzard_SharedXML/NineSlice.lua",
pieces = "Interface/AddOns/Blizzard_SharedXML/NineSlice.lua",
player = "Interface/AddOns/Blizzard_CooldownViewer/CooldownViewerAlert.lua",
points = "Interface/AddOns/Blizzard_EncounterJournal/Mainline/Blizzard_MonthlyActivities.lua",
policy = "Interface/AddOns/Blizzard_SharedXMLGame/Mainline/Localization.lua",
Expand Down
7 changes: 7 additions & 0 deletions tests/helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,11 @@ function Helpers.LoadClickGrid(workbench, saved)
return ns, cg, ns.Workbench
end

local proof
function Helpers.Snapshot(name, region, options)
if os.getenv("UF_PROOF") ~= "1" then return nil end
proof = proof or dofile("tests/proof/setup.lua").Proof()
return proof:Snapshot(region, "spec-" .. name, options)
end

return Helpers
128 changes: 116 additions & 12 deletions tests/mock/wow.lua
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,10 @@ end
function Methods:SetRotation(radians) self.__state.rotation = radians end
function Methods:GetFrameRef(label) return self.__state.frameRefs and self.__state.frameRefs[label] end

function Methods:SetScript(name, fn) self.__state.scripts[name] = fn end
function Methods:SetScript(name, fn)
if name == "OnSizeChanged" then self.__state.backdropSizeScript = false end
self.__state.scripts[name] = fn
end
function Methods:GetScript(name) return self.__state.scripts[name] end
function Methods:HookScript(name, fn)
local previous = self.__state.scripts[name]
Expand Down Expand Up @@ -288,7 +291,12 @@ local function Resize(self, width, height)
local s = self.__state
local changed = s.width ~= width or s.height ~= height
s.width, s.height = width, height
if changed and s.scripts.OnSizeChanged and not Mock.HasLayoutAspect(self) then
if not changed or Mock.HasLayoutAspect(self) then return end
if s.backdropSizeScript and s.backdrop then
local setup = rawget(self, "SetupTextureCoordinates") or BackdropTemplateMixin.SetupTextureCoordinates
setup(self)
end
if s.scripts.OnSizeChanged then
s.scripts.OnSizeChanged(self, width, height)
end
end
Expand Down Expand Up @@ -586,16 +594,83 @@ function Methods:GetStringWidth() return 50 end
-- Backdrop (BackdropTemplate)
local borderPieces = { "TopLeftCorner", "TopRightCorner", "BottomLeftCorner", "BottomRightCorner",
"TopEdge", "BottomEdge", "LeftEdge", "RightEdge" }

local NINE_SLICE = {
{ name = "TopLeftCorner", point = "TOPLEFT" },
{ name = "TopRightCorner", point = "TOPRIGHT" },
{ name = "BottomLeftCorner", point = "BOTTOMLEFT" },
{ name = "BottomRightCorner", point = "BOTTOMRIGHT" },
{ name = "TopEdge", point = "TOPLEFT", relativePoint = "TOPRIGHT", between = { "TopLeftCorner", "TopRightCorner" } },
{ name = "BottomEdge", point = "BOTTOMLEFT", relativePoint = "BOTTOMRIGHT", between = { "BottomLeftCorner", "BottomRightCorner" } },
{ name = "LeftEdge", point = "TOPLEFT", relativePoint = "BOTTOMLEFT", between = { "TopLeftCorner", "BottomLeftCorner" } },
{ name = "RightEdge", point = "TOPRIGHT", relativePoint = "BOTTOMRIGHT", between = { "TopRightCorner", "BottomRightCorner" } },
{ name = "Center" },
}
local BACKDROP_COORD_START = 0.0625
local BACKDROP_COORD_END = 1 - BACKDROP_COORD_START
local BACKDROP_UV_ORDER = { "ULx", "ULy", "LLx", "LLy", "URx", "URy", "LRx", "LRy" }
local BACKDROP_UVS = {
TopLeftCorner = { ULx = 0.5078125, ULy = BACKDROP_COORD_START, LLx = 0.5078125, LLy = BACKDROP_COORD_END,
URx = 0.6171875, URy = BACKDROP_COORD_START, LRx = 0.6171875, LRy = BACKDROP_COORD_END },
TopRightCorner = { ULx = 0.6328125, ULy = BACKDROP_COORD_START, LLx = 0.6328125, LLy = BACKDROP_COORD_END,
URx = 0.7421875, URy = BACKDROP_COORD_START, LRx = 0.7421875, LRy = BACKDROP_COORD_END },
BottomLeftCorner = { ULx = 0.7578125, ULy = BACKDROP_COORD_START, LLx = 0.7578125, LLy = BACKDROP_COORD_END,
URx = 0.8671875, URy = BACKDROP_COORD_START, LRx = 0.8671875, LRy = BACKDROP_COORD_END },
BottomRightCorner = { ULx = 0.8828125, ULy = BACKDROP_COORD_START, LLx = 0.8828125, LLy = BACKDROP_COORD_END,
URx = 0.9921875, URy = BACKDROP_COORD_START, LRx = 0.9921875, LRy = BACKDROP_COORD_END },
TopEdge = { ULx = 0.2578125, ULy = "repeatX", LLx = 0.3671875, LLy = "repeatX",
URx = 0.2578125, URy = BACKDROP_COORD_START, LRx = 0.3671875, LRy = BACKDROP_COORD_START },
BottomEdge = { ULx = 0.3828125, ULy = "repeatX", LLx = 0.4921875, LLy = "repeatX",
URx = 0.3828125, URy = BACKDROP_COORD_START, LRx = 0.4921875, LRy = BACKDROP_COORD_START },
LeftEdge = { ULx = 0.0078125, ULy = BACKDROP_COORD_START, LLx = 0.0078125, LLy = "repeatY",
URx = 0.1171875, URy = BACKDROP_COORD_START, LRx = 0.1171875, LRy = "repeatY" },
RightEdge = { ULx = 0.1328125, ULy = BACKDROP_COORD_START, LLx = 0.1328125, LLy = "repeatY",
URx = 0.2421875, URy = BACKDROP_COORD_START, LRx = 0.2421875, LRy = "repeatY" },
Center = { ULx = 0, ULy = 0, LLx = 0, LLy = "repeatY", URx = "repeatX", URy = 0, LRx = "repeatX", LRy = "repeatY" },
}
local CORNER_SIZE = { TopLeftCorner = "both", TopRightCorner = "both", BottomLeftCorner = "both",
BottomRightCorner = "both", TopEdge = "height", BottomEdge = "height", LeftEdge = "width", RightEdge = "width" }

function Methods:SetBackdrop(info)
if not info or not (info.edgeFile or info.bgFile) then self:ClearBackdrop(); return end
-- BackdropTemplateMixin:SetBackdrop ignores the info table it already holds.
if self.__state.backdrop == info then return end
self.__state.backdrop = info
for _, key in ipairs(borderPieces) do
local texture = rawget(self, key) or self:CreateTexture(nil, "BORDER")
self[key] = texture
texture:SetTexture(info.edgeFile)
local edgeSize = self:GetEdgeSize()
local x, y, x1, y1 = 0, 0, 0, 0
if info.bgFile then
local insets = info.insets or {}
x, y = -edgeSize + (insets.left or 0), edgeSize - (insets.top or 0)
x1, y1 = edgeSize - (insets.right or 0), -edgeSize + (insets.bottom or 0)
end
local pieces = self.__state.backdropPieces or {}
self.__state.backdropPieces = pieces
for _, setup in ipairs(NINE_SLICE) do
local center = setup.name == "Center"
local piece = rawget(self, setup.name) or self:CreateTexture(nil, center and "BACKGROUND" or "BORDER")
self[setup.name], pieces[setup.name] = piece, piece
piece:ClearAllPoints()
if center then
piece:SetPoint("TOPLEFT", pieces.TopLeftCorner, "BOTTOMRIGHT", x, y)
piece:SetPoint("BOTTOMRIGHT", pieces.BottomRightCorner, "TOPLEFT", x1, y1)
piece:SetTexture(info.bgFile)
piece:SetSize(0, 0)
else
if setup.between then
piece:SetPoint(setup.point, pieces[setup.between[1]], setup.relativePoint)
piece:SetPoint(setup.relativePoint, pieces[setup.between[2]], setup.point)
else
piece:SetPoint(setup.point, self, setup.point)
end
piece:SetTexture(info.edgeFile)
local size = CORNER_SIZE[setup.name]
piece:SetSize((size == "both" or size == "width") and edgeSize or 0, (size == "both" or size == "height") and edgeSize or 0)
end
end
self:SetBackdropColor(1, 1, 1, 1)
self:SetBackdropBorderColor(1, 1, 1, 1)
local setupTextureCoordinates = rawget(self, "SetupTextureCoordinates") or BackdropTemplateMixin.SetupTextureCoordinates
setupTextureCoordinates(self)
end
function Methods:GetBackdrop() return self.__state.backdrop end
function Methods:GetEdgeSize()
Expand All @@ -604,12 +679,16 @@ function Methods:GetEdgeSize()
end
function Methods:ClearBackdrop()
self.__state.backdrop = nil
for _, key in ipairs(borderPieces) do
local texture = rawget(self, key)
for _, setup in ipairs(NINE_SLICE) do
local texture = rawget(self, setup.name)
if texture then texture:SetTexture(nil) end
end
end
function Methods:SetBackdropColor(r, g, b, a) self.__state.backdropColor = { r, g, b, a } end
function Methods:SetBackdropColor(r, g, b, a)
self.__state.backdropColor = { r, g, b, a }
local center = rawget(self, "Center")
if center then center:SetVertexColor(r, g, b, a) end
end
function Methods:SetBackdropBorderColor(r, g, b, a)
self.__state.backdropBorderColor = { r, g, b, a }
for _, key in ipairs(borderPieces) do
Expand Down Expand Up @@ -1088,6 +1167,7 @@ function Mock.Install()
obj.__state.template = template
if template and template:find("Secure", 1, true) then obj.__state.protected = true end
if template and template:find(LAYOUT_ASPECT_TEMPLATE, 1, true) then obj.__state.layoutAspect = true end
if template and template:find("BackdropTemplate", 1, true) then obj.__state.backdropSizeScript = true end
if parent and parent == rawget(_G, "Minimap") then rawset(obj, "__strict", true) end
if frameType == "AuraContainer" then
assert(not InCombatLockdown(), "Native aura containers cannot be created in combat")
Expand Down Expand Up @@ -1191,7 +1271,12 @@ function Mock.Install()
}
Mock.spells = {}
-- Blizzard_UnitFrame (always loaded): a sprite sheet cell of the raid icon sheet.
_G.SetRaidTargetIconTexture = function(texture, index) texture.__state.raidTargetIndex = index end
_G.SetRaidTargetIconTexture = function(texture, index)
texture.__state.raidTargetIndex = index
local cell = (Mock.IsSecret(index) and index.secretValue or index) - 1
local column, row = cell % 4, math.floor(cell / 4)
texture.__state.texCoords = { column / 4, (column + 1) / 4, row / 4, (row + 1) / 4 }
end
Mock.spellOverrides, Mock.unknownSpells, Mock.cooldowns, Mock.spellQueueWindow = {}, {}, {}, 400
-- Mock.latency = { home, world } in milliseconds.
Mock.latency = { 40, 80 }
Expand Down Expand Up @@ -1398,10 +1483,29 @@ function Mock.Install()
_G.BackdropTemplateMixin = {
SetupTextureCoordinates = function(self)
local edgeSize, scale = self:GetEdgeSize(), self:GetEffectiveScale()
local width, height = self:GetWidth(), self:GetHeight()
self.__state.backdropRepeat = {
math.max(0, self:GetWidth() / edgeSize * scale - 2),
math.max(0, self:GetHeight() / edgeSize * scale - 2),
math.max(0, width / edgeSize * scale - 2),
math.max(0, height / edgeSize * scale - 2),
}
local edgeX = math.max(0, width / edgeSize * scale - 2 - BACKDROP_COORD_START)
local edgeY = math.max(0, height / edgeSize * scale - 2 - BACKDROP_COORD_START)
local info = self.__state.backdrop
for name, piece in pairs(self.__state.backdropPieces or {}) do
local repeatX, repeatY = edgeX, edgeY
if name == "Center" then
repeatX, repeatY = 1, 1
local divisor = info and info.tile and (info.tileSize ~= 0 and info.tileSize or edgeSize)
if divisor and divisor ~= 0 then repeatX, repeatY = width / divisor * scale, height / divisor * scale end
end
local coords = {}
for index, key in ipairs(BACKDROP_UV_ORDER) do
local value = BACKDROP_UVS[name][key]
if value == "repeatX" then value = repeatX elseif value == "repeatY" then value = repeatY end
coords[index] = value
end
piece:SetTexCoord(unpack(coords))
end
end,
}
_G.AuraUtil = {
Expand Down
20 changes: 20 additions & 0 deletions tests/proof/run.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
local Setup = dofile("tests/proof/setup.lua")
local Runner = require("wowproof.runner")

local SCENARIO_FILES = { "tests/proof/units.lua", "tests/proof/workbench.lua" }

local write = io.write
local function Print(line) write(line, "\n") end

local scenarios = {}
for _, file in ipairs(SCENARIO_FILES) do
for _, scenario in ipairs(dofile(file)) do scenarios[#scenarios + 1] = scenario end
end

local _, failed = Runner.Run({
proof = Setup.Proof(),
scenarios = scenarios,
filters = arg,
print = Print,
})
os.exit(failed == 0 and 0 or 1, true)
Loading
Loading