Repository navigation
Expand file tree
/
Copy pathcheck_spec.lua
More file actions
105 lines (96 loc) · 3.04 KB
/
Copy pathcheck_spec.lua
File metadata and controls
105 lines (96 loc) · 3.04 KB
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
local util = require("spec.util")
describe("check command", function()
it("should do basic type checking of a single file", function()
util.run_mock_project(finally, {
cmd = "check",
args = { "foo.tl" },
dir_structure = {
["foo.tl"] = [[local x: number = "hello"]]
},
cmd_output_match = "Error",
exit_code = 1,
})
end)
it("should do basic type checking of many files", function()
util.run_mock_project(finally, {
cmd = "check",
args = { "foo.tl", "bar.tl" },
dir_structure = {
["foo.tl"] = [[local _x: number = "hello"]],
["bar.tl"] = [[local _x: string = "hello"]],
},
cmd_output_match_lines = {
[1] = "Error.*%d.*foo%.tl",
[6] = "Type checked.*bar%.tl",
},
exit_code = 1,
})
end)
it("should report errors in dependencies", function()
util.run_mock_project(finally, {
cmd = "check",
args = { "foo.tl" },
dir_structure = {
["foo.tl"] = [[require"bar"]],
["bar.tl"] = [[local _x: number = "hello"]],
},
-- cmd_output_match_lines = {
-- },
exit_code = 1,
})
end)
it("should handle being told to type check a non-file", function()
util.run_mock_project(finally, {
cmd = "check",
args = { "foo" },
dir_structure = {
foo = {},
},
cmd_output_match = "is not a file",
exit_code = 1,
})
end)
it("should chdir into the root before checking", function()
util.do_in(util.write_tmp_dir(finally, {
[util.configfile] = [[return {}]],
foo = {
["bar.tl"] = [[require("foo.baz")]],
["baz.tl"] = [[return 10]],
},
}), function()
local out = util.run_command("cd foo && " .. util.cyan_cmd("check", "bar.tl") .. " 2>&1")
assert.match("Type checked", out)
end)
end)
it("should show type errors along with the line that they occur on", function()
util.run_mock_project(finally, {
cmd = "check",
args = { "foo.tl" },
dir_structure = {
["foo.tl"] = [[local x: string = 10]],
},
cmd_output_match = [[1.-|.-local.-x: string]],
exit_code = 1,
})
end)
it("should properly report syntax errors", function()
util.run_mock_project(finally, {
cmd = "check",
args = { "foo.tl" },
dir_structure = {
["foo.tl"] = [[print(1 != 2)]]
},
cmd_output_match = [[syntax error]],
exit_code = 1,
})
end)
it("should work with a relative path in the parent directory", function()
util.do_in(util.write_tmp_dir(finally, {
["foo.tl"] = [[local _: integer = 1]],
bar = {},
}), function()
local out = util.run_command("cd bar && " .. util.cyan_cmd("check", "../foo.tl") .. " 2>&1")
assert.match("Type checked", out)
end)
end)
end)