seeing_is_believing 3.4.0 → 3.6.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 +5 -5
- data/.travis.yml +1 -0
- data/appveyor.yml +2 -0
- data/features/flags.feature +237 -1
- data/features/regression.feature +8 -0
- data/lib/seeing_is_believing/binary.rb +5 -0
- data/lib/seeing_is_believing/binary/annotate_end_of_file.rb +1 -1
- data/lib/seeing_is_believing/binary/annotate_marked_lines.rb +4 -2
- data/lib/seeing_is_believing/binary/comment_lines.rb +1 -1
- data/lib/seeing_is_believing/binary/config.rb +14 -0
- data/lib/seeing_is_believing/binary/engine.rb +58 -1
- data/lib/seeing_is_believing/code.rb +2 -2
- data/lib/seeing_is_believing/evaluate_by_moving_files.rb +7 -2
- data/lib/seeing_is_believing/version.rb +1 -1
- data/lib/seeing_is_believing/wrap_expressions.rb +5 -5
- data/seeing_is_believing.gemspec +1 -1
- data/spec/binary/config_spec.rb +48 -30
- data/spec/binary/engine_spec.rb +11 -1
- data/spec/seeing_is_believing_spec.rb +4 -0
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2191c3427344ea922d31c319fe5442b7cc548d35
|
4
|
+
data.tar.gz: c9d3e073bbeb2d093a69ffbea07f287750b42f73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbfb8141efc9ca5a3ec5eaaae28588439b593911eb411305843d39d5b42ab0d670386c0934e95d2b709f90e2d5a80133637b7b6e2181ef37387530387b8caa31
|
7
|
+
data.tar.gz: 37148dff2dd6e2231a1a8be45437f41160e747eef14e52f5df2bb68258ec630ffe2345ea310b47b1b432507cf9253c9c2b7dca26d59d98f0c786df4a55087ad2
|
data/.travis.yml
CHANGED
data/appveyor.yml
CHANGED
data/features/flags.feature
CHANGED
@@ -268,7 +268,7 @@ Feature: Using flags
|
|
268
268
|
|
269
269
|
|
270
270
|
Scenario: --alignment-strategy file
|
271
|
-
|
271
|
+
Given the file "file_alignments.rb":
|
272
272
|
"""
|
273
273
|
# comment
|
274
274
|
1
|
@@ -614,3 +614,239 @@ Feature: Using flags
|
|
614
614
|
And stdout is '__FILE__ # => "cwd_of_file_test.rb"'
|
615
615
|
|
616
616
|
|
617
|
+
Scenario: --toggle-mark adds a mark to the line if it is unmarked and exists
|
618
|
+
Given the file "unmarked.rb":
|
619
|
+
"""
|
620
|
+
1
|
621
|
+
2
|
622
|
+
"""
|
623
|
+
When I run "seeing_is_believing unmarked.rb --toggle-mark 1"
|
624
|
+
Then stderr is empty
|
625
|
+
And the exit status is 0
|
626
|
+
And stdout is '{{"1 # => \n2"}}'
|
627
|
+
When I run "seeing_is_believing unmarked.rb --toggle-mark 2"
|
628
|
+
Then stderr is empty
|
629
|
+
And the exit status is 0
|
630
|
+
And stdout is '{{"1\n2 # => "}}'
|
631
|
+
When I run "seeing_is_believing unmarked.rb --toggle-mark 3"
|
632
|
+
Then stderr is empty
|
633
|
+
And the exit status is 0
|
634
|
+
And stdout is '{{"1\n2"}}'
|
635
|
+
|
636
|
+
|
637
|
+
Scenario: --toggle-mark doesn't add a mark to the line if it has a comment or can't be commented
|
638
|
+
Given the file "no_toggle_line_here.rb":
|
639
|
+
"""
|
640
|
+
1 # comment
|
641
|
+
"2
|
642
|
+
"
|
643
|
+
"""
|
644
|
+
When I run "seeing_is_believing no_toggle_line_here.rb --toggle-mark 1"
|
645
|
+
Then stderr is empty
|
646
|
+
And the exit status is 0
|
647
|
+
And stdout is:
|
648
|
+
"""
|
649
|
+
1 # comment
|
650
|
+
"2
|
651
|
+
"
|
652
|
+
"""
|
653
|
+
When I run "seeing_is_believing no_toggle_line_here.rb --toggle-mark 2"
|
654
|
+
Then stderr is empty
|
655
|
+
And the exit status is 0
|
656
|
+
And stdout is:
|
657
|
+
"""
|
658
|
+
1 # comment
|
659
|
+
"2
|
660
|
+
"
|
661
|
+
"""
|
662
|
+
When I run "seeing_is_believing no_toggle_line_here.rb --toggle-mark 3"
|
663
|
+
Then stderr is empty
|
664
|
+
And the exit status is 0
|
665
|
+
And stdout is:
|
666
|
+
"""
|
667
|
+
1 # comment
|
668
|
+
"2
|
669
|
+
" # =>{{" "}}
|
670
|
+
"""
|
671
|
+
|
672
|
+
|
673
|
+
Scenario: --toggle-mark removes a mark from the line if it is marked and exists
|
674
|
+
Given the file "marked.rb":
|
675
|
+
"""
|
676
|
+
1 # =>
|
677
|
+
2 + 2 # =>
|
678
|
+
"""
|
679
|
+
When I run "seeing_is_believing marked.rb --toggle-mark 1"
|
680
|
+
Then stderr is empty
|
681
|
+
And the exit status is 0
|
682
|
+
And stdout is '{{"1\n2 + 2 # => "}}'
|
683
|
+
When I run "seeing_is_believing marked.rb --toggle-mark 2"
|
684
|
+
Then stderr is empty
|
685
|
+
And the exit status is 0
|
686
|
+
And stdout is '{{"1 # => \n2 + 2"}}'
|
687
|
+
When I run "seeing_is_believing marked.rb --toggle-mark 3"
|
688
|
+
Then stderr is empty
|
689
|
+
And the exit status is 0
|
690
|
+
And stdout is '{{"1 # => \n2 + 2 # => "}}'
|
691
|
+
|
692
|
+
|
693
|
+
Scenario: --toggle-mark removes error lines, and stdout/stderr output
|
694
|
+
Given the file "output_to_toggle_off.rb":
|
695
|
+
"""
|
696
|
+
1 + "a" # ~> b
|
697
|
+
# >> c
|
698
|
+
# !> d
|
699
|
+
# ~> e
|
700
|
+
"""
|
701
|
+
When I run "seeing_is_believing output_to_toggle_off.rb --toggle-mark 1"
|
702
|
+
Then stdout is:
|
703
|
+
"""
|
704
|
+
1 + "a"
|
705
|
+
# >> c
|
706
|
+
# !> d
|
707
|
+
# ~> e
|
708
|
+
"""
|
709
|
+
When I run "seeing_is_believing output_to_toggle_off.rb --toggle-mark 2"
|
710
|
+
Then stdout is:
|
711
|
+
"""
|
712
|
+
1 + "a" # ~> b
|
713
|
+
|
714
|
+
# !> d
|
715
|
+
# ~> e
|
716
|
+
"""
|
717
|
+
When I run "seeing_is_believing output_to_toggle_off.rb --toggle-mark 3"
|
718
|
+
Then stdout is:
|
719
|
+
"""
|
720
|
+
1 + "a" # ~> b
|
721
|
+
# >> c
|
722
|
+
|
723
|
+
# ~> e
|
724
|
+
"""
|
725
|
+
When I run "seeing_is_believing output_to_toggle_off.rb --toggle-mark 4"
|
726
|
+
Then stdout is:
|
727
|
+
"""
|
728
|
+
1 + "a" # ~> b
|
729
|
+
# >> c
|
730
|
+
# !> d
|
731
|
+
"""
|
732
|
+
|
733
|
+
|
734
|
+
Scenario: --toggle-mark respects the --alignment-strategy of file and updates any existing annotations to respect it
|
735
|
+
Given the file "toggle_mark_with_file_alignment.rb":
|
736
|
+
"""
|
737
|
+
1
|
738
|
+
|
739
|
+
1 + 1 # => 2
|
740
|
+
1 + 1 + 1 # => 3
|
741
|
+
1 + 1 + 1 + 1
|
742
|
+
"""
|
743
|
+
When I run "seeing_is_believing --toggle-mark 1 --alignment-strategy file toggle_mark_with_file_alignment.rb"
|
744
|
+
Then stderr is empty
|
745
|
+
And the exit status is 0
|
746
|
+
And stdout is:
|
747
|
+
"""
|
748
|
+
1 # =>{{" "}}
|
749
|
+
|
750
|
+
1 + 1 # => 2
|
751
|
+
1 + 1 + 1 # => 3
|
752
|
+
1 + 1 + 1 + 1
|
753
|
+
"""
|
754
|
+
When I run "seeing_is_believing --toggle-mark 3 --alignment-strategy file toggle_mark_with_file_alignment.rb"
|
755
|
+
Then stderr is empty
|
756
|
+
And the exit status is 0
|
757
|
+
And stdout is:
|
758
|
+
"""
|
759
|
+
1
|
760
|
+
|
761
|
+
1 + 1
|
762
|
+
1 + 1 + 1 # => 3
|
763
|
+
1 + 1 + 1 + 1
|
764
|
+
"""
|
765
|
+
|
766
|
+
|
767
|
+
Scenario: --toggle-mark respects the --alignment-strategy of chunk and updates any existing annotations to respect it
|
768
|
+
Given the file "toggle_mark_with_chunk_alignments.rb":
|
769
|
+
"""
|
770
|
+
1+1# => 2
|
771
|
+
1+1+1
|
772
|
+
1+1+1+1
|
773
|
+
|
774
|
+
1 + 1
|
775
|
+
# comment in the middle!
|
776
|
+
1
|
777
|
+
"""
|
778
|
+
When I run "seeing_is_believing --toggle-mark 2 --alignment-strategy chunk toggle_mark_with_chunk_alignments.rb"
|
779
|
+
Then stderr is empty
|
780
|
+
And the exit status is 0
|
781
|
+
And stdout is:
|
782
|
+
"""
|
783
|
+
1+1 # => 2
|
784
|
+
1+1+1 # =>{{" "}}
|
785
|
+
1+1+1+1
|
786
|
+
|
787
|
+
1 + 1
|
788
|
+
# comment in the middle!
|
789
|
+
1
|
790
|
+
"""
|
791
|
+
When I run "seeing_is_believing --toggle-mark 5 --alignment-strategy chunk toggle_mark_with_chunk_alignments.rb"
|
792
|
+
Then stderr is empty
|
793
|
+
And the exit status is 0
|
794
|
+
And stdout is:
|
795
|
+
"""
|
796
|
+
1+1 # => 2
|
797
|
+
1+1+1
|
798
|
+
1+1+1+1
|
799
|
+
|
800
|
+
1 + 1 # =>{{" "}}
|
801
|
+
# comment in the middle!
|
802
|
+
1
|
803
|
+
"""
|
804
|
+
When I run "seeing_is_believing --toggle-mark 1 --alignment-strategy chunk toggle_mark_with_chunk_alignments.rb"
|
805
|
+
Then stderr is empty
|
806
|
+
And the exit status is 0
|
807
|
+
And stdout is:
|
808
|
+
"""
|
809
|
+
1+1
|
810
|
+
1+1+1
|
811
|
+
1+1+1+1
|
812
|
+
|
813
|
+
1 + 1
|
814
|
+
# comment in the middle!
|
815
|
+
1
|
816
|
+
"""
|
817
|
+
|
818
|
+
|
819
|
+
Scenario: --toggle-mark respects the --alignment-strategy of line and updates any existing annotations to respect it
|
820
|
+
Given the file "toggle_mark_with_line_alignments.rb":
|
821
|
+
"""
|
822
|
+
1
|
823
|
+
1 + 1# => x
|
824
|
+
1 + 1 + 1
|
825
|
+
"""
|
826
|
+
When I run "seeing_is_believing --toggle-mark 1 --alignment-strategy line toggle_mark_with_line_alignments.rb"
|
827
|
+
Then stderr is empty
|
828
|
+
And the exit status is 0
|
829
|
+
And stdout is:
|
830
|
+
"""
|
831
|
+
1 # =>{{" "}}
|
832
|
+
1 + 1 # => x
|
833
|
+
1 + 1 + 1
|
834
|
+
"""
|
835
|
+
When I run "seeing_is_believing --toggle-mark 2 --alignment-strategy line toggle_mark_with_line_alignments.rb"
|
836
|
+
Then stderr is empty
|
837
|
+
And the exit status is 0
|
838
|
+
And stdout is:
|
839
|
+
"""
|
840
|
+
1
|
841
|
+
1 + 1
|
842
|
+
1 + 1 + 1
|
843
|
+
"""
|
844
|
+
When I run "seeing_is_believing --toggle-mark 3 --alignment-strategy line toggle_mark_with_line_alignments.rb"
|
845
|
+
Then stderr is empty
|
846
|
+
And the exit status is 0
|
847
|
+
And stdout is:
|
848
|
+
"""
|
849
|
+
1
|
850
|
+
1 + 1 # => x
|
851
|
+
1 + 1 + 1 # =>{{" "}}
|
852
|
+
"""
|
data/features/regression.feature
CHANGED
@@ -471,6 +471,7 @@ Feature:
|
|
471
471
|
# Not going to get too detailed on what it prints, b/c that message seems pretty fragile,
|
472
472
|
# but just generally that it doesn't fkn blow up
|
473
473
|
@not-2.4
|
474
|
+
@not-2.5
|
474
475
|
Scenario: Old JSON bug
|
475
476
|
Given the file "json_and_encodings.rb":
|
476
477
|
"""
|
@@ -826,3 +827,10 @@ Feature:
|
|
826
827
|
end
|
827
828
|
str # => a string
|
828
829
|
"""
|
830
|
+
|
831
|
+
|
832
|
+
Scenario: The last line can end in a semicolon
|
833
|
+
When I run "seeing_is_believing -e '1'"
|
834
|
+
Then stdout is "1 # => 1"
|
835
|
+
When I run "seeing_is_believing -e '1;'"
|
836
|
+
Then stdout is "1; # => 1"
|
@@ -32,6 +32,11 @@ class SeeingIsBelieving
|
|
32
32
|
return SUCCESS_STATUS
|
33
33
|
end
|
34
34
|
|
35
|
+
if config.toggle_mark?
|
36
|
+
stdout.print engine.toggled_mark
|
37
|
+
return SUCCESS_STATUS
|
38
|
+
end
|
39
|
+
|
35
40
|
if engine.syntax_error?
|
36
41
|
stderr.puts engine.syntax_error
|
37
42
|
return NONDISPLAYABLE_ERROR_STATUS
|
@@ -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 code.body_range, output
|
16
16
|
new_body.replace code.rewriter.process
|
17
17
|
end
|
18
18
|
|
@@ -47,8 +47,6 @@ class SeeingIsBelieving
|
|
47
47
|
WrapExpressions.call \
|
48
48
|
program,
|
49
49
|
before_each: -> line_number {
|
50
|
-
# 74 b/c pretty print_defaults to 79 (guessing 80 chars with 1 reserved for newline), and
|
51
|
-
# 79 - "# => ".length # => 4
|
52
50
|
inspect = "$SiB.record_result(:inspect, #{line_number}, ("
|
53
51
|
pp = "$SiB.record_result(:pp, #{line_number}, ("
|
54
52
|
|
@@ -62,6 +60,10 @@ class SeeingIsBelieving
|
|
62
60
|
end
|
63
61
|
},
|
64
62
|
after_each: -> line_number {
|
63
|
+
# 74 b/c pretty print_defaults to 79 (guessing 80 chars with 1 reserved for newline), and
|
64
|
+
# 79 - "# => ".length # => 4
|
65
|
+
# ALSO: This should be configurable, b/c otherwise you have to go into the guts of `pp`
|
66
|
+
# https://gist.github.com/JoshCheek/6472c8f334ae493f4ab1f7865e2470e5
|
65
67
|
inspect = "))"
|
66
68
|
pp = ")) { |v| PP.pp v, '', 74 }"
|
67
69
|
|
@@ -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 range, comment_text
|
26
26
|
end
|
27
27
|
commentable_lines.rewriter.process
|
28
28
|
end
|
@@ -30,6 +30,7 @@ class SeeingIsBelieving
|
|
30
30
|
predicate(:remove_value_prefixes) { true }
|
31
31
|
predicate(:debug) { false }
|
32
32
|
predicate(:ignore_unknown_flags) { false }
|
33
|
+
predicate(:toggle_mark) { nil }
|
33
34
|
attribute(:body) { nil }
|
34
35
|
attribute(:filename) { nil }
|
35
36
|
attribute(:errors) { [] }
|
@@ -109,6 +110,11 @@ class SeeingIsBelieving
|
|
109
110
|
self.lib_options.require_files << 'pp'
|
110
111
|
self.lib_options.require_files << 'seeing_is_believing/customize_pp'
|
111
112
|
|
113
|
+
when '--toggle-mark'
|
114
|
+
extract_positive_int_for.call arg do |n|
|
115
|
+
self.toggle_mark = n
|
116
|
+
end
|
117
|
+
|
112
118
|
when '-i', '--inherit-exitstatus', '--inherit-exit-status'
|
113
119
|
self.inherit_exitstatus = true
|
114
120
|
arg.include?("exit-status") &&
|
@@ -252,6 +258,13 @@ class SeeingIsBelieving
|
|
252
258
|
print_event_stream? && (result_as_json? || annotator == AnnotateMarkedLines) &&
|
253
259
|
add_error("can only have one output format, --stream is not compatible with --json, -x, and --xmpfilter-style")
|
254
260
|
|
261
|
+
toggle_mark? && print_event_stream? &&
|
262
|
+
add_error("--toggle-mark and --stream are mutually exclusive")
|
263
|
+
|
264
|
+
toggle_mark? && result_as_json? &&
|
265
|
+
add_error("--toggle-mark and --json are mutually exclusive")
|
266
|
+
|
267
|
+
|
255
268
|
self.filename = filenames.first
|
256
269
|
self.lib_options.filename = as || filename
|
257
270
|
self.lib_options.debugger = debugger
|
@@ -342,6 +355,7 @@ Options:
|
|
342
355
|
-g, --debug # print debugging information
|
343
356
|
--debug-to FILE # print debugging information to FILE
|
344
357
|
-x, --xmpfilter-style # annotate marked lines instead of every line
|
358
|
+
--toggle-mark n # add / remove annotation on line n
|
345
359
|
-j, --json # print results in json format (i.e. so another program can consume them)
|
346
360
|
-i, --inherit-exitstatus # exit with the exit status of the program being evaluated
|
347
361
|
--stream # a JSON stream of every event ias it is seen (such as recording a line)
|
@@ -18,12 +18,69 @@ class SeeingIsBelieving
|
|
18
18
|
|
19
19
|
def cleaned_body
|
20
20
|
@cleaned_body ||= if missing_newline?
|
21
|
-
normalized_cleaned_body.chomp
|
21
|
+
normalized_cleaned_body.chomp
|
22
22
|
else
|
23
23
|
normalized_cleaned_body
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
|
28
|
+
require 'seeing_is_believing/binary/rewrite_comments'
|
29
|
+
require 'seeing_is_believing/binary/format_comment'
|
30
|
+
module ToggleMark
|
31
|
+
def self.call(options)
|
32
|
+
options = options.dup
|
33
|
+
body = options.delete :body
|
34
|
+
line = options.delete :line
|
35
|
+
markers = options.delete :markers
|
36
|
+
alignment_strategy = options.delete :alignment_strategy
|
37
|
+
|
38
|
+
marker_regexes = markers.values.map(&:regex)
|
39
|
+
RewriteComments.call body, include_lines: [line] do |comment|
|
40
|
+
if line == comment.line_number && marker_regexes.any? { |r| r =~ comment.text }
|
41
|
+
new_comment = ''
|
42
|
+
elsif line == comment.line_number && comment.text.empty?
|
43
|
+
new_comment = FormatComment.call(
|
44
|
+
comment.whitespace_col,
|
45
|
+
markers.value.prefix,
|
46
|
+
'',
|
47
|
+
options.merge(
|
48
|
+
pad_to: alignment_strategy.line_length_for(comment.line_number)
|
49
|
+
),
|
50
|
+
)
|
51
|
+
elsif line == comment.line_number
|
52
|
+
new_comment = comment.whitespace + comment.text
|
53
|
+
elsif match = markers.value.regex.match(comment.text)
|
54
|
+
new_comment = FormatComment.call(
|
55
|
+
comment.whitespace_col,
|
56
|
+
markers.value.prefix,
|
57
|
+
match.post_match,
|
58
|
+
options.merge(
|
59
|
+
pad_to: alignment_strategy.line_length_for(comment.line_number)
|
60
|
+
)
|
61
|
+
)
|
62
|
+
else
|
63
|
+
new_comment = comment.whitespace + comment.text
|
64
|
+
end
|
65
|
+
[new_comment[/^\s*/], new_comment.lstrip]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def toggled_mark
|
71
|
+
body = config.body
|
72
|
+
body += "\n" if missing_newline?
|
73
|
+
toggled = ToggleMark.call(
|
74
|
+
body: body,
|
75
|
+
line: config.toggle_mark,
|
76
|
+
markers: config.markers,
|
77
|
+
alignment_strategy: config.annotator_options.alignment_strategy.new(normalized_cleaned_body),
|
78
|
+
options: config.annotator_options.to_h,
|
79
|
+
)
|
80
|
+
toggled.chomp! if missing_newline?
|
81
|
+
toggled
|
82
|
+
end
|
83
|
+
|
27
84
|
def syntax_error?
|
28
85
|
code.syntax.invalid?
|
29
86
|
end
|
@@ -25,7 +25,7 @@ class SeeingIsBelieving
|
|
25
25
|
@raw = raw_code
|
26
26
|
@buffer = Parser::Source::Buffer.new(name||"SeeingIsBelieving")
|
27
27
|
@buffer.source = raw
|
28
|
-
@rewriter = Parser::Source::
|
28
|
+
@rewriter = Parser::Source::TreeRewriter.new buffer
|
29
29
|
builder = Parser::Builders::Default.new.tap { |b| b.emit_file_line_as_literals = false }
|
30
30
|
@parser = Parser::CurrentRuby.new builder
|
31
31
|
@syntax = Syntax.new
|
@@ -109,7 +109,7 @@ class SeeingIsBelieving
|
|
109
109
|
(name, (_, range)) = tokens.max_by { |name, (data, range)| range.end_pos } ||
|
110
110
|
[nil, [nil, range_for(0, 1)]]
|
111
111
|
end_pos = range.end_pos
|
112
|
-
end_pos += 1 if name == :tCOMMENT || name == :tSTRING_END
|
112
|
+
end_pos += 1 if name == :tCOMMENT || name == :tSTRING_END || name == :tSEMI
|
113
113
|
range_for 0, end_pos
|
114
114
|
end
|
115
115
|
|
@@ -102,8 +102,13 @@ class SeeingIsBelieving
|
|
102
102
|
|
103
103
|
# send stdin (char at a time b/c input could come from a stream)
|
104
104
|
Thread.new do
|
105
|
-
|
106
|
-
|
105
|
+
begin
|
106
|
+
provided_input.each_char { |char| child.io.stdin.write char }
|
107
|
+
rescue
|
108
|
+
# don't explode if child closes IO
|
109
|
+
ensure
|
110
|
+
child.io.stdin.close
|
111
|
+
end
|
107
112
|
end
|
108
113
|
|
109
114
|
# set up the event consumer
|
@@ -30,20 +30,20 @@ class SeeingIsBelieving
|
|
30
30
|
when :total_fucking_failure
|
31
31
|
rewriter.replace range, '.....TOTAL FUCKING FAILURE!.....'
|
32
32
|
when :match_current_line
|
33
|
-
rewriter.
|
33
|
+
rewriter.insert_before range, '~' # Regexp#~
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
wrappings.each do |line_num, (range, last_col, meta)|
|
38
|
-
rewriter.
|
38
|
+
rewriter.insert_before range, before_each.call(line_num)
|
39
39
|
end
|
40
40
|
|
41
41
|
wrappings.each do |line_num, (range, last_col, meta)|
|
42
|
-
rewriter.
|
42
|
+
rewriter.insert_after range, after_each.call(line_num)
|
43
43
|
end
|
44
44
|
|
45
|
-
rewriter.
|
46
|
-
rewriter.
|
45
|
+
rewriter.insert_before root_range, before_all.call
|
46
|
+
rewriter.insert_after root_range, after_all_text
|
47
47
|
rewriter.process
|
48
48
|
end
|
49
49
|
end
|
data/seeing_is_believing.gemspec
CHANGED
@@ -19,7 +19,7 @@ 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.5.0"
|
23
23
|
s.add_dependency "childprocess","~> 0.8.0"
|
24
24
|
|
25
25
|
s.add_development_dependency "pry"
|
data/spec/binary/config_spec.rb
CHANGED
@@ -611,40 +611,58 @@ RSpec.describe SeeingIsBelieving::Binary::Config do
|
|
611
611
|
it('defaults :stdout to "# >> "') { expect(default_markers.stdout .prefix).to eq "# >> " }
|
612
612
|
it('defaults :stderr to "# !> "') { expect(default_markers.stderr .prefix).to eq "# !> " }
|
613
613
|
end
|
614
|
-
end
|
615
614
|
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
615
|
+
describe 'print_event_stream?' do
|
616
|
+
it 'print_event_stream? is false by default' do
|
617
|
+
expect(parse([]).print_event_stream?).to eq false
|
618
|
+
end
|
619
|
+
it 'print_event_stream? can be turned on with --stream' do
|
620
|
+
expect(parse(['--stream']).print_event_stream?).to eq true
|
621
|
+
end
|
622
|
+
it 'adds an error if --stream is used with --json' do
|
623
|
+
expect(parse(['--stream'])).to_not have_error '--stream'
|
624
|
+
expect(parse(['--stream', '--json'])).to have_error '--stream'
|
625
|
+
expect(parse(['--json', '--stream'])).to have_error '--stream'
|
626
|
+
end
|
627
|
+
it 'adds an error if --stream is used with -x or --xmpfilter-style' do
|
628
|
+
expect(parse(['--stream'])).to_not have_error '--stream'
|
629
|
+
expect(parse(['--stream', '-x'])).to have_error '--stream'
|
630
|
+
expect(parse(['-x', '--stream'])).to have_error '--stream'
|
631
|
+
expect(parse(['--xmpfilter-style', '--stream'])).to have_error '--stream'
|
632
|
+
end
|
633
633
|
end
|
634
|
-
end
|
635
|
-
|
636
634
|
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
635
|
+
describe 'align_results?' do
|
636
|
+
it 'defaults to true' do
|
637
|
+
expect(parse([]).annotator_options.interline_align?).to eq true
|
638
|
+
end
|
639
|
+
it 'can be turned on with --interline-align' do
|
640
|
+
expect(parse(['--interline-align'])).to_not have_error '--interline-align'
|
641
|
+
expect(parse(['--interline-align']).annotator_options.interline_align?).to eq true
|
642
|
+
end
|
643
|
+
it 'can be turned off with --no-interline-align' do
|
644
|
+
expect(parse(['--no-interline-align'])).to_not have_error '--no-interline-align'
|
645
|
+
expect(parse(['--no-interline-align']).annotator_options.interline_align?).to eq false
|
646
|
+
end
|
644
647
|
end
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
+
|
649
|
+
describe 'toggle_mark/toggle_mark?' do
|
650
|
+
it 'defaults to nil/false' do
|
651
|
+
expect(parse([]).toggle_mark).to eq nil
|
652
|
+
expect(parse([]).toggle_mark?).to eq false
|
653
|
+
end
|
654
|
+
it 'can be set to true/linenum with --toggle-mark' do
|
655
|
+
expect(parse(['--toggle-mark', '123']).toggle_mark).to eq 123
|
656
|
+
expect(parse(['--toggle-mark', '123']).toggle_mark?).to eq true
|
657
|
+
end
|
658
|
+
it_behaves_like 'it requires a positive int argument', ['--toggle-mark']
|
659
|
+
it 'adds an error if used with --json or --stream' do
|
660
|
+
# expect(parse(['--toggle-mark', '123'])).to_not have_error /--toggle-mark/
|
661
|
+
expect(parse(['--stream', '--toggle-mark', '123'])).to have_error /--toggle-mark/
|
662
|
+
expect(parse(['--toggle-mark', '123', '--stream'])).to have_error /--toggle-mark/
|
663
|
+
expect(parse(['--json', '--toggle-mark', '123'])).to have_error /--toggle-mark/
|
664
|
+
expect(parse(['--toggle-mark', '123', '--json'])).to have_error /--toggle-mark/
|
665
|
+
end
|
648
666
|
end
|
649
667
|
end
|
650
668
|
|
data/spec/binary/engine_spec.rb
CHANGED
@@ -7,7 +7,8 @@ class SeeingIsBelieving
|
|
7
7
|
def call(body, options={})
|
8
8
|
timeout = options.fetch :timeout, 0
|
9
9
|
filename = options.fetch :filename, "program.rb"
|
10
|
-
|
10
|
+
toggle = options.fetch :toggled_mark, nil
|
11
|
+
config = Config.new body: body, timeout_seconds: timeout, toggle_mark: toggle
|
11
12
|
config.lib_options.timeout_seconds = timeout
|
12
13
|
config.lib_options.filename = filename
|
13
14
|
Engine.new config
|
@@ -50,6 +51,15 @@ class SeeingIsBelieving
|
|
50
51
|
end
|
51
52
|
end
|
52
53
|
|
54
|
+
context 'toggled_mark' do
|
55
|
+
it 'has the mark toggled and doesn\'t change the newline' do
|
56
|
+
expect(call("1", toggled_mark: 1).toggled_mark).to eq "1 # => "
|
57
|
+
expect(call("1 # => ", toggled_mark: 1).toggled_mark).to eq "1"
|
58
|
+
expect(call("1\n", toggled_mark: 1).toggled_mark).to eq "1 # => \n"
|
59
|
+
expect(call("1 # =>\n", toggled_mark: 1).toggled_mark).to eq "1\n"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
53
63
|
context 'before evaluating it raises if asked for' do
|
54
64
|
specify('result') { assert_must_evaluate :result }
|
55
65
|
specify('exitstatus') { assert_must_evaluate :exitstatus }
|
@@ -531,6 +531,10 @@ RSpec.describe SeeingIsBelieving do
|
|
531
531
|
expect(result.exception.message).to match /recursive/i
|
532
532
|
end
|
533
533
|
|
534
|
+
it 'does not blow up when the first line looks like it might have a magic comment in it (#126)' do
|
535
|
+
expect(values_for "1+1 # and a comment with 'Accept-Encoding: gzip' in it").to eq [['2']]
|
536
|
+
end
|
537
|
+
|
534
538
|
it 'makes the SeeingIsBelieving::VERSION available to the program' do
|
535
539
|
expect(values_for "SeeingIsBelieving::VERSION").to eq [[SeeingIsBelieving::VERSION.inspect]]
|
536
540
|
end
|
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.
|
4
|
+
version: 3.6.0
|
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: 2018-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.
|
19
|
+
version: 2.5.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.
|
26
|
+
version: 2.5.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: childprocess
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -287,7 +287,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
287
287
|
version: '0'
|
288
288
|
requirements: []
|
289
289
|
rubyforge_project: seeing_is_believing
|
290
|
-
rubygems_version: 2.
|
290
|
+
rubygems_version: 2.5.2
|
291
291
|
signing_key:
|
292
292
|
specification_version: 4
|
293
293
|
summary: Records results of every line of code in your file
|