seeing_is_believing 3.1.1 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/Rakefile +43 -16
- data/Readme.md +27 -242
- data/appveyor.yml +29 -0
- data/bin/seeing_is_believing +2 -1
- data/features/deprecated-flags.feature +19 -0
- data/features/errors.feature +57 -0
- data/features/examples.feature +4 -2
- data/features/flags.feature +35 -2
- data/features/regression.feature +107 -10
- data/features/support/env.rb +61 -2
- data/features/xmpfilter-style.feature +3 -2
- data/lib/seeing_is_believing/binary/annotate_end_of_file.rb +11 -9
- data/lib/seeing_is_believing/binary/annotate_every_line.rb +9 -8
- data/lib/seeing_is_believing/binary/annotate_marked_lines.rb +9 -8
- data/lib/seeing_is_believing/binary/config.rb +19 -3
- data/lib/seeing_is_believing/binary/engine.rb +5 -10
- data/lib/seeing_is_believing/evaluate_by_moving_files.rb +60 -45
- data/lib/seeing_is_believing/event_stream/consumer.rb +6 -1
- data/lib/seeing_is_believing/event_stream/handlers/debug.rb +5 -1
- data/lib/seeing_is_believing/event_stream/producer.rb +1 -1
- data/lib/seeing_is_believing/hard_core_ensure.rb +6 -0
- data/lib/seeing_is_believing/result.rb +26 -14
- data/lib/seeing_is_believing/safe.rb +6 -1
- data/lib/seeing_is_believing/the_matrix.rb +16 -4
- data/lib/seeing_is_believing/version.rb +1 -1
- data/lib/seeing_is_believing/wrap_expressions.rb +1 -1
- data/lib/seeing_is_believing.rb +7 -10
- data/seeing_is_believing.gemspec +9 -8
- data/spec/binary/config_spec.rb +65 -4
- data/spec/binary/engine_spec.rb +1 -1
- data/spec/evaluate_by_moving_files_spec.rb +31 -5
- data/spec/event_stream_spec.rb +14 -6
- data/spec/hard_core_ensure_spec.rb +70 -44
- data/spec/seeing_is_believing_spec.rb +136 -42
- data/spec/spec_helper.rb +8 -0
- data/spec/wrap_expressions_spec.rb +15 -0
- metadata +21 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd4c625530426d55efef82e47755e16b6178a677
|
4
|
+
data.tar.gz: 72bd371886e9f902eaf9cb4989c9ff3dc322ede6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94ff5a19f0e9292bc25400263d1772aaef661768fc0a922e0f7b9b65577d8bb6227a03b90a35e6cfa1ebe315292969bf7aaf2cc19084e9dee0cc4c2a07de8c18
|
7
|
+
data.tar.gz: 975e4ef13344fb4f96eacccddb6f2f862304c73a77552cb5c54b6788ea7326ce55dd5525fd6ec5c61c29e85a963ed8aee147efdff9ebc596bc4adb8682da8b10
|
data/.travis.yml
CHANGED
data/Rakefile
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
desc 'Have Bundler setup a standalone environment -- run tests in this, b/c its faster and safer'
|
2
2
|
task :install do
|
3
|
-
|
4
|
-
unless
|
5
|
-
sh 'gem', 'install', 'bundler'
|
3
|
+
exe_path = which("bundle")
|
4
|
+
unless exe_path
|
5
|
+
sh 'gem', 'install', 'bundler', '--no-ri', '--no-rdoc'
|
6
6
|
end
|
7
7
|
|
8
8
|
unless Dir.exist? 'bundle'
|
@@ -14,12 +14,13 @@ end
|
|
14
14
|
desc 'Remove generated and irrelevant files'
|
15
15
|
task :clean do
|
16
16
|
rm_rf [
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
'bundle',
|
18
|
+
'.bundle',
|
19
|
+
'Gemfile.lock',
|
20
|
+
'proving_grounds',
|
21
|
+
'tags',
|
22
|
+
*Dir['*.gem'],
|
23
|
+
]
|
23
24
|
end
|
24
25
|
|
25
26
|
directory 'bundle' do
|
@@ -33,26 +34,52 @@ def require_paths
|
|
33
34
|
spec.require_paths.map do |path|
|
34
35
|
File.join(spec.full_gem_path, path)
|
35
36
|
end
|
36
|
-
}.flat_map { |p| ['-I', p
|
37
|
+
}.flat_map { |p| ['-I', p] }
|
38
|
+
end
|
39
|
+
|
40
|
+
desc 'Print the require paths for arbitrary binary execution'
|
41
|
+
task :require_paths, [:delimiter] => :bundle do |delimiter: ' '|
|
42
|
+
puts require_paths.join(delimiter)
|
37
43
|
end
|
38
44
|
|
39
45
|
desc 'Run specs'
|
40
46
|
task spec: :bundle do
|
41
|
-
sh 'ruby', '--disable-gem', *require_paths, '-S', 'bundle/bin/
|
47
|
+
sh 'ruby', '--disable-gem', *require_paths, '-S', 'bundle/bin/rspec', '--fail-fast'
|
42
48
|
end
|
43
49
|
|
44
50
|
desc 'Run cukes'
|
45
51
|
task cuke: :bundle do
|
46
52
|
require 'bundler'
|
53
|
+
platform_filter = Gem.win_platform? ? %W[--tags ~@not-windows] : []
|
54
|
+
sh 'ruby', '--disable-gem',
|
55
|
+
*require_paths,
|
56
|
+
'-S', 'bundle/bin/cucumber',
|
57
|
+
'--tags', '~@not-implemented',
|
58
|
+
'--tags', "~@not-#{RUBY_VERSION}",
|
59
|
+
*platform_filter
|
60
|
+
end
|
61
|
+
|
62
|
+
desc 'Generate tags for quick navigation'
|
63
|
+
task tags: :bundle do
|
64
|
+
excludes = %w[tmp tmpgem bundle proving_grounds].map { |dir| "--exclude=#{dir}" }
|
47
65
|
sh 'ruby', '--disable-gem',
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
'--tags', "~@not-#{RUBY_VERSION}"
|
66
|
+
*require_paths,
|
67
|
+
'-S', 'bundle/bin/ripper-tags',
|
68
|
+
'-R', *excludes
|
52
69
|
end
|
70
|
+
task ctags: :tags # an alias
|
71
|
+
|
53
72
|
|
54
73
|
desc 'Run all specs and cukes'
|
55
74
|
task default: [:spec, :cuke]
|
56
75
|
|
57
76
|
desc 'Install dependencies and run tests (mainly for Travis CI)'
|
58
|
-
task ci: [:
|
77
|
+
task ci: [:spec, :cuke]
|
78
|
+
|
79
|
+
def which(exe)
|
80
|
+
dirs = ENV["PATH"].split(File::PATH_SEPARATOR)
|
81
|
+
exts = [""]
|
82
|
+
exts.concat(ENV["PathExt"].to_s.split(File::PATH_SEPARATOR))
|
83
|
+
candidates = dirs.product(exts) { |dir, ext| File.join(dir, exe + ext) }
|
84
|
+
exe_path = candidates.find { |c| File.executable?(c) }
|
85
|
+
end
|
data/Readme.md
CHANGED
@@ -1,265 +1,50 @@
|
|
1
|
-
[![
|
2
|
-
[![Build Status](https://secure.travis-ci.org/JoshCheek/seeing_is_believing.png?branch=master)](http://travis-ci.org/JoshCheek/seeing_is_believing)
|
1
|
+
Unix/Mac: [![Unix Build Status](https://secure.travis-ci.org/JoshCheek/seeing_is_believing.png?branch=master)](http://travis-ci.org/JoshCheek/seeing_is_believing) Windows: [![Windows Build Status](https://ci.appveyor.com/api/projects/status/32r7s2skrgm9ubva?svg=true)](https://ci.appveyor.com/project/JoshCheek/seeing-is-believing)
|
3
2
|
|
4
3
|
Seeing Is Believing
|
5
4
|
===================
|
6
5
|
|
7
6
|
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
|
7
|
+
Integrates with any extensible editor (I've integrated it with many already, see [the list](https://github.com/JoshCheek/seeing_is_believing/wiki/Editor-Integration)).
|
9
8
|
If you like Swift Playgrounds, you'll like SiB.
|
10
9
|
|
11
10
|
![example](https://s3.amazonaws.com/josh.cheek/images/scratch/sib-example1.gif)
|
12
11
|
|
13
|
-
Watch a [longer video](http://vimeo.com/73866851).
|
14
12
|
|
13
|
+
Helpful links
|
14
|
+
-------------
|
15
15
|
|
16
|
-
Install
|
17
|
-
|
16
|
+
* [Install](https://github.com/JoshCheek/seeing_is_believing/wiki/Installation)
|
17
|
+
* [Integrate with your editor](https://github.com/JoshCheek/seeing_is_believing/wiki/Editor-Integration)
|
18
|
+
* [Use as a library](https://github.com/JoshCheek/seeing_is_believing/wiki/Library-example)
|
19
|
+
* [Use on the command line](https://github.com/JoshCheek/seeing_is_believing/wiki/Command-Line-Usage)
|
20
|
+
* [Pro Tips (useful patterns)](https://github.com/JoshCheek/seeing_is_believing/wiki/Pro-Tips)
|
21
|
+
* [Features](https://github.com/JoshCheek/seeing_is_believing/tree/master/features)
|
22
|
+
* [Potential Future Features](https://github.com/JoshCheek/seeing_is_believing/wiki/Potential-future-features)
|
23
|
+
* [Set up it up for development work](https://github.com/JoshCheek/seeing_is_believing/wiki/Setting-it-up-for-Development)
|
18
24
|
|
19
|
-
Requires Ruby >= 2.1
|
20
25
|
|
21
|
-
|
22
|
-
|
23
|
-
```
|
26
|
+
Examples
|
27
|
+
--------
|
24
28
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
```
|
31
|
-
|
32
|
-
|
33
|
-
Use The Binary
|
34
|
-
==============
|
35
|
-
|
36
|
-
Given the file `simple_example.rb`
|
37
|
-
|
38
|
-
```ruby
|
39
|
-
5.times do |i|
|
40
|
-
i * 2
|
41
|
-
end
|
42
|
-
```
|
43
|
-
|
44
|
-
`$ seeing_is_believing simple_example.rb` will print:
|
45
|
-
|
46
|
-
```ruby
|
47
|
-
5.times do |i| # => 5
|
48
|
-
i * 2 # => 0, 2, 4, 6, 8
|
49
|
-
end # => 5
|
50
|
-
```
|
51
|
-
|
52
|
-
`$ seeing_is_believing simple_example.rb --json` will print:
|
53
|
-
|
54
|
-
```json
|
55
|
-
{"stdout":"","stderr":"","exitstatus":0,"exception":null,"lines":{"1":["5"],"2":["0","2","4","6","8"],"3":["5"]}}
|
56
|
-
```
|
57
|
-
|
58
|
-
Protips
|
59
|
-
=======
|
60
|
-
|
61
|
-
These things have been useful for integrating.
|
62
|
-
|
63
|
-
If you want to execute from some specific dir (eg if your editor is in the wrong dir)
|
64
|
-
try using `Dir.chdir` at the top of the script.
|
65
|
-
Eg I used that [here](https://github.com/JoshCheek/seeing_is_believing/issues/58#issuecomment-91600783)
|
66
|
-
so I could run with a full Rails app available in "Completely against the real env".
|
67
|
-
|
68
|
-
If you want some specific file to be available in that environment, require the fullpath to the file.
|
69
|
-
Eg I used that [here](https://github.com/JoshCheek/seeing_is_believing/issues/58#issuecomment-91600783)
|
70
|
-
to load up the Rils schema in "Running against the real schema".
|
71
|
-
|
72
|
-
You can also set the `$LOAD_PATH` to a gem you're working on and then require files as if
|
73
|
-
it was installed.
|
74
|
-
|
75
|
-
You work with `gets` by setting `$stdin` to the `DATA` segment and writing inputs there.
|
76
|
-
|
77
|
-
```ruby
|
78
|
-
$stdin = DATA
|
79
|
-
|
80
|
-
puts "What's your name?"
|
81
|
-
name = gets.chomp
|
82
|
-
puts "What's your favourite colour?"
|
83
|
-
colour = gets.chomp
|
84
|
-
puts "#{name}'s favourite colour is #{colour}."
|
85
|
-
|
86
|
-
# >> What's your name?
|
87
|
-
# >> What's your favourite colour?
|
88
|
-
# >> Josh's favourite colour is brown.
|
89
|
-
|
90
|
-
__END__
|
91
|
-
Josh
|
92
|
-
brown
|
93
|
-
```
|
94
|
-
|
95
|
-
Rescue lines you expect to explode so that it displays the expected result and continues evaluating.
|
96
|
-
|
97
|
-
```ruby
|
98
|
-
lambda { |x| x }.call() rescue $! # => #<ArgumentError: wrong number of arguments (given 0, expected 1)>
|
99
|
-
lambda { |x| x }.call(1) # => 1
|
100
|
-
lambda { |x| x }.call(1, 2) rescue $! # => #<ArgumentError: wrong number of arguments (given 2, expected 1)>
|
101
|
-
```
|
102
|
-
|
103
|
-
Use `fork` to look at what a program does when run two different ways.
|
104
|
-
|
105
|
-
```ruby
|
106
|
-
class A
|
107
|
-
fork && raise("omg") # => nil
|
108
|
-
rescue
|
109
|
-
$! # => #<RuntimeError: omg>
|
110
|
-
else
|
111
|
-
:nothing_raised # => :nothing_raised
|
112
|
-
end # => #<RuntimeError: omg>, :nothing_raised
|
113
|
-
```
|
114
|
-
|
115
|
-
Use The Lib
|
116
|
-
===========
|
117
|
-
|
118
|
-
```ruby
|
119
|
-
require 'seeing_is_believing'
|
120
|
-
|
121
|
-
# There are a lot of options you can pass here, including a custom handler
|
122
|
-
handler = SeeingIsBelieving.call("[:a, :b, :c].each do |i|
|
123
|
-
i.upcase
|
124
|
-
end")
|
125
|
-
result = handler.result
|
126
|
-
|
127
|
-
result[2] # => [":A", ":B", ":C"]
|
128
|
-
result[2][0] # => ":A"
|
129
|
-
result[2][1] # => ":B"
|
130
|
-
result[2][2] # => ":C"
|
131
|
-
result[2].join(", ") # => ":A, :B, :C"
|
132
|
-
|
133
|
-
result.stdout # => ""
|
134
|
-
result.stderr # => ""
|
135
|
-
result.exception # => nil
|
136
|
-
```
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
Editor Integration
|
141
|
-
==================
|
142
|
-
|
143
|
-
* [Atom](https://github.com/JoshCheek/atom-seeing-is-believing) (prob has best installation instructions, overall best integration, but config and filesystem events are iffy)
|
144
|
-
* [Sublime 2 and 3](https://github.com/JoshCheek/sublime-text-2-and-3-seeing-is-believing) (works reasonably, but isn't integrated with the package manager)
|
145
|
-
* [TextMate 1](https://github.com/JoshCheek/text_mate_1-seeing-is_believing)
|
146
|
-
* [TextMate 2](https://github.com/JoshCheek/text_mate_2-seeing-is_believing) (TM2 is actually looking really nice these days -- Josh Cheek, 18 Feb 2015)
|
147
|
-
|
148
|
-
|
149
|
-
Vim
|
150
|
-
---
|
151
|
-
|
152
|
-
These packages support SiB:
|
153
|
-
|
154
|
-
* [vim-seeing-is-believing](https://github.com/hwartig/vim-seeing-is-believing)
|
155
|
-
* [vim-ruby-xmpfilter](https://github.com/t9md/vim-ruby-xmpfilter)
|
156
|
-
|
157
|
-
Personally, I had difficulty with them, but this configuration has gotten me pretty far:
|
158
|
-
|
159
|
-
```viml
|
160
|
-
" ===== Seeing Is Believing =====
|
161
|
-
" Assumes you have a Ruby with SiB available in the PATH
|
162
|
-
" If it doesn't work, you may need to `gem install seeing_is_believing -v 3.0.0.beta.6`
|
163
|
-
" ...yeah, current release is a beta, which won't auto-install
|
164
|
-
|
165
|
-
" Annotate every line
|
166
|
-
nmap <leader>b :%!seeing_is_believing --timeout 12 --line-length 500 --number-of-captures 300 --alignment-strategy chunk<CR>;
|
167
|
-
" Annotate marked lines
|
168
|
-
nmap <leader>n :%.!seeing_is_believing --timeout 12 --line-length 500 --number-of-captures 300 --alignment-strategy chunk --xmpfilter-style<CR>;
|
169
|
-
" Remove annotations
|
170
|
-
nmap <leader>c :%.!seeing_is_believing --clean<CR>;
|
171
|
-
" Mark the current line for annotation
|
172
|
-
nmap <leader>m A # => <Esc>
|
173
|
-
" Mark the highlighted lines for annotation
|
174
|
-
vmap <leader>m :norm A # => <Esc>
|
175
|
-
```
|
176
|
-
|
177
|
-
|
178
|
-
Emacs Integration
|
179
|
-
-----------------
|
180
|
-
|
181
|
-
You can use my friend's configuration [file](https://github.com/jcinnamond/seeing-is-believing).
|
182
|
-
You can see him use it in [this](http://brightonruby.com/2016/the-point-of-objects-john-cinnamond/?utm_source=rubyweekly&utm_medium=email)
|
183
|
-
presentation at 10 minutes.
|
184
|
-
|
185
|
-
Alternatively, adding this function to your Emacs configuration will get you pretty far:
|
186
|
-
|
187
|
-
```scheme
|
188
|
-
(defun seeing-is-believing ()
|
189
|
-
"Replace the current region (or the whole buffer, if none) with the output
|
190
|
-
of seeing_is_believing."
|
191
|
-
(interactive)
|
192
|
-
(let ((beg (if (region-active-p) (region-beginning) (point-min)))
|
193
|
-
(end (if (region-active-p) (region-end) (point-max)))
|
194
|
-
(origin (point)))
|
195
|
-
(shell-command-on-region beg end "seeing_is_believing" nil 'replace)
|
196
|
-
(goto-char origin)))
|
197
|
-
```
|
198
|
-
|
199
|
-
You can now call `seeing-is-believing` to replace the current region
|
200
|
-
or current buffer contents with the output of running it through
|
201
|
-
`seeing_is_believing`.
|
202
|
-
|
203
|
-
|
204
|
-
Features
|
205
|
-
========
|
206
|
-
|
207
|
-
Check the [features](features) directory.
|
29
|
+
* Watch a [longer video](http://vimeo.com/73866851).
|
30
|
+
* Watch John Cinnamond use it in a [presentation](http://brightonruby.com/2016/the-point-of-objects-john-cinnamond/)
|
31
|
+
at the 10 minute mark.
|
32
|
+
* [Avdi](https://github.com/avdi) uses it in [Ruby Tapas](https://www.rubytapas.com/),
|
33
|
+
an amazing resource for developers in general and Ruby Developers in particular!
|
208
34
|
|
209
35
|
|
210
36
|
Known Issues
|
211
|
-
|
37
|
+
------------
|
212
38
|
|
213
|
-
*
|
39
|
+
* Assumes utf-8 everywhere. If this is an issue, please see the [encodings](https://github.com/JoshCheek/seeing_is_believing/wiki/Encodings) section of the wiki.
|
40
|
+
* `begin; else; break; end` this code (an else without a rescue) will emit a warning in Ruby, and is omitted from `Parser`'s AST.
|
214
41
|
As such, I doubt that anyone will ever write it. But if you were to write it, it would blow up, because SiB rewrites your code, wrapping every expression that could have a value.
|
215
|
-
This code will be wrapped. But using the value is **syntactically** invalid in Ruby, because it constitutes a "void value expression" (aka a pointless
|
216
|
-
Unfortunately, I can't easily check it to
|
217
|
-
|
218
|
-
Setting up Development
|
219
|
-
======================
|
220
|
-
|
221
|
-
* Make sure you have Ruby (I use [chruby](https://github.com/postmodern/chruby) and [ruby-install](https://github.com/postmodern/ruby-install) for this).
|
222
|
-
* Make sure you have bundler and rake (`gem install bundler rake`)
|
223
|
-
* Fork the repo (there's a button on Github)
|
224
|
-
* Clone your fork (`git clone git@github.com:YOUR_GITHUB_NAME/seeing_is_believing.git`)
|
225
|
-
* Install the dependencies (`rake install`) This approach is painful, but it means the test suite is like 30s instead of 5min.
|
226
|
-
* Get a list of rake tasks (`rake -T`)
|
227
|
-
* Run the full test suite (`rake`)
|
228
|
-
* Run the rspec tests `bundle exec rspec` from here you can pass options you want, such as a tag for the tests you're interested in.
|
229
|
-
* Run the Cucumber tests `bundle exec cucumber` (these literally invoke the executable, as a user would)
|
230
|
-
|
231
|
-
|
232
|
-
Some stuff that might happen one day
|
233
|
-
====================================
|
234
|
-
|
235
|
-
* Add default to number of captures (1000), require user to explicitly set it to infinity
|
236
|
-
* Expose markers via the CLI
|
237
|
-
* Spruce up editor integration
|
238
|
-
* Integrate with package managers where they are available
|
239
|
-
* Expose options to use the streaming API (update as events are seen)
|
240
|
-
* Ship with Traveling Ruby so that new users can just press a button and it works,
|
241
|
-
rather than having to figure out all the compmlex ecosystem around installing
|
242
|
-
* Would be nice to have real integration with Emacs
|
243
|
-
* Would be nice to support Ruby Mine
|
244
|
-
* How about if begin/rescue/end was able to record the result on the rescue section
|
245
|
-
* How about if you could configure which kinds of results you were interested in
|
246
|
-
(e.g. turn on/off recording of method definitions, and other results)
|
247
|
-
* What about recording the result of a line inside of a string interpolation,
|
248
|
-
e.g. "a#{\n1\n}b" could record line 2 is 1 and line 3 is "a\n1\nb"
|
249
|
-
This would require smarter annotators.
|
250
|
-
* Allow debugger to take a filename (ie debug to a file insteaad of to stderr)
|
251
|
-
* `--cd dir` cd to that dir before executing the code
|
252
|
-
* `--cd -` cd to the dir of the file being executed before executing it
|
253
|
-
* `--only-show-lines` output only on specified lines (doesn't change stdout/stderr/exceptions)
|
254
|
-
* More alignment strategies e.g. `min=40` would align to 40, unless that was too short.
|
255
|
-
Could have fallback strategies, so e.g. `-s min=40,fallback=line`
|
256
|
-
* Package Ruby with the editor downloads so that they don't require you to know so fkn much to set it up.
|
257
|
-
* Allow user to set marker
|
258
|
-
* Maybe rename xmpfilter style, not many people know what that is, so the name doesn't help users
|
42
|
+
This code will be wrapped. But using the value is **syntactically** invalid in Ruby, because it constitutes a "void value expression" (aka a pointless time sink and the cause of many bugs in SiB).
|
43
|
+
Unfortunately, I can't easily check it to see if it's void since it's not in the parsed AST. But it's so edge that I don't think it's worth worrying about.
|
259
44
|
|
260
45
|
|
261
46
|
Inspiration
|
262
|
-
|
47
|
+
-----------
|
263
48
|
|
264
49
|
* [Xmpfilter](http://www.rubydoc.info/gems/rcodetools/0.8.5.0/Rcodetools/XMPFilter), which is a part of the [rcodetools gem](https://rubygems.org/gems/rcodetools).
|
265
50
|
* Bret Victor's completely inspiring talk [Inventing on Principle](https://www.youtube.com/watch?v=PUv66718DII).
|
@@ -267,7 +52,7 @@ Inspiration
|
|
267
52
|
|
268
53
|
|
269
54
|
Shout outs
|
270
|
-
|
55
|
+
----------
|
271
56
|
|
272
57
|
* Whitequark for all the work on [Parser](http://github.com/whitequark/parser/), which dramatically dramatically improved SiB (I used to have my own horribly shitty line-based parser)
|
273
58
|
* [Travis CI](https://travis-ci.org/JoshCheek/seeing_is_believing)... I love you times a million! So many difficult bugs have been caught by this.
|
@@ -275,7 +60,7 @@ Shout outs
|
|
275
60
|
I literally have a Travis CI sticker on my laptop, I love you that much.
|
276
61
|
|
277
62
|
License
|
278
|
-
|
63
|
+
-------
|
279
64
|
|
280
65
|
<a href="http://www.wtfpl.net/"><img src="http://www.wtfpl.net/wp-content/uploads/2012/12/wtfpl.svg" height="20" alt="WTFPL" /></a>
|
281
66
|
|
data/appveyor.yml
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Based this off of https://github.com/rspec/rspec-core/blob/22ed96bb3dbb0214dc48d6b8490ade04cdf8eedd/appveyor.yml
|
2
|
+
# Docs are at https://www.appveyor.com/docs
|
3
|
+
|
4
|
+
# I don't really understand what this is for
|
5
|
+
version: "{build}"
|
6
|
+
|
7
|
+
# This will build all PRs targetting matching branches.
|
8
|
+
# Without this, each PR builds twice -- once for the PR branch HEAD,
|
9
|
+
# and once for the merge commit that github creates for each mergable PR.
|
10
|
+
branches:
|
11
|
+
only:
|
12
|
+
- master
|
13
|
+
- /.*-maintenance$/
|
14
|
+
|
15
|
+
# Disable normal Windows builds in favor of our test script.
|
16
|
+
build: off
|
17
|
+
|
18
|
+
install:
|
19
|
+
- SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
|
20
|
+
- ruby --version
|
21
|
+
- gem --version
|
22
|
+
- rake install
|
23
|
+
|
24
|
+
test_script:
|
25
|
+
- bundle exec rake ci
|
26
|
+
|
27
|
+
environment:
|
28
|
+
matrix:
|
29
|
+
- ruby_version: '21'
|
data/bin/seeing_is_believing
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
3
|
+
lib_dir = File.realpath('../lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift lib_dir
|
4
5
|
|
5
6
|
require 'seeing_is_believing/binary'
|
6
7
|
exit SeeingIsBelieving::Binary.call(ARGV, $stdin, $stdout, $stderr)
|
@@ -70,3 +70,22 @@ Feature: Flags that are deprecated
|
|
70
70
|
Error: not_a_file.rb does not exist!
|
71
71
|
Deprecated: `--inherit-exit-status` Dash has been removed for consistency, use --inherit-exitstatus
|
72
72
|
"""
|
73
|
+
|
74
|
+
Scenario: -K without errors
|
75
|
+
Given the file "deprecated_K.rb" "__ENCODING__"
|
76
|
+
When I run "seeing_is_believing -Ke deprecated_K.rb"
|
77
|
+
Then stdout is '__ENCODING__ # => #<Encoding:EUC-JP>'
|
78
|
+
And stderr is empty
|
79
|
+
When I run "seeing_is_believing -Ku deprecated_K.rb"
|
80
|
+
Then stdout is '__ENCODING__ # => #<Encoding:UTF-8>'
|
81
|
+
And stderr is empty
|
82
|
+
|
83
|
+
Scenario: -K with errors
|
84
|
+
Given the file "deprecated_K.rb" "__ENCODING__"
|
85
|
+
When I run "seeing_is_believing -Ke not_a_file.rb"
|
86
|
+
Then stdout is empty
|
87
|
+
And stderr is:
|
88
|
+
"""
|
89
|
+
Error: not_a_file.rb does not exist!
|
90
|
+
Deprecated: `-Ke` The ability to set encodings is deprecated. If you need this, details are at https://github.com/JoshCheek/seeing_is_believing/wiki/Encodings
|
91
|
+
"""
|
data/features/errors.feature
CHANGED
@@ -48,6 +48,63 @@ Feature: Running the binary unsuccessfully
|
|
48
48
|
# ~> requires_exception_raising_code.rb:9:in `<main>'
|
49
49
|
"""
|
50
50
|
|
51
|
+
@not-windows
|
52
|
+
Scenario: Raising multiple exceptions
|
53
|
+
Given the file "multiple_exceptions.rb":
|
54
|
+
"""
|
55
|
+
if pid = fork #
|
56
|
+
Process.wait pid #
|
57
|
+
raise "parent"
|
58
|
+
else
|
59
|
+
raise "child"
|
60
|
+
end
|
61
|
+
|
62
|
+
"""
|
63
|
+
When I run "seeing_is_believing multiple_exceptions.rb"
|
64
|
+
Then stderr is empty
|
65
|
+
And the exit status is 1
|
66
|
+
And stdout is:
|
67
|
+
"""
|
68
|
+
if pid = fork #
|
69
|
+
Process.wait pid #
|
70
|
+
raise "parent" # ~> RuntimeError: parent
|
71
|
+
else
|
72
|
+
raise "child" # ~> RuntimeError: child
|
73
|
+
end
|
74
|
+
|
75
|
+
# ~> RuntimeError
|
76
|
+
# ~> child
|
77
|
+
# ~>
|
78
|
+
# ~> multiple_exceptions.rb:5:in `<main>'
|
79
|
+
|
80
|
+
# ~> RuntimeError
|
81
|
+
# ~> parent
|
82
|
+
# ~>
|
83
|
+
# ~> multiple_exceptions.rb:3:in `<main>'
|
84
|
+
"""
|
85
|
+
When I run "seeing_is_believing multiple_exceptions.rb -x"
|
86
|
+
Then stderr is empty
|
87
|
+
And the exit status is 1
|
88
|
+
And stdout is:
|
89
|
+
"""
|
90
|
+
if pid = fork #
|
91
|
+
Process.wait pid #
|
92
|
+
raise "parent" # ~> RuntimeError: parent
|
93
|
+
else
|
94
|
+
raise "child" # ~> RuntimeError: child
|
95
|
+
end
|
96
|
+
|
97
|
+
# ~> RuntimeError
|
98
|
+
# ~> child
|
99
|
+
# ~>
|
100
|
+
# ~> multiple_exceptions.rb:5:in `<main>'
|
101
|
+
|
102
|
+
# ~> RuntimeError
|
103
|
+
# ~> parent
|
104
|
+
# ~>
|
105
|
+
# ~> multiple_exceptions.rb:3:in `<main>'
|
106
|
+
"""
|
107
|
+
|
51
108
|
Scenario: Syntactically invalid file
|
52
109
|
Given the file "invalid_syntax.rb":
|
53
110
|
"""
|
data/features/examples.feature
CHANGED
@@ -258,6 +258,7 @@ Feature: Running the binary successfully
|
|
258
258
|
"""
|
259
259
|
And the exit status is 0
|
260
260
|
|
261
|
+
@not-windows
|
261
262
|
Scenario: Fork records data in parent and child, parent exec does not affect it.
|
262
263
|
Given the file "fork_exec_parent.rb":
|
263
264
|
"""
|
@@ -289,12 +290,13 @@ Feature: Running the binary successfully
|
|
289
290
|
# >> hello
|
290
291
|
"""
|
291
292
|
|
293
|
+
@not-windows
|
292
294
|
Scenario: Fork records data in parent and child, child exec does not affect it.
|
293
295
|
Given the file "fork_exec_child.rb":
|
294
296
|
"""
|
295
297
|
:both
|
296
298
|
if fork #
|
297
|
-
sleep 1
|
299
|
+
sleep 1 #
|
298
300
|
:parent
|
299
301
|
else
|
300
302
|
:child
|
@@ -309,7 +311,7 @@ Feature: Running the binary successfully
|
|
309
311
|
"""
|
310
312
|
:both # => :both
|
311
313
|
if fork #
|
312
|
-
sleep 1
|
314
|
+
sleep 1 #
|
313
315
|
:parent # => :parent
|
314
316
|
else
|
315
317
|
:child # => :child
|
data/features/flags.feature
CHANGED
@@ -154,7 +154,7 @@ Feature: Using flags
|
|
154
154
|
|
155
155
|
|
156
156
|
Scenario: --encoding
|
157
|
-
Given the file "utf-8.rb" "'ç'"
|
157
|
+
Given the binary file "utf-8.rb" "'ç'"
|
158
158
|
When I run "seeing_is_believing --encoding u utf-8.rb"
|
159
159
|
Then stderr is empty
|
160
160
|
And the exit status is 0
|
@@ -445,7 +445,32 @@ Feature: Using flags
|
|
445
445
|
2 # => 2
|
446
446
|
"""
|
447
447
|
|
448
|
-
Scenario: --json
|
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
|
449
474
|
Given the file "all_kinds_of_output.rb":
|
450
475
|
"""
|
451
476
|
3.times do |i|
|
@@ -458,6 +483,8 @@ Feature: Using flags
|
|
458
483
|
When I run "seeing_is_believing --json all_kinds_of_output.rb"
|
459
484
|
Then stderr is empty
|
460
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.
|
461
488
|
And stdout is the JSON:
|
462
489
|
"""
|
463
490
|
{ "lines": {
|
@@ -474,6 +501,12 @@ Feature: Using flags
|
|
474
501
|
"message": "omg",
|
475
502
|
"backtrace": ["all_kinds_of_output.rb:6:in `<main>'"]
|
476
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
|
+
}],
|
477
510
|
"stdout": "b\n",
|
478
511
|
"stderr": "c\n",
|
479
512
|
"exitstatus": 1
|