Adding example of XML loading test
This commit is contained in:
4
.github/workflows/test.yml
vendored
4
.github/workflows/test.yml
vendored
@@ -21,8 +21,8 @@ jobs:
|
||||
- name: Unzip for lua libs
|
||||
run: unzip runtime-win32.zip
|
||||
- name: Set LUA_PATH
|
||||
run: cp lua/*.lua ./
|
||||
run: export LUA_PATH=./lua/?.lua
|
||||
- name: Run tests
|
||||
run: busted -c Test/TestRunner.lua
|
||||
run: busted -c --lua=/usr/bin/luajit --helper=HeadlessWrapper.lua .
|
||||
- name: Report coverage
|
||||
run: luacov-coveralls
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
function TestBuilds:fetchBuilds(path, buildList)
|
||||
local buildList = buildList or {}
|
||||
for file in lfs.dir(path) do
|
||||
if file ~= "." and file ~= ".." then
|
||||
local f = path..'/'..file
|
||||
local attr = lfs.attributes (f)
|
||||
assert (type(attr) == "table")
|
||||
if attr.mode == "directory" then
|
||||
TestBuilds:fetchBuilds(f, buildList)
|
||||
else
|
||||
table.insert(buildList, LoadModule(f))
|
||||
end
|
||||
end
|
||||
end
|
||||
return buildList
|
||||
end
|
||||
|
||||
describe("test all test builds", function()
|
||||
it("finds all test builds and compares their output", function()
|
||||
local buildList = TestBuilds:fetchBuilds("Test/TestBuilds")
|
||||
for _, testBuild in ipairs(buildList) do
|
||||
loadBuildFromXML(testBuild.xml)
|
||||
for key, value in pairs(testBuild.output) do
|
||||
assert.same(build.calcsTab.mainOutput[key], value)
|
||||
end
|
||||
end
|
||||
end)
|
||||
end)
|
||||
@@ -1,11 +0,0 @@
|
||||
require("HeadlessWrapper")
|
||||
lfs = require("lfs")
|
||||
require 'busted.runner'()
|
||||
describe("some", function()
|
||||
it("does something", function()
|
||||
assert.same(1,1)
|
||||
end)
|
||||
end)
|
||||
|
||||
LoadModule("Test/System/TestAttacks")
|
||||
LoadModule("Test/System/TestBuilds")
|
||||
@@ -8,18 +8,18 @@ describe("TestAttacks", function()
|
||||
end)
|
||||
|
||||
it("creates an item and has the correct crit chance", function()
|
||||
assert.same(build.calcsTab.mainOutput.CritChance, 0)
|
||||
assert.are.equals(build.calcsTab.mainOutput.CritChance, 0)
|
||||
build.itemsTab:CreateDisplayItemFromRaw("New Item\nMaraketh Bow\nCrafted: true\nPrefix: None\nPrefix: None\nPrefix: None\nSuffix: None\nSuffix: None\nSuffix: None\nQuality: 20\nSockets: G-G-G-G-G-G\nLevelReq: 71\nImplicits: 1\n{tags:speed}10% increased Movement Speed")
|
||||
build.itemsTab:AddDisplayItem()
|
||||
runCallback("OnFrame")
|
||||
assert.same(build.calcsTab.mainOutput.CritChance, 5.5 * build.calcsTab.mainOutput.HitChance / 100)
|
||||
assert.are.equals(build.calcsTab.mainOutput.CritChance, 5.5 * build.calcsTab.mainOutput.HitChance / 100)
|
||||
end)
|
||||
|
||||
it("creates an item and has the correct crit multi", function()
|
||||
assert.same(1.5, build.calcsTab.mainOutput.CritMultiplier)
|
||||
assert.are.equals(1.5, build.calcsTab.mainOutput.CritMultiplier)
|
||||
build.itemsTab:CreateDisplayItemFromRaw("New Item\nAssassin Bow\nCrafted: true\nPrefix: None\nPrefix: None\nPrefix: None\nSuffix: None\nSuffix: None\nSuffix: None\nQuality: 20\nSockets: G-G-G-G-G-G\nLevelReq: 62\nImplicits: 1\n{tags:damage,critical}{range:0.5}+(15-25)% to Global Critical Strike Multiplier")
|
||||
build.itemsTab:AddDisplayItem()
|
||||
runCallback("OnFrame")
|
||||
assert.same(1.5 + .2, build.calcsTab.mainOutput.CritMultiplier)
|
||||
assert.are.equals(1.5 + .2, build.calcsTab.mainOutput.CritMultiplier)
|
||||
end)
|
||||
end)
|
||||
33
spec/System/TestBuilds_spec.lua
Normal file
33
spec/System/TestBuilds_spec.lua
Normal file
@@ -0,0 +1,33 @@
|
||||
local function fetchBuilds(path, buildList)
|
||||
local buildList = buildList or {}
|
||||
for file in lfs.dir(path) do
|
||||
if file ~= "." and file ~= ".." then
|
||||
local f = path..'/'..file
|
||||
local attr = lfs.attributes (f)
|
||||
assert (type(attr) == "table")
|
||||
if attr.mode == "directory" then
|
||||
fetchBuilds(f, buildList)
|
||||
else
|
||||
table.insert(buildList, LoadModule(f))
|
||||
end
|
||||
end
|
||||
end
|
||||
return buildList
|
||||
end
|
||||
|
||||
describe("test all test builds", function()
|
||||
|
||||
local buildList = fetchBuilds("spec/TestBuilds")
|
||||
for _, testBuild in ipairs(buildList) do
|
||||
loadBuildFromXML(testBuild.xml)
|
||||
for key, value in pairs(testBuild.output) do
|
||||
it("test key: " .. key, function()
|
||||
if type(value) == 'number' then
|
||||
value = round(value, 4)
|
||||
build.calcsTab.mainOutput[key] = round(build.calcsTab.mainOutput[key], 4)
|
||||
end
|
||||
assert.are.equals(build.calcsTab.mainOutput[key], value)
|
||||
end)
|
||||
end
|
||||
end
|
||||
end)
|
||||
Reference in New Issue
Block a user