seeing_is_believing 0.0.19 → 0.0.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/features/errors.feature +5 -6
- data/features/examples.feature +14 -14
- data/features/flags.feature +50 -6
- data/lib/seeing_is_believing/binary.rb +14 -8
- data/lib/seeing_is_believing/binary/align_chunk.rb +3 -1
- data/lib/seeing_is_believing/binary/arg_parser.rb +5 -5
- data/lib/seeing_is_believing/version.rb +1 -1
- data/spec/arg_parser_spec.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9ba8a14985e629d8a7aa7f9f850bbbe9b720563
|
4
|
+
data.tar.gz: 562f431d621620445ab1387c8a20f781f0cfb26c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1c475f28d6b6125acdcd00c42393a623d72f3a89fa07b31619b484fa18e427bbdce098386e23ab3d4add181be07ed513aa5b4caeb41e48ff002e4f130520cb6
|
7
|
+
data.tar.gz: 61fd93446e41d472e1d4afd745e7d5bd981af84c7bf139154fec8dfcf5416330374f87e91759be6f21c64f369d60c0628f1f055e359cf7377167d99cc7e3a921
|
data/.gitignore
CHANGED
data/features/errors.feature
CHANGED
@@ -5,7 +5,6 @@ Feature: Running the binary unsuccessfully
|
|
5
5
|
|
6
6
|
# show that it displalys next to the first place in the file
|
7
7
|
# and should maybe print the stacktrace at the bottom
|
8
|
-
@wip
|
9
8
|
Scenario: Raising exceptions
|
10
9
|
Given the file "raises_exception.rb":
|
11
10
|
"""
|
@@ -30,7 +29,7 @@ Feature: Running the binary unsuccessfully
|
|
30
29
|
"""
|
31
30
|
def first_defined
|
32
31
|
second_defined
|
33
|
-
end
|
32
|
+
end # => nil
|
34
33
|
|
35
34
|
def second_defined
|
36
35
|
require_relative 'raises_exception' # ~> RuntimeError: ZOMG!
|
@@ -46,26 +45,26 @@ Feature: Running the binary unsuccessfully
|
|
46
45
|
"""
|
47
46
|
When I run "seeing_is_believing invalid_syntax.rb"
|
48
47
|
Then stderr includes "1: unterminated string meets end of file"
|
49
|
-
And the exit status is
|
48
|
+
And the exit status is 2
|
50
49
|
And stdout is empty
|
51
50
|
|
52
51
|
Scenario: Passing a nonexistent file
|
53
52
|
When I run "seeing_is_believing this_file_does_not_exist.rb"
|
54
53
|
Then stderr is "this_file_does_not_exist.rb does not exist!"
|
55
|
-
And the exit status is
|
54
|
+
And the exit status is 2
|
56
55
|
And stdout is empty
|
57
56
|
|
58
57
|
Scenario: Passing unknown options
|
59
58
|
Given the file "some_file" "1"
|
60
59
|
When I run "seeing_is_believing --unknown-option"
|
61
60
|
Then stderr is 'Unknown option: "--unknown-option"'
|
62
|
-
And the exit status is
|
61
|
+
And the exit status is 2
|
63
62
|
And stdout is empty
|
64
63
|
|
65
64
|
Scenario: Passing an unknown option with a value but forgetting the filename
|
66
65
|
When I run "seeing_is_believing --unknown-option some-value"
|
67
66
|
Then stderr is 'Unknown option: "--unknown-option"'
|
68
|
-
And the exit status is
|
67
|
+
And the exit status is 2
|
69
68
|
And stdout is empty
|
70
69
|
|
71
70
|
Scenario: Stack overflow
|
data/features/examples.feature
CHANGED
@@ -64,16 +64,16 @@ Feature: Running the binary successfully
|
|
64
64
|
"""
|
65
65
|
# iteration
|
66
66
|
5.times do |i|
|
67
|
-
i * 2
|
68
|
-
end
|
67
|
+
i * 2 # => 0, 2, 4, 6, 8
|
68
|
+
end # => 5
|
69
69
|
|
70
70
|
# method and invocations
|
71
71
|
def meth(n)
|
72
|
-
n
|
73
|
-
end
|
72
|
+
n # => "12", "34"
|
73
|
+
end # => nil
|
74
74
|
|
75
|
-
meth "12"
|
76
|
-
meth "34"
|
75
|
+
meth "12" # => "12"
|
76
|
+
meth "34" # => "34"
|
77
77
|
|
78
78
|
# block style comments
|
79
79
|
=begin
|
@@ -83,9 +83,9 @@ Feature: Running the binary successfully
|
|
83
83
|
|
84
84
|
# multilinezzz
|
85
85
|
"a
|
86
|
-
b"
|
86
|
+
b" # => "a\n b"
|
87
87
|
/a
|
88
|
-
b/x
|
88
|
+
b/x # => /a\n b/x
|
89
89
|
|
90
90
|
# don't record heredocs b/c they're just too fucking different
|
91
91
|
<<HERE
|
@@ -94,7 +94,7 @@ Feature: Running the binary successfully
|
|
94
94
|
|
95
95
|
# method invocation that occurs entirely on the next line
|
96
96
|
[*1..10]
|
97
|
-
.select(&:even?)
|
97
|
+
.select(&:even?) # => [2, 4, 6, 8, 10]
|
98
98
|
|
99
99
|
# mutliple levels of nesting
|
100
100
|
class User
|
@@ -103,12 +103,12 @@ Feature: Running the binary successfully
|
|
103
103
|
end # => nil
|
104
104
|
|
105
105
|
def name
|
106
|
-
@name
|
107
|
-
end
|
108
|
-
end
|
106
|
+
@name # => "Josh", "Rick"
|
107
|
+
end # => nil
|
108
|
+
end # => nil
|
109
109
|
|
110
|
-
User.new("Josh").name
|
111
|
-
User.new("Rick").name
|
110
|
+
User.new("Josh").name # => "Josh"
|
111
|
+
User.new("Rick").name # => "Rick"
|
112
112
|
"""
|
113
113
|
|
114
114
|
Scenario: Passing previous output back into input
|
data/features/flags.feature
CHANGED
@@ -9,7 +9,7 @@ Feature: Using flags
|
|
9
9
|
2
|
10
10
|
3
|
11
11
|
"""
|
12
|
-
When I run "seeing_is_believing --start-line 2 start_line.rb"
|
12
|
+
When I run "seeing_is_believing -s file --start-line 2 start_line.rb"
|
13
13
|
Then stderr is empty
|
14
14
|
And the exit status is 0
|
15
15
|
And stdout is:
|
@@ -18,6 +18,20 @@ Feature: Using flags
|
|
18
18
|
2 # => 2
|
19
19
|
3 # => 3
|
20
20
|
"""
|
21
|
+
When I run "seeing_is_believing -s chunk --start-line 2 start_line.rb"
|
22
|
+
Then stdout is:
|
23
|
+
"""
|
24
|
+
1 + 1
|
25
|
+
2 # => 2
|
26
|
+
3 # => 3
|
27
|
+
"""
|
28
|
+
When I run "seeing_is_believing -s line --start-line 2 start_line.rb"
|
29
|
+
Then stdout is:
|
30
|
+
"""
|
31
|
+
1 + 1
|
32
|
+
2 # => 2
|
33
|
+
3 # => 3
|
34
|
+
"""
|
21
35
|
|
22
36
|
Scenario: --end-line
|
23
37
|
Given the file "end_line.rb":
|
@@ -26,7 +40,7 @@ Feature: Using flags
|
|
26
40
|
2
|
27
41
|
3 + 3
|
28
42
|
"""
|
29
|
-
When I run "seeing_is_believing --end-line 2 end_line.rb"
|
43
|
+
When I run "seeing_is_believing -s file --end-line 2 end_line.rb"
|
30
44
|
Then stderr is empty
|
31
45
|
And the exit status is 0
|
32
46
|
And stdout is:
|
@@ -35,6 +49,20 @@ Feature: Using flags
|
|
35
49
|
2 # => 2
|
36
50
|
3 + 3
|
37
51
|
"""
|
52
|
+
When I run "seeing_is_believing -s chunk --end-line 2 end_line.rb"
|
53
|
+
Then stdout is:
|
54
|
+
"""
|
55
|
+
1 # => 1
|
56
|
+
2 # => 2
|
57
|
+
3 + 3
|
58
|
+
"""
|
59
|
+
When I run "seeing_is_believing -s line --end-line 2 end_line.rb"
|
60
|
+
Then stdout is:
|
61
|
+
"""
|
62
|
+
1 # => 1
|
63
|
+
2 # => 2
|
64
|
+
3 + 3
|
65
|
+
"""
|
38
66
|
|
39
67
|
Scenario: --start-line and --end-line
|
40
68
|
Given the file "start_and_end_line.rb":
|
@@ -44,7 +72,7 @@ Feature: Using flags
|
|
44
72
|
3
|
45
73
|
4 + 4
|
46
74
|
"""
|
47
|
-
When I run "seeing_is_believing --start-line 2 --end-line 3 start_and_end_line.rb"
|
75
|
+
When I run "seeing_is_believing -s file --start-line 2 --end-line 3 start_and_end_line.rb"
|
48
76
|
Then stderr is empty
|
49
77
|
And the exit status is 0
|
50
78
|
And stdout is:
|
@@ -54,6 +82,22 @@ Feature: Using flags
|
|
54
82
|
3 # => 3
|
55
83
|
4 + 4
|
56
84
|
"""
|
85
|
+
When I run "seeing_is_believing -s chunk --start-line 2 --end-line 3 start_and_end_line.rb"
|
86
|
+
Then stdout is:
|
87
|
+
"""
|
88
|
+
1 + 1
|
89
|
+
2 # => 2
|
90
|
+
3 # => 3
|
91
|
+
4 + 4
|
92
|
+
"""
|
93
|
+
When I run "seeing_is_believing -s line --start-line 2 --end-line 3 start_and_end_line.rb"
|
94
|
+
Then stdout is:
|
95
|
+
"""
|
96
|
+
1 + 1
|
97
|
+
2 # => 2
|
98
|
+
3 # => 3
|
99
|
+
4 + 4
|
100
|
+
"""
|
57
101
|
|
58
102
|
Scenario: --result-length sets the length of the portion including and after the # =>
|
59
103
|
Given the file "result_lengths.rb":
|
@@ -68,7 +112,7 @@ Feature: Using flags
|
|
68
112
|
|
69
113
|
raise "a"*100
|
70
114
|
"""
|
71
|
-
When I run "seeing_is_believing --result-length 10 result_lengths.rb"
|
115
|
+
When I run "seeing_is_believing -s file --result-length 10 result_lengths.rb"
|
72
116
|
Then stderr is empty
|
73
117
|
And stdout is:
|
74
118
|
"""
|
@@ -98,7 +142,7 @@ Feature: Using flags
|
|
98
142
|
|
99
143
|
raise "a"*100
|
100
144
|
"""
|
101
|
-
When I run "seeing_is_believing --line-length 32 line_lengths.rb"
|
145
|
+
When I run "seeing_is_believing -s file --line-length 32 line_lengths.rb"
|
102
146
|
Then stderr is empty
|
103
147
|
And stdout is:
|
104
148
|
"""
|
@@ -247,7 +291,7 @@ Feature: Using flags
|
|
247
291
|
Given the file "example.rb" "sleep 1"
|
248
292
|
When I run "seeing_is_believing --timeout 0.1 example.rb"
|
249
293
|
Then stdout is empty
|
250
|
-
And the exit status is
|
294
|
+
And the exit status is 2
|
251
295
|
And stderr is "Timeout Error after 0.1 seconds!"
|
252
296
|
|
253
297
|
Scenario: --timeout
|
@@ -6,6 +6,10 @@ require 'timeout'
|
|
6
6
|
|
7
7
|
class SeeingIsBelieving
|
8
8
|
class Binary
|
9
|
+
SUCCESS_STATUS = 0
|
10
|
+
DISPLAYABLE_ERROR_STATUS = 1 # e.g. there was an error, but the output is legit (we can display exceptions)
|
11
|
+
NONDISPLAYABLE_ERROR_STATUS = 2 # e.g. an error like incorrect invocation or syntax that can't be displayed in the input program
|
12
|
+
|
9
13
|
attr_accessor :argv, :stdin, :stdout, :stderr, :timeout_error
|
10
14
|
|
11
15
|
def initialize(argv, stdin, stdout, stderr)
|
@@ -16,14 +20,16 @@ class SeeingIsBelieving
|
|
16
20
|
end
|
17
21
|
|
18
22
|
def call
|
19
|
-
@exitstatus ||= if flags_have_errors? then print_errors ;
|
20
|
-
elsif should_print_help? then print_help ;
|
21
|
-
elsif should_print_version? then print_version ;
|
22
|
-
elsif has_filename? && file_dne? then print_file_dne ;
|
23
|
-
elsif should_clean? then print_cleaned_program ;
|
24
|
-
elsif invalid_syntax? then print_syntax_error ;
|
25
|
-
elsif program_timedout? then print_timeout_error ;
|
26
|
-
else print_program ; (results.has_exception? ?
|
23
|
+
@exitstatus ||= if flags_have_errors? then print_errors ; NONDISPLAYABLE_ERROR_STATUS
|
24
|
+
elsif should_print_help? then print_help ; SUCCESS_STATUS
|
25
|
+
elsif should_print_version? then print_version ; SUCCESS_STATUS
|
26
|
+
elsif has_filename? && file_dne? then print_file_dne ; NONDISPLAYABLE_ERROR_STATUS
|
27
|
+
elsif should_clean? then print_cleaned_program ; SUCCESS_STATUS
|
28
|
+
elsif invalid_syntax? then print_syntax_error ; NONDISPLAYABLE_ERROR_STATUS
|
29
|
+
elsif program_timedout? then print_timeout_error ; NONDISPLAYABLE_ERROR_STATUS
|
30
|
+
else print_program ; (results.has_exception? ?
|
31
|
+
DISPLAYABLE_ERROR_STATUS :
|
32
|
+
SUCCESS_STATUS)
|
27
33
|
end
|
28
34
|
end
|
29
35
|
|
@@ -22,7 +22,9 @@ class SeeingIsBelieving
|
|
22
22
|
.reject { |line, index| SyntaxAnalyzer.ends_in_comment? line }
|
23
23
|
.slice_before { |line, index| line == '' }
|
24
24
|
.map { |slice|
|
25
|
-
max_chunk_length = 2 + slice.
|
25
|
+
max_chunk_length = 2 + slice.select { |line, index| start_line <= index && index <= end_line }
|
26
|
+
.map { |line, index| line.length }
|
27
|
+
.max
|
26
28
|
slice.map { |line, index| [index, max_chunk_length] }
|
27
29
|
}
|
28
30
|
.flatten(1)
|
@@ -77,7 +77,7 @@ class SeeingIsBelieving
|
|
77
77
|
errors: [],
|
78
78
|
require: [],
|
79
79
|
load_path: [],
|
80
|
-
alignment_strategy:
|
80
|
+
alignment_strategy: AlignChunk,
|
81
81
|
}
|
82
82
|
end
|
83
83
|
|
@@ -124,9 +124,9 @@ class SeeingIsBelieving
|
|
124
124
|
|
125
125
|
def ArgParser.help_screen
|
126
126
|
<<HELP_SCREEN
|
127
|
-
Usage:
|
127
|
+
Usage: seeing_is_believing [options] [filename]
|
128
128
|
|
129
|
-
|
129
|
+
seeing_is_believing is a program and library that will evaluate a Ruby file and capture/display the results.
|
130
130
|
|
131
131
|
If no filename is provided, the binary will read the program from standard input.
|
132
132
|
|
@@ -135,8 +135,8 @@ Usage: #{$0} [options] [filename]
|
|
135
135
|
-d, --line-length n # max length of the entire line (only truncates results, not source lines)
|
136
136
|
-D, --result-length n # max length of the portion after the "# => "
|
137
137
|
-s, --alignment-strategy # select the alignment strategy:
|
138
|
-
|
139
|
-
|
138
|
+
chunk (DEFAULT) => each chunk of code is at the same alignment
|
139
|
+
file => the entire file is at the same alignment
|
140
140
|
line => each line is at its own alignment
|
141
141
|
-t, --timeout n # timeout limit in seconds when evaluating source file (ex. -t 0.3 or -t 3)
|
142
142
|
-I, --load-path dir # a dir that should be added to the $LOAD_PATH
|
data/spec/arg_parser_spec.rb
CHANGED
@@ -290,8 +290,8 @@ describe SeeingIsBelieving::Binary::ArgParser do
|
|
290
290
|
AlignChunk = SeeingIsBelieving::Binary::AlignChunk
|
291
291
|
|
292
292
|
# maybe change the default?
|
293
|
-
it 'defaults to
|
294
|
-
parse([])[:alignment_strategy].should ==
|
293
|
+
it 'defaults to AlignChunk' do
|
294
|
+
parse([])[:alignment_strategy].should == AlignChunk
|
295
295
|
end
|
296
296
|
|
297
297
|
specify '-s and --alignment-strategy sets the alignment strategy' do
|