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,852 @@
|
|
1
|
+
Feature: Using flags
|
2
|
+
|
3
|
+
Sometimes you want more control over what comes out, for that we give you flags.
|
4
|
+
Note that some flags are significant enough to have their own file.
|
5
|
+
|
6
|
+
Scenario: --result-length sets the length of the portion including and after the # =>
|
7
|
+
Given the file "result_lengths.rb":
|
8
|
+
"""
|
9
|
+
$stdout.puts "a"*100
|
10
|
+
$stderr.puts "a"*100
|
11
|
+
|
12
|
+
"a"
|
13
|
+
"aa"
|
14
|
+
"aaa"
|
15
|
+
"aaaa"
|
16
|
+
|
17
|
+
raise "a"*100
|
18
|
+
"""
|
19
|
+
When I run "seeing_is_believing -s file --result-length 10 result_lengths.rb"
|
20
|
+
Then stderr is empty
|
21
|
+
And stdout is:
|
22
|
+
"""
|
23
|
+
$stdout.puts "a"*100 # => nil
|
24
|
+
$stderr.puts "a"*100 # => nil
|
25
|
+
|
26
|
+
"a" # => "a"
|
27
|
+
"aa" # => "aa"
|
28
|
+
"aaa" # => "aaa"
|
29
|
+
"aaaa" # => "a...
|
30
|
+
|
31
|
+
raise "a"*100 # ~> Ru...
|
32
|
+
|
33
|
+
# >> aa...
|
34
|
+
|
35
|
+
# !> aa...
|
36
|
+
|
37
|
+
# ~> Ru...
|
38
|
+
# ~> aa...
|
39
|
+
# ~>
|
40
|
+
# ~> re...
|
41
|
+
"""
|
42
|
+
|
43
|
+
|
44
|
+
Scenario: --line-length sets the total length of a given line
|
45
|
+
Given the file "line_lengths.rb":
|
46
|
+
"""
|
47
|
+
$stdout.puts "a"*100
|
48
|
+
$stderr.puts "a"*100
|
49
|
+
|
50
|
+
"aaa"
|
51
|
+
"aaaa"
|
52
|
+
|
53
|
+
raise "a"*100
|
54
|
+
"""
|
55
|
+
When I run "seeing_is_believing -s file --line-length 32 line_lengths.rb"
|
56
|
+
Then stderr is empty
|
57
|
+
And stdout is:
|
58
|
+
"""
|
59
|
+
$stdout.puts "a"*100 # => nil
|
60
|
+
$stderr.puts "a"*100 # => nil
|
61
|
+
|
62
|
+
"aaa" # => "aaa"
|
63
|
+
"aaaa" # => "a...
|
64
|
+
|
65
|
+
raise "a"*100 # ~> Ru...
|
66
|
+
|
67
|
+
# >> aaaaaaaaaaaaaaaaaaaaaaaa...
|
68
|
+
|
69
|
+
# !> aaaaaaaaaaaaaaaaaaaaaaaa...
|
70
|
+
|
71
|
+
# ~> RuntimeError
|
72
|
+
# ~> aaaaaaaaaaaaaaaaaaaaaaaa...
|
73
|
+
# ~>
|
74
|
+
# ~> line_lengths.rb:7:in `<m...
|
75
|
+
"""
|
76
|
+
Given the file "line_lengths2.rb":
|
77
|
+
"""
|
78
|
+
12345
|
79
|
+
"""
|
80
|
+
When I run "seeing_is_believing --line-length 1 line_lengths2.rb"
|
81
|
+
Then stdout is "12345"
|
82
|
+
When I run "seeing_is_believing --line-length 15 line_lengths2.rb"
|
83
|
+
Then stdout is "12345 # => ..."
|
84
|
+
When I run "seeing_is_believing --line-length 14 line_lengths2.rb"
|
85
|
+
Then stdout is "12345"
|
86
|
+
|
87
|
+
|
88
|
+
Scenario: --max-line-captures determines how many times a line will be recorded
|
89
|
+
Given the file "max_line_captures.rb":
|
90
|
+
"""
|
91
|
+
5.times do |i|
|
92
|
+
i
|
93
|
+
end
|
94
|
+
"""
|
95
|
+
When I run "seeing_is_believing --max-line-captures 4 max_line_captures.rb"
|
96
|
+
Then stdout is:
|
97
|
+
"""
|
98
|
+
5.times do |i| # => 5
|
99
|
+
i # => 0, 1, 2, 3, ...
|
100
|
+
end # => 5
|
101
|
+
"""
|
102
|
+
When I run "seeing_is_believing --max-line-captures 5 max_line_captures.rb"
|
103
|
+
Then stdout is:
|
104
|
+
"""
|
105
|
+
5.times do |i| # => 5
|
106
|
+
i # => 0, 1, 2, 3, 4
|
107
|
+
end # => 5
|
108
|
+
"""
|
109
|
+
|
110
|
+
|
111
|
+
Scenario: --require
|
112
|
+
Given the file "r_print_1.rb" "puts 1"
|
113
|
+
Given the file "r_print_2.rb" "puts 2"
|
114
|
+
And the file "r_print_3.rb" "puts 3"
|
115
|
+
When I run "seeing_is_believing --require ./r_print_1 --require ./r_print_2 r_print_3.rb"
|
116
|
+
Then stderr is empty
|
117
|
+
And the exit status is 0
|
118
|
+
And stdout is:
|
119
|
+
"""
|
120
|
+
puts 3 # => nil
|
121
|
+
|
122
|
+
# >> 1
|
123
|
+
# >> 2
|
124
|
+
# >> 3
|
125
|
+
"""
|
126
|
+
|
127
|
+
|
128
|
+
Scenario: --program
|
129
|
+
When I run "seeing_is_believing --program '1'"
|
130
|
+
Then stderr is empty
|
131
|
+
And the exit status is 0
|
132
|
+
And stdout is:
|
133
|
+
"""
|
134
|
+
1 # => 1
|
135
|
+
"""
|
136
|
+
|
137
|
+
|
138
|
+
Scenario: --load-path
|
139
|
+
Given the file "lp_print_1.rb" "puts 1"
|
140
|
+
And the file "some_dir/lp_print_2.rb" "puts 2"
|
141
|
+
And the file "require_lp_print_1.rb" "require 'lp_print_1'"
|
142
|
+
When I run "seeing_is_believing require_lp_print_1.rb"
|
143
|
+
Then the exit status is 1
|
144
|
+
When I run "seeing_is_believing --load-path . -I ./some_dir -r lp_print_2 require_lp_print_1.rb"
|
145
|
+
Then stderr is empty
|
146
|
+
And stdout is:
|
147
|
+
"""
|
148
|
+
require 'lp_print_1' # => true
|
149
|
+
|
150
|
+
# >> 2
|
151
|
+
# >> 1
|
152
|
+
"""
|
153
|
+
And the exit status is 0
|
154
|
+
|
155
|
+
|
156
|
+
Scenario: --encoding
|
157
|
+
Given the binary file "utf-8.rb" "'ç'"
|
158
|
+
When I run "seeing_is_believing --encoding u utf-8.rb"
|
159
|
+
Then stderr is empty
|
160
|
+
And the exit status is 0
|
161
|
+
And stdout is:
|
162
|
+
"""
|
163
|
+
'ç' # => "ç"
|
164
|
+
"""
|
165
|
+
|
166
|
+
|
167
|
+
Scenario: --as and stdin
|
168
|
+
Given the stdin content:
|
169
|
+
"""
|
170
|
+
__FILE__
|
171
|
+
"""
|
172
|
+
When I run "seeing_is_believing --as as_and_stdin.rb"
|
173
|
+
Then stderr is empty
|
174
|
+
Then the exit status is 0
|
175
|
+
And stdout is:
|
176
|
+
"""
|
177
|
+
__FILE__ # => "as_and_stdin.rb"
|
178
|
+
"""
|
179
|
+
|
180
|
+
|
181
|
+
Scenario: --as and -e
|
182
|
+
When I run 'seeing_is_believing --as as_and_e.rb -e "__FILE__"'
|
183
|
+
Then stderr is empty
|
184
|
+
And the exit status is 0
|
185
|
+
And stdout is '__FILE__ # => "as_and_e.rb"'
|
186
|
+
|
187
|
+
|
188
|
+
Scenario: --as and filename
|
189
|
+
Given the file "as_and_filename.rb" "__FILE__"
|
190
|
+
When I run 'seeing_is_believing as_and_filename.rb --as not_as_and_filename.rb'
|
191
|
+
Then stderr is empty
|
192
|
+
And the exit status is 0
|
193
|
+
And stdout is '__FILE__ # => "not_as_and_filename.rb"'
|
194
|
+
|
195
|
+
|
196
|
+
Scenario: --clean
|
197
|
+
Given the file "uncleaned.rb":
|
198
|
+
"""
|
199
|
+
# comment # => still a comment
|
200
|
+
1 + 1 # => not 2
|
201
|
+
2 + 2 # ~> Exception, something
|
202
|
+
|
203
|
+
|
204
|
+
# >> some stdout output
|
205
|
+
|
206
|
+
# !> some stderr output
|
207
|
+
__END__
|
208
|
+
1
|
209
|
+
"""
|
210
|
+
When I run "seeing_is_believing --clean uncleaned.rb"
|
211
|
+
Then stderr is empty
|
212
|
+
And the exit status is 0
|
213
|
+
And stdout is:
|
214
|
+
"""
|
215
|
+
# comment # => still a comment
|
216
|
+
1 + 1
|
217
|
+
2 + 2
|
218
|
+
|
219
|
+
__END__
|
220
|
+
1
|
221
|
+
"""
|
222
|
+
|
223
|
+
|
224
|
+
Scenario: --clean on an invalid file will clean
|
225
|
+
When I run 'seeing_is_believing --clean -e "1+ # => lkj"'
|
226
|
+
Then stderr is empty
|
227
|
+
And the exit status is 0
|
228
|
+
And stdout is '1+'
|
229
|
+
|
230
|
+
|
231
|
+
Scenario: --version
|
232
|
+
When I run 'seeing_is_believing --version'
|
233
|
+
Then stderr is empty
|
234
|
+
And the exit status is 0
|
235
|
+
And stdout is '{{SeeingIsBelieving::VERSION}}'
|
236
|
+
|
237
|
+
|
238
|
+
Scenario: --help
|
239
|
+
When I run "seeing_is_believing --help"
|
240
|
+
Then stderr is empty
|
241
|
+
And the exit status is 0
|
242
|
+
And stdout includes "Usage"
|
243
|
+
And stdout does not include "Examples:"
|
244
|
+
|
245
|
+
|
246
|
+
Scenario: --help+
|
247
|
+
When I run "seeing_is_believing --help+"
|
248
|
+
Then stderr is empty
|
249
|
+
And the exit status is 0
|
250
|
+
And stdout includes "Usage"
|
251
|
+
And stdout includes "Examples:"
|
252
|
+
|
253
|
+
|
254
|
+
Scenario: --timeout-seconds
|
255
|
+
Given the file "will_timeout.rb" "sleep 1"
|
256
|
+
When I run "seeing_is_believing --timeout-seconds 0.1 will_timeout.rb"
|
257
|
+
Then stdout is empty
|
258
|
+
And the exit status is 2
|
259
|
+
And stderr is "Timeout Error after 0.1 seconds!"
|
260
|
+
|
261
|
+
|
262
|
+
Scenario: --timeout-seconds
|
263
|
+
Given the file "will_not_timeout.rb" "1 + 1"
|
264
|
+
When I run "seeing_is_believing --timeout-seconds 1.0 will_not_timeout.rb"
|
265
|
+
Then stderr is empty
|
266
|
+
And the exit status is 0
|
267
|
+
And stdout is "1 + 1 # => 2"
|
268
|
+
|
269
|
+
|
270
|
+
Scenario: --alignment-strategy file
|
271
|
+
Given the file "file_alignments.rb":
|
272
|
+
"""
|
273
|
+
# comment
|
274
|
+
1
|
275
|
+
|
276
|
+
=begin
|
277
|
+
multiline comment
|
278
|
+
=end
|
279
|
+
1 + 1
|
280
|
+
1 + 1 + 1
|
281
|
+
"""
|
282
|
+
When I run "seeing_is_believing --alignment-strategy file file_alignments.rb"
|
283
|
+
Then stderr is empty
|
284
|
+
And the exit status is 0
|
285
|
+
And stdout is:
|
286
|
+
"""
|
287
|
+
# comment
|
288
|
+
1 # => 1
|
289
|
+
|
290
|
+
=begin
|
291
|
+
multiline comment
|
292
|
+
=end
|
293
|
+
1 + 1 # => 2
|
294
|
+
1 + 1 + 1 # => 3
|
295
|
+
"""
|
296
|
+
|
297
|
+
|
298
|
+
Scenario: --alignment-strategy chunk
|
299
|
+
Given the file "chunk_alignments.rb":
|
300
|
+
"""
|
301
|
+
# comment
|
302
|
+
1
|
303
|
+
|
304
|
+
=begin
|
305
|
+
multiline comment
|
306
|
+
=end
|
307
|
+
1 + 1
|
308
|
+
1 + 1 + 1
|
309
|
+
|
310
|
+
1+1+1
|
311
|
+
1+1
|
312
|
+
|
313
|
+
1 + 1
|
314
|
+
# comment in the middle!
|
315
|
+
1 + 1 + 1 + 1
|
316
|
+
1 + 1
|
317
|
+
"""
|
318
|
+
When I run "seeing_is_believing --alignment-strategy chunk chunk_alignments.rb"
|
319
|
+
Then stderr is empty
|
320
|
+
And the exit status is 0
|
321
|
+
And stdout is:
|
322
|
+
"""
|
323
|
+
# comment
|
324
|
+
1 # => 1
|
325
|
+
|
326
|
+
=begin
|
327
|
+
multiline comment
|
328
|
+
=end
|
329
|
+
1 + 1 # => 2
|
330
|
+
1 + 1 + 1 # => 3
|
331
|
+
|
332
|
+
1+1+1 # => 3
|
333
|
+
1+1 # => 2
|
334
|
+
|
335
|
+
1 + 1 # => 2
|
336
|
+
# comment in the middle!
|
337
|
+
1 + 1 + 1 + 1 # => 4
|
338
|
+
1 + 1 # => 2
|
339
|
+
"""
|
340
|
+
|
341
|
+
|
342
|
+
Scenario: --alignment-strategy line
|
343
|
+
Given the file "line_alignments.rb":
|
344
|
+
"""
|
345
|
+
# comment
|
346
|
+
1
|
347
|
+
|
348
|
+
=begin
|
349
|
+
multiline comment
|
350
|
+
=end
|
351
|
+
1 + 1
|
352
|
+
1 + 1 + 1
|
353
|
+
"""
|
354
|
+
When I run "seeing_is_believing --alignment-strategy line line_alignments.rb"
|
355
|
+
Then stderr is empty
|
356
|
+
And the exit status is 0
|
357
|
+
And stdout is:
|
358
|
+
"""
|
359
|
+
# comment
|
360
|
+
1 # => 1
|
361
|
+
|
362
|
+
=begin
|
363
|
+
multiline comment
|
364
|
+
=end
|
365
|
+
1 + 1 # => 2
|
366
|
+
1 + 1 + 1 # => 3
|
367
|
+
"""
|
368
|
+
|
369
|
+
|
370
|
+
Scenario: --inherit-exitstatus causes SiB to exit with the status of the evaluated file
|
371
|
+
Given the file "exitstatus.rb" "exit 123"
|
372
|
+
|
373
|
+
When I run "seeing_is_believing exitstatus.rb"
|
374
|
+
Then the exit status is 1
|
375
|
+
And stderr is empty
|
376
|
+
And stdout is "exit 123"
|
377
|
+
|
378
|
+
When I run "seeing_is_believing -i exitstatus.rb"
|
379
|
+
Then the exit status is 123
|
380
|
+
And stderr is empty
|
381
|
+
And stdout is "exit 123"
|
382
|
+
|
383
|
+
|
384
|
+
Scenario: --inherit-exitstatus works with exit!
|
385
|
+
Given the file "exit_bang.rb":
|
386
|
+
"""
|
387
|
+
:hello
|
388
|
+
exit! 100
|
389
|
+
"""
|
390
|
+
|
391
|
+
When I run "seeing_is_believing exit_bang.rb"
|
392
|
+
Then stderr is empty
|
393
|
+
And the exit status is 1
|
394
|
+
And stdout is:
|
395
|
+
"""
|
396
|
+
:hello # => :hello
|
397
|
+
exit! 100
|
398
|
+
"""
|
399
|
+
|
400
|
+
When I run "seeing_is_believing -i exit_bang.rb"
|
401
|
+
Then stderr is empty
|
402
|
+
And the exit status is 100
|
403
|
+
And stdout is:
|
404
|
+
"""
|
405
|
+
:hello # => :hello
|
406
|
+
exit! 100
|
407
|
+
"""
|
408
|
+
|
409
|
+
|
410
|
+
# Show that Ruby exceptions exit with 1, and --inherit-exitstatus does as well
|
411
|
+
Scenario: --inherit-exitstatus
|
412
|
+
Given the file "exception_exitstatus.rb" "raise Exception"
|
413
|
+
When I run "ruby exception_exitstatus.rb"
|
414
|
+
Then the exit status is 1
|
415
|
+
When I run "seeing_is_believing -i exception_exitstatus.rb"
|
416
|
+
Then the exit status is 1
|
417
|
+
|
418
|
+
|
419
|
+
Scenario: --inherit-exitstatus in an at_exit block
|
420
|
+
Given the file "exitstatus_in_at_exit_block.rb" "at_exit { exit 10 }"
|
421
|
+
When I run "seeing_is_believing exitstatus_in_at_exit_block.rb"
|
422
|
+
Then the exit status is 1
|
423
|
+
When I run "seeing_is_believing -i exitstatus_in_at_exit_block.rb"
|
424
|
+
Then the exit status is 10
|
425
|
+
|
426
|
+
|
427
|
+
Scenario: --debug
|
428
|
+
Given the file "simple_program.rb":
|
429
|
+
"""
|
430
|
+
# encoding: utf-8
|
431
|
+
1# 123
|
432
|
+
2
|
433
|
+
"""
|
434
|
+
When I run "seeing_is_believing --debug simple_program.rb"
|
435
|
+
Then stdout is empty
|
436
|
+
And the exit status is 0
|
437
|
+
And stderr includes "REWRITTEN PROGRAM:"
|
438
|
+
And stderr includes "$SiB"
|
439
|
+
And stderr includes "EVENTS:"
|
440
|
+
And stderr includes "OUTPUT:"
|
441
|
+
And stderr includes:
|
442
|
+
"""
|
443
|
+
# encoding: utf-8
|
444
|
+
1# 123
|
445
|
+
2 # => 2
|
446
|
+
"""
|
447
|
+
|
448
|
+
Scenario: --json without exceptions
|
449
|
+
Given the file "simple_json.rb":
|
450
|
+
"""
|
451
|
+
3.times do |i|
|
452
|
+
i.to_s
|
453
|
+
end
|
454
|
+
"""
|
455
|
+
When I run "seeing_is_believing --json simple_json.rb"
|
456
|
+
Then stderr is empty
|
457
|
+
And the exit status is 0
|
458
|
+
And stdout is the JSON:
|
459
|
+
"""
|
460
|
+
{ "lines": {
|
461
|
+
"1": ["3"],
|
462
|
+
"2": ["\"0\"", "\"1\"", "\"2\""],
|
463
|
+
"3": ["3"]
|
464
|
+
},
|
465
|
+
"exception": null,
|
466
|
+
"exceptions": [],
|
467
|
+
"stdout": "",
|
468
|
+
"stderr": "",
|
469
|
+
"exitstatus": 0
|
470
|
+
}
|
471
|
+
"""
|
472
|
+
|
473
|
+
Scenario: --json with exceptions
|
474
|
+
Given the file "all_kinds_of_output.rb":
|
475
|
+
"""
|
476
|
+
3.times do |i|
|
477
|
+
i.to_s
|
478
|
+
end
|
479
|
+
$stdout.puts "b"
|
480
|
+
$stderr.puts "c"
|
481
|
+
raise "omg"
|
482
|
+
"""
|
483
|
+
When I run "seeing_is_believing --json all_kinds_of_output.rb"
|
484
|
+
Then stderr is empty
|
485
|
+
And the exit status is 0
|
486
|
+
# Use the exceptions array rather than the singule exception, it's less correct
|
487
|
+
# as there can be multiple exceptions. It only exists for backwards compatibility.
|
488
|
+
And stdout is the JSON:
|
489
|
+
"""
|
490
|
+
{ "lines": {
|
491
|
+
"1": ["3"],
|
492
|
+
"2": ["\"0\"", "\"1\"", "\"2\""],
|
493
|
+
"3": ["3"],
|
494
|
+
"4": ["nil"],
|
495
|
+
"5": ["nil"],
|
496
|
+
"6": []
|
497
|
+
},
|
498
|
+
"exception": {
|
499
|
+
"line_number_in_this_file": 6,
|
500
|
+
"class_name": "RuntimeError",
|
501
|
+
"message": "omg",
|
502
|
+
"backtrace": ["all_kinds_of_output.rb:6:in `<main>'"]
|
503
|
+
},
|
504
|
+
"exceptions": [{
|
505
|
+
"line_number_in_this_file": 6,
|
506
|
+
"class_name": "RuntimeError",
|
507
|
+
"message": "omg",
|
508
|
+
"backtrace": ["all_kinds_of_output.rb:6:in `<main>'"]
|
509
|
+
}],
|
510
|
+
"stdout": "b\n",
|
511
|
+
"stderr": "c\n",
|
512
|
+
"exitstatus": 1
|
513
|
+
}
|
514
|
+
"""
|
515
|
+
|
516
|
+
Scenario: --stream prints events from the event stream as they are seen
|
517
|
+
Given the file "record_event_stream.rb" "3.times { |i| p i }"
|
518
|
+
When I run "seeing_is_believing record_event_stream.rb --stream"
|
519
|
+
Then stderr is empty
|
520
|
+
And the exit status is 0
|
521
|
+
And stdout includes:
|
522
|
+
"""
|
523
|
+
["stdout",{"value":"0\n"}]
|
524
|
+
"""
|
525
|
+
And stdout includes:
|
526
|
+
"""
|
527
|
+
["exitstatus",{"value":0}]
|
528
|
+
"""
|
529
|
+
And stdout includes:
|
530
|
+
"""
|
531
|
+
["max_line_captures",{"value":-1,"is_infinity":true}]
|
532
|
+
"""
|
533
|
+
|
534
|
+
Scenario: --stream respects the exit status
|
535
|
+
When I run "seeing_is_believing -ie 'exit 12' --stream"
|
536
|
+
Then stderr is empty
|
537
|
+
And the exit status is 12
|
538
|
+
|
539
|
+
Scenario: --stream sees leading data even with a hostile BEGIN block.
|
540
|
+
When I run "seeing_is_believing -e 'BEGIN { exit! }' --stream"
|
541
|
+
Then stdout includes:
|
542
|
+
"""
|
543
|
+
["sib_version",{"value":"{{SeeingIsBelieving::VERSION}}"}]
|
544
|
+
"""
|
545
|
+
|
546
|
+
Scenario: --stream emits a timeout event and finishes successfully when the process times out.
|
547
|
+
When I run "seeing_is_believing -e 'loop { sleep 1 }' -t 0.01 --stream"
|
548
|
+
Then the exit status is 2
|
549
|
+
And stderr is "Timeout Error after 0.01 seconds!"
|
550
|
+
And stdout includes:
|
551
|
+
"""
|
552
|
+
["finished",{}]
|
553
|
+
"""
|
554
|
+
And stdout includes:
|
555
|
+
"""
|
556
|
+
["timeout",{"seconds":0.01}]
|
557
|
+
"""
|
558
|
+
|
559
|
+
Scenario: --ignore-unknown-flags prevents errors on unknown flags for forward compatibility
|
560
|
+
When I run "seeing_is_believing -e '1' --ignore-unknown-flags --zomg-wat"
|
561
|
+
Then the exit status is 0
|
562
|
+
And stderr is empty
|
563
|
+
And stdout is "1 # => 1"
|
564
|
+
|
565
|
+
Scenario: --interline-align and --no-interline-align determine whether adjacent lines with the same number of results get lined up, it defaults to --align
|
566
|
+
Given the file "interline_alignment.rb":
|
567
|
+
"""
|
568
|
+
3.times do |num|
|
569
|
+
num
|
570
|
+
.to_s
|
571
|
+
end
|
572
|
+
"""
|
573
|
+
When I run "seeing_is_believing interline_alignment.rb"
|
574
|
+
Then stderr is empty
|
575
|
+
And the exit status is 0
|
576
|
+
And stdout is:
|
577
|
+
"""
|
578
|
+
3.times do |num| # => 3
|
579
|
+
num # => 0, 1, 2
|
580
|
+
.to_s # => "0", "1", "2"
|
581
|
+
end # => 3
|
582
|
+
"""
|
583
|
+
When I run "seeing_is_believing --interline-align interline_alignment.rb"
|
584
|
+
Then stderr is empty
|
585
|
+
And the exit status is 0
|
586
|
+
And stdout is:
|
587
|
+
"""
|
588
|
+
3.times do |num| # => 3
|
589
|
+
num # => 0, 1, 2
|
590
|
+
.to_s # => "0", "1", "2"
|
591
|
+
end # => 3
|
592
|
+
"""
|
593
|
+
When I run "seeing_is_believing --no-interline-align interline_alignment.rb"
|
594
|
+
Then stderr is empty
|
595
|
+
And the exit status is 0
|
596
|
+
And stdout is:
|
597
|
+
"""
|
598
|
+
3.times do |num| # => 3
|
599
|
+
num # => 0, 1, 2
|
600
|
+
.to_s # => "0", "1", "2"
|
601
|
+
end # => 3
|
602
|
+
"""
|
603
|
+
|
604
|
+
|
605
|
+
Scenario: --local-cwd causes the current working directory to be the same as the file
|
606
|
+
Given the file "subdir/cwd_of_file_test.rb" "__FILE__"
|
607
|
+
When I run "seeing_is_believing subdir/cwd_of_file_test.rb"
|
608
|
+
Then stderr is empty
|
609
|
+
And the exit status is 0
|
610
|
+
And stdout is '__FILE__ # => "subdir/cwd_of_file_test.rb"'
|
611
|
+
When I run "seeing_is_believing subdir/cwd_of_file_test.rb --local-cwd"
|
612
|
+
Then stderr is empty
|
613
|
+
And the exit status is 0
|
614
|
+
And stdout is '__FILE__ # => "cwd_of_file_test.rb"'
|
615
|
+
|
616
|
+
|
617
|
+
Scenario: --toggle-mark adds a mark to the line if it is unmarked and exists
|
618
|
+
Given the file "unmarked.rb":
|
619
|
+
"""
|
620
|
+
1
|
621
|
+
2
|
622
|
+
"""
|
623
|
+
When I run "seeing_is_believing unmarked.rb --toggle-mark 1"
|
624
|
+
Then stderr is empty
|
625
|
+
And the exit status is 0
|
626
|
+
And stdout is '{{"1 # => \n2"}}'
|
627
|
+
When I run "seeing_is_believing unmarked.rb --toggle-mark 2"
|
628
|
+
Then stderr is empty
|
629
|
+
And the exit status is 0
|
630
|
+
And stdout is '{{"1\n2 # => "}}'
|
631
|
+
When I run "seeing_is_believing unmarked.rb --toggle-mark 3"
|
632
|
+
Then stderr is empty
|
633
|
+
And the exit status is 0
|
634
|
+
And stdout is '{{"1\n2"}}'
|
635
|
+
|
636
|
+
|
637
|
+
Scenario: --toggle-mark doesn't add a mark to the line if it has a comment or can't be commented
|
638
|
+
Given the file "no_toggle_line_here.rb":
|
639
|
+
"""
|
640
|
+
1 # comment
|
641
|
+
"2
|
642
|
+
"
|
643
|
+
"""
|
644
|
+
When I run "seeing_is_believing no_toggle_line_here.rb --toggle-mark 1"
|
645
|
+
Then stderr is empty
|
646
|
+
And the exit status is 0
|
647
|
+
And stdout is:
|
648
|
+
"""
|
649
|
+
1 # comment
|
650
|
+
"2
|
651
|
+
"
|
652
|
+
"""
|
653
|
+
When I run "seeing_is_believing no_toggle_line_here.rb --toggle-mark 2"
|
654
|
+
Then stderr is empty
|
655
|
+
And the exit status is 0
|
656
|
+
And stdout is:
|
657
|
+
"""
|
658
|
+
1 # comment
|
659
|
+
"2
|
660
|
+
"
|
661
|
+
"""
|
662
|
+
When I run "seeing_is_believing no_toggle_line_here.rb --toggle-mark 3"
|
663
|
+
Then stderr is empty
|
664
|
+
And the exit status is 0
|
665
|
+
And stdout is:
|
666
|
+
"""
|
667
|
+
1 # comment
|
668
|
+
"2
|
669
|
+
" # =>{{" "}}
|
670
|
+
"""
|
671
|
+
|
672
|
+
|
673
|
+
Scenario: --toggle-mark removes a mark from the line if it is marked and exists
|
674
|
+
Given the file "marked.rb":
|
675
|
+
"""
|
676
|
+
1 # =>
|
677
|
+
2 + 2 # =>
|
678
|
+
"""
|
679
|
+
When I run "seeing_is_believing marked.rb --toggle-mark 1"
|
680
|
+
Then stderr is empty
|
681
|
+
And the exit status is 0
|
682
|
+
And stdout is '{{"1\n2 + 2 # => "}}'
|
683
|
+
When I run "seeing_is_believing marked.rb --toggle-mark 2"
|
684
|
+
Then stderr is empty
|
685
|
+
And the exit status is 0
|
686
|
+
And stdout is '{{"1 # => \n2 + 2"}}'
|
687
|
+
When I run "seeing_is_believing marked.rb --toggle-mark 3"
|
688
|
+
Then stderr is empty
|
689
|
+
And the exit status is 0
|
690
|
+
And stdout is '{{"1 # => \n2 + 2 # => "}}'
|
691
|
+
|
692
|
+
|
693
|
+
Scenario: --toggle-mark removes error lines, and stdout/stderr output
|
694
|
+
Given the file "output_to_toggle_off.rb":
|
695
|
+
"""
|
696
|
+
1 + "a" # ~> b
|
697
|
+
# >> c
|
698
|
+
# !> d
|
699
|
+
# ~> e
|
700
|
+
"""
|
701
|
+
When I run "seeing_is_believing output_to_toggle_off.rb --toggle-mark 1"
|
702
|
+
Then stdout is:
|
703
|
+
"""
|
704
|
+
1 + "a"
|
705
|
+
# >> c
|
706
|
+
# !> d
|
707
|
+
# ~> e
|
708
|
+
"""
|
709
|
+
When I run "seeing_is_believing output_to_toggle_off.rb --toggle-mark 2"
|
710
|
+
Then stdout is:
|
711
|
+
"""
|
712
|
+
1 + "a" # ~> b
|
713
|
+
|
714
|
+
# !> d
|
715
|
+
# ~> e
|
716
|
+
"""
|
717
|
+
When I run "seeing_is_believing output_to_toggle_off.rb --toggle-mark 3"
|
718
|
+
Then stdout is:
|
719
|
+
"""
|
720
|
+
1 + "a" # ~> b
|
721
|
+
# >> c
|
722
|
+
|
723
|
+
# ~> e
|
724
|
+
"""
|
725
|
+
When I run "seeing_is_believing output_to_toggle_off.rb --toggle-mark 4"
|
726
|
+
Then stdout is:
|
727
|
+
"""
|
728
|
+
1 + "a" # ~> b
|
729
|
+
# >> c
|
730
|
+
# !> d
|
731
|
+
"""
|
732
|
+
|
733
|
+
|
734
|
+
Scenario: --toggle-mark respects the --alignment-strategy of file and updates any existing annotations to respect it
|
735
|
+
Given the file "toggle_mark_with_file_alignment.rb":
|
736
|
+
"""
|
737
|
+
1
|
738
|
+
|
739
|
+
1 + 1 # => 2
|
740
|
+
1 + 1 + 1 # => 3
|
741
|
+
1 + 1 + 1 + 1
|
742
|
+
"""
|
743
|
+
When I run "seeing_is_believing --toggle-mark 1 --alignment-strategy file toggle_mark_with_file_alignment.rb"
|
744
|
+
Then stderr is empty
|
745
|
+
And the exit status is 0
|
746
|
+
And stdout is:
|
747
|
+
"""
|
748
|
+
1 # =>{{" "}}
|
749
|
+
|
750
|
+
1 + 1 # => 2
|
751
|
+
1 + 1 + 1 # => 3
|
752
|
+
1 + 1 + 1 + 1
|
753
|
+
"""
|
754
|
+
When I run "seeing_is_believing --toggle-mark 3 --alignment-strategy file toggle_mark_with_file_alignment.rb"
|
755
|
+
Then stderr is empty
|
756
|
+
And the exit status is 0
|
757
|
+
And stdout is:
|
758
|
+
"""
|
759
|
+
1
|
760
|
+
|
761
|
+
1 + 1
|
762
|
+
1 + 1 + 1 # => 3
|
763
|
+
1 + 1 + 1 + 1
|
764
|
+
"""
|
765
|
+
|
766
|
+
|
767
|
+
Scenario: --toggle-mark respects the --alignment-strategy of chunk and updates any existing annotations to respect it
|
768
|
+
Given the file "toggle_mark_with_chunk_alignments.rb":
|
769
|
+
"""
|
770
|
+
1+1# => 2
|
771
|
+
1+1+1
|
772
|
+
1+1+1+1
|
773
|
+
|
774
|
+
1 + 1
|
775
|
+
# comment in the middle!
|
776
|
+
1
|
777
|
+
"""
|
778
|
+
When I run "seeing_is_believing --toggle-mark 2 --alignment-strategy chunk toggle_mark_with_chunk_alignments.rb"
|
779
|
+
Then stderr is empty
|
780
|
+
And the exit status is 0
|
781
|
+
And stdout is:
|
782
|
+
"""
|
783
|
+
1+1 # => 2
|
784
|
+
1+1+1 # =>{{" "}}
|
785
|
+
1+1+1+1
|
786
|
+
|
787
|
+
1 + 1
|
788
|
+
# comment in the middle!
|
789
|
+
1
|
790
|
+
"""
|
791
|
+
When I run "seeing_is_believing --toggle-mark 5 --alignment-strategy chunk toggle_mark_with_chunk_alignments.rb"
|
792
|
+
Then stderr is empty
|
793
|
+
And the exit status is 0
|
794
|
+
And stdout is:
|
795
|
+
"""
|
796
|
+
1+1 # => 2
|
797
|
+
1+1+1
|
798
|
+
1+1+1+1
|
799
|
+
|
800
|
+
1 + 1 # =>{{" "}}
|
801
|
+
# comment in the middle!
|
802
|
+
1
|
803
|
+
"""
|
804
|
+
When I run "seeing_is_believing --toggle-mark 1 --alignment-strategy chunk toggle_mark_with_chunk_alignments.rb"
|
805
|
+
Then stderr is empty
|
806
|
+
And the exit status is 0
|
807
|
+
And stdout is:
|
808
|
+
"""
|
809
|
+
1+1
|
810
|
+
1+1+1
|
811
|
+
1+1+1+1
|
812
|
+
|
813
|
+
1 + 1
|
814
|
+
# comment in the middle!
|
815
|
+
1
|
816
|
+
"""
|
817
|
+
|
818
|
+
|
819
|
+
Scenario: --toggle-mark respects the --alignment-strategy of line and updates any existing annotations to respect it
|
820
|
+
Given the file "toggle_mark_with_line_alignments.rb":
|
821
|
+
"""
|
822
|
+
1
|
823
|
+
1 + 1# => x
|
824
|
+
1 + 1 + 1
|
825
|
+
"""
|
826
|
+
When I run "seeing_is_believing --toggle-mark 1 --alignment-strategy line toggle_mark_with_line_alignments.rb"
|
827
|
+
Then stderr is empty
|
828
|
+
And the exit status is 0
|
829
|
+
And stdout is:
|
830
|
+
"""
|
831
|
+
1 # =>{{" "}}
|
832
|
+
1 + 1 # => x
|
833
|
+
1 + 1 + 1
|
834
|
+
"""
|
835
|
+
When I run "seeing_is_believing --toggle-mark 2 --alignment-strategy line toggle_mark_with_line_alignments.rb"
|
836
|
+
Then stderr is empty
|
837
|
+
And the exit status is 0
|
838
|
+
And stdout is:
|
839
|
+
"""
|
840
|
+
1
|
841
|
+
1 + 1
|
842
|
+
1 + 1 + 1
|
843
|
+
"""
|
844
|
+
When I run "seeing_is_believing --toggle-mark 3 --alignment-strategy line toggle_mark_with_line_alignments.rb"
|
845
|
+
Then stderr is empty
|
846
|
+
And the exit status is 0
|
847
|
+
And stdout is:
|
848
|
+
"""
|
849
|
+
1
|
850
|
+
1 + 1 # => x
|
851
|
+
1 + 1 + 1 # =>{{" "}}
|
852
|
+
"""
|