-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.lua
199 lines (162 loc) · 4.88 KB
/
test.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/usr/bin/env luvit
local fs = require"fs"
local http, https = require"http", require"https"
local jit = require"jit"
local OS = require"los".type()
local timer = require"timer"
-- thanks to https://github.com/zerkman/zzlib
local zzlib = require"./tests/zzlib"
local toml_test = {
version = "v1.4.0",
repo = "https://github.com/toml-lang/toml-test/",
-- version/filename
release = "releases/download/%s/%s",
-- version-os-arch
filename = "toml-test-%s-%s-%s.gz",
x64 = "amd64",
arm64 = "arm64",
linux = "linux",
win32 = "windows",
osx = "darwin",
bsd = "openbsd"
}
local skips = {
-- trailling coma are cool (don't want to switch to toml v1.1.0 as it's not official)
"invalid/inline-table/trailing-comma",
-- aren't we supposed to put anything we want in a comment ????
"invalid/encoding/bad-codepoint",
"invalid/encoding/bad-utf8-in-comment",
"invalid/control/comment-*",
-- I'm too dumb to rewrite lua's number or something like that
"valid/integer/long",
-- don't know how to implement that without breaking every other valid use cases
"invalid/table/redefine-2",
"invalid/table/append-with-dotted-keys-*",
-- idk and idc (unless it's an issue for you)
"invalid/encoding/*"
}
local function httpget(url, callback)
url = http.parseUrl(url)
local req = (url.protocol == 'https' and https or http).get(url, function(res)
local body={}
res:on('data', function(s)
body[#body+1] = s
end)
res:on('end', function()
res.body = table.concat(body)
coroutine.wrap(callback)(res)
end)
res:on('error', function(err)
coroutine.wrap(callback)(res, err)
end)
end)
req:on('error', function(err)
coroutine.wrap(callback)(nil, err)
end)
end
if not fs.existsSync"./tests/toml-test" then
print("toml-test not found")
local OS = toml_test[OS] or OS
local arch = toml_test[jit.arch] or jit.arch
local file = toml_test.filename:format(toml_test.version, OS, arch)
local release = toml_test.release:format(toml_test.version, file)
print(("downloading toml-test\n\tversion: \t%s \n\tfor: \t\t%s-%s \n\tfrom: \t\t%s"):format(toml_test.version, OS, arch, toml_test.repo))
local done, status, data
print("> " .. toml_test.repo .. release)
httpget(toml_test.repo..release, function(res, err)
if res then print("> status " .. res.statusCode) end
if err then
print("ERROR", err)
done, data, status = true, res.body, res.statusCode
else
if res.statusCode == 302 then
print("> following redirection...")
httpget(res.headers["Location"], function(res, err)
if res then print("> status " .. res.statusCode) end
if err then
print("ERROR", err)
done, data, status = true, res.body, res.statusCode
else
done, data, status = true, res.body, res.statusCode
end
end) --httpget location
else
done, data, status = true, res.body, res.statusCode
end
end
end)-- httpget
local i = 0
while not done do
local thread = coroutine.running()
timer.setTimeout(1000, function ()
coroutine.resume(thread)
i = i + 1
end)
coroutine.yield()
if i >= 30 then
break
end
end
if not done then
print("Downloading took too long, aborting.")
os.exit(1)
end
if status ~= 200 or #data <= 0 then
print("Failed to download toml-test. please download it by hand to 'tests/toml-test'")
os.exit(1)
end
print("> decompressing...")
local decompressed, err = zzlib.gunzip(data)
if not decompressed then
print("ERROR cannot decompress:", err)
end
fs.writeFileSync("tests/toml-test", decompressed)
print("> decompressed to tests/toml-test")
---@diagnostic disable-next-line: cast-local-type
decompressed, data = nil, nil
collectgarbage("collect")
end
local runtime = args[2] or "luvit"
print("Using lua runtime:", runtime)
local test = os.execute(runtime .. " -v")
if not test then
print("ERROR: Cannot use this runtime. Ensure '" .. runtime .. "' is in the PATH.")
os.exit(1)
end
print("===============")
local file, err = io.popen(runtime.." ./tests/info.lua", "r")
if not file then
print("ERROR: cannot dump information tests/info.lua: ", err)
os.exit(1)
end
local failed = false
file:flush()
for line in file:lines() do
if line:match("^failed") then
failed = true
end
print(line)
end
file:close()
if failed then
os.exit(1)
end
-- actual test
print("===============")
print("starting decoder checking:")
local cmd = "./tests/toml-test -testdir ./tests/tests "..runtime.." ./tests/decoder.lua"
for i,v in ipairs(skips) do
cmd = cmd .. " -skip \""..v.."\""
end
print("> "..cmd)
local decode, err = io.popen(cmd, "r")
if not decode then
print("ERROR: start tests : ", err)
os.exit(1)
end
decode:flush()
for line in decode:lines() do
print(line)
end
decode:close()
print("===============")