Skip to content

Commit 5a0804e

Browse files
committed
clean up tests
1 parent dab3ea3 commit 5a0804e

15 files changed

+302
-351
lines changed

test/diagnostics/common.lua

Lines changed: 0 additions & 296 deletions
Original file line numberDiff line numberDiff line change
@@ -1,298 +1,6 @@
11
local config = require 'config'
22
local util = require 'utility'
33

4-
local disables = config.get(nil, 'Lua.diagnostics.disable')
5-
6-
TEST [[
7-
local <!x!>
8-
]]
9-
10-
TEST [[
11-
local y
12-
local x <close> = y
13-
]]
14-
15-
TEST [[
16-
local function x()
17-
end
18-
x()
19-
]]
20-
21-
TEST [[
22-
return function (x)
23-
x.a = 1
24-
end
25-
]]
26-
27-
TEST [[
28-
local <!t!> = {}
29-
<!t!>.a = 1
30-
]]
31-
32-
TEST [[
33-
local <!function <!x!>()
34-
end!>
35-
]]
36-
37-
38-
TEST [[
39-
local <!x!> = <!function () end!>
40-
]]
41-
42-
TEST [[
43-
local <!x!>
44-
<!x!> = <!function () end!>
45-
]]
46-
47-
TEST [[
48-
local <!function x()
49-
end!>
50-
local <!function <!y!>()
51-
x()
52-
end!>
53-
]]
54-
55-
TEST [[
56-
local print, _G
57-
print(<!x!>)
58-
print(<!log!>)
59-
print(<!X!>)
60-
print(<!Log!>)
61-
print(<!y!>)
62-
print(Z)
63-
print(_G)
64-
Z = 1
65-
]]
66-
67-
TEST [[
68-
::<!LABEL!>::
69-
]]
70-
71-
TEST [[
72-
<! !>
73-
]]
74-
75-
TEST [[
76-
77-
<! !>
78-
]]
79-
80-
TEST [[
81-
X = 1<! !>
82-
]]
83-
84-
TEST [[
85-
X = [=[
86-
]=]
87-
]]
88-
89-
TEST [[
90-
-- xxxx
91-
]]
92-
93-
TEST [[
94-
-- [=[
95-
]=]
96-
]]
97-
98-
TEST [[
99-
local x
100-
print(x)
101-
local <!x!>
102-
print(x)
103-
]]
104-
105-
TEST [[
106-
local x
107-
print(x)
108-
local <!x!>
109-
print(x)
110-
local <!x!>
111-
print(x)
112-
]]
113-
114-
TEST [[
115-
local _
116-
print(_)
117-
local _
118-
print(_)
119-
local _ENV
120-
<!print!>(_ENV) -- 由于重定义了_ENV,因此print变为了未定义全局变量
121-
]]
122-
123-
TEST [[
124-
local x
125-
return x, function (<!x!>)
126-
return x
127-
end
128-
]]
129-
130-
TEST [[
131-
print(1)
132-
_ENV = nil
133-
]]
134-
135-
TEST [[
136-
---@diagnostic disable: undefined-global
137-
_ENV = nil
138-
<!print!>(<!A!>) -- `print` and `A` should warning
139-
]]
140-
141-
TEST [[
142-
---@diagnostic disable: undefined-global
143-
local _ENV = nil
144-
<!print!>(<!A!>) -- `print` and `A` should warning
145-
]]
146-
147-
TEST [[
148-
_ENV = {}
149-
print(A) -- no warning
150-
]]
151-
152-
TEST [[
153-
local _ENV = {}
154-
print(A) -- no warning
155-
]]
156-
157-
TEST [[
158-
---@type iolib
159-
_ENV = io
160-
<!print!>(stderr) -- `print` is warning but `stderr` is not
161-
]]
162-
163-
TEST [[
164-
---@type iolib
165-
local _ENV = io
166-
<!print!>(stderr) -- `print` is warning but `stderr` is not
167-
]]
168-
169-
TEST [[
170-
local _ENV = { print = print }
171-
print(1)
172-
]]
173-
174-
util.arrayInsert(disables, 'undefined-env-child')
175-
TEST [[
176-
_ENV = nil
177-
<!GLOBAL!> = 1 --> _ENV.GLOBAL = 1
178-
]]
179-
180-
TEST [[
181-
_ENV = nil
182-
local _ = <!print!> --> local _ = _ENV.print
183-
]]
184-
185-
TEST [[
186-
_ENV = {}
187-
GLOBAL = 1 --> _ENV.GLOBAL = 1
188-
]]
189-
190-
TEST [[
191-
_ENV = {}
192-
local _ = print --> local _ = _ENV.print
193-
]]
194-
195-
TEST [[
196-
GLOBAL = 1
197-
_ENV = nil
198-
]]
199-
200-
util.arrayRemove(disables, 'undefined-env-child')
201-
TEST [[
202-
<!print()
203-
('string')!>:sub(1, 1)
204-
]]
205-
206-
TEST [[
207-
print()
208-
('string')
209-
]]
210-
211-
TEST [[
212-
print
213-
{}
214-
{}
215-
]]
216-
217-
TEST [[
218-
local x
219-
return x
220-
: f(1)
221-
: f(1)
222-
]]
223-
224-
TEST [[
225-
return {
226-
<!print
227-
'string'!>
228-
}
229-
]]
230-
231-
TEST [[
232-
return {
233-
<!print
234-
{
235-
x = 1,
236-
}!>
237-
}
238-
]]
239-
240-
TEST [[
241-
print()
242-
'string'
243-
]]
244-
245-
TEST [[
246-
print
247-
{
248-
x = 1,
249-
}
250-
]]
251-
252-
TEST [[
253-
local function x(a, b)
254-
return a, b
255-
end
256-
x(1, 2, <!3!>)
257-
]]
258-
259-
TEST [[
260-
local function x(a, b, ...)
261-
return a, b, ...
262-
end
263-
x(1, 2, 3, 4, 5)
264-
]]
265-
266-
TEST [[
267-
---@type fun(a, b, ...)
268-
local x
269-
x(1, 2, 3, 4, 5)
270-
]]
271-
272-
TEST [[
273-
local m = {}
274-
function m:x(a, b)
275-
return a, b
276-
end
277-
m:x(1, 2, <!3!>)
278-
]]
279-
280-
TEST [[
281-
local m = {}
282-
function m:x(a, b)
283-
return a, b
284-
end
285-
m.x(m, 2, 3, <!4!>)
286-
]]
287-
288-
TEST [[
289-
local m = {}
290-
function m.x(a, b)
291-
return a, b
292-
end
293-
m:x(1, <!2!>, <!3!>, <!4!>)
294-
]]
295-
2964
TEST [[
2975
local function x(a, b)
2986
return a, b
@@ -329,8 +37,6 @@ x(1, 2)
32937
]]
33038

33139
TEST [[
332-
---@diagnostic disable: unused-local
333-
33440
---@param a integer
33541
---@param b integer
33642
local function f(a, b)
@@ -340,8 +46,6 @@ f(...)
34046
]]
34147

34248
TEST [[
343-
---@diagnostic disable: unused-local
344-
34549
---@param a integer
34650
---@param b integer
34751
local function f(a, b)

test/diagnostics/global-element.lua

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,5 @@
11
local config = require 'config'
2-
local util = require 'utility'
32

4-
-- disable all default groups to make isolated tests
5-
config.set(nil, 'Lua.diagnostics.groupFileStatus',
6-
{
7-
['ambiguity'] = 'None',
8-
['await'] = 'None',
9-
['codestyle'] = 'None',
10-
['conventions'] = 'None',
11-
['duplicate'] = 'None',
12-
['global'] = 'None',
13-
['luadoc'] = 'None',
14-
['redefined'] = 'None',
15-
['strict'] = 'None',
16-
['strong'] = 'None',
17-
['type-check'] = 'None',
18-
['unbalanced'] = 'None',
19-
['unused'] = 'None'
20-
})
21-
22-
-- enable single diagnostic that is to be tested
23-
config.set(nil, 'Lua.diagnostics.neededFileStatus',
24-
{
25-
['global-element'] = 'Any!' -- override groupFileStatus
26-
})
27-
28-
-- check that local elements are not warned about
293
TEST [[
304
local x = 123
315
x = 321
@@ -87,11 +61,3 @@ function GLOBAL_CLOSURE()
8761
<!elem2!> = 2
8862
end
8963
]]
90-
91-
-- reset configurations
92-
config.set(nil, 'Lua.diagnostics.groupFileStatus',
93-
{})
94-
config.set(nil, 'Lua.diagnostics.neededFileStatus',
95-
{})
96-
config.set(nil, 'Lua.diagnostics.globals',
97-
{})
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
TEST [[
2+
local _
3+
print(_)
4+
local _
5+
print(_)
6+
local _ENV
7+
<!print!>(_ENV) -- 由于重定义了_ENV,因此print变为了未定义全局变量
8+
]]
9+
10+
TEST [[
11+
_ENV = nil
12+
<!print!>(<!A!>) -- `print` and `A` should warning
13+
]]
14+
15+
TEST [[
16+
local _ENV = nil
17+
<!print!>(<!A!>) -- `print` and `A` should warning
18+
]]
19+
20+
TEST [[
21+
_ENV = {}
22+
print(A) -- no warning
23+
]]
24+
25+
TEST [[
26+
local _ENV = {}
27+
print(A) -- no warning
28+
]]
29+
30+
TEST [[
31+
_ENV = nil
32+
<!GLOBAL!> = 1 --> _ENV.GLOBAL = 1
33+
]]
34+
35+
TEST [[
36+
_ENV = nil
37+
local _ = <!print!> --> local _ = _ENV.print
38+
]]

0 commit comments

Comments
 (0)