seeing_is_believing 3.0.0.beta.6 → 3.0.0.beta.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -3
- data/.travis.yml +3 -2
- data/Gemfile +0 -1
- data/Rakefile +5 -5
- data/Readme.md +9 -5
- data/features/regression.feature +1 -2
- data/lib/seeing_is_believing/binary/annotate_end_of_file.rb +1 -1
- data/lib/seeing_is_believing/binary/annotate_marked_lines.rb +19 -8
- data/lib/seeing_is_believing/binary/comment_lines.rb +1 -1
- data/lib/seeing_is_believing/code.rb +11 -36
- data/lib/seeing_is_believing/the_matrix.rb +4 -0
- data/lib/seeing_is_believing/version.rb +1 -1
- data/lib/seeing_is_believing/wrap_expressions.rb +12 -5
- data/lib/seeing_is_believing/wrap_expressions_with_inspect.rb +4 -2
- data/seeing_is_believing.gemspec +2 -1
- data/spec/event_stream_spec.rb +1 -1
- data/spec/seeing_is_believing_spec.rb +8 -0
- data/spec/wrap_expressions_spec.rb +6 -10
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 866178b03727394e7c24c5cfbaa48ea4edbca4e1
|
4
|
+
data.tar.gz: cfe4540e781ec9aa65b79a950d8760058136a85d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 514947858dab6b669eeb25f8b729e330d9435b438f2821073a56a12226451710a54f775415591e56c8673d071e276c102ec7ca001f4f6f2ce03fe9d2f1282b7b
|
7
|
+
data.tar.gz: 341dea9e96e9e1c57565254830f5f22648bcd2b9363d492b1a8718dddc54e30861c449d5374f3822e7ef7c88ce89ea107c79e5049c7e216a35a88c3b8440f735
|
data/.rspec
CHANGED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'bundler'
|
2
2
|
|
3
3
|
desc 'Have Bundler setup a standalone environment -- run tests in this, b/c its faster and safer'
|
4
|
-
task :
|
4
|
+
task :install do
|
5
5
|
# Running without rubygems # http://myronmars.to/n/dev-blog/2012/03/faster-test-boot-times-with-bundler-standalone
|
6
6
|
sh 'bundle install --standalone --binstubs bundle/bin'
|
7
7
|
end
|
@@ -17,14 +17,14 @@ task :clean do
|
|
17
17
|
]
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
$stderr.puts "\e[31mLooks like the gems aren\'t installed, run `rake
|
20
|
+
directory 'bundle' do
|
21
|
+
$stderr.puts "\e[31mLooks like the gems aren\'t installed, run `rake install` to install them\e[39m"
|
22
22
|
exit 1
|
23
23
|
end
|
24
24
|
|
25
25
|
desc 'Run specs'
|
26
26
|
task spec: :bundle do
|
27
|
-
sh 'ruby', '--disable-gem', *Bundler.load.specs.flat_map(&:full_require_paths).flat_map { |p| ['-I', p ] }, '-S', 'bundle/bin/
|
27
|
+
sh 'ruby', '--disable-gem', *Bundler.load.specs.flat_map(&:full_require_paths).flat_map { |p| ['-I', p ] }, '-S', 'bundle/bin/mrspec'
|
28
28
|
end
|
29
29
|
|
30
30
|
desc 'Run cukes'
|
@@ -36,4 +36,4 @@ desc 'Run all specs and cukes'
|
|
36
36
|
task default: [:spec, :cuke]
|
37
37
|
|
38
38
|
desc 'Install dependencies and run tests (mainly for Travis CI)'
|
39
|
-
task ci: [:
|
39
|
+
task ci: [:install, :spec, :cuke]
|
data/Readme.md
CHANGED
@@ -5,7 +5,7 @@ Seeing Is Believing
|
|
5
5
|
===================
|
6
6
|
|
7
7
|
Evaluates Ruby code, recording the results of each line.
|
8
|
-
Integrates with any extensible editor (I've integrated it with many already, see [the list](https://github.com/JoshCheek/seeing_is_believing#editor-integration).
|
8
|
+
Integrates with any extensible editor (I've integrated it with many already, see [the list](https://github.com/JoshCheek/seeing_is_believing#editor-integration)).
|
9
9
|
|
10
10
|
![example](https://s3.amazonaws.com/josh.cheek/images/scratch/sib-example1.gif)
|
11
11
|
|
@@ -72,7 +72,7 @@ Editor Integration
|
|
72
72
|
Vim
|
73
73
|
===
|
74
74
|
|
75
|
-
I didn't write either of these, but they both support Seeing Is
|
75
|
+
I didn't write either of these, but they both support Seeing Is Believing. I've looked through the code, it works reasonably. One of them, I wound up having to edit the installed package, don't remember which.
|
76
76
|
|
77
77
|
* [vim-ruby-xmpfilter](https://github.com/t9md/vim-ruby-xmpfilter)
|
78
78
|
* [vim-seeing-is-believing](https://github.com/hwartig/vim-seeing-is-believing)
|
@@ -80,7 +80,9 @@ I didn't write either of these, but they both support Seeing Is Beleiving. I've
|
|
80
80
|
Emacs Integration
|
81
81
|
=================
|
82
82
|
|
83
|
-
|
83
|
+
You can use my friend's configuration [file](https://github.com/jcinnamond/seeing-is-believing).
|
84
|
+
|
85
|
+
Or, adding this function to your Emacs configuration will get you pretty far:
|
84
86
|
|
85
87
|
```scheme
|
86
88
|
(defun seeing-is-believing ()
|
@@ -88,8 +90,10 @@ Add this function to your Emacs configuration:
|
|
88
90
|
of seeing_is_believing."
|
89
91
|
(interactive)
|
90
92
|
(let ((beg (if (region-active-p) (region-beginning) (point-min)))
|
91
|
-
(end (if (region-active-p) (region-end) (point-max)))
|
92
|
-
|
93
|
+
(end (if (region-active-p) (region-end) (point-max)))
|
94
|
+
(origin (point)))
|
95
|
+
(shell-command-on-region beg end "seeing_is_believing" nil 'replace)
|
96
|
+
(goto-char origin)))
|
93
97
|
```
|
94
98
|
|
95
99
|
You can now call `seeing-is-believing` to replace the current region
|
data/features/regression.feature
CHANGED
@@ -12,7 +12,7 @@ class SeeingIsBelieving
|
|
12
12
|
exception_output_for(results, options)
|
13
13
|
|
14
14
|
code = Code.new(new_body)
|
15
|
-
code.rewriter.
|
15
|
+
code.rewriter.insert_after_multi code.body_range, output
|
16
16
|
new_body.replace code.rewriter.process
|
17
17
|
end
|
18
18
|
|
@@ -27,19 +27,30 @@ class SeeingIsBelieving
|
|
27
27
|
WrapExpressions.call \
|
28
28
|
program,
|
29
29
|
before_each: -> line_number {
|
30
|
+
# 74 b/c pretty print_defaults to 79 (guessing 80 chars with 1 reserved for newline), and
|
31
|
+
# 79 - "# => ".length # => 4
|
32
|
+
inspect = "$SiB.record_result(:inspect, #{line_number}, ("
|
33
|
+
pp = "$SiB.record_result(:pp, #{line_number}, ("
|
34
|
+
|
30
35
|
should_inspect = inspect_linenos.include? line_number
|
31
36
|
should_pp = pp_linenos.include? line_number
|
32
|
-
|
37
|
+
|
38
|
+
if should_inspect && should_pp then "#{pp}#{inspect}"
|
39
|
+
elsif should_inspect then inspect
|
40
|
+
elsif should_pp then pp
|
41
|
+
else ""
|
42
|
+
end
|
33
43
|
},
|
34
44
|
after_each: -> line_number {
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
45
|
+
inspect = "))"
|
46
|
+
pp = ")) { |v| PP.pp v, '', 74 }"
|
47
|
+
|
48
|
+
should_inspect = inspect_linenos.include? line_number
|
49
|
+
should_pp = pp_linenos.include? line_number
|
39
50
|
|
40
|
-
if should_inspect && should_pp then "
|
41
|
-
elsif should_inspect then
|
42
|
-
elsif should_pp then
|
51
|
+
if should_inspect && should_pp then "#{inspect}#{pp}"
|
52
|
+
elsif should_inspect then inspect
|
53
|
+
elsif should_pp then pp
|
43
54
|
else ""
|
44
55
|
end
|
45
56
|
}
|
@@ -22,7 +22,7 @@ class SeeingIsBelieving
|
|
22
22
|
first_index -= 1 while first_index > 0 && raw_code[first_index-1] != "\n"
|
23
23
|
comment_text = commenter.call raw_code[first_index...last_index], line_number
|
24
24
|
range = Parser::Source::Range.new(commentable_lines.buffer, first_index, last_index)
|
25
|
-
commentable_lines.rewriter.
|
25
|
+
commentable_lines.rewriter.insert_after_multi range, comment_text
|
26
26
|
end
|
27
27
|
commentable_lines.rewriter.process
|
28
28
|
end
|
@@ -24,20 +24,19 @@ class SeeingIsBelieving
|
|
24
24
|
@raw = raw_code
|
25
25
|
@buffer = Parser::Source::Buffer.new(name||"SeeingIsBelieving")
|
26
26
|
@buffer.source = raw
|
27
|
-
builder = Parser::Builders::Default.new.tap { |b| b.emit_file_line_as_literals = false }
|
28
27
|
@rewriter = Parser::Source::Rewriter.new buffer
|
29
|
-
|
30
|
-
@body_range = body_range_from_tokens(tokens)
|
28
|
+
builder = Parser::Builders::Default.new.tap { |b| b.emit_file_line_as_literals = false }
|
31
29
|
@parser = Parser::CurrentRuby.new builder
|
32
|
-
@
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
@syntax = Syntax.new error_message: $!.message, line_number: index_to_linenum($!.diagnostic.location.begin_pos)
|
38
|
-
ensure
|
39
|
-
@root ||= null_node
|
30
|
+
@syntax = Syntax.new
|
31
|
+
parser.diagnostics.consumer = lambda do |diagnostic|
|
32
|
+
if :fatal == diagnostic.level || :error == diagnostic.level
|
33
|
+
@syntax = Syntax.new error_message: diagnostic.message, line_number: index_to_linenum(diagnostic.location.begin_pos)
|
34
|
+
end
|
40
35
|
end
|
36
|
+
@root, @raw_comments, @tokens = parser.tokenize(@buffer, true)
|
37
|
+
@body_range = body_range_from_tokens(@tokens)
|
38
|
+
@inline_comments = raw_comments.select(&:inline?).map { |c| wrap_comment c }
|
39
|
+
@root ||= null_node
|
41
40
|
end
|
42
41
|
|
43
42
|
def range_for(start_index, end_index)
|
@@ -91,32 +90,8 @@ class SeeingIsBelieving
|
|
91
90
|
private
|
92
91
|
|
93
92
|
def comments_and_tokens(builder, buffer)
|
94
|
-
# THIS IS SO WE CAN EXTRACT COMMENTS FROM INVALID FILES.
|
95
|
-
# We do it by telling Parser's diagnostic to not blow up.
|
96
|
-
# https://github.com/whitequark/parser/blob/2d69a1b5f34ef15b3a8330beb036ac4bf4775e29/lib/parser/diagnostic/engine.rb
|
97
|
-
# However, this probably implies SiB won't work on Rbx/JRuby
|
98
|
-
# https://github.com/whitequark/parser/blob/2d69a1b5f34ef15b3a8330beb036ac4bf4775e29/lib/parser/base.rb#L129-134
|
99
|
-
# Ideally we could just do this
|
100
|
-
# parser.diagnostics.all_errors_are_fatal = false
|
101
|
-
# parser.diagnostics.ignore_warnings = false
|
102
|
-
# But, the parser will still blow up on "fatal" errors (e.g. unterminated string) So we need to actually change it.
|
103
|
-
# https://github.com/whitequark/parser/blob/2d69a1b5f34ef15b3a8330beb036ac4bf4775e29/lib/parser/diagnostic/engine.rb#L99
|
104
|
-
# We could make a NullDiagnostics like this:
|
105
|
-
# class NullDiagnostics < Parser::Diagnostic::Engine
|
106
|
-
# def process(*)
|
107
|
-
# # no op
|
108
|
-
# end
|
109
|
-
# end
|
110
|
-
# But we don't control initialization of the variable, and the value gets passed around, at least into the lexer.
|
111
|
-
# https://github.com/whitequark/parser/blob/2d69a1b5f34ef15b3a8330beb036ac4bf4775e29/lib/parser/base.rb#L139
|
112
|
-
# and since it's all private, it could change at any time (Parser is very state based),
|
113
|
-
# so I think it's just generally safer to mutate that one object, as we do now.
|
114
93
|
parser = Parser::CurrentRuby.new builder
|
115
|
-
|
116
|
-
def diagnostics.process(*)
|
117
|
-
self
|
118
|
-
end
|
119
|
-
_, all_comments, tokens = parser.tokenize(@buffer)
|
94
|
+
_, all_comments, tokens = parser.tokenize(@buffer, true)
|
120
95
|
[all_comments, tokens]
|
121
96
|
end
|
122
97
|
|
@@ -23,20 +23,27 @@ class SeeingIsBelieving
|
|
23
23
|
@called ||= begin
|
24
24
|
wrap_recursive code.root
|
25
25
|
|
26
|
-
|
26
|
+
wrappings = wrappings().sort_by(&:first)
|
27
27
|
|
28
28
|
wrappings.each do |line_num, (range, last_col, meta)|
|
29
|
-
rewriter.insert_before range, before_each.call(line_num)
|
30
29
|
case meta
|
31
30
|
when :total_fucking_failure
|
32
31
|
rewriter.replace range, '.....TOTAL FUCKING FAILURE!.....'
|
33
32
|
when :match_current_line
|
34
|
-
rewriter.
|
33
|
+
rewriter.insert_before_multi range, '~' # Regexp#~
|
35
34
|
end
|
36
|
-
rewriter.insert_after range, after_each.call(line_num)
|
37
35
|
end
|
38
36
|
|
39
|
-
|
37
|
+
wrappings.each do |line_num, (range, last_col, meta)|
|
38
|
+
rewriter.insert_before_multi range, before_each.call(line_num)
|
39
|
+
end
|
40
|
+
|
41
|
+
wrappings.each do |line_num, (range, last_col, meta)|
|
42
|
+
rewriter.insert_after_multi range, after_each.call(line_num)
|
43
|
+
end
|
44
|
+
|
45
|
+
rewriter.insert_before_multi root_range, before_all.call
|
46
|
+
rewriter.insert_after_multi root_range, after_all_text
|
40
47
|
rewriter.process
|
41
48
|
end
|
42
49
|
end
|
@@ -2,12 +2,14 @@ require 'seeing_is_believing/wrap_expressions'
|
|
2
2
|
class SeeingIsBelieving
|
3
3
|
module WrapExpressionsWithInspect
|
4
4
|
def self.call(program)
|
5
|
+
# NOTE: if it received the AST, it could figure out if it needs
|
6
|
+
# to always wrap the expression in parentheses
|
5
7
|
WrapExpressions.call program,
|
6
8
|
before_each: -> line_number {
|
7
|
-
"("
|
9
|
+
"$SiB.record_result(:inspect, #{line_number}, ("
|
8
10
|
},
|
9
11
|
after_each: -> line_number {
|
10
|
-
")
|
12
|
+
"))"
|
11
13
|
}
|
12
14
|
end
|
13
15
|
end
|
data/seeing_is_believing.gemspec
CHANGED
@@ -19,11 +19,12 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
20
|
s.require_paths = ["lib"]
|
21
21
|
|
22
|
-
s.add_dependency "parser", ">= 2.
|
22
|
+
s.add_dependency "parser", ">= 2.3.0.7", "< 3.0"
|
23
23
|
|
24
24
|
s.add_development_dependency "what_weve_got_here_is_an_error_to_communicate"
|
25
25
|
s.add_development_dependency "haiti", ">= 0.1", "< 0.3"
|
26
26
|
s.add_development_dependency "rake", "~> 10.0"
|
27
|
+
s.add_development_dependency "mrspec", "~> 0.3.0"
|
27
28
|
s.add_development_dependency "rspec", "~> 3.2"
|
28
29
|
s.add_development_dependency "cucumber", "~> 1.2"
|
29
30
|
s.add_development_dependency "ichannel", "~> 5.1"
|
data/spec/event_stream_spec.rb
CHANGED
@@ -394,7 +394,7 @@ module SeeingIsBelieving::EventStream
|
|
394
394
|
backtrace_filename: __FILE__
|
395
395
|
end
|
396
396
|
|
397
|
-
example 'Example: Common edge case: name error'
|
397
|
+
example 'Example: Common edge case: name error' do
|
398
398
|
backtrace_line = record_exception(99) { BasicObject.new.instance_eval { not_a_local_or_meth } }
|
399
399
|
backtrace_frame = 0
|
400
400
|
backtrace_frame += 1 if defined? Rubinius # their method missing goes into the kernel
|
@@ -503,6 +503,10 @@ RSpec.describe SeeingIsBelieving do
|
|
503
503
|
expect(values_for "File.read(__FILE__).lines.count").to eq [['1']]
|
504
504
|
end
|
505
505
|
|
506
|
+
it 'records instances of BasicObject' do
|
507
|
+
expect(values_for 'o = BasicObject.new; def o.inspect; "some obj"; end; o').to eq [['some obj']]
|
508
|
+
end
|
509
|
+
|
506
510
|
context 'when given a debugger' do
|
507
511
|
let(:stream) { StringIO.new }
|
508
512
|
let(:debugger) { SeeingIsBelieving::Debugger.new stream: stream }
|
@@ -551,6 +555,10 @@ RSpec.describe SeeingIsBelieving do
|
|
551
555
|
it 'gets the exit status off of the child process' do
|
552
556
|
expect(invoke('exec "ruby", "-e", "exit 5"').exitstatus).to eq 5
|
553
557
|
end
|
558
|
+
|
559
|
+
it 'emits otuput on expicit invocations to warn' do
|
560
|
+
expect(invoke('warn "hello"').stderr).to eq "hello\n"
|
561
|
+
end
|
554
562
|
end
|
555
563
|
|
556
564
|
# Looked through the implementation of event_stream/producer to find a list of core behaviour it depends on
|
@@ -104,13 +104,11 @@ RSpec.describe SeeingIsBelieving::WrapExpressions do
|
|
104
104
|
end
|
105
105
|
|
106
106
|
it 'passes the current line number to the before_each and after_each wrappers' do
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
expect(pre_line_num).to eq 2
|
113
|
-
expect(post_line_num).to eq 2
|
107
|
+
result = described_class.call("a.each { |b|\n}\n",
|
108
|
+
before_each: -> n { "(#{n})" },
|
109
|
+
after_each: -> n { "<#{n}>" }
|
110
|
+
)
|
111
|
+
expect(result).to eq "(2)(1)a<1>.each { |b|\n}<2>\n"
|
114
112
|
end
|
115
113
|
|
116
114
|
it 'does nothing for an empty program' do
|
@@ -168,9 +166,7 @@ RSpec.describe SeeingIsBelieving::WrapExpressions do
|
|
168
166
|
0b001_001
|
169
167
|
|
170
168
|
?a
|
171
|
-
|
172
|
-
?\M-a
|
173
|
-
?\M-\C-a
|
169
|
+
?\\C-a
|
174
170
|
|
175
171
|
1..2
|
176
172
|
1...2
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seeing_is_believing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.0.beta.
|
4
|
+
version: 3.0.0.beta.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Cheek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -16,7 +16,7 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.
|
19
|
+
version: 2.3.0.7
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '3.0'
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 2.
|
29
|
+
version: 2.3.0.7
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '3.0'
|
@@ -78,6 +78,20 @@ dependencies:
|
|
78
78
|
- - "~>"
|
79
79
|
- !ruby/object:Gem::Version
|
80
80
|
version: '10.0'
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: mrspec
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - "~>"
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 0.3.0
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - "~>"
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 0.3.0
|
81
95
|
- !ruby/object:Gem::Dependency
|
82
96
|
name: rspec
|
83
97
|
requirement: !ruby/object:Gem::Requirement
|