forked from RealNeGate/Cuik
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tests.lua
57 lines (48 loc) · 1.03 KB
/
tests.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
function test(file)
local f = io.open(file, "rb")
-- find expected list
local expected = {}
for l in f:lines() do
local comment = l:match('//#(.*)')
if comment ~= nil then
expected[#expected + 1] = comment
end
end
f:close()
-- run compiler
local cmd = "cuik "..file.." -o test/a.out 2>&1"
print(cmd)
local compiler_result = io.popen(cmd)
local got = {}
for l in compiler_result:lines() do
got[#got + 1] = l
end
local exit = compiler_result:close()
if exit ~= 0 then
print("Failed to compile "..file)
print("Output:")
for i, l in ipairs(got) do
print(l)
end
os.exit(1)
end
local correct = true
for i, l in ipairs(got) do
if not supress then
if i <= #expected then
-- not enough expected
print("output is too short!")
elseif expected[i] ~= l then
print("line "..i.." is incorrect:")
print(" expected: '"..expected[i].."'")
print(" got: '"..l.."'")
correct = false
end
end
end
if not correct then
os.exit(1)
end
end
test("tests/hello_world.c")
print("Hello")