andyw8-seeing_is_believing 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/test.yml +60 -0
  3. data/.gitignore +19 -0
  4. data/.rspec +2 -0
  5. data/Gemfile +2 -0
  6. data/README.md +70 -0
  7. data/Rakefile +88 -0
  8. data/appveyor.yml +32 -0
  9. data/bin/seeing_is_believing +7 -0
  10. data/docs/example.gif +0 -0
  11. data/docs/frog-brown.png +0 -0
  12. data/docs/sib-streaming.gif +0 -0
  13. data/features/deprecated-flags.feature +91 -0
  14. data/features/errors.feature +155 -0
  15. data/features/examples.feature +423 -0
  16. data/features/flags.feature +852 -0
  17. data/features/regression.feature +898 -0
  18. data/features/support/env.rb +102 -0
  19. data/features/xmpfilter-style.feature +471 -0
  20. data/lib/seeing_is_believing/binary/align_chunk.rb +47 -0
  21. data/lib/seeing_is_believing/binary/align_file.rb +24 -0
  22. data/lib/seeing_is_believing/binary/align_line.rb +25 -0
  23. data/lib/seeing_is_believing/binary/annotate_end_of_file.rb +56 -0
  24. data/lib/seeing_is_believing/binary/annotate_every_line.rb +52 -0
  25. data/lib/seeing_is_believing/binary/annotate_marked_lines.rb +179 -0
  26. data/lib/seeing_is_believing/binary/comment_lines.rb +36 -0
  27. data/lib/seeing_is_believing/binary/commentable_lines.rb +126 -0
  28. data/lib/seeing_is_believing/binary/config.rb +455 -0
  29. data/lib/seeing_is_believing/binary/data_structures.rb +58 -0
  30. data/lib/seeing_is_believing/binary/engine.rb +161 -0
  31. data/lib/seeing_is_believing/binary/format_comment.rb +79 -0
  32. data/lib/seeing_is_believing/binary/interline_align.rb +57 -0
  33. data/lib/seeing_is_believing/binary/remove_annotations.rb +113 -0
  34. data/lib/seeing_is_believing/binary/rewrite_comments.rb +62 -0
  35. data/lib/seeing_is_believing/binary.rb +73 -0
  36. data/lib/seeing_is_believing/code.rb +139 -0
  37. data/lib/seeing_is_believing/compatibility.rb +28 -0
  38. data/lib/seeing_is_believing/debugger.rb +32 -0
  39. data/lib/seeing_is_believing/error.rb +17 -0
  40. data/lib/seeing_is_believing/evaluate_by_moving_files.rb +195 -0
  41. data/lib/seeing_is_believing/event_stream/consumer.rb +221 -0
  42. data/lib/seeing_is_believing/event_stream/events.rb +193 -0
  43. data/lib/seeing_is_believing/event_stream/handlers/debug.rb +61 -0
  44. data/lib/seeing_is_believing/event_stream/handlers/record_exit_events.rb +26 -0
  45. data/lib/seeing_is_believing/event_stream/handlers/stream_json_events.rb +23 -0
  46. data/lib/seeing_is_believing/event_stream/handlers/update_result.rb +41 -0
  47. data/lib/seeing_is_believing/event_stream/producer.rb +178 -0
  48. data/lib/seeing_is_believing/hard_core_ensure.rb +58 -0
  49. data/lib/seeing_is_believing/hash_struct.rb +206 -0
  50. data/lib/seeing_is_believing/result.rb +89 -0
  51. data/lib/seeing_is_believing/safe.rb +112 -0
  52. data/lib/seeing_is_believing/swap_files.rb +90 -0
  53. data/lib/seeing_is_believing/the_matrix.rb +97 -0
  54. data/lib/seeing_is_believing/version.rb +3 -0
  55. data/lib/seeing_is_believing/wrap_expressions.rb +265 -0
  56. data/lib/seeing_is_believing/wrap_expressions_with_inspect.rb +19 -0
  57. data/lib/seeing_is_believing.rb +69 -0
  58. data/seeing_is_believing.gemspec +84 -0
  59. data/spec/binary/alignment_specs.rb +27 -0
  60. data/spec/binary/comment_lines_spec.rb +852 -0
  61. data/spec/binary/config_spec.rb +831 -0
  62. data/spec/binary/engine_spec.rb +114 -0
  63. data/spec/binary/format_comment_spec.rb +210 -0
  64. data/spec/binary/marker_spec.rb +71 -0
  65. data/spec/binary/remove_annotations_spec.rb +342 -0
  66. data/spec/binary/rewrite_comments_spec.rb +106 -0
  67. data/spec/code_spec.rb +233 -0
  68. data/spec/debugger_spec.rb +45 -0
  69. data/spec/evaluate_by_moving_files_spec.rb +204 -0
  70. data/spec/event_stream_spec.rb +762 -0
  71. data/spec/hard_core_ensure_spec.rb +120 -0
  72. data/spec/hash_struct_spec.rb +514 -0
  73. data/spec/seeing_is_believing_spec.rb +1094 -0
  74. data/spec/sib_spec_helpers/version.rb +17 -0
  75. data/spec/spec_helper.rb +26 -0
  76. data/spec/spec_helper_spec.rb +16 -0
  77. data/spec/wrap_expressions_spec.rb +1013 -0
  78. metadata +340 -0
