-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathtestgen.lua
38 lines (32 loc) · 824 Bytes
/
testgen.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
local lfs = require "lfs"
local path, testfile = ...
testfile = testfile or "test.lua"
assert(path)
lfs.chdir(path)
local function gen_test(file)
local out = { "-- " .. file, "", "s = [=[" }
for line in io.lines(file) do
out[#out+1] = line
end
out[#out+1] = "]=]"
out[#out+1] = ""
out[#out+1] = "e = [=["
os.execute("tlc " .. file .. " > out.txt 2> out.txt")
for line in io.lines("out.txt") do
if line:match(file) then
out[#out+1] = line:gsub(file, testfile)
end
end
out[#out+1] = "]=]"
out[#out+1] = ""
out[#out+1] = "r = typecheck(s)"
out[#out+1] = "check(e, r)"
out[#out+1] = ""
os.remove("out.txt")
print(table.concat(out, "\n"))
end
for file in lfs.dir(".") do
if lfs.attributes(file, "mode") == "file" and file:match("%.tl$") then
gen_test(file)
end
end