-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomponentlint.lua
145 lines (126 loc) · 4.3 KB
/
componentlint.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!lua
local files = {}
for k, v in ipairs(arg) do
if k > 0 then
table.insert(files, v)
end
end
if #files == 0 then
print("No files to lint!")
os.exit(1)
end
require("lib/shared")
EMVU = {stored = {}}
function EMVU.AddAutoComponent(emvu, data, name)
local runner = RUNNER:New()
runner.name = name:Replace(" ", "_")
function runner:testName()
self:AssertIsNotNumeric(name)
self:AssertIsNonEmptyString(name)
end
function runner:testModel()
self:AssertIsNilOrString(data.Model)
if data.Model then
self:AssertIsNonEmptyString(data.Model)
self:AssertIsNotNumeric(data.Model)
self:Assert(data.Model:sub(1, 7) == "models/", self:_assertMessage(data.Model, "in the models/ directory"))
end
end
function runner:testSkin()
self:AssertIsNilOrNumber(data.Skin)
end
function runner:testBodygroups()
self:AssertIsNilOrTable(data.Bodygroups)
if data.Bodygroups then
for id, bgdata in ipairs(data.Bodygroups) do
self:AssertIsTable(bgdata)
local bgid, bgval = bgdata[1], bgdata[2]
self:AssertIsNumeric(bgid, self:_assertMessage(
string.format("bodygroup key ('%s')", tostring(bgid)),
"numeric"
))
self:AssertIsNumeric(bgval, self:_assertMessage(
string.format("bodygroup value ('%s')", tostring(bgid)),
"numeric"
))
end
end
end
function runner:testColorInput()
self:AssertIsNilOrTable(data.DefaultColors)
if data.DefaultColors then
for id, color in pairs(data.DefaultColors) do
self:AssertIsNumeric(id)
self:AssertIsString(color)
end
end
if data.Sections then
for sectionID, sectionData in pairs(data.Sections) do
for frameID, lights in ipairs(sectionData) do
for lightIdx, light in ipairs(lights) do
local col = light[2]
if col:StartWith("_") then
local colId = tonumber(col:sub(2))
self:AssertIsString(data.DefaultColors[colId], self:_assertMessage(string.format("default color ('%s' / %s)", col, colId), "string"))
end
end
end
end
end
end
if data.Meta then
for id, meta in pairs(data.Meta) do
runner["testMeta" .. id] = function(self)
self:Assert(isnumber(meta.AngleOffset) or meta.AngleOffset == "R", self:_assertMessage(meta.AngleOffset, "number or 'R'"))
self:AssertIsNumber(meta.W)
self:AssertIsNumber(meta.H)
self:AssertIsString(meta.Sprite)
self:AssertIsNilOrNumber(meta.WMult)
self:AssertIsNilOrNumber(meta.Scale)
end
end
end
runner:Test()
table.insert(emvu.stored, runner)
end
local badFiles = {}
for _, file in ipairs(files) do
local success, msg = pcall(dofile, file)
if not success then
table.insert(badFiles, {file, msg})
end
end
local failed = {}
local succeeded = 0
local asserts = 0
for _, runner in ipairs(EMVU.stored) do
for _, test in ipairs(runner.tests) do
if test.success then
succeeded = succeeded + 1
asserts = asserts + test.assertions
else
print(test)
table.insert(failed, string.format(
"Test %s :: [%s][%s]\n\t%s",
test.errored and "Errored" or "Failed",
runner.name,
test.name,
test.errored and test.error or test.message
))
end
end
end
for _, file in ipairs(badFiles) do
print("Error whilst loading " .. file[1] .. "\n\t" .. file[2])
end
local count = #failed
local tests = succeeded + #failed
local sirens = #EMVU.stored
print(string.format(
"Stats:\n\tFiles Failed: %d\n\tComponents Checked: %d\n\tTests Ran: %d\n\tTests Succeeded: %d\n\tTests Failed: %d\n\tAssertions: %d",
#badFiles, sirens, tests, succeeded, count, asserts
))
for _, msg in ipairs(failed) do
print(msg)
end
os.exit(math.min(count, 1))