File: format_spec.lua

package info (click to toggle)
luacheck 0.17.1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 968 kB
  • ctags: 731
  • sloc: python: 35; makefile: 18
file content (205 lines) | stat: -rw-r--r-- 4,487 bytes parent folder | download
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
200
201
202
203
204
205
local format = require "luacheck.format".format

local function mark_colors(s)
   return (s:gsub("\27%[%d+m", "\27"):gsub("\27+", "#"))
end

describe("format", function()
   it("returns formatted report", function()
      assert.equal([[Checking stdin                                    1 warning

    stdin:2:7: unused global variable 'foo'

Checking foo.lua                                  1 warning

    foo.lua:2:7: empty statement

Checking bar.lua                                  OK
Checking baz.lua                                  1 error

    baz.lua:4:3: something went wrong

Total: 2 warnings / 1 error in 4 files]], format({
   warnings = 2,
   errors = 1,
   fatals = 0,
   {
      {
         code = "131",
         name = "foo",
         line = 2,
         column = 7
      }
   },
   {
      {
         code = "551",
         line = 2,
         column = 7
      }
   },
   {},
   {
      {
         code = "011",
         line = 4,
         column = 3,
         msg = "something went wrong"
      }
   }
}, {"stdin", "foo.lua", "bar.lua", "baz.lua"}, {color = false}))
   end)

   it("does not output OK messages with options.quiet >= 1", function()
      assert.equal([[Checking stdin                                    1 warning

    stdin:2:7: unused global variable 'foo'

Checking foo.lua                                  1 warning / 1 error

    foo.lua:2:7: unused global variable 'foo'
    foo.lua:3:10: invalid inline option

Checking baz.lua                                  Syntax error

    baz.lua: error message

Total: 2 warnings / 1 error in 3 files, couldn't check 1 file]], format({
   warnings = 2,
   errors = 1,
   fatals = 1,
   {
      {
         code = "131",
         name = "foo",
         line = 2,
         column = 7
      }
   },
   {
      {
         code = "131",
         name = "foo",
         line = 2,
         column = 7
      },
      {
         code = "021",
         line = 3,
         column = 10
      }
   },
   {},
   {
      fatal = "syntax",
      msg = "error message"
   }
}, {"stdin", "foo.lua", "bar.lua", "baz.lua"}, {quiet = 1, color = false}))
   end)

   it("does not output warnings with options.quiet >= 2", function()
      assert.equal([[Checking stdin                                    1 warning
Checking foo.lua                                  1 warning
Checking baz.lua                                  Syntax error

Total: 2 warnings / 0 errors in 3 files, couldn't check 1 file]], format({
   warnings = 2,
   errors = 0,
   fatals = 1,
   {
      {
         code = "131",
         name = "foo",
         line = 2,
         column = 7
      }
   },
   {
      {
         code = "131",
         name = "foo",
         line = 2,
         column = 7
      }
   },
   {},
   {
      fatal = "syntax"
   }
}, {"stdin", "foo.lua", "bar.lua", "baz.lua"}, {quiet = 2, color = false}))
   end)

   it("does not output file info with options.quiet == 3", function()
      assert.equal("Total: 2 warnings / 0 errors in 3 files, couldn't check 1 file", format({
   warnings = 2,
   errors = 0,
   fatals = 1,
   {
      {
         code = "131",
         name = "foo",
         line = 2,
         column = 7
      }
   },
   {
      {
         code = "131",
         name = "foo",
         line = 2,
         column = 7
      }
   },
   {},
   {
      fatal = "syntax"
   }
}, {"stdin", "foo.lua", "bar.lua", "baz.lua"}, {quiet = 3, color = false}))
   end)

   it("colors output by default", function()
      if package.config:sub(1, 1) == "\\" and not os.getenv("ANSICON") then
         pending("uses terminal colors")
      end

      assert.equal([[Checking stdin                                    #1 warning#

    stdin:2:7: unused global variable #foo#

Checking foo.lua                                  #1 warning#

    foo.lua:2:7: unused global variable #foo#

Checking bar.lua                                  #OK#
Checking baz.lua                                  #Syntax error#

    baz.lua: error message

Total: #2# warnings / #0# errors in 3 files, couldn't check 1 file]], mark_colors(format({
   warnings = 2,
   errors = 0,
   fatals = 1,
   {
      {
         code = "131",
         name = "foo",
         line = 2,
         column = 7
      }
   },
   {
      {
         code = "131",
         name = "foo",
         line = 2,
         column = 7
      }
   },
   {},
   {
      fatal = "syntax",
      msg = "error message"
   }
}, {"stdin", "foo.lua", "bar.lua", "baz.lua"}, {})))
   end)
end)