-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiff.lua
127 lines (113 loc) · 3.23 KB
/
diff.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
local lfs = require "lfs"
local dirBefore, dirAfter = ...
local function readFile(file)
local f, err = io.open(file, "rb")
if not f then return "" end
local res, err = f:read("*a")
if not res then error(err) end
return res
end
local function gatherFiles(dir)
local tests = {}
for entry in lfs.dir(dir) do
local path = dir .. "/" .. entry
if not entry:match("^%.") and lfs.attributes(path).mode == "directory" then
tests[entry] = {
errors = readFile(path .. "/" .. "1-Errors.txt"),
report = readFile(path .. "/" .. "2-Test-Report.txt"),
addMsg = readFile(path .. "/" .. "3-DBM-AddMsg.txt"),
debug = readFile(path .. "/" .. "4-DBM-Debug.txt"),
}
end
end
return tests
end
local function diffTest(before, after)
local diff = {}
if before and after then
if before.addMsg == after.addMsg and before.debug == after.debug and before.errors == after.errors and before.report == after.report then
diff.state = "Unchanged"
diff.description = "Test output did not change."
elseif before.errors == "" and after.errors ~= "" then
diff.state = "Error"
diff.description = "Test has new errors."
else
diff.state = "Info"
local messages = {}
if before.errors ~= after.errors then
messages[#messages + 1] = "Test has different errors than before."
diff.state = "Error"
end
if before.report ~= after.report then
messages[#messages + 1] = "Test report changed."
end
if before.addMsg ~= after.addMsg then
messages[#messages + 1] = "DBM:AddMsg() output changed."
end
if before.debug ~= after.debug then
messages[#messages + 1] = "DBM:Debug() output changed."
end
diff.description = table.concat(messages, " ")
end
elseif not after then
diff.state = "Info"
diff.description = "Test deleted."
elseif not before then
if after.errors ~= "" then
diff.state = "Error"
diff.description = "Test has new errors."
else
diff.state = "Info"
diff.description = "New test."
end
end
local report = after and after.report or before.report
diff.name = report:match("\nTest: (.-)\r?\n")
return diff
end
local function diff(before, after)
local testDiffs = {}
for k in pairs(before) do
testDiffs[k] = diffTest(before[k], after[k])
end
for k in pairs(after) do
if not testDiffs[k] then
testDiffs[k] = diffTest(before[k], after[k])
end
end
return testDiffs
end
local before = gatherFiles(dirBefore)
local after = gatherFiles(dirAfter)
local diffs = diff(before, after)
local sortedDiffs = {}
local numTests = 0
for _, v in pairs(diffs) do
numTests = numTests + 1
if v.state ~= "Unchanged" then
sortedDiffs[#sortedDiffs + 1] = v
end
end
table.sort(sortedDiffs, function(e1, e2)
if e1.state == e2.state then
return e1.name < e2.name
else
return e1.state < e2.state
end
end)
print(("Executed %d boss mod tests."):format(numTests))
if #sortedDiffs == 0 then
print("No diffs found. [View full test results]({{fullResultsLink}}).")
else
print("[View full diff of all tests]({{fullDiffLink}}).")
print()
print("|Status|Test|Description|")
print("|:-----|:---|:----------|")
end
local stateToEmoji = {
["Info"] = "ℹ️",
["Error"] = "⚠️",
}
for k, v in ipairs(sortedDiffs) do
print(("|%s|%s|%s|"):format(stateToEmoji[v.state] or v.state, v.name, v.description))
end