seeing_is_believing 0.0.26 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Readme.md +0 -2
- data/features/errors.feature +13 -3
- data/features/examples.feature +5 -0
- data/features/flags.feature +64 -1
- data/features/regression.feature +63 -0
- data/lib/seeing_is_believing.rb +12 -7
- data/lib/seeing_is_believing/binary.rb +5 -4
- data/lib/seeing_is_believing/binary/{print_results_next_to_lines.rb → add_annotations.rb} +35 -19
- data/lib/seeing_is_believing/binary/arg_parser.rb +6 -1
- data/lib/seeing_is_believing/binary/remove_previous_annotations.rb +75 -0
- data/lib/seeing_is_believing/debugger.rb +36 -0
- data/lib/seeing_is_believing/expression_list.rb +15 -17
- data/lib/seeing_is_believing/remove_inline_comments.rb +33 -9
- data/lib/seeing_is_believing/syntax_analyzer.rb +2 -1
- data/lib/seeing_is_believing/version.rb +1 -1
- data/seeing_is_believing.gemspec +1 -1
- data/spec/{arg_parser_spec.rb → binary/arg_parser_spec.rb} +11 -0
- data/spec/{line_formatter_spec.rb → binary/line_formatter_spec.rb} +0 -0
- data/spec/binary/remove_previous_annotations_spec.rb +198 -0
- data/spec/debugger_spec.rb +27 -0
- data/spec/expression_list_spec.rb +4 -4
- data/spec/seeing_is_believing_spec.rb +42 -7
- data/spec/syntax_analyzer_spec.rb +1 -0
- metadata +16 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd476d63d1de8b5fced222b2d26b906a19b4cb5f
|
4
|
+
data.tar.gz: ce1c44ebecbe7c565f47131a554d368299078319
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee60234e1717c3cde6319b2930ead345af9e94723edfef4784ee479584476041bcaf87d2c896bb247c98b48a38a05062a71767f2bb86102fedcc4d009604b1a1
|
7
|
+
data.tar.gz: 8839249d298c32500fab42c3501eb4dc1705981c01b05932ff12ac94ab30a7e8df5924d39e895b0d971cae19ca7c4620c0caa0ad7ec941bb780057fd4b16e445
|
data/Readme.md
CHANGED
@@ -151,8 +151,6 @@ Todo
|
|
151
151
|
* Add xmpfilter option to sublime text
|
152
152
|
* Update TextMate examples to use same keys as sublime, add xmpfilter option on cmd+opt+N
|
153
153
|
* Move as much of the SyntaxAnalyzer as possible over to Parser and ditch Ripper altogether
|
154
|
-
* print exceptions at the end of the file, too
|
155
|
-
|
156
154
|
|
157
155
|
|
158
156
|
License
|
data/features/errors.feature
CHANGED
@@ -8,7 +8,7 @@ Feature: Running the binary unsuccessfully
|
|
8
8
|
Scenario: Raising exceptions
|
9
9
|
Given the file "raises_exception.rb":
|
10
10
|
"""
|
11
|
-
raise "ZOMG
|
11
|
+
raise "ZOMG\n!!!!"
|
12
12
|
"""
|
13
13
|
And the file "requires_exception_raising_code.rb":
|
14
14
|
"""
|
@@ -32,10 +32,20 @@ Feature: Running the binary unsuccessfully
|
|
32
32
|
end # => nil
|
33
33
|
|
34
34
|
def second_defined
|
35
|
-
require_relative 'raises_exception' # ~> RuntimeError: ZOMG
|
35
|
+
require_relative 'raises_exception' # ~> RuntimeError: ZOMG\n!!!!
|
36
36
|
end # => nil
|
37
37
|
|
38
38
|
first_defined
|
39
|
+
|
40
|
+
# ~> RuntimeError
|
41
|
+
# ~> ZOMG
|
42
|
+
# ~> !!!!
|
43
|
+
# ~>
|
44
|
+
# ~> {{Haiti.config.proving_grounds_dir}}/raises_exception.rb:1:in `<top (required)>'
|
45
|
+
# ~> requires_exception_raising_code.rb:6:in `require_relative'
|
46
|
+
# ~> requires_exception_raising_code.rb:6:in `second_defined'
|
47
|
+
# ~> requires_exception_raising_code.rb:2:in `first_defined'
|
48
|
+
# ~> requires_exception_raising_code.rb:9:in `<main>'
|
39
49
|
"""
|
40
50
|
|
41
51
|
Scenario: Syntactically invalid file
|
@@ -76,7 +86,7 @@ Feature: Running the binary unsuccessfully
|
|
76
86
|
When I run "seeing_is_believing stack_overflow.rb"
|
77
87
|
Then stderr is empty
|
78
88
|
And the exit status is 1
|
79
|
-
And stdout
|
89
|
+
And stdout includes:
|
80
90
|
"""
|
81
91
|
def m() m end # ~> SystemStackError: stack level too deep
|
82
92
|
m
|
data/features/examples.feature
CHANGED
data/features/flags.feature
CHANGED
@@ -2,6 +2,7 @@ Feature: Using flags
|
|
2
2
|
|
3
3
|
Sometimes you want more control over what comes out, for that we give you flags.
|
4
4
|
|
5
|
+
|
5
6
|
Scenario: --start-line
|
6
7
|
Given the file "start_line.rb":
|
7
8
|
"""
|
@@ -33,6 +34,7 @@ Feature: Using flags
|
|
33
34
|
3 # => 3
|
34
35
|
"""
|
35
36
|
|
37
|
+
|
36
38
|
Scenario: --end-line
|
37
39
|
Given the file "end_line.rb":
|
38
40
|
"""
|
@@ -64,6 +66,7 @@ Feature: Using flags
|
|
64
66
|
3 + 3
|
65
67
|
"""
|
66
68
|
|
69
|
+
|
67
70
|
Scenario: --start-line and --end-line
|
68
71
|
Given the file "start_and_end_line.rb":
|
69
72
|
"""
|
@@ -99,6 +102,7 @@ Feature: Using flags
|
|
99
102
|
4 + 4
|
100
103
|
"""
|
101
104
|
|
105
|
+
|
102
106
|
Scenario: --result-length sets the length of the portion including and after the # =>
|
103
107
|
Given the file "result_lengths.rb":
|
104
108
|
"""
|
@@ -129,8 +133,14 @@ Feature: Using flags
|
|
129
133
|
# >> aa...
|
130
134
|
|
131
135
|
# !> aa...
|
136
|
+
|
137
|
+
# ~> Ru...
|
138
|
+
# ~> aa...
|
139
|
+
# ~>
|
140
|
+
# ~> re...
|
132
141
|
"""
|
133
142
|
|
143
|
+
|
134
144
|
Scenario: --line-length sets the total length of a given line
|
135
145
|
Given the file "line_lengths.rb":
|
136
146
|
"""
|
@@ -157,6 +167,11 @@ Feature: Using flags
|
|
157
167
|
# >> aaaaaaaaaaaaaaaaaaaaaaaa...
|
158
168
|
|
159
169
|
# !> aaaaaaaaaaaaaaaaaaaaaaaa...
|
170
|
+
|
171
|
+
# ~> RuntimeError
|
172
|
+
# ~> aaaaaaaaaaaaaaaaaaaaaaaa...
|
173
|
+
# ~>
|
174
|
+
# ~> line_lengths.rb:7:in `<m...
|
160
175
|
"""
|
161
176
|
Given the file "line_lengths2.rb":
|
162
177
|
"""
|
@@ -169,6 +184,7 @@ Feature: Using flags
|
|
169
184
|
When I run "seeing_is_believing --line-length 14 line_lengths2.rb"
|
170
185
|
Then stdout is "12345"
|
171
186
|
|
187
|
+
|
172
188
|
Scenario: --require
|
173
189
|
Given the file "print_1.rb" "puts 1"
|
174
190
|
Given the file "print_2.rb" "puts 2"
|
@@ -185,6 +201,7 @@ Feature: Using flags
|
|
185
201
|
# >> 3
|
186
202
|
"""
|
187
203
|
|
204
|
+
|
188
205
|
Scenario: --program
|
189
206
|
When I run "seeing_is_believing --program '1'"
|
190
207
|
Then stderr is empty
|
@@ -194,6 +211,7 @@ Feature: Using flags
|
|
194
211
|
1 # => 1
|
195
212
|
"""
|
196
213
|
|
214
|
+
|
197
215
|
Scenario: --load-path
|
198
216
|
Given the file "print_1.rb" "puts 1"
|
199
217
|
And the file "some_dir/print_2.rb" "puts 2"
|
@@ -211,6 +229,7 @@ Feature: Using flags
|
|
211
229
|
"""
|
212
230
|
And the exit status is 0
|
213
231
|
|
232
|
+
|
214
233
|
Scenario: --encoding
|
215
234
|
Given the file "utf-8.rb" "'ç'"
|
216
235
|
When I run "seeing_is_believing --encoding u utf-8.rb"
|
@@ -221,6 +240,7 @@ Feature: Using flags
|
|
221
240
|
'ç' # => "ç"
|
222
241
|
"""
|
223
242
|
|
243
|
+
|
224
244
|
Scenario: --as and stdin
|
225
245
|
Given the file "example.rb" "1+1"
|
226
246
|
Given the stdin content:
|
@@ -237,6 +257,7 @@ Feature: Using flags
|
|
237
257
|
__FILE__ # => "example.rb"
|
238
258
|
"""
|
239
259
|
|
260
|
+
|
240
261
|
Scenario: --as and -e
|
241
262
|
Given the file "example.rb" "1+1"
|
242
263
|
When I run 'seeing_is_believing --as example.rb -e "__FILE__"'
|
@@ -244,6 +265,7 @@ Feature: Using flags
|
|
244
265
|
And the exit status is 0
|
245
266
|
And stdout is '__FILE__ # => "example.rb"'
|
246
267
|
|
268
|
+
|
247
269
|
Scenario: --clean
|
248
270
|
Given the file "example.rb":
|
249
271
|
"""
|
@@ -269,24 +291,28 @@ Feature: Using flags
|
|
269
291
|
1
|
270
292
|
"""
|
271
293
|
|
294
|
+
|
272
295
|
Scenario: --clean on an invalid file will clean
|
273
296
|
When I run 'seeing_is_believing --clean -e "1+ # => lkj"'
|
274
297
|
Then stderr is empty
|
275
298
|
And the exit status is 0
|
276
299
|
And stdout is '1+'
|
277
300
|
|
301
|
+
|
278
302
|
Scenario: --version
|
279
303
|
When I run 'seeing_is_believing --version'
|
280
304
|
Then stderr is empty
|
281
305
|
And the exit status is 0
|
282
306
|
And stdout is '{{SeeingIsBelieving::VERSION}}'
|
283
307
|
|
308
|
+
|
284
309
|
Scenario: --help
|
285
310
|
When I run "seeing_is_believing --help"
|
286
311
|
Then stderr is empty
|
287
312
|
And the exit status is 0
|
288
313
|
And stdout includes "Usage"
|
289
314
|
|
315
|
+
|
290
316
|
Scenario: --timeout
|
291
317
|
Given the file "example.rb" "sleep 1"
|
292
318
|
When I run "seeing_is_believing --timeout 0.1 example.rb"
|
@@ -294,6 +320,7 @@ Feature: Using flags
|
|
294
320
|
And the exit status is 2
|
295
321
|
And stderr is "Timeout Error after 0.1 seconds!"
|
296
322
|
|
323
|
+
|
297
324
|
Scenario: --timeout
|
298
325
|
Given the file "example.rb" "1 + 1"
|
299
326
|
When I run "seeing_is_believing --timeout 1.0 example.rb"
|
@@ -301,6 +328,7 @@ Feature: Using flags
|
|
301
328
|
And the exit status is 0
|
302
329
|
And stdout is "1 + 1 # => 2"
|
303
330
|
|
331
|
+
|
304
332
|
Scenario: --alignment-strategy file
|
305
333
|
Given the file "file_alignments.rb":
|
306
334
|
"""
|
@@ -405,6 +433,7 @@ Feature: Using flags
|
|
405
433
|
When I run "seeing_is_believing --inherit-exit-status exit_status.rb"
|
406
434
|
Then the exit status is 123
|
407
435
|
|
436
|
+
|
408
437
|
# Show that Ruby exceptions exit with 1, and --inherit-exit-status does as well
|
409
438
|
Scenario: --inherit-exit-status
|
410
439
|
Given the file "exception_exit_status.rb" "raise Exception"
|
@@ -413,6 +442,7 @@ Feature: Using flags
|
|
413
442
|
When I run "seeing_is_believing --inherit-exit-status exception_exit_status.rb"
|
414
443
|
Then the exit status is 1
|
415
444
|
|
445
|
+
|
416
446
|
Scenario: --inherit-exit-status in an at_exit block
|
417
447
|
Given the file "exit_status_in_at_exit_block.rb" "at_exit { exit 10 }"
|
418
448
|
When I run "seeing_is_believing exit_status_in_at_exit_block.rb"
|
@@ -420,7 +450,7 @@ Feature: Using flags
|
|
420
450
|
When I run "seeing_is_believing --inherit-exit-status exit_status_in_at_exit_block.rb"
|
421
451
|
Then the exit status is 10
|
422
452
|
|
423
|
-
|
453
|
+
|
424
454
|
Scenario: --xmpfilter-style
|
425
455
|
Given the file "magic_comments.rb":
|
426
456
|
"""
|
@@ -449,3 +479,36 @@ Feature: Using flags
|
|
449
479
|
"omg2"
|
450
480
|
# => "omg2"
|
451
481
|
"""
|
482
|
+
|
483
|
+
Scenario: --debug
|
484
|
+
Given the file "simple_program.rb":
|
485
|
+
"""
|
486
|
+
# encoding: utf-8
|
487
|
+
1# 123
|
488
|
+
2
|
489
|
+
"""
|
490
|
+
When I run "seeing_is_believing --debug simple_program.rb"
|
491
|
+
Then stderr is empty
|
492
|
+
And the exit status is 0
|
493
|
+
# source without comments
|
494
|
+
And stdout includes "SOURCE WITHOUT COMMENTS:"
|
495
|
+
And stdout includes:
|
496
|
+
"""
|
497
|
+
# encoding: utf-8
|
498
|
+
1
|
499
|
+
2
|
500
|
+
"""
|
501
|
+
# expression evaluation
|
502
|
+
And stdout includes "EXPRESSION EVALUATION:"
|
503
|
+
And stdout includes "GENERATED"
|
504
|
+
# translated program
|
505
|
+
And stdout includes "TRANSLATED PROGRAM:"
|
506
|
+
And stdout includes "$seeing_is_believing_current_result"
|
507
|
+
# result
|
508
|
+
And stdout includes "RESULT:"
|
509
|
+
And stdout includes:
|
510
|
+
"""
|
511
|
+
# encoding: utf-8
|
512
|
+
1# 123
|
513
|
+
2 # => 2
|
514
|
+
"""
|
data/features/regression.feature
CHANGED
@@ -3,6 +3,7 @@ Feature:
|
|
3
3
|
As the dev who wrote SeeingIsBelieving
|
4
4
|
I want to have tests on those bugs that I found and could not have predicted
|
5
5
|
|
6
|
+
|
6
7
|
Scenario: A program containing a single comment
|
7
8
|
Given the stdin content "# single comment"
|
8
9
|
When I run "seeing_is_believing"
|
@@ -10,6 +11,7 @@ Feature:
|
|
10
11
|
And the exit status is 0
|
11
12
|
And stdout is "# single comment"
|
12
13
|
|
14
|
+
|
13
15
|
Scenario: Name error just fucks everything
|
14
16
|
Given the file "no_method_error.rb":
|
15
17
|
"""
|
@@ -21,8 +23,14 @@ Feature:
|
|
21
23
|
And stdout is:
|
22
24
|
"""
|
23
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>'
|
24
31
|
"""
|
25
32
|
|
33
|
+
|
26
34
|
Scenario: Errors being raised in the evaluated code that don't exist in the evaluating code
|
27
35
|
Given the file "raising_custom_errors.rb":
|
28
36
|
"""
|
@@ -37,6 +45,7 @@ Feature:
|
|
37
45
|
Then stderr is empty
|
38
46
|
And the exit status is 1
|
39
47
|
|
48
|
+
|
40
49
|
Scenario: statements that inherit void value expressions
|
41
50
|
Given the file "statements_that_inherit_void_value_expressions.rb":
|
42
51
|
"""
|
@@ -60,6 +69,7 @@ Feature:
|
|
60
69
|
m # => 1
|
61
70
|
"""
|
62
71
|
|
72
|
+
|
63
73
|
Scenario: comments aren't updated with values
|
64
74
|
Given the file "comments_arent_updated_with_values.rb":
|
65
75
|
"""
|
@@ -73,6 +83,7 @@ Feature:
|
|
73
83
|
2 # some other comment
|
74
84
|
"""
|
75
85
|
|
86
|
+
|
76
87
|
# NOTE: Don't change the body of this file, it's nondeterministic
|
77
88
|
# I have no idea why this particular string fucks Parser up, but other similar ones don't
|
78
89
|
# We can probably remove this once parser reaches 2.0.0, they've fixed this bug now.
|
@@ -100,3 +111,55 @@ Feature:
|
|
100
111
|
2 # => 2
|
101
112
|
__END__
|
102
113
|
"""
|
114
|
+
|
115
|
+
|
116
|
+
Scenario: Unintentional magic comment on not-first line
|
117
|
+
Given the file "wtf.rb":
|
118
|
+
"""
|
119
|
+
1
|
120
|
+
# Transfer-Encoding: chunked
|
121
|
+
"""
|
122
|
+
When I run "seeing_is_believing wtf.rb"
|
123
|
+
Then stdout is:
|
124
|
+
"""
|
125
|
+
1 # => 1
|
126
|
+
# Transfer-Encoding: chunked
|
127
|
+
"""
|
128
|
+
|
129
|
+
|
130
|
+
Scenario: The file contains content that looks like previous output, should not be removed
|
131
|
+
Given the file "not_actually_previous_output.rb":
|
132
|
+
"""
|
133
|
+
"1 # => 1"
|
134
|
+
"2 # ~> SomeError: some message"
|
135
|
+
|
136
|
+
"# >> some stdout"
|
137
|
+
|
138
|
+
"# !> some stderr"
|
139
|
+
"""
|
140
|
+
When I run "seeing_is_believing not_actually_previous_output.rb"
|
141
|
+
Then stdout is:
|
142
|
+
"""
|
143
|
+
"1 # => 1" # => "1 # => 1"
|
144
|
+
"2 # ~> SomeError: some message" # => "2 # ~> SomeError: some message"
|
145
|
+
|
146
|
+
"# >> some stdout" # => "# >> some stdout"
|
147
|
+
|
148
|
+
"# !> some stderr" # => "# !> some stderr"
|
149
|
+
"""
|
150
|
+
|
151
|
+
|
152
|
+
Scenario: Multiple leading inline comments should make it through to the final program
|
153
|
+
Given the file "multiple_leading_comments.rb":
|
154
|
+
"""
|
155
|
+
#!/usr/bin/env ruby
|
156
|
+
# encoding: utf-8
|
157
|
+
'ç'
|
158
|
+
"""
|
159
|
+
When I run "seeing_is_believing multiple_leading_comments.rb"
|
160
|
+
Then stdout is:
|
161
|
+
"""
|
162
|
+
#!/usr/bin/env ruby
|
163
|
+
# encoding: utf-8
|
164
|
+
'ç' # => "ç"
|
165
|
+
"""
|
data/lib/seeing_is_believing.rb
CHANGED
@@ -5,6 +5,7 @@ require 'timeout'
|
|
5
5
|
require 'seeing_is_believing/queue'
|
6
6
|
require 'seeing_is_believing/result'
|
7
7
|
require 'seeing_is_believing/version'
|
8
|
+
require 'seeing_is_believing/debugger'
|
8
9
|
require 'seeing_is_believing/expression_list'
|
9
10
|
require 'seeing_is_believing/remove_inline_comments'
|
10
11
|
require 'seeing_is_believing/evaluate_by_moving_files'
|
@@ -18,9 +19,9 @@ class SeeingIsBelieving
|
|
18
19
|
new(*args).call
|
19
20
|
end
|
20
21
|
|
21
|
-
def initialize(
|
22
|
-
|
23
|
-
@stream = to_stream
|
22
|
+
def initialize(program, options={})
|
23
|
+
program_string = RemoveInlineComments::NonLeading.call program
|
24
|
+
@stream = to_stream program_string
|
24
25
|
@matrix_filename = options[:matrix_filename]
|
25
26
|
@filename = options[:filename]
|
26
27
|
@stdin = to_stream options.fetch(:stdin, '')
|
@@ -29,6 +30,9 @@ class SeeingIsBelieving
|
|
29
30
|
@encoding = options.fetch :encoding, nil
|
30
31
|
@line_number = 1
|
31
32
|
@timeout = options[:timeout]
|
33
|
+
@debugger = options.fetch :debugger, Debugger.new(enabled: false)
|
34
|
+
|
35
|
+
debugger.context("SOURCE WITHOUT COMMENTS") { program_string }
|
32
36
|
end
|
33
37
|
|
34
38
|
# I'd like to refactor this, but I was unsatisfied with the three different things I tried.
|
@@ -71,6 +75,7 @@ class SeeingIsBelieving
|
|
71
75
|
|
72
76
|
# build the program
|
73
77
|
program = leading_comments << record_exceptions_in(body) << data_segment
|
78
|
+
debugger.context("TRANSLATED PROGRAM") { program }
|
74
79
|
|
75
80
|
# return the result
|
76
81
|
result_for program, max_line_number
|
@@ -79,14 +84,14 @@ class SeeingIsBelieving
|
|
79
84
|
|
80
85
|
private
|
81
86
|
|
82
|
-
attr_reader :stream, :matrix_filename
|
87
|
+
attr_reader :stream, :matrix_filename, :debugger
|
83
88
|
|
84
89
|
def expression_list
|
85
|
-
@expression_list ||= ExpressionList.new
|
90
|
+
@expression_list ||= ExpressionList.new debugger: debugger,
|
91
|
+
get_next_line: lambda { next_line_queue.dequeue },
|
86
92
|
peek_next_line: lambda { next_line_queue.peek },
|
87
93
|
on_complete: lambda { |line, children, completions, offset|
|
88
|
-
expression =
|
89
|
-
[line, *children, *completions].map(&:chomp).join("\n")
|
94
|
+
expression = [line, *children, *completions].map(&:chomp).join("\n")
|
90
95
|
|
91
96
|
if do_not_record? expression
|
92
97
|
expression + "\n"
|