andyw8-seeing_is_believing 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/test.yml +60 -0
- data/.gitignore +19 -0
- data/.rspec +2 -0
- data/Gemfile +2 -0
- data/README.md +70 -0
- data/Rakefile +88 -0
- data/appveyor.yml +32 -0
- data/bin/seeing_is_believing +7 -0
- data/docs/example.gif +0 -0
- data/docs/frog-brown.png +0 -0
- data/docs/sib-streaming.gif +0 -0
- data/features/deprecated-flags.feature +91 -0
- data/features/errors.feature +155 -0
- data/features/examples.feature +423 -0
- data/features/flags.feature +852 -0
- data/features/regression.feature +898 -0
- data/features/support/env.rb +102 -0
- data/features/xmpfilter-style.feature +471 -0
- data/lib/seeing_is_believing/binary/align_chunk.rb +47 -0
- data/lib/seeing_is_believing/binary/align_file.rb +24 -0
- data/lib/seeing_is_believing/binary/align_line.rb +25 -0
- data/lib/seeing_is_believing/binary/annotate_end_of_file.rb +56 -0
- data/lib/seeing_is_believing/binary/annotate_every_line.rb +52 -0
- data/lib/seeing_is_believing/binary/annotate_marked_lines.rb +179 -0
- data/lib/seeing_is_believing/binary/comment_lines.rb +36 -0
- data/lib/seeing_is_believing/binary/commentable_lines.rb +126 -0
- data/lib/seeing_is_believing/binary/config.rb +455 -0
- data/lib/seeing_is_believing/binary/data_structures.rb +58 -0
- data/lib/seeing_is_believing/binary/engine.rb +161 -0
- data/lib/seeing_is_believing/binary/format_comment.rb +79 -0
- data/lib/seeing_is_believing/binary/interline_align.rb +57 -0
- data/lib/seeing_is_believing/binary/remove_annotations.rb +113 -0
- data/lib/seeing_is_believing/binary/rewrite_comments.rb +62 -0
- data/lib/seeing_is_believing/binary.rb +73 -0
- data/lib/seeing_is_believing/code.rb +139 -0
- data/lib/seeing_is_believing/compatibility.rb +28 -0
- data/lib/seeing_is_believing/debugger.rb +32 -0
- data/lib/seeing_is_believing/error.rb +17 -0
- data/lib/seeing_is_believing/evaluate_by_moving_files.rb +195 -0
- data/lib/seeing_is_believing/event_stream/consumer.rb +221 -0
- data/lib/seeing_is_believing/event_stream/events.rb +193 -0
- data/lib/seeing_is_believing/event_stream/handlers/debug.rb +61 -0
- data/lib/seeing_is_believing/event_stream/handlers/record_exit_events.rb +26 -0
- data/lib/seeing_is_believing/event_stream/handlers/stream_json_events.rb +23 -0
- data/lib/seeing_is_believing/event_stream/handlers/update_result.rb +41 -0
- data/lib/seeing_is_believing/event_stream/producer.rb +178 -0
- data/lib/seeing_is_believing/hard_core_ensure.rb +58 -0
- data/lib/seeing_is_believing/hash_struct.rb +206 -0
- data/lib/seeing_is_believing/result.rb +89 -0
- data/lib/seeing_is_believing/safe.rb +112 -0
- data/lib/seeing_is_believing/swap_files.rb +90 -0
- data/lib/seeing_is_believing/the_matrix.rb +97 -0
- data/lib/seeing_is_believing/version.rb +3 -0
- data/lib/seeing_is_believing/wrap_expressions.rb +265 -0
- data/lib/seeing_is_believing/wrap_expressions_with_inspect.rb +19 -0
- data/lib/seeing_is_believing.rb +69 -0
- data/seeing_is_believing.gemspec +84 -0
- data/spec/binary/alignment_specs.rb +27 -0
- data/spec/binary/comment_lines_spec.rb +852 -0
- data/spec/binary/config_spec.rb +831 -0
- data/spec/binary/engine_spec.rb +114 -0
- data/spec/binary/format_comment_spec.rb +210 -0
- data/spec/binary/marker_spec.rb +71 -0
- data/spec/binary/remove_annotations_spec.rb +342 -0
- data/spec/binary/rewrite_comments_spec.rb +106 -0
- data/spec/code_spec.rb +233 -0
- data/spec/debugger_spec.rb +45 -0
- data/spec/evaluate_by_moving_files_spec.rb +204 -0
- data/spec/event_stream_spec.rb +762 -0
- data/spec/hard_core_ensure_spec.rb +120 -0
- data/spec/hash_struct_spec.rb +514 -0
- data/spec/seeing_is_believing_spec.rb +1094 -0
- data/spec/sib_spec_helpers/version.rb +17 -0
- data/spec/spec_helper.rb +26 -0
- data/spec/spec_helper_spec.rb +16 -0
- data/spec/wrap_expressions_spec.rb +1013 -0
- metadata +340 -0
@@ -0,0 +1,898 @@
|
|
1
|
+
Feature:
|
2
|
+
In order to not fix the same shit over and over again
|
3
|
+
As the dev who wrote SeeingIsBelieving
|
4
|
+
I want to have tests on those bugs that I found and could not have predicted
|
5
|
+
|
6
|
+
|
7
|
+
Scenario: A program containing a single comment
|
8
|
+
Given the stdin content "# single comment"
|
9
|
+
When I run "seeing_is_believing"
|
10
|
+
Then stderr is empty
|
11
|
+
And the exit status is 0
|
12
|
+
And stdout is "# single comment"
|
13
|
+
|
14
|
+
|
15
|
+
Scenario: Name error just fucks everything
|
16
|
+
Given the file "no_method_error.rb":
|
17
|
+
"""
|
18
|
+
a
|
19
|
+
"""
|
20
|
+
When I run "seeing_is_believing no_method_error.rb"
|
21
|
+
Then stderr is empty
|
22
|
+
And the exit status is 1
|
23
|
+
And stdout is:
|
24
|
+
"""
|
25
|
+
a # ~> NameError: undefined local variable or method `a' for main:Object
|
26
|
+
|
27
|
+
# ~> NameError
|
28
|
+
# ~> undefined local variable or method `a' for main:Object
|
29
|
+
# ~>
|
30
|
+
# ~> no_method_error.rb:1:in `<main>'
|
31
|
+
"""
|
32
|
+
|
33
|
+
|
34
|
+
Scenario: Errors being raised in the evaluated code that don't exist in the evaluating code
|
35
|
+
Given the file "raising_custom_errors.rb":
|
36
|
+
"""
|
37
|
+
MyError = Class.new StandardError
|
38
|
+
begin
|
39
|
+
raise "a"
|
40
|
+
rescue
|
41
|
+
raise MyError.new("c")
|
42
|
+
end
|
43
|
+
"""
|
44
|
+
When I run "seeing_is_believing raising_custom_errors.rb"
|
45
|
+
Then stderr is empty
|
46
|
+
And the exit status is 1
|
47
|
+
|
48
|
+
|
49
|
+
Scenario: statements that inherit void value expressions
|
50
|
+
Given the file "statements_that_inherit_void_value_expressions.rb":
|
51
|
+
"""
|
52
|
+
def m
|
53
|
+
if true
|
54
|
+
return 1
|
55
|
+
end
|
56
|
+
end
|
57
|
+
m
|
58
|
+
"""
|
59
|
+
When I run "seeing_is_believing statements_that_inherit_void_value_expressions.rb"
|
60
|
+
Then stderr is empty
|
61
|
+
And the exit status is 0
|
62
|
+
Then stdout is:
|
63
|
+
"""
|
64
|
+
def m
|
65
|
+
if true # => true
|
66
|
+
return 1 # => 1
|
67
|
+
end
|
68
|
+
end # => {{method_result :m}}
|
69
|
+
m # => 1
|
70
|
+
"""
|
71
|
+
|
72
|
+
|
73
|
+
Scenario: comments aren't updated with values
|
74
|
+
Given the file "comments_arent_updated_with_values.rb":
|
75
|
+
"""
|
76
|
+
1 # some comment
|
77
|
+
2 # some other comment
|
78
|
+
"""
|
79
|
+
When I run "seeing_is_believing comments_arent_updated_with_values.rb"
|
80
|
+
Then stdout is:
|
81
|
+
"""
|
82
|
+
1 # some comment
|
83
|
+
2 # some other comment
|
84
|
+
"""
|
85
|
+
|
86
|
+
|
87
|
+
Scenario: Modifying output doesn't fuck it up when passing it back again as input
|
88
|
+
Given the file "modified_result.rb":
|
89
|
+
"""
|
90
|
+
1
|
91
|
+
# >> stdout
|
92
|
+
2
|
93
|
+
# !> stderr
|
94
|
+
__END__
|
95
|
+
"""
|
96
|
+
When I run "seeing_is_believing modified_result.rb"
|
97
|
+
Then stdout is exactly:
|
98
|
+
"""
|
99
|
+
1 # => 1
|
100
|
+
2 # => 2
|
101
|
+
__END__
|
102
|
+
"""
|
103
|
+
|
104
|
+
|
105
|
+
Scenario: Unintentional magic comment on not-first line
|
106
|
+
Given the file "wtf.rb":
|
107
|
+
"""
|
108
|
+
1
|
109
|
+
# Transfer-Encoding: chunked
|
110
|
+
"""
|
111
|
+
When I run "seeing_is_believing wtf.rb"
|
112
|
+
Then stdout is:
|
113
|
+
"""
|
114
|
+
1 # => 1
|
115
|
+
# Transfer-Encoding: chunked
|
116
|
+
"""
|
117
|
+
|
118
|
+
|
119
|
+
Scenario: The file contains content that looks like previous output, should not be removed
|
120
|
+
Given the file "not_actually_previous_output.rb":
|
121
|
+
"""
|
122
|
+
"1 # => 1"
|
123
|
+
"2 # ~> SomeError: some message"
|
124
|
+
|
125
|
+
"# >> some stdout"
|
126
|
+
|
127
|
+
"# !> some stderr"
|
128
|
+
"""
|
129
|
+
When I run "seeing_is_believing not_actually_previous_output.rb"
|
130
|
+
Then stdout is:
|
131
|
+
"""
|
132
|
+
"1 # => 1" # => "1 # => 1"
|
133
|
+
"2 # ~> SomeError: some message" # => "2 # ~> SomeError: some message"
|
134
|
+
|
135
|
+
"# >> some stdout" # => "# >> some stdout"
|
136
|
+
|
137
|
+
"# !> some stderr" # => "# !> some stderr"
|
138
|
+
"""
|
139
|
+
|
140
|
+
|
141
|
+
Scenario: Multiple leading inline comments should make it through to the final program
|
142
|
+
Given the file "multiple_leading_comments.rb":
|
143
|
+
"""
|
144
|
+
#!/usr/bin/env ruby
|
145
|
+
# encoding: utf-8
|
146
|
+
'ç'
|
147
|
+
"""
|
148
|
+
When I run "seeing_is_believing multiple_leading_comments.rb"
|
149
|
+
Then stdout is:
|
150
|
+
"""
|
151
|
+
#!/usr/bin/env ruby
|
152
|
+
# encoding: utf-8
|
153
|
+
'ç' # => "ç"
|
154
|
+
"""
|
155
|
+
|
156
|
+
|
157
|
+
Scenario: Some strings look like comments
|
158
|
+
Given the file "strings_that_look_like_comments.rb":
|
159
|
+
"""
|
160
|
+
"1
|
161
|
+
#{2}"
|
162
|
+
"""
|
163
|
+
When I run "seeing_is_believing strings_that_look_like_comments.rb"
|
164
|
+
Then stdout is:
|
165
|
+
"""
|
166
|
+
"1
|
167
|
+
#{2}" # => "1\n 2"
|
168
|
+
"""
|
169
|
+
|
170
|
+
|
171
|
+
Scenario: Kori's bug (Issue #11)
|
172
|
+
Given the file "koris_bug.rb":
|
173
|
+
"""
|
174
|
+
class CreditCard
|
175
|
+
|
176
|
+
end
|
177
|
+
|
178
|
+
describe CreditCard do
|
179
|
+
|
180
|
+
end
|
181
|
+
"""
|
182
|
+
When I run "seeing_is_believing koris_bug.rb"
|
183
|
+
Then stdout is:
|
184
|
+
"""
|
185
|
+
class CreditCard
|
186
|
+
|
187
|
+
end # => nil
|
188
|
+
|
189
|
+
describe CreditCard do # ~> NoMethodError: undefined method `describe' for main:Object
|
190
|
+
|
191
|
+
end
|
192
|
+
|
193
|
+
# ~> NoMethodError
|
194
|
+
# ~> undefined method `describe' for main:Object
|
195
|
+
# ~>
|
196
|
+
# ~> koris_bug.rb:5:in `<main>'
|
197
|
+
"""
|
198
|
+
|
199
|
+
|
200
|
+
Scenario: lambda-style fibonacci generator
|
201
|
+
Given the file "lambda_style_fib_gen.rb":
|
202
|
+
"""
|
203
|
+
class Proc
|
204
|
+
def inspect
|
205
|
+
"<PROC>"
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
generic_fib_gen = -> current, prev {
|
210
|
+
-> {
|
211
|
+
[(current+prev), generic_fib_gen.(current+prev, current)]
|
212
|
+
}
|
213
|
+
}
|
214
|
+
|
215
|
+
fib_gen = generic_fib_gen.(1, -1)
|
216
|
+
n, fib_gen = fib_gen.()
|
217
|
+
n, fib_gen = fib_gen.()
|
218
|
+
n, fib_gen = fib_gen.()
|
219
|
+
"""
|
220
|
+
When I run "seeing_is_believing lambda_style_fib_gen.rb"
|
221
|
+
Then stdout is:
|
222
|
+
"""
|
223
|
+
class Proc
|
224
|
+
def inspect
|
225
|
+
"<PROC>" # => "<PROC>", "<PROC>", "<PROC>", "<PROC>", "<PROC>", "<PROC>", "<PROC>", "<PROC>", "<PROC>", "<PROC>", "<PROC>", "<PROC>"
|
226
|
+
end # => {{method_result :inspect}}
|
227
|
+
end # => {{method_result :inspect}}
|
228
|
+
|
229
|
+
generic_fib_gen = -> current, prev {
|
230
|
+
-> {
|
231
|
+
[(current+prev), generic_fib_gen.(current+prev, current)] # => [0, <PROC>], [1, <PROC>], [1, <PROC>]
|
232
|
+
} # => <PROC>, <PROC>, <PROC>, <PROC>
|
233
|
+
} # => <PROC>
|
234
|
+
|
235
|
+
fib_gen = generic_fib_gen.(1, -1) # => <PROC>
|
236
|
+
n, fib_gen = fib_gen.() # => [0, <PROC>]
|
237
|
+
n, fib_gen = fib_gen.() # => [1, <PROC>]
|
238
|
+
n, fib_gen = fib_gen.() # => [1, <PROC>]
|
239
|
+
"""
|
240
|
+
|
241
|
+
|
242
|
+
Scenario: Repeated invocations
|
243
|
+
When I run the pipeline "echo puts 1" | "seeing_is_believing" | "seeing_is_believing"
|
244
|
+
Then stdout is:
|
245
|
+
"""
|
246
|
+
puts 1 # => nil
|
247
|
+
|
248
|
+
# >> 1
|
249
|
+
"""
|
250
|
+
|
251
|
+
|
252
|
+
Scenario: Heredoc at the end test
|
253
|
+
Given the file "heredoc_at_the_end.rb":
|
254
|
+
"""
|
255
|
+
puts(<<A)
|
256
|
+
omg
|
257
|
+
A
|
258
|
+
"""
|
259
|
+
When I run "seeing_is_believing heredoc_at_the_end.rb"
|
260
|
+
Then stdout is:
|
261
|
+
"""
|
262
|
+
puts(<<A) # => nil
|
263
|
+
omg
|
264
|
+
A
|
265
|
+
|
266
|
+
# >> omg
|
267
|
+
"""
|
268
|
+
|
269
|
+
|
270
|
+
# ChildProcess doesn't seem to handle this well in Windows. IDK.
|
271
|
+
@not-windows
|
272
|
+
Scenario: Long DATA segment in a valid file
|
273
|
+
Given the file "long_valid_data_segment.rb":
|
274
|
+
"""
|
275
|
+
__END__
|
276
|
+
{{'.' * 100_000}}
|
277
|
+
"""
|
278
|
+
When I run "seeing_is_believing long_valid_data_segment.rb"
|
279
|
+
Then stderr is empty
|
280
|
+
Then stdout is:
|
281
|
+
"""
|
282
|
+
__END__
|
283
|
+
{{'.' * 100_000}}
|
284
|
+
"""
|
285
|
+
|
286
|
+
|
287
|
+
Scenario: Long DATA segment in an invalid file
|
288
|
+
Given the file "long_invalid_data_segment.rb":
|
289
|
+
"""
|
290
|
+
'
|
291
|
+
__END__
|
292
|
+
{{'.' * 100_000}}
|
293
|
+
"""
|
294
|
+
When I run "seeing_is_believing long_invalid_data_segment.rb"
|
295
|
+
Then stderr is:
|
296
|
+
"""
|
297
|
+
Syntax Error: long_invalid_data_segment.rb:1
|
298
|
+
unterminated string meets end of file
|
299
|
+
"""
|
300
|
+
And the exit status is 2
|
301
|
+
And stdout is empty
|
302
|
+
|
303
|
+
|
304
|
+
Scenario: A program using system
|
305
|
+
Given the file "invoking_system.rb":
|
306
|
+
"""
|
307
|
+
system %(ruby -e '$stdout.puts %(hello)')
|
308
|
+
system %(ruby -e '$stderr.puts %(world)')
|
309
|
+
"""
|
310
|
+
When I run "seeing_is_believing invoking_system.rb"
|
311
|
+
Then stderr is empty
|
312
|
+
And the exit status is 0
|
313
|
+
And stdout is:
|
314
|
+
"""
|
315
|
+
system %(ruby -e '$stdout.puts %(hello)') # => true
|
316
|
+
system %(ruby -e '$stderr.puts %(world)') # => true
|
317
|
+
|
318
|
+
# >> hello
|
319
|
+
|
320
|
+
# !> world
|
321
|
+
"""
|
322
|
+
|
323
|
+
|
324
|
+
Scenario: A program overriding stdout/stderr
|
325
|
+
Given the file "black_hole.rb":
|
326
|
+
"""
|
327
|
+
require 'rubygems'
|
328
|
+
File.open IO::NULL, 'w' do |black_hole|
|
329
|
+
STDERR = $stderr = black_hole; nil
|
330
|
+
STDOUT = $stdout = black_hole; nil
|
331
|
+
puts "You won't see this, it goes into the black hole"
|
332
|
+
system %q(ruby -e '$stdout.puts "stdout gets past it b/c of dumb ruby bug"')
|
333
|
+
system %q(ruby -e '$stderr.puts "stderr gets past it b/c of dumb ruby bug"')
|
334
|
+
end
|
335
|
+
"""
|
336
|
+
When I run "seeing_is_believing black_hole.rb"
|
337
|
+
Then stderr is empty
|
338
|
+
And the exit status is 0
|
339
|
+
And stdout is:
|
340
|
+
"""
|
341
|
+
require 'rubygems' # => false
|
342
|
+
File.open IO::NULL, 'w' do |black_hole| # => File
|
343
|
+
STDERR = $stderr = black_hole; nil # => nil
|
344
|
+
STDOUT = $stdout = black_hole; nil # => nil
|
345
|
+
puts "You won't see this, it goes into the black hole" # => nil
|
346
|
+
system %q(ruby -e '$stdout.puts "stdout gets past it b/c of dumb ruby bug"') # => true
|
347
|
+
system %q(ruby -e '$stderr.puts "stderr gets past it b/c of dumb ruby bug"') # => true
|
348
|
+
end # => true
|
349
|
+
|
350
|
+
# >> stdout gets past it b/c of dumb ruby bug
|
351
|
+
|
352
|
+
# !> stderr gets past it b/c of dumb ruby bug
|
353
|
+
"""
|
354
|
+
|
355
|
+
|
356
|
+
Scenario: Incorrect wrapping in some programs
|
357
|
+
Given the file "incorrect_wrapping.rb":
|
358
|
+
"""
|
359
|
+
a
|
360
|
+
class B
|
361
|
+
def c
|
362
|
+
d = 1
|
363
|
+
end
|
364
|
+
end
|
365
|
+
"""
|
366
|
+
When I run "seeing_is_believing incorrect_wrapping.rb"
|
367
|
+
Then stderr is empty
|
368
|
+
And the exit status is 1
|
369
|
+
And stdout is:
|
370
|
+
"""
|
371
|
+
a # ~> NameError: undefined local variable or method `a' for main:Object
|
372
|
+
class B
|
373
|
+
def c
|
374
|
+
d = 1
|
375
|
+
end
|
376
|
+
end
|
377
|
+
|
378
|
+
# ~> NameError
|
379
|
+
# ~> undefined local variable or method `a' for main:Object
|
380
|
+
# ~>
|
381
|
+
# ~> incorrect_wrapping.rb:1:in `<main>'
|
382
|
+
"""
|
383
|
+
|
384
|
+
|
385
|
+
Scenario: Can deal with hostile environments
|
386
|
+
Given the file "bang_object.rb":
|
387
|
+
"""
|
388
|
+
class Object
|
389
|
+
def !(a)
|
390
|
+
end
|
391
|
+
end
|
392
|
+
"""
|
393
|
+
When I run "seeing_is_believing bang_object.rb"
|
394
|
+
Then stderr is empty
|
395
|
+
And the exit status is 0
|
396
|
+
And stdout is:
|
397
|
+
"""
|
398
|
+
class Object
|
399
|
+
def !(a)
|
400
|
+
end # => {{method_result :!}}
|
401
|
+
end # => {{method_result :!}}
|
402
|
+
"""
|
403
|
+
|
404
|
+
|
405
|
+
Scenario: Is cool with exceptions raised in at_exit hooks
|
406
|
+
Given the file "at_exit_exception_direct.rb" "at_exit { raise 'zomg' }"
|
407
|
+
When I run "seeing_is_believing at_exit_exception_direct.rb"
|
408
|
+
Then stderr is empty
|
409
|
+
And the exit status is 1
|
410
|
+
And stdout includes "at_exit { raise 'zomg' } # ~>"
|
411
|
+
And stdout includes "RuntimeError"
|
412
|
+
And stdout includes "zomg"
|
413
|
+
And stdout does not include "the_matrix"
|
414
|
+
|
415
|
+
|
416
|
+
Scenario: Is cool with exceptions raised in at_exit exceptions by code not in the running file (e.g. SimpleCov)
|
417
|
+
Given the file "at_exit_exception_indirect1.rb" "at_exit { raise 'zomg' }"
|
418
|
+
Given the file "at_exit_exception_indirect2.rb" "require_relative 'at_exit_exception_indirect1'"
|
419
|
+
When I run "seeing_is_believing at_exit_exception_indirect2.rb"
|
420
|
+
Then stderr is empty
|
421
|
+
And the exit status is 1
|
422
|
+
And stdout includes "require_relative 'at_exit_exception_indirect1' # => true"
|
423
|
+
And stdout includes "RuntimeError"
|
424
|
+
And stdout includes "zomg"
|
425
|
+
|
426
|
+
|
427
|
+
Scenario: Comments with markers elsewhere in them
|
428
|
+
Given the file "comments_with_markers_elsewhere.rb":
|
429
|
+
"""
|
430
|
+
# a # => a
|
431
|
+
"""
|
432
|
+
When I run "seeing_is_believing comments_with_markers_elsewhere.rb"
|
433
|
+
Then stdout is:
|
434
|
+
"""
|
435
|
+
# a # => a
|
436
|
+
"""
|
437
|
+
|
438
|
+
|
439
|
+
# 2.4 and 2.5 don't correclty detect deadlock on Windows: https://bugs.ruby-lang.org/issues/16110
|
440
|
+
@not-2.4
|
441
|
+
@not-2.5
|
442
|
+
Scenario: Deadlocked
|
443
|
+
Given the file "deadlocked.rb":
|
444
|
+
"""
|
445
|
+
require 'thread'
|
446
|
+
Thread.new { Queue.new.shift }.join
|
447
|
+
"""
|
448
|
+
When I run "seeing_is_believing deadlocked.rb"
|
449
|
+
Then stdout includes:
|
450
|
+
"""
|
451
|
+
require 'thread' # => false
|
452
|
+
Thread.new { Queue.new.shift }.join # ~> fatal
|
453
|
+
"""
|
454
|
+
|
455
|
+
|
456
|
+
Scenario: Xmpfilter does not write the error messages inside of strings
|
457
|
+
Given the file "error_within_string.rb":
|
458
|
+
"""
|
459
|
+
1.send "a
|
460
|
+
b"
|
461
|
+
"""
|
462
|
+
When I run "seeing_is_believing --xmpfilter-style error_within_string.rb"
|
463
|
+
Then stdout includes:
|
464
|
+
"""
|
465
|
+
1.send "a
|
466
|
+
b"
|
467
|
+
|
468
|
+
# ~> NoMethodError
|
469
|
+
# ~> undefined method
|
470
|
+
"""
|
471
|
+
|
472
|
+
|
473
|
+
# https://github.com/JoshCheek/seeing_is_believing/wiki/Encodings
|
474
|
+
# https://github.com/JoshCheek/seeing_is_believing/issues/109
|
475
|
+
Scenario: Assumes utf-8 for files regardless of what Ruby thinks
|
476
|
+
Given the environment variable "LANG" is set to ''
|
477
|
+
And the file "utf8_file_without_magic_comment.rb" "縧 = 1"
|
478
|
+
When I run "seeing_is_believing utf8_file_without_magic_comment.rb"
|
479
|
+
Then stderr is empty
|
480
|
+
And the exit status is 0
|
481
|
+
And stdout is "縧 = 1 # => 1"
|
482
|
+
|
483
|
+
|
484
|
+
# https://github.com/JoshCheek/seeing_is_believing/issues/109
|
485
|
+
Scenario: Assumes utf-8 for files regardless of what Ruby thinks
|
486
|
+
Given the environment variable "LANG" is set to ''
|
487
|
+
Given the stdin content "縧 = 1"
|
488
|
+
When I run "seeing_is_believing utf8_file_without_magic_comment.rb"
|
489
|
+
Then stderr is empty
|
490
|
+
And the exit status is 0
|
491
|
+
And stdout is "縧 = 1 # => 1"
|
492
|
+
|
493
|
+
|
494
|
+
Scenario: Correctly identify end of file
|
495
|
+
Given the file "fake_data_segment.rb":
|
496
|
+
"""
|
497
|
+
puts "output"
|
498
|
+
"
|
499
|
+
__END__
|
500
|
+
"
|
501
|
+
__END__
|
502
|
+
"""
|
503
|
+
When I run "seeing_is_believing fake_data_segment.rb"
|
504
|
+
Then stdout is:
|
505
|
+
"""
|
506
|
+
puts "output" # => nil
|
507
|
+
"
|
508
|
+
__END__
|
509
|
+
" # => "\n__END__\n"
|
510
|
+
|
511
|
+
# >> output
|
512
|
+
__END__
|
513
|
+
"""
|
514
|
+
|
515
|
+
@not-implemented
|
516
|
+
Scenario: Interpolating in a heredoc and walking backwards with xmpfilter style to figure out which expression to record (#83)
|
517
|
+
Given the file "heredoc_woes.rb":
|
518
|
+
"""
|
519
|
+
<<-HERE # =>
|
520
|
+
1#{1+1}3
|
521
|
+
HERE
|
522
|
+
# =>
|
523
|
+
"""
|
524
|
+
When I run "seeing_is_believing -x heredoc_woes.rb"
|
525
|
+
Then stdout is:
|
526
|
+
"""
|
527
|
+
<<-HERE # => "123\n"
|
528
|
+
1#{1+1}3
|
529
|
+
HERE
|
530
|
+
# => "123\n"
|
531
|
+
"""
|
532
|
+
|
533
|
+
@not-2.0.0
|
534
|
+
Scenario: Executing correctly in a hostile world
|
535
|
+
Given the file "hostile_world.rb":
|
536
|
+
"""
|
537
|
+
# SiB works, but Ruby will explode while trying to make the exception
|
538
|
+
# if we do it later, so we'll make it up here
|
539
|
+
zde = (1/0 rescue $!)
|
540
|
+
|
541
|
+
class Hash
|
542
|
+
undef []
|
543
|
+
undef []=
|
544
|
+
undef fetch
|
545
|
+
end
|
546
|
+
class IO
|
547
|
+
undef sync
|
548
|
+
undef <<
|
549
|
+
undef flush
|
550
|
+
undef puts
|
551
|
+
undef close
|
552
|
+
end
|
553
|
+
class Queue
|
554
|
+
undef <<
|
555
|
+
undef shift
|
556
|
+
undef clear
|
557
|
+
end
|
558
|
+
class Symbol
|
559
|
+
undef ==
|
560
|
+
undef to_s
|
561
|
+
undef inspect
|
562
|
+
end
|
563
|
+
class String
|
564
|
+
undef ==
|
565
|
+
undef to_s
|
566
|
+
undef to_str
|
567
|
+
undef inspect
|
568
|
+
undef to_i
|
569
|
+
end
|
570
|
+
class Fixnum
|
571
|
+
undef <
|
572
|
+
undef <<
|
573
|
+
undef ==
|
574
|
+
def next # "redefining instead of undefing b/c it comes from Integer"
|
575
|
+
end
|
576
|
+
undef to_s
|
577
|
+
undef inspect
|
578
|
+
end
|
579
|
+
class Array
|
580
|
+
undef pack
|
581
|
+
undef <<
|
582
|
+
undef to_ary
|
583
|
+
undef grep
|
584
|
+
undef first
|
585
|
+
undef []
|
586
|
+
undef []=
|
587
|
+
undef each
|
588
|
+
undef map
|
589
|
+
undef join
|
590
|
+
undef size
|
591
|
+
undef to_s
|
592
|
+
end
|
593
|
+
class << Marshal
|
594
|
+
undef dump
|
595
|
+
undef load
|
596
|
+
end
|
597
|
+
module Kernel
|
598
|
+
undef kind_of?
|
599
|
+
undef block_given?
|
600
|
+
end
|
601
|
+
module Enumerable
|
602
|
+
undef map
|
603
|
+
end
|
604
|
+
class SystemExit
|
605
|
+
undef status
|
606
|
+
end
|
607
|
+
class Exception
|
608
|
+
undef message
|
609
|
+
# undef backtrace # https://bugs.ruby-lang.org/issues/12925
|
610
|
+
def class
|
611
|
+
"totally the wrong thing"
|
612
|
+
end
|
613
|
+
end
|
614
|
+
class << Thread
|
615
|
+
undef new
|
616
|
+
undef current
|
617
|
+
end
|
618
|
+
class Thread
|
619
|
+
undef join
|
620
|
+
undef abort_on_exception
|
621
|
+
end
|
622
|
+
class Class
|
623
|
+
undef new
|
624
|
+
undef allocate
|
625
|
+
undef singleton_class
|
626
|
+
undef class_eval
|
627
|
+
end
|
628
|
+
class BasicObject
|
629
|
+
undef initialize
|
630
|
+
end
|
631
|
+
class Module
|
632
|
+
undef ===
|
633
|
+
undef define_method
|
634
|
+
undef instance_method
|
635
|
+
end
|
636
|
+
class UnboundMethod
|
637
|
+
undef bind
|
638
|
+
end
|
639
|
+
class Method
|
640
|
+
undef call
|
641
|
+
end
|
642
|
+
class Proc
|
643
|
+
undef call
|
644
|
+
undef to_proc
|
645
|
+
end
|
646
|
+
class NilClass
|
647
|
+
undef to_s
|
648
|
+
end
|
649
|
+
|
650
|
+
# ---
|
651
|
+
|
652
|
+
class Zomg
|
653
|
+
end
|
654
|
+
|
655
|
+
Zomg # =>
|
656
|
+
class << Zomg
|
657
|
+
attr_accessor :inspect
|
658
|
+
end
|
659
|
+
Zomg.inspect = "lolol"
|
660
|
+
Zomg # =>
|
661
|
+
raise zde
|
662
|
+
"""
|
663
|
+
When I run "seeing_is_believing -x hostile_world.rb"
|
664
|
+
Then stdout includes 'Zomg # => Zomg'
|
665
|
+
And stdout includes 'Zomg # => lolol'
|
666
|
+
And stdout includes '# ~> ZeroDivisionError'
|
667
|
+
And stdout includes '# ~> divided by 0'
|
668
|
+
|
669
|
+
|
670
|
+
Scenario: All objects have an object id (Issue #91)
|
671
|
+
Given the file "object_ids.rb":
|
672
|
+
"""
|
673
|
+
ObjectSpace.each_object { |o| o.object_id || p(obj: o) }#
|
674
|
+
"""
|
675
|
+
When I run "seeing_is_believing object_ids.rb"
|
676
|
+
Then stderr is empty
|
677
|
+
And stdout is:
|
678
|
+
"""
|
679
|
+
ObjectSpace.each_object { |o| o.object_id || p(obj: o) }#
|
680
|
+
"""
|
681
|
+
|
682
|
+
|
683
|
+
Scenario: Does not blow up when the program closes its stdin/stdout/stderr
|
684
|
+
Given the stdin content "input"
|
685
|
+
And the file "closed_pipes.rb":
|
686
|
+
"""
|
687
|
+
[$stdin, $stdout, $stderr].each &:close#
|
688
|
+
"""
|
689
|
+
When I run "seeing_is_believing closed_pipes.rb"
|
690
|
+
Then stderr is empty
|
691
|
+
And the exit status is 0
|
692
|
+
And stdout is:
|
693
|
+
"""
|
694
|
+
[$stdin, $stdout, $stderr].each &:close#
|
695
|
+
"""
|
696
|
+
|
697
|
+
|
698
|
+
Scenario: Overriding Symbol#inspect
|
699
|
+
Given the file "overriding_symbol_inspect.rb":
|
700
|
+
"""
|
701
|
+
:abc # =>
|
702
|
+
class Symbol
|
703
|
+
def inspect
|
704
|
+
"overridden"
|
705
|
+
end
|
706
|
+
end
|
707
|
+
:abc # =>
|
708
|
+
"""
|
709
|
+
When I run "seeing_is_believing overriding_symbol_inspect.rb -x"
|
710
|
+
Then stderr is empty
|
711
|
+
And the exit status is 0
|
712
|
+
Then stdout is:
|
713
|
+
"""
|
714
|
+
:abc # => :abc
|
715
|
+
class Symbol
|
716
|
+
def inspect
|
717
|
+
"overridden"
|
718
|
+
end
|
719
|
+
end
|
720
|
+
:abc # => overridden
|
721
|
+
"""
|
722
|
+
|
723
|
+
|
724
|
+
Scenario: SiB running SiB
|
725
|
+
Given the file "sib_running_sib.rb":
|
726
|
+
"""
|
727
|
+
require 'seeing_is_believing'
|
728
|
+
SeeingIsBelieving.call("1+1").result[1][0]
|
729
|
+
"""
|
730
|
+
When I run "seeing_is_believing sib_running_sib.rb"
|
731
|
+
Then stderr is empty
|
732
|
+
And the exit status is 0
|
733
|
+
And stdout is:
|
734
|
+
"""
|
735
|
+
require 'seeing_is_believing' # => true
|
736
|
+
SeeingIsBelieving.call("1+1").result[1][0] # => "2"
|
737
|
+
"""
|
738
|
+
|
739
|
+
|
740
|
+
Scenario: Errors should not blow away comments (Issue #120)
|
741
|
+
Given the file "sib_with_error_on_uncommented_line.rb" "dne"
|
742
|
+
And the file "sib_with_error_on_commented_line.rb" "dne # this doesn't exist!"
|
743
|
+
When I run "seeing_is_believing -x sib_with_error_on_uncommented_line.rb"
|
744
|
+
Then stdout is:
|
745
|
+
"""
|
746
|
+
dne # ~> NameError: undefined local variable or method `dne' for main:Object
|
747
|
+
|
748
|
+
# ~> NameError
|
749
|
+
# ~> undefined local variable or method `dne' for main:Object
|
750
|
+
# ~>
|
751
|
+
# ~> sib_with_error_on_uncommented_line.rb:1:in `<main>'
|
752
|
+
"""
|
753
|
+
When I run "seeing_is_believing -x sib_with_error_on_commented_line.rb"
|
754
|
+
Then stdout is:
|
755
|
+
"""
|
756
|
+
dne # this doesn't exist!
|
757
|
+
|
758
|
+
# ~> NameError
|
759
|
+
# ~> undefined local variable or method `dne' for main:Object
|
760
|
+
# ~>
|
761
|
+
# ~> sib_with_error_on_commented_line.rb:1:in `<main>'
|
762
|
+
"""
|
763
|
+
When I run "seeing_is_believing sib_with_error_on_uncommented_line.rb"
|
764
|
+
Then stdout is:
|
765
|
+
"""
|
766
|
+
dne # ~> NameError: undefined local variable or method `dne' for main:Object
|
767
|
+
|
768
|
+
# ~> NameError
|
769
|
+
# ~> undefined local variable or method `dne' for main:Object
|
770
|
+
# ~>
|
771
|
+
# ~> sib_with_error_on_uncommented_line.rb:1:in `<main>'
|
772
|
+
"""
|
773
|
+
When I run "seeing_is_believing sib_with_error_on_commented_line.rb"
|
774
|
+
Then stdout is:
|
775
|
+
"""
|
776
|
+
dne # this doesn't exist!
|
777
|
+
|
778
|
+
# ~> NameError
|
779
|
+
# ~> undefined local variable or method `dne' for main:Object
|
780
|
+
# ~>
|
781
|
+
# ~> sib_with_error_on_commented_line.rb:1:in `<main>'
|
782
|
+
"""
|
783
|
+
|
784
|
+
|
785
|
+
Scenario: Errors on files read from stdin with --local-cwd are matched to the correct lines
|
786
|
+
Given the file "local_cwd_and_error_on_uncommented_line.rb" "dne"
|
787
|
+
When I run "seeing_is_believing --local-cwd < local_cwd_and_error_on_uncommented_line.rb"
|
788
|
+
Then stdout includes "dne # ~> NameError: undefined local variable or method `dne' for main:Object"
|
789
|
+
|
790
|
+
|
791
|
+
Scenario: Inspects strings even when they have a singleton class (Issue #118)
|
792
|
+
Given the file "result_of_inspect_has_a_singleton_class.rb":
|
793
|
+
"""
|
794
|
+
str = "a string"
|
795
|
+
def str.inspect
|
796
|
+
self
|
797
|
+
end
|
798
|
+
str # =>
|
799
|
+
"""
|
800
|
+
When I run "seeing_is_believing -x result_of_inspect_has_a_singleton_class.rb"
|
801
|
+
Then stderr is empty
|
802
|
+
And the exit status is 0
|
803
|
+
And stdout is:
|
804
|
+
"""
|
805
|
+
str = "a string"
|
806
|
+
def str.inspect
|
807
|
+
self
|
808
|
+
end
|
809
|
+
str # => a string
|
810
|
+
"""
|
811
|
+
|
812
|
+
|
813
|
+
Scenario: The last line can end in a semicolon
|
814
|
+
When I run "seeing_is_believing -e '1'"
|
815
|
+
Then stdout is "1 # => 1"
|
816
|
+
When I run "seeing_is_believing -e '1;'"
|
817
|
+
Then stdout is "1; # => 1"
|
818
|
+
|
819
|
+
|
820
|
+
Scenario: A spy / proxy class (Issue #136)
|
821
|
+
Given the file "spy_class.rb":
|
822
|
+
"""
|
823
|
+
class String
|
824
|
+
def self.===(obj)
|
825
|
+
true
|
826
|
+
end
|
827
|
+
end
|
828
|
+
class Spy < BasicObject
|
829
|
+
def method_missing(name, *args, &block)
|
830
|
+
self
|
831
|
+
end
|
832
|
+
end
|
833
|
+
Spy.new # =>
|
834
|
+
"""
|
835
|
+
When I run "seeing_is_believing -x spy_class.rb"
|
836
|
+
Then stderr is empty
|
837
|
+
And the exit status is 0
|
838
|
+
And stdout includes "Spy.new # => #<Spy:"
|
839
|
+
|
840
|
+
|
841
|
+
Scenario: Refined inspect
|
842
|
+
Given the file "refined_inspect.rb":
|
843
|
+
"""
|
844
|
+
module Humanize
|
845
|
+
refine Float do
|
846
|
+
def inspect
|
847
|
+
rounded = "%.2f" % self
|
848
|
+
rounded.reverse!
|
849
|
+
rounded.gsub! /(\d{3})/, '\1,'
|
850
|
+
rounded.chomp! ","
|
851
|
+
rounded.reverse!
|
852
|
+
rounded
|
853
|
+
end #
|
854
|
+
end
|
855
|
+
end
|
856
|
+
using Humanize
|
857
|
+
12345.6789 # =>
|
858
|
+
"""
|
859
|
+
When I run "seeing_is_believing refined_inspect.rb"
|
860
|
+
Then stderr is empty
|
861
|
+
And the exit status is 0
|
862
|
+
And stdout is:
|
863
|
+
"""
|
864
|
+
module Humanize
|
865
|
+
refine Float do
|
866
|
+
def inspect
|
867
|
+
rounded = "%.2f" % self # => "12345.68"
|
868
|
+
rounded.reverse! # => "86.54321"
|
869
|
+
rounded.gsub! /(\d{3})/, '\1,' # => "86.543,21"
|
870
|
+
rounded.chomp! "," # => nil
|
871
|
+
rounded.reverse! # => "12,345.68"
|
872
|
+
rounded # => "12,345.68"
|
873
|
+
end #
|
874
|
+
end # => #<refinement:Float@Humanize>
|
875
|
+
end # => #<refinement:Float@Humanize>
|
876
|
+
using Humanize # => main
|
877
|
+
12345.6789 # => 12,345.68
|
878
|
+
"""
|
879
|
+
When I run "seeing_is_believing refined_inspect.rb -x"
|
880
|
+
Then stderr is empty
|
881
|
+
And the exit status is 0
|
882
|
+
Then stdout is:
|
883
|
+
"""
|
884
|
+
module Humanize
|
885
|
+
refine Float do
|
886
|
+
def inspect
|
887
|
+
rounded = "%.2f" % self
|
888
|
+
rounded.reverse!
|
889
|
+
rounded.gsub! /(\d{3})/, '\1,'
|
890
|
+
rounded.chomp! ","
|
891
|
+
rounded.reverse!
|
892
|
+
rounded
|
893
|
+
end #
|
894
|
+
end
|
895
|
+
end
|
896
|
+
using Humanize
|
897
|
+
12345.6789 # => 12,345.68
|
898
|
+
"""
|