Skip to content

Commit

Permalink
FEAT: add output only diff.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paliak committed Mar 2, 2024
1 parent 7842581 commit c78ad3b
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 6 deletions.
9 changes: 9 additions & 0 deletions spec/buildDiff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,20 @@ fi
for build in $CACHEDIR/*.build
do
BASENAME=$(basename "$build")

# Only print the header if there is a diff to display
DIFFOUTPUT=$(diff <(xmllint --exc-c14n "$build") <(xmllint --exc-c14n "/tmp/devref/$BASENAME")) || {
echo "## Savefile Diff for $BASENAME"
echo '```diff'
echo "$DIFFOUTPUT"
echo '```'
}

# Dedicated output diff
DIFFOUTPUT=$(luajit spec/diffOutput.lua "$build" "/tmp/devref/$BASENAME") || {
echo "## Output Diff for $BASENAME"
echo '```'
echo "$DIFFOUTPUT"
echo '```'
}
done
72 changes: 72 additions & 0 deletions spec/diffOutput.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
-- https://stackoverflow.com/questions/19326368/iterate-over-lines-including-blank-lines
local function splitLines(s)
if s:sub(-1)~="\n" then s=s.."\n" end
return s:gmatch("(.-)\n")
end

local function buildOutputMap(filecontent)
local playerOutput = {}
local minionOutput = {}
for line in splitLines(filecontent) do
local key, val = line:match('PlayerStat stat="(.-)" value="(.-)"')
if key then
playerOutput[key] = val
else
local key,val = line:match('MinionStat stat="(.-)" value="(.-)"')
if key then
minionOutput[key] = val
end
end
end
return playerOutput, minionOutput
end

local headhnd = io.open(arg[1], "r")
local devhnd = io.open(arg[2], "r")

if headhnd and devhnd then
local playerHEADOutput, minionHEADOutput = buildOutputMap(headhnd:read("*a"))
local playerDEVOutput, minionDEVOutput = buildOutputMap(devhnd:read("*a"))
local mismatch = {}
local mismatchFound = false
for key, val in pairs(playerHEADOutput) do
if not playerDEVOutput[key] or playerDEVOutput[key] ~= val then
mismatch[key] = {devOutput = playerDEVOutput[key], headOutput = val}
mismatchFound = true
end
end
for key, val in pairs(playerDEVOutput) do
if not mismatch[key] and (not playerHEADOutput[key] or playerHEADOutput[key] ~= val) then
mismatch[key] = {headOutput = playerHEADOutput[key], devOutput = val}
mismatchFound = true
end
end
for key, val in pairs(mismatch) do
print(key .. " Mismatch in player outputs: ")
print("\t" .."head Output: " .. tostring(val["headOutput"]))
print("\t" .."dev Output: " .. tostring(val["devOutput"]))
end
mismatch = {}
for key, val in pairs(minionHEADOutput) do
if not minionDEVOutput[key] or minionDEVOutput[key] ~= val then
mismatch[key] = {devOutput = minionDEVOutput[key], headOutput = val}
mismatchFound = true
end
end
for key, val in pairs(minionDEVOutput) do
if not mismatch[key] and (not minionHEADOutput[key] or minionHEADOutput[key] ~= val) then
mismatch[key] = {headOutput = minionHEADOutput[key], devOutput = val}
mismatchFound = true
end
end
for key, val in pairs(mismatch) do
print(key .. " Mismatch in minion outputs: ")
print("\t" .."head Output: " .. tostring(val["headOutput"]))
print("\t" .."dev Output: " .. tostring(val["devOutput"]))
end
if mismatchFound then
os.exit(1) -- Make the exit codes of the script match the exit codes of the diff utility
end
else
os.exit(2)
end
6 changes: 0 additions & 6 deletions src/Modules/Build.lua
Original file line number Diff line number Diff line change
Expand Up @@ -962,12 +962,6 @@ function buildMode:Save(xml, options)
end
end

if options and (options.fullPlayerStat or options.fullMinionStat) then
table.sort(xml, function(a, b)
return a.attrib and a.attrib.stat and b.attrib and b.attrib.stat and (a.elem == "MinionStat" or b.elem == "PlayerStat") and a.attrib.stat < b.attrib.stat
end)
end

local timelessData = {
elem = "TimelessData",
attrib = {
Expand Down

0 comments on commit c78ad3b

Please sign in to comment.