@@ -0,0 +1,423 @@
1
+ Feature: Running the binary successfully
2
+
3
+ They say seeing is believing. So to believe that this works
4
+ I want to execute the actual binary and look at actual results.
5
+
6
+ It should generally record every line of code and display the results
7
+ adjacent to the line, with output and errors displayed at the end of the file.
8
+
9
+ Scenario: Some basic functionality
10
+ Given the file "basic_functionality.rb":
11
+ """
12
+ # iteration
13
+ 5.times do |i|
14
+ i * 2
15
+ end
16
+
17
+ # method and invocations
18
+ def meth(n)
19
+ n
20
+ end
21
+
22
+ meth "12"
23
+ meth "34"
24
+
25
+ # block style comments
26
+ =begin
27
+ I don't ever actually write
28
+ comments like this
29
+ =end
30
+
31
+ # multilinezzz
32
+ "a
33
+ b"
34
+ /a
35
+ b/x
36
+
37
+ <<HERE
38
+ is a doc
39
+ HERE
40
+
41
+ # method invocation that occurs entirely on the next line
42
+ [*1..10]
43
+ .select(&:even?)
44
+ .map { |n| n * 2 }
45
+
46
+ # mutliple levels of nesting
47
+ class User
48
+ def initialize(name)
49
+ @name = name
50
+ end
51
+
52
+ def name
53
+ @name
54
+ end
55
+ end
56
+
57
+ User.new("Josh").name
58
+ User.new("Rick").name
59
+ """
60
+ When I run "seeing_is_believing basic_functionality.rb"
61
+ Then stderr is empty
62
+ And the exit status is 0
63
+ And stdout is:
64
+ """
65
+ # iteration
66
+ 5.times do |i| # => 5
67
+ i * 2 # => 0, 2, 4, 6, 8
68
+ end # => 5
69
+
70
+ # method and invocations
71
+ def meth(n)
72
+ n # => "12", "34"
73
+ end # => {{method_result :meth}}
74
+
75
+ meth "12" # => "12"
76
+ meth "34" # => "34"
77
+
78
+ # block style comments
79
+ =begin
80
+ I don't ever actually write
81
+ comments like this
82
+ =end
83
+
84
+ # multilinezzz
85
+ "a
86
+ b" # => "a\n b"
87
+ /a
88
+ b/x # => /a\n b/x
89
+
90
+ <<HERE # => "is a doc\n"
91
+ is a doc
92
+ HERE
93
+
94
+ # method invocation that occurs entirely on the next line
95
+ [*1..10] # => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
96
+ .select(&:even?) # => [2, 4, 6, 8, 10]
97
+ .map { |n| n * 2 } # => [4, 8, 12, 16, 20]
98
+
99
+ # mutliple levels of nesting
100
+ class User
101
+ def initialize(name)
102
+ @name = name # => "Josh", "Rick"
103
+ end # => {{method_result :initialize}}
104
+
105
+ def name
106
+ @name # => "Josh", "Rick"
107
+ end # => {{method_result :name}}
108
+ end # => {{method_result :name}}
109
+
110
+ User.new("Josh").name # => "Josh"
111
+ User.new("Rick").name # => "Rick"
112
+ """
113
+
114
+ Scenario: Passing previous output back into input
115
+ Given the file "previous_output.rb":
116
+ """
117
+ 1 + 1 # => not 2
118
+ 2 + 2 # ~> Exception, something
119
+
120
+
121
+ # >> some stdout output
122
+
123
+ # !> some stderr output
124
+
125
+ # ~> Exception
126
+ # ~> message
127
+ # ~>
128
+ # ~> backtrace
129
+ __END__
130
+ """
131
+ When I run "seeing_is_believing previous_output.rb"
132
+ Then stderr is empty
133
+ And the exit status is 0
134
+ And stdout is:
135
+ """
136
+ 1 + 1 # => 2
137
+ 2 + 2 # => 4
138
+
139
+ __END__
140
+ """
141
+
142
+ Scenario: Printing within the file
143
+ Given the file "printing.rb":
144
+ """
145
+ print "hel"
146
+ puts "lo!"
147
+ puts ":)"
148
+ $stderr.puts "goodbye"
149
+ """
150
+ When I run "seeing_is_believing printing.rb"
151
+ Then stderr is empty
152
+ And the exit status is 0
153
+ And stdout is:
154
+ """
155
+ print "hel" # => nil
156
+ puts "lo!" # => nil
157
+ puts ":)" # => nil
158
+ $stderr.puts "goodbye" # => nil
159
+
160
+ # >> hello!
161
+ # >> :)
162
+
163
+ # !> goodbye
164
+ """
165
+
166
+ Scenario: Respects macros / magic comments
167
+ Given the file "some_dir/uses_macros.rb":
168
+ """
169
+ # encoding: EUC-JP
170
+ __FILE__
171
+ __LINE__
172
+ __ENCODING__
173
+ $stdout.puts "omg"
174
+ $stderr.puts "hi"
175
+ DATA.read
176
+ __LINE__
177
+ __END__
178
+ 1
179
+ 2
180
+ """
181
+ When I run "seeing_is_believing some_dir/uses_macros.rb"
182
+ Then stderr is empty
183
+ And the exit status is 0
184
+ And stdout is:
185
+ """
186
+ # encoding: EUC-JP
187
+ __FILE__ # => "some_dir/uses_macros.rb"
188
+ __LINE__ # => 3
189
+ __ENCODING__ # => #<Encoding:EUC-JP>
190
+ $stdout.puts "omg" # => nil
191
+ $stderr.puts "hi" # => nil
192
+ DATA.read # => "1\n2\n"
193
+ __LINE__ # => 8
194
+
195
+ # >> omg
196
+
197
+ # !> hi
198
+ __END__
199
+ 1
200
+ 2
201
+ """
202
+
203
+ Scenario: Reading from stdin
204
+ Given the stdin content "hi!"
205
+ And the file "reads_from_stdin.rb":
206
+ """
207
+ puts "You said: #{gets}"
208
+ """
209
+ When I run "seeing_is_believing reads_from_stdin.rb"
210
+ Then stderr is empty
211
+ And the exit status is 0
212
+ And stdout is:
213
+ """
214
+ puts "You said: #{gets}" # => nil
215
+
216
+ # >> You said: hi!
217
+ """
218
+
219
+ Scenario: Passing the file on stdin
220
+ Given the stdin content "1 + 1"
221
+ When I run "seeing_is_believing"
222
+ Then stderr is empty
223
+ And the exit status is 0
224
+ And stdout is "1 + 1 # => 2"
225
+
226
+ Scenario: Can exec another process, it records as many lines get exec'd, passes file descriptors, records exec'd output data
227
+ Given the stdin content "pass this through"
228
+ And the file "calls_exec.rb":
229
+ """
230
+ $stdout.puts "First program to stdout"
231
+ $stderr.puts "First program to stderr"
232
+ exec 'ruby', '-e', '
233
+ $stdout.puts "Stdin passed to second program: #{gets.inspect}"
234
+ $stderr.puts "Exec\'d file to stderr"
235
+ $stdout.flush
236
+ exec "ruby", "-v"
237
+ '
238
+ """
239
+ When I run "seeing_is_believing calls_exec.rb"
240
+ Then stderr is empty
241
+ And stdout is:
242
+ """
243
+ $stdout.puts "First program to stdout" # => nil
244
+ $stderr.puts "First program to stderr" # => nil
245
+ exec 'ruby', '-e', '
246
+ $stdout.puts "Stdin passed to second program: #{gets.inspect}"
247
+ $stderr.puts "Exec\'d file to stderr"
248
+ $stdout.flush
249
+ exec "ruby", "-v"
250
+ '
251
+
252
+ # >> First program to stdout
253
+ # >> Stdin passed to second program: "pass this through"
254
+ # >> {{`ruby -v`.chomp}}
255
+
256
+ # !> First program to stderr
257
+ # !> Exec'd file to stderr
258
+ """
259
+ And the exit status is 0
260
+
261
+ @not-windows
262
+ Scenario: Fork records data in parent and child, parent exec does not affect it.
263
+ Given the file "fork_exec_parent.rb":
264
+ """
265
+ :both
266
+ if fork #
267
+ :parent
268
+ exec 'echo', 'hello'
269
+ else
270
+ sleep 1 #
271
+ :child
272
+ end
273
+ :child
274
+
275
+ # >> hello
276
+ """
277
+ When I run "seeing_is_believing fork_exec_parent.rb"
278
+ Then stdout is:
279
+ """
280
+ :both # => :both
281
+ if fork #
282
+ :parent # => :parent
283
+ exec 'echo', 'hello'
284
+ else
285
+ sleep 1 #
286
+ :child # => :child
287
+ end # => :child
288
+ :child # => :child
289
+
290
+ # >> hello
291
+ """
292
+
293
+ @not-windows
294
+ Scenario: Fork records data in parent and child, child exec does not affect it.
295
+ Given the file "fork_exec_child.rb":
296
+ """
297
+ :both
298
+ if fork #
299
+ sleep 1 #
300
+ :parent
301
+ else
302
+ :child
303
+ exec 'echo', 'hello'
304
+ end
305
+ :parent
306
+
307
+ # >> hello
308
+ """
309
+ When I run "seeing_is_believing fork_exec_child.rb"
310
+ Then stdout is:
311
+ """
312
+ :both # => :both
313
+ if fork #
314
+ sleep 1 #
315
+ :parent # => :parent
316
+ else
317
+ :child # => :child
318
+ exec 'echo', 'hello'
319
+ end # => :parent
320
+ :parent # => :parent
321
+
322
+ # >> hello
323
+ """
324
+
325
+
326
+ Scenario: Implicit regexp conditional
327
+ Given the stdin content "abc"
328
+ And the file "implicit_regex_conditional.rb":
329
+ """
330
+ gets
331
+ if /(.)c/
332
+ $1
333
+ end
334
+ """
335
+ When I run "seeing_is_believing implicit_regex_conditional.rb"
336
+ Then stdout is:
337
+ """
338
+ gets # => "abc"
339
+ if /(.)c/ # => 1
340
+ $1 # => "b"
341
+ end # => "b"
342
+ """
343
+
344
+
345
+ Scenario: BEGIN and END blocks
346
+ Given the file "BEGIN_and_END.rb":
347
+ """
348
+ # encoding: utf-8
349
+ p [:a, __LINE__]
350
+ BEGIN {
351
+ p [:b, __LINE__]
352
+ BEGIN { p [:c, __LINE__] }
353
+ }
354
+ p [:d, __LINE__]
355
+ END {
356
+ p [:e, __LINE__]
357
+ }
358
+ p [:f, __LINE__]
359
+ BEGIN { p [:g, __LINE__] }
360
+ END { p [:h, __LINE__] }
361
+ p [:i, __LINE__]
362
+ "π"
363
+ """
364
+ When I run "seeing_is_believing BEGIN_and_END.rb"
365
+ Then stderr is empty
366
+ Then stdout is:
367
+ """
368
+ # encoding: utf-8
369
+ p [:a, __LINE__] # => [:a, 2]
370
+ BEGIN {
371
+ p [:b, __LINE__] # => [:b, 4]
372
+ BEGIN { p [:c, __LINE__] } # => [:c, 5]
373
+ }
374
+ p [:d, __LINE__] # => [:d, 7]
375
+ END {
376
+ p [:e, __LINE__] # => [:e, 9]
377
+ }
378
+ p [:f, __LINE__] # => [:f, 11]
379
+ BEGIN { p [:g, __LINE__] } # => [:g, 12]
380
+ END { p [:h, __LINE__] } # => [:h, 13]
381
+ p [:i, __LINE__] # => [:i, 14]
382
+ "π" # => "π"
383
+
384
+ # >> [:c, 5]
385
+ # >> [:b, 4]
386
+ # >> [:g, 12]
387
+ # >> [:a, 2]
388
+ # >> [:d, 7]
389
+ # >> [:f, 11]
390
+ # >> [:i, 14]
391
+ # >> [:h, 13]
392
+ # >> [:e, 9]
393
+ """
394
+ When I run "seeing_is_believing BEGIN_and_END.rb --xmpfilter-style"
395
+ Then stderr is empty
396
+ Then stdout is:
397
+ """
398
+ # encoding: utf-8
399
+ p [:a, __LINE__]
400
+ BEGIN {
401
+ p [:b, __LINE__]
402
+ BEGIN { p [:c, __LINE__] }
403
+ }
404
+ p [:d, __LINE__]
405
+ END {
406
+ p [:e, __LINE__]
407
+ }
408
+ p [:f, __LINE__]
409
+ BEGIN { p [:g, __LINE__] }
410
+ END { p [:h, __LINE__] }
411
+ p [:i, __LINE__]
412
+ "π"
413
+
414
+ # >> [:c, 5]
415
+ # >> [:b, 4]
416
+ # >> [:g, 12]
417
+ # >> [:a, 2]
418
+ # >> [:d, 7]
419
+ # >> [:f, 11]
420
+ # >> [:i, 14]
421
+ # >> [:h, 13]
422
+ # >> [:e, 9]
423
+ """