Skip to content

Commit 05632bc

Browse files
TheDechevLocalIdentity
andauthored
Fix: StatDescriber scope loading on Linux/WSL with comprehensive test coverage (#1169)
* Fix path case sensitivity of 'specific skill stat description' in StatDescriber (for Linux) * Fix file handler leak in StatDescriber * Normalize scope name handling for case sensitivity on Linux * Add tests for the StatDescriber getScope * Fix indents --------- Co-authored-by: LocalIdentity <localidentity2@gmail.com>
1 parent 9b201c2 commit 05632bc

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
describe("StatDescriber getScope scenarios", function()
2+
before_each(function()
3+
newBuild()
4+
end)
5+
6+
teardown(function()
7+
-- newBuild() resets environment in setup()
8+
end)
9+
10+
local cases = {
11+
{ name = "should_load_lowercase_prefixed_herald_scope", scope = "specific_skill_stat_descriptions/herald_of_thunder_statset_1", stats = {}, shouldSucceed = true, expectedOutputLines = 0 },
12+
{ name = "should_load_herald_scope_without_prefix", scope = "herald_of_thunder_statset_1", stats = {}, shouldSucceed = true, expectedOutputLines = 0 },
13+
{ name = "should_load_alchemist_boon_scope", scope = "alchemist_boon", stats = {}, shouldSucceed = true, expectedOutputLines = 0 },
14+
{ name = "should_load_skill_stat_descriptions", scope = "skill_stat_descriptions", stats = {}, shouldSucceed = true, expectedOutputLines = 0 },
15+
{ name = "should_generate_output_for_life_stat", scope = "stat_descriptions", stats = { base_maximum_life = 50 }, shouldSucceed = true, expectedOutputLines = 1 },
16+
{ name = "should_generate_output_for_alchemist_boon_flask_recovery", scope = "alchemist_boon", stats = { ["recovery_from_flasks_applies_to_allies_in_presence_%"] = 30 }, shouldSucceed = true, expectedOutputLines = 1 },
17+
{ name = "should_generate_output_for_fireball_area_radius", scope = "fireball", stats = { active_skill_base_area_of_effect_radius = 15 }, shouldSucceed = true, expectedOutputLines = 1 },
18+
{ name = "should_fail_for_nonexistent_scope", scope = "definitely_nonexistent_scope_12345", stats = {}, shouldSucceed = false },
19+
{ name = "should_fail_for_nonexistent_prefixed_scope", scope = "specific_skill_stat_descriptions/definitely_nonexistent_scope_12345", stats = {}, shouldSucceed = false },
20+
}
21+
22+
for _, case in ipairs(cases) do
23+
it(case.name, function()
24+
ConPrintf("[StatDescriber getScope] %s", case.name)
25+
local describe = require("Modules/StatDescriber")
26+
27+
if case.shouldSucceed then
28+
local out, lineMap = describe(case.stats, case.scope)
29+
assert.are.equal("table", type(out))
30+
assert.are.equal("table", type(lineMap))
31+
if case.expectedOutputLines then
32+
assert.are.equal(case.expectedOutputLines, #out)
33+
end
34+
else
35+
local ok, err = pcall(function()
36+
describe(case.stats, case.scope)
37+
end)
38+
assert.False(ok)
39+
assert.is_string(err)
40+
end
41+
end)
42+
end
43+
end)

src/Modules/StatDescriber.lua

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ local scopes = { }
1313
local function getScope(scopeName)
1414
if not scopes[scopeName] then
1515
local scope = nil
16-
local file = io.open("Data/StatDescriptions/specific_skill_stat_descriptions/"..scopeName..".lua", 'rb')
16+
-- Allow lowercase "specific_skill_stat_descriptions/<name>" by stripping the prefix (Linux is case-sensitive).
17+
local normalizedScopeName = scopeName:gsub("^specific_skill_stat_descriptions/", "")
18+
19+
local file = io.open("Data/StatDescriptions/Specific_Skill_Stat_Descriptions/"..normalizedScopeName..".lua", 'rb')
1720
if file then
18-
file.close()
19-
scope = LoadModule("Data/StatDescriptions/Specific_Skill_Stat_Descriptions/"..scopeName)
21+
file:close()
22+
scope = LoadModule("Data/StatDescriptions/Specific_Skill_Stat_Descriptions/"..normalizedScopeName)
2023
else
21-
scope = LoadModule("Data/StatDescriptions/"..scopeName)
24+
scope = LoadModule("Data/StatDescriptions/"..normalizedScopeName)
2225
end
2326
scope.name = scopeName
2427
if scope.parent then

0 commit comments

Comments
 (0)