cute_print 1.1.4 → 1.2.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/CHANGELOG.md +6 -0
- data/Gemfile +1 -17
- data/README.md +3 -3
- data/cute_print.gemspec +63 -77
- data/lib/cute_print/release.rb +13 -0
- metadata +98 -62
- data/.config/cucumber.yml +0 -1
- data/.rspec +0 -1
- data/.travis.yml +0 -6
- data/.yardopts +0 -7
- data/Gemfile.lock +0 -110
- data/VERSION +0 -1
- data/features/.nav +0 -10
- data/features/call_chain.feature +0 -96
- data/features/configuring/configure_output.feature +0 -21
- data/features/configuring/configure_position_format.feature +0 -39
- data/features/configuring/readme.md +0 -1
- data/features/configuring/reset_configuration.feature +0 -24
- data/features/inspect/core.feature +0 -18
- data/features/inspect/inspect.feature +0 -29
- data/features/inspect/inspect_with_location.feature +0 -54
- data/features/inspect/inspect_with_source.feature +0 -16
- data/features/inspect/readme.md +0 -1
- data/features/pretty_print/pretty_print.feature +0 -41
- data/features/pretty_print/pretty_print_with_location.feature +0 -73
- data/features/pretty_print/pretty_print_with_source.feature +0 -27
- data/features/readme.md +0 -1
- data/features/support/env.rb +0 -9
- data/features/support/helpers/example.rb +0 -52
- data/features/support/helpers/example_runner.rb +0 -24
- data/features/support/helpers/fork_example_runner.rb +0 -37
- data/features/support/helpers/lib_path.rb +0 -7
- data/features/support/helpers/shell_example_runner.rb +0 -26
- data/features/support/helpers/temp_dir.rb +0 -15
- data/features/support/step_definitions.rb +0 -49
- data/spec/cute_print_spec.rb +0 -54
- data/spec/format/inspect_spec.rb +0 -20
- data/spec/format/pretty_print_spec.rb +0 -36
- data/spec/inline_labeler_spec.rb +0 -39
- data/spec/irb_spec.rb +0 -25
- data/spec/labeler_spec.rb +0 -97
- data/spec/outline_labeler_spec.rb +0 -37
- data/spec/printer_spec.rb +0 -79
- data/spec/silence_warnings.rb +0 -24
- data/spec/spec_helper.rb +0 -21
- data/spec/support/captures_stderr.rb +0 -3
- data/tasks/cucumber.rake +0 -8
- data/tasks/default.rake +0 -1
- data/tasks/jeweler.rake +0 -39
- data/tasks/spec.rake +0 -5
- data/tasks/test.rake +0 -2
- data/tasks/yard.rake +0 -3
- data/test_support/captures_stderr.rb +0 -16
- data/test_support/captures_stdout.rb +0 -16
- data/test_support/thread_unsafe_string_io.rb +0 -13
data/spec/format/inspect_spec.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require_relative "../spec_helper"
|
2
|
-
|
3
|
-
require "cute_print/format/inspect"
|
4
|
-
|
5
|
-
module CutePrint
|
6
|
-
module Format
|
7
|
-
describe Inspect do
|
8
|
-
|
9
|
-
let(:width) { 80 }
|
10
|
-
let(:value) { (1..5).to_a }
|
11
|
-
subject { Inspect.new.format(width, value) }
|
12
|
-
specify do
|
13
|
-
expect(subject).to eq [
|
14
|
-
"[1, 2, 3, 4, 5]\n",
|
15
|
-
]
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require_relative "../spec_helper"
|
2
|
-
|
3
|
-
require "cute_print/format/pretty_print"
|
4
|
-
|
5
|
-
module CutePrint
|
6
|
-
module Format
|
7
|
-
describe PrettyPrint do
|
8
|
-
|
9
|
-
let(:value) { (1..5).to_a }
|
10
|
-
subject { PrettyPrint.new.format(width, value).to_a }
|
11
|
-
|
12
|
-
context "fits on one line" do
|
13
|
-
let(:width) { 80 }
|
14
|
-
specify do
|
15
|
-
expect(subject).to eq [
|
16
|
-
"[1, 2, 3, 4, 5]\n",
|
17
|
-
]
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context "needs multiple lines" do
|
22
|
-
let(:width) { 5 }
|
23
|
-
specify do
|
24
|
-
expect(subject).to eq [
|
25
|
-
"[1,\n",
|
26
|
-
" 2,\n",
|
27
|
-
" 3,\n",
|
28
|
-
" 4,\n",
|
29
|
-
" 5]\n",
|
30
|
-
]
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
data/spec/inline_labeler_spec.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
require_relative "spec_helper"
|
2
|
-
|
3
|
-
require "cute_print/inline_labeler"
|
4
|
-
|
5
|
-
module CutePrint
|
6
|
-
describe InlineLabeler do
|
7
|
-
|
8
|
-
let(:label) { "foo.rb:1: " }
|
9
|
-
let(:value) { [1, 2, 3, 4, 5] }
|
10
|
-
subject { InlineLabeler.label(formatter, width, label, value) }
|
11
|
-
|
12
|
-
context "single line" do
|
13
|
-
let(:formatter) { Format::Inspect.new }
|
14
|
-
let(:width) { 80 }
|
15
|
-
specify do
|
16
|
-
expect(subject).to eq [
|
17
|
-
"foo.rb:1:\n",
|
18
|
-
" [1, 2, 3, 4, 5]\n",
|
19
|
-
]
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context "multiple lines" do
|
24
|
-
let(:formatter) { Format::PrettyPrint.new }
|
25
|
-
let(:width) { 4 }
|
26
|
-
specify do
|
27
|
-
expect(subject).to eq [
|
28
|
-
"foo.rb:1:\n",
|
29
|
-
" [1,\n",
|
30
|
-
" 2,\n",
|
31
|
-
" 3,\n",
|
32
|
-
" 4,\n",
|
33
|
-
" 5]\n",
|
34
|
-
]
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
end
|
data/spec/irb_spec.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require_relative "spec_helper"
|
2
|
-
|
3
|
-
require "irb"
|
4
|
-
require "open3"
|
5
|
-
require "stringio"
|
6
|
-
|
7
|
-
require "cute_print"
|
8
|
-
|
9
|
-
describe CutePrint do
|
10
|
-
|
11
|
-
it "should be able to inspect source when called from irb" do
|
12
|
-
lib_path = File.join(File.dirname(__FILE__), "../lib/cute_print")
|
13
|
-
_stdout_output, stderr_output =
|
14
|
-
Open3.popen3("irb") do |stdin, stdout, stderr, wait_thr|
|
15
|
-
stdin.puts "require #{lib_path.inspect}"
|
16
|
-
stdin.puts "def foo"
|
17
|
-
stdin.puts "end"
|
18
|
-
stdin.puts "q {1 + 2}"
|
19
|
-
stdin.close
|
20
|
-
[stdout.read, stderr.read]
|
21
|
-
end
|
22
|
-
expect(stderr_output).to eq "(1 + 2) is 3\n"
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
data/spec/labeler_spec.rb
DELETED
@@ -1,97 +0,0 @@
|
|
1
|
-
require_relative "spec_helper"
|
2
|
-
|
3
|
-
require "cute_print/labeler"
|
4
|
-
|
5
|
-
module CutePrint
|
6
|
-
describe Labeler do
|
7
|
-
|
8
|
-
WIDTH = 5
|
9
|
-
WIDTHS = {
|
10
|
-
fits: WIDTH,
|
11
|
-
too_wide: WIDTH + 1,
|
12
|
-
way_too_wide: WIDTH + 2,
|
13
|
-
}
|
14
|
-
|
15
|
-
def make_lines(opts)
|
16
|
-
size = opts.fetch(:size)
|
17
|
-
width = WIDTHS.fetch(opts.fetch(:width))
|
18
|
-
line = ('x' * width) + "\n"
|
19
|
-
Array.new(size, line)
|
20
|
-
end
|
21
|
-
|
22
|
-
let(:format) {double "format" }
|
23
|
-
let(:label) { double "label" }
|
24
|
-
let(:value) { double "value" }
|
25
|
-
before(:each) do
|
26
|
-
allow(OutlineLabeler)
|
27
|
-
.to receive(:label)
|
28
|
-
.with(format, WIDTH, label, value)
|
29
|
-
.and_return(outlined_lines)
|
30
|
-
allow(InlineLabeler)
|
31
|
-
.to receive(:label)
|
32
|
-
.with(format, WIDTH, label, value)
|
33
|
-
.and_return(inlined_lines)
|
34
|
-
end
|
35
|
-
subject { Labeler.label(format, WIDTH, label, value) }
|
36
|
-
|
37
|
-
context "the inline format fits on one line" do
|
38
|
-
let(:outlined_lines) { make_lines(size: 1, width: :fits) }
|
39
|
-
let(:inlined_lines) { double "inlined lines" }
|
40
|
-
it "should return inline lines" do
|
41
|
-
expect(subject).to equal outlined_lines
|
42
|
-
end
|
43
|
-
it "should not compute outlined lines" do
|
44
|
-
expect(OutlineLabeler).to_not have_received(:label)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context "both formats fit in the width; the inlined has fewer lines" do
|
49
|
-
let(:outlined_lines) { make_lines(size: 3, width: :fits) }
|
50
|
-
let(:inlined_lines) { make_lines(size: 2, width: :fits) }
|
51
|
-
it "should return inlined lines" do
|
52
|
-
expect(subject).to equal inlined_lines
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context "both formats fit in the width, are multiline, and have same size" do
|
57
|
-
let(:outlined_lines) { make_lines(size: 2, width: :fits) }
|
58
|
-
let(:inlined_lines) { make_lines(size: 2, width: :fits) }
|
59
|
-
it "should return inline lines" do
|
60
|
-
expect(subject).to equal outlined_lines
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
context "inlined format fits in the width; inline format does not" do
|
65
|
-
let(:outlined_lines) { make_lines(size: 2, width: :too_wide) }
|
66
|
-
let(:inlined_lines) { make_lines(size: 2, width: :fits) }
|
67
|
-
it "should return inlined lines" do
|
68
|
-
expect(subject).to equal inlined_lines
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
context "inlined format does not fits in the width; inline format does" do
|
73
|
-
let(:outlined_lines) { make_lines(size: 2, width: :fits) }
|
74
|
-
let(:inlined_lines) { make_lines(size: 2, width: :too_wide) }
|
75
|
-
it "should return inline lines" do
|
76
|
-
expect(subject).to equal outlined_lines
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
context "neither format fits in the width; inlined is narrower" do
|
81
|
-
let(:outlined_lines) { make_lines(size: 2, width: :way_too_wide) }
|
82
|
-
let(:inlined_lines) { make_lines(size: 2, width: :too_wide) }
|
83
|
-
it "should return inlined lines" do
|
84
|
-
expect(subject).to equal inlined_lines
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
context "neither format fits in width; are same width; inlined is shorter" do
|
89
|
-
let(:outlined_lines) { make_lines(size: 3, width: :too_wide) }
|
90
|
-
let(:inlined_lines) { make_lines(size: 2, width: :too_wide) }
|
91
|
-
it "should return inlined lines" do
|
92
|
-
expect(subject).to equal inlined_lines
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|
97
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require_relative "spec_helper"
|
2
|
-
|
3
|
-
require "cute_print/outline_labeler"
|
4
|
-
|
5
|
-
module CutePrint
|
6
|
-
describe OutlineLabeler do
|
7
|
-
|
8
|
-
let(:label) { "foo.rb:1: " }
|
9
|
-
let(:value) { [1, 2, 3, 4, 5] }
|
10
|
-
subject { OutlineLabeler.label(formatter, width, label, value) }
|
11
|
-
|
12
|
-
context "single line" do
|
13
|
-
let(:formatter) { Format::Inspect.new }
|
14
|
-
let(:width) { 80 }
|
15
|
-
specify do
|
16
|
-
expect(subject).to eq [
|
17
|
-
"foo.rb:1: [1, 2, 3, 4, 5]\n",
|
18
|
-
]
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
context "multiple lines" do
|
23
|
-
let(:formatter) { Format::PrettyPrint.new }
|
24
|
-
let(:width) { 4 }
|
25
|
-
specify do
|
26
|
-
expect(subject).to eq [
|
27
|
-
"foo.rb:1: [1,\n",
|
28
|
-
" 2,\n",
|
29
|
-
" 3,\n",
|
30
|
-
" 4,\n",
|
31
|
-
" 5]\n",
|
32
|
-
]
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
end
|
data/spec/printer_spec.rb
DELETED
@@ -1,79 +0,0 @@
|
|
1
|
-
require_relative "spec_helper"
|
2
|
-
|
3
|
-
require "cute_print/printer"
|
4
|
-
|
5
|
-
module CutePrint
|
6
|
-
|
7
|
-
describe Printer do
|
8
|
-
|
9
|
-
describe "#q" do
|
10
|
-
|
11
|
-
context "single value" do
|
12
|
-
Given(:out) { StringIO.new }
|
13
|
-
Given(:printer) { Printer.new(out: out) }
|
14
|
-
When { printer.q [1, 2] }
|
15
|
-
Then { out.string == "[1, 2]\n" }
|
16
|
-
end
|
17
|
-
|
18
|
-
context "multiple values" do
|
19
|
-
Given(:out) { StringIO.new }
|
20
|
-
Given(:printer) { Printer.new(out: out) }
|
21
|
-
When { printer.q 1, 2 }
|
22
|
-
Then { out.string == "1\n2\n" }
|
23
|
-
end
|
24
|
-
|
25
|
-
context "arguments and closure" do
|
26
|
-
Given(:out) { StringIO.new }
|
27
|
-
Given(:printer) { Printer.new(out: out) }
|
28
|
-
When(:result) { printer.q("foo") {1 + 2} }
|
29
|
-
Then { result == Failure(ArgumentError) }
|
30
|
-
end
|
31
|
-
|
32
|
-
context "closure (one line)" do
|
33
|
-
Given(:out) { StringIO.new }
|
34
|
-
Given(:printer) { Printer.new(out: out) }
|
35
|
-
When { printer.q {1 + 2} }
|
36
|
-
Then { out.string == "(1 + 2) is 3\n" }
|
37
|
-
end
|
38
|
-
|
39
|
-
context "closure (two lines)" do
|
40
|
-
Given(:out) { StringIO.new }
|
41
|
-
Given(:printer) { Printer.new(out: out) }
|
42
|
-
When do
|
43
|
-
printer.q do
|
44
|
-
(1 + 2)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
Then { out.string == "(1 + 2) is 3\n" }
|
48
|
-
end
|
49
|
-
|
50
|
-
context "multiple threads" do
|
51
|
-
Given(:out) { ThreadUnsafeStringIO.new }
|
52
|
-
Given(:printer) { Printer.new(out: out) }
|
53
|
-
When do
|
54
|
-
10.times.map do
|
55
|
-
Thread.new do
|
56
|
-
10.times do
|
57
|
-
printer.q "foo"
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end.map(&:join)
|
61
|
-
end
|
62
|
-
Then { expect(out.string).to match(/\A("foo"\n)+\Z/) }
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
describe "#ql" do
|
68
|
-
Given(:out) { StringIO.new }
|
69
|
-
Given(:printer) { Printer.new(out: out) }
|
70
|
-
When do
|
71
|
-
@location = [File.basename(__FILE__), __LINE__ + 1].join(":")
|
72
|
-
printer.ql [1, 2]
|
73
|
-
end
|
74
|
-
Then { out.string == "#{@location}: [1, 2]\n" }
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
data/spec/silence_warnings.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
# From [Ruby verbose mode and how it's broken][1] by Mislav Marohnić
|
3
|
-
# [1]: http://mislav.uniqpath.com/2011/06/ruby-verbose-mode/
|
4
|
-
#
|
5
|
-
# Silence Ruby verbose output. Use this to quiet warnings from
|
6
|
-
# a third-party library:
|
7
|
-
#
|
8
|
-
# silence_warnings do
|
9
|
-
# require "library_with_many_warnings"
|
10
|
-
# end
|
11
|
-
module Kernel
|
12
|
-
|
13
|
-
def silence_warnings
|
14
|
-
with_warnings(nil) { yield }
|
15
|
-
end
|
16
|
-
|
17
|
-
def with_warnings(flag)
|
18
|
-
old_verbose, $VERBOSE = $VERBOSE, flag
|
19
|
-
yield
|
20
|
-
ensure
|
21
|
-
$VERBOSE = old_verbose
|
22
|
-
end
|
23
|
-
|
24
|
-
end unless Kernel.respond_to? :silence_warnings
|
data/spec/spec_helper.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
$VERBOSE=true
|
2
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
3
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
4
|
-
|
5
|
-
require_relative "silence_warnings"
|
6
|
-
|
7
|
-
require "pp"
|
8
|
-
require "rspec"
|
9
|
-
silence_warnings do
|
10
|
-
require "rspec-given"
|
11
|
-
end
|
12
|
-
|
13
|
-
globs = [
|
14
|
-
"../test_support",
|
15
|
-
"support",
|
16
|
-
].map do |dir|
|
17
|
-
File.join(File.dirname(__FILE__), dir, '**/*.rb')
|
18
|
-
end
|
19
|
-
Dir[*globs].each do |path|
|
20
|
-
require path
|
21
|
-
end
|
data/tasks/cucumber.rake
DELETED
data/tasks/default.rake
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
task :default => [:test]
|
data/tasks/jeweler.rake
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'jeweler'
|
4
|
-
|
5
|
-
def readme
|
6
|
-
File.read(File.join(File.dirname(__FILE__), '../README.md'))
|
7
|
-
end
|
8
|
-
|
9
|
-
def remove_badges(s)
|
10
|
-
s.gsub(/^\[![^\n]+\n/, '')
|
11
|
-
end
|
12
|
-
|
13
|
-
def join_lines(s)
|
14
|
-
s.gsub(/\n/, ' ').strip
|
15
|
-
end
|
16
|
-
|
17
|
-
def description
|
18
|
-
unless (desc = readme[/\A#[^\n]*\n*(.*?)\n*^#/m, 1])
|
19
|
-
raise "Failed to extract description from readme"
|
20
|
-
end
|
21
|
-
desc = remove_badges(desc)
|
22
|
-
desc = join_lines(desc)
|
23
|
-
desc
|
24
|
-
end
|
25
|
-
|
26
|
-
Jeweler::Tasks.new do |gem|
|
27
|
-
# gem is a Gem::Specification... see
|
28
|
-
# http://docs.rubygems.org/read/chapter/20 for more options
|
29
|
-
gem.name = 'cute_print'
|
30
|
-
gem.homepage = 'http://github.com/wconrad/cute_print'
|
31
|
-
gem.license = 'MIT'
|
32
|
-
gem.summary = %Q{print debug to stderr, with flair}
|
33
|
-
gem.description = description
|
34
|
-
gem.email = 'wconrad@yagni.com'
|
35
|
-
gem.authors = ['Wayne Conrad']
|
36
|
-
# dependencies defined in Gemfile
|
37
|
-
end
|
38
|
-
|
39
|
-
Jeweler::RubygemsDotOrgTasks.new
|