-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathtc_test.rb
348 lines (312 loc) · 13.9 KB
/
tc_test.rb
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
# typed: true
# frozen_string_literal: true
require "test_with_project"
module Spoom
module Cli
module Srb
class TcTest < TestWithProject
def setup
@project.bundle_install!
@project.write!("file.rb", "# typed: true")
@project.write!("errors/errors.rb", <<~RB)
# typed: true
# frozen_string_literal: true
class Foo
sig { params(bar: Bar).returns(C) }
def foo(bar)
end
end
b = Foo.new(42)
b.foo(b, c)
RB
end
def test_timeline_outside_sorbet_dir
@project.remove!("sorbet/config")
result = @project.spoom("srb tc --no-color")
assert_empty(result.out)
assert_equal("Error: not in a Sorbet project (`sorbet/config` not found)", result.err&.lines&.first&.chomp)
refute(result.status)
end
def test_display_no_errors_without_filter
@project.write_sorbet_config!("file.rb")
result = @project.spoom("srb tc")
assert_equal(<<~MSG, result.err)
No errors! Great job.
MSG
assert(result.status)
end
def test_display_no_errors_with_sort
@project.write_sorbet_config!("file.rb")
result = @project.spoom("srb tc --no-color -s")
assert_equal(<<~MSG, result.err)
No errors! Great job.
MSG
assert(result.status)
end
def test_display_errors_with_bad_sort
result = @project.spoom("srb tc --no-color -s bad")
assert_equal(<<~MSG, result.err)
Expected '--sort' to be one of code, loc; got bad
MSG
refute(result.status)
end
def test_display_errors_with_sort_default
result = @project.spoom("srb tc --no-color -s")
assert_equal(<<~MSG, result.err)
5002 - errors/errors.rb:5: Unable to resolve constant `Bar`
5002 - errors/errors.rb:5: Unable to resolve constant `C`
7003 - errors/errors.rb:5: Method `params` does not exist on `T.class_of(Foo)`
7003 - errors/errors.rb:5: Method `sig` does not exist on `T.class_of(Foo)`
7004 - errors/errors.rb:10: Wrong number of arguments for constructor. Expected: `0`, got: `1`
7003 - errors/errors.rb:11: Method `c` does not exist on `T.class_of(<root>)`
7004 - errors/errors.rb:11: Too many arguments provided for method `Foo#foo`. Expected: `1`, got: `2`
Errors: 7
MSG
refute(result.status)
end
def test_display_errors_with_sort_default_with_custom_url
@project.write_sorbet_config!(<<~CONFIG)
.
--error-url-base=https://custom#
CONFIG
result = @project.spoom("srb tc --no-color -s")
assert_equal(<<~MSG, result.err)
5002 - errors/errors.rb:5: Unable to resolve constant `Bar`
5002 - errors/errors.rb:5: Unable to resolve constant `C`
7003 - errors/errors.rb:5: Method `params` does not exist on `T.class_of(Foo)`
7003 - errors/errors.rb:5: Method `sig` does not exist on `T.class_of(Foo)`
7004 - errors/errors.rb:10: Wrong number of arguments for constructor. Expected: `0`, got: `1`
7003 - errors/errors.rb:11: Method `c` does not exist on `T.class_of(<root>)`
7004 - errors/errors.rb:11: Too many arguments provided for method `Foo#foo`. Expected: `1`, got: `2`
Errors: 7
MSG
refute(result.status)
end
def test_display_errors_with_sort_loc
result = @project.spoom("srb tc --no-color -s loc")
assert_equal(<<~MSG, result.err)
5002 - errors/errors.rb:5: Unable to resolve constant `Bar`
5002 - errors/errors.rb:5: Unable to resolve constant `C`
7003 - errors/errors.rb:5: Method `params` does not exist on `T.class_of(Foo)`
7003 - errors/errors.rb:5: Method `sig` does not exist on `T.class_of(Foo)`
7004 - errors/errors.rb:10: Wrong number of arguments for constructor. Expected: `0`, got: `1`
7003 - errors/errors.rb:11: Method `c` does not exist on `T.class_of(<root>)`
7004 - errors/errors.rb:11: Too many arguments provided for method `Foo#foo`. Expected: `1`, got: `2`
Errors: 7
MSG
refute(result.status)
end
def test_display_errors_with_sort_code
result = @project.spoom("srb tc --no-color -s code")
assert_equal(<<~MSG, result.err)
5002 - errors/errors.rb:5: Unable to resolve constant `Bar`
5002 - errors/errors.rb:5: Unable to resolve constant `C`
7003 - errors/errors.rb:5: Method `params` does not exist on `T.class_of(Foo)`
7003 - errors/errors.rb:5: Method `sig` does not exist on `T.class_of(Foo)`
7003 - errors/errors.rb:11: Method `c` does not exist on `T.class_of(<root>)`
7004 - errors/errors.rb:10: Wrong number of arguments for constructor. Expected: `0`, got: `1`
7004 - errors/errors.rb:11: Too many arguments provided for method `Foo#foo`. Expected: `1`, got: `2`
Errors: 7
MSG
refute(result.status)
end
def test_display_errors_with_sort_code_but_no_count
result = @project.spoom("srb tc --no-color -s code --no-count")
assert_equal(<<~MSG, result.err)
5002 - errors/errors.rb:5: Unable to resolve constant `Bar`
5002 - errors/errors.rb:5: Unable to resolve constant `C`
7003 - errors/errors.rb:5: Method `params` does not exist on `T.class_of(Foo)`
7003 - errors/errors.rb:5: Method `sig` does not exist on `T.class_of(Foo)`
7003 - errors/errors.rb:11: Method `c` does not exist on `T.class_of(<root>)`
7004 - errors/errors.rb:10: Wrong number of arguments for constructor. Expected: `0`, got: `1`
7004 - errors/errors.rb:11: Too many arguments provided for method `Foo#foo`. Expected: `1`, got: `2`
MSG
refute(result.status)
end
def test_display_errors_with_limit
result = @project.spoom("srb tc --no-color -s code -l 1")
assert_equal(<<~MSG, result.err)
5002 - errors/errors.rb:5: Unable to resolve constant `Bar`
Errors: 1 shown, 7 total
MSG
refute(result.status)
end
def test_display_errors_with_format
result = @project.spoom("srb tc --no-color -s code -f '%F:%L %M %C'")
assert_equal(<<~MSG, result.err)
errors/errors.rb:5 Unable to resolve constant `Bar` 5002
errors/errors.rb:5 Unable to resolve constant `C` 5002
errors/errors.rb:5 Method `params` does not exist on `T.class_of(Foo)` 7003
errors/errors.rb:5 Method `sig` does not exist on `T.class_of(Foo)` 7003
errors/errors.rb:11 Method `c` does not exist on `T.class_of(<root>)` 7003
errors/errors.rb:10 Wrong number of arguments for constructor. Expected: `0`, got: `1` 7004
errors/errors.rb:11 Too many arguments provided for method `Foo#foo`. Expected: `1`, got: `2` 7004
Errors: 7
MSG
refute(result.status)
end
def test_display_errors_with_format_partial
result = @project.spoom("srb tc --no-color -s code -f '%F'")
assert_equal(<<~MSG, result.err)
errors/errors.rb
errors/errors.rb
errors/errors.rb
errors/errors.rb
errors/errors.rb
errors/errors.rb
errors/errors.rb
Errors: 7
MSG
refute(result.status)
end
def test_display_errors_with_format_and_uniq
result = @project.spoom("srb tc --no-color -s code -f '%F' --no-count -u")
assert_equal(<<~MSG, result.err)
errors/errors.rb
MSG
refute(result.status)
end
def test_display_errors_with_code
result = @project.spoom("srb tc --no-color -c 7004")
assert_equal(<<~MSG, result.err)
7004 - errors/errors.rb:10: Wrong number of arguments for constructor. Expected: `0`, got: `1`
7004 - errors/errors.rb:11: Too many arguments provided for method `Foo#foo`. Expected: `1`, got: `2`
Errors: 2 shown, 7 total
MSG
refute(result.status)
end
def test_display_errors_with_limit_and_code
result = @project.spoom("srb tc --no-color -c 7004 -l 1")
assert_equal(<<~MSG, result.err)
7004 - errors/errors.rb:10: Wrong number of arguments for constructor. Expected: `0`, got: `1`
Errors: 1 shown, 7 total
MSG
refute(result.status)
end
def test_display_errors_with_limit_and_code_but_no_count
result = @project.spoom("srb tc --no-color -c 7004 -l 1 --no-count")
assert_equal(<<~MSG, result.err)
7004 - errors/errors.rb:10: Wrong number of arguments for constructor. Expected: `0`, got: `1`
MSG
refute(result.status)
end
def test_display_errors_from_path
@project = new_project
@project.write!("path_a/file1.rb", <<~RB)
# typed: true
foo
RB
@project.write!("path_a/file2.rb", <<~RB)
# typed: true
bar
RB
@project.write!("path_b/file1.rb", <<~RB)
# typed: true
baz
RB
result = @project.spoom("srb tc --no-color")
assert_equal(<<~MSG, result.err)
7003 - path_a/file1.rb:2: Method `foo` does not exist on `T.class_of(<root>)`
7003 - path_a/file2.rb:2: Method `bar` does not exist on `T.class_of(<root>)`
7003 - path_b/file1.rb:2: Method `baz` does not exist on `T.class_of(<root>)`
Errors: 3
MSG
refute(result.status)
result = @project.spoom("srb tc --no-color path_a/file1.rb")
assert_equal(<<~MSG, result.err)
7003 - path_a/file1.rb:2: Method `foo` does not exist on `T.class_of(<root>)`
Errors: 1 shown, 3 total
MSG
refute(result.status)
result = @project.spoom("srb tc --no-color path_a")
assert_equal(<<~MSG, result.err)
7003 - path_a/file1.rb:2: Method `foo` does not exist on `T.class_of(<root>)`
7003 - path_a/file2.rb:2: Method `bar` does not exist on `T.class_of(<root>)`
Errors: 2 shown, 3 total
MSG
refute(result.status)
result = @project.spoom("srb tc --no-color path_a/file1.rb path_b/file1.rb")
assert_equal(<<~MSG, result.err)
7003 - path_a/file1.rb:2: Method `foo` does not exist on `T.class_of(<root>)`
7003 - path_b/file1.rb:2: Method `baz` does not exist on `T.class_of(<root>)`
Errors: 2 shown, 3 total
MSG
refute(result.status)
end
def test_display_errors_with_path_option
project = new_project("test_display_errors_with_path_option_2")
result = project.spoom("srb tc --no-color -s code -l 1 -p #{@project.absolute_path}")
assert_equal(<<~MSG, result.err)
5002 - errors/errors.rb:5: Unable to resolve constant `Bar`
Errors: 1 shown, 7 total
MSG
refute(result.status)
project.destroy!
end
def test_pass_options_to_sorbet
result = @project.spoom("srb tc --no-color --sorbet-options \"--no-config -e 'foo'\"")
assert_equal(<<~MSG, result.err)
7003 - -e:1: Method `foo` does not exist on `T.class_of(<root>)`
Errors: 1
MSG
refute(result.status)
end
def test_display_sorbet_segfault
# Create a fake Sorbet that will segfault
@project.write!("mock_sorbet", <<~RB)
#!/usr/bin/env ruby
$stderr.puts "segfault"
exit(#{Spoom::Sorbet::SEGFAULT_CODE})
RB
@project.exec("chmod +x mock_sorbet")
# Any file will segfault with this
@project.write!("will_segfault.rb", <<~RB)
# typed: true
foo
RB
result = @project.spoom("srb tc --no-color --sorbet #{@project.absolute_path}/mock_sorbet")
assert_equal(<<~OUT, result.err)
!!! Sorbet exited with code 139 - SEGFAULT !!!
This is most likely related to a bug in Sorbet.
OUT
refute(result.status)
end
def test_display_sorbet_killed
# Create a fake Sorbet that will segfault
@project.write!("mock_sorbet", <<~RB)
#!/usr/bin/env ruby
$stderr.puts "segfault"
exit(#{Spoom::Sorbet::KILLED_CODE})
RB
@project.exec("chmod +x mock_sorbet")
# Any file will segfault with this
@project.write!("will_segfault.rb", <<~RB)
# typed: true
foo
RB
result = @project.spoom("srb tc --no-color --sorbet #{@project.absolute_path}/mock_sorbet")
assert_equal(<<~OUT, result.err)
!!! Sorbet exited with code 137 - KILLED !!!
OUT
refute(result.status)
end
def test_display_sorbet_error
result = @project.spoom("srb tc --no-color --sorbet-options=\"--not-found\"")
assert_equal(<<~MSG, result.err)
Option ‘not-found’ does not exist. To see all available options pass `--help`.
MSG
refute(result.status)
end
def test_deprecated_command_spoom_tc
@project.remove!("errors")
result = @project.spoom("tc --no-color")
assert_equal(<<~MSG, result.err)
Warning: This command is deprecated. Please use `spoom srb tc` instead.
No errors! Great job.
MSG
assert(result.status)
end
end
end
end
end