-
-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
231 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# frozen_string_literal: true | ||
|
||
describe Nanoc::CLI::ErrorHandler do | ||
subject(:error_handler) { described_class.new } | ||
|
||
describe '#forwards_stack_trace?' do | ||
subject { error_handler.forwards_stack_trace? } | ||
|
||
context 'feature enabled' do | ||
around do |ex| | ||
Nanoc::Feature.enable(Nanoc::Feature::SENSIBLE_STACK_TRACES) do | ||
ex.run | ||
end | ||
end | ||
|
||
context 'Ruby 2.4' do | ||
it { is_expected.to be(true) } | ||
end | ||
|
||
context 'Ruby 2.5' do | ||
it { is_expected.to be(true) } | ||
end | ||
end | ||
|
||
context 'feature not enabled' do | ||
context 'Ruby 2.4' do | ||
before do | ||
expect(error_handler).to receive(:ruby_version).and_return('2.4.2') | ||
end | ||
|
||
it { is_expected.to be(false) } | ||
end | ||
|
||
context 'Ruby 2.5' do | ||
before do | ||
expect(error_handler).to receive(:ruby_version).and_return('2.5.0') | ||
end | ||
|
||
it { is_expected.to be(true) } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,156 @@ | ||
# frozen_string_literal: true | ||
|
||
describe Nanoc::CLI::StackTraceWriter do | ||
let(:exception) do | ||
backtrace_generator = lambda do |af| | ||
if af.zero? | ||
raise 'finally!' | ||
else | ||
backtrace_generator.call(af - 1) | ||
subject(:writer) do | ||
described_class.new(io, forwards: forwards) | ||
end | ||
|
||
let(:io) { StringIO.new } | ||
let(:forwards) { true } | ||
|
||
describe '#write' do | ||
let(:exception) do | ||
backtrace_generator = lambda do |af| | ||
if af.zero? | ||
raise 'finally!' | ||
else | ||
backtrace_generator.call(af - 1) | ||
end | ||
end | ||
end | ||
|
||
begin | ||
backtrace_generator.call(3) | ||
rescue => e | ||
return e | ||
begin | ||
backtrace_generator.call(3) | ||
rescue => e | ||
return e | ||
end | ||
end | ||
end | ||
|
||
subject { described_class.new(io).write(exception, verbose: verbose) } | ||
subject { writer.write(exception, verbose: verbose) } | ||
|
||
let(:io) { StringIO.new } | ||
let(:verbose) { false } | ||
let(:verbose) { false } | ||
|
||
context 'verbose' do | ||
let(:verbose) { true } | ||
context 'backwards' do | ||
let(:forwards) { false } | ||
|
||
it 'starts with zero' do | ||
expect { subject } | ||
.to change { io.string } | ||
.from('') | ||
.to(start_with(' 0. ')) | ||
end | ||
context 'verbose' do | ||
let(:verbose) { true } | ||
|
||
it 'has more recent stack frames at the top' do | ||
expect { subject } | ||
.to change { io.string } | ||
.from('') | ||
.to(match(%r{^ 0\. /.+/spec/nanoc/cli/stack_trace_writer_spec\.rb:\d+.*$\n 1\. /.+/spec/nanoc/cli/stack_trace_writer_spec\.rb:\d}m)) | ||
end | ||
it 'starts with zero' do | ||
expect { subject } | ||
.to change { io.string } | ||
.from('') | ||
.to(start_with(' 0. ')) | ||
end | ||
|
||
it 'has more than 10 stack frames' do | ||
expect { subject } | ||
.to change { io.string } | ||
.from('') | ||
.to(match(%r{^ 11\. })) | ||
end | ||
it 'has more recent stack frames at the top' do | ||
expect { subject } | ||
.to change { io.string } | ||
.from('') | ||
.to(match(%r{^ 0\. /.+/spec/nanoc/cli/stack_trace_writer_spec\.rb:\d+.*$\n 1\. /.+/spec/nanoc/cli/stack_trace_writer_spec\.rb:\d}m)) | ||
end | ||
|
||
it 'does not contain a see-more explanation' do | ||
subject | ||
expect(io.string).not_to match(/crash\.log/) | ||
end | ||
end | ||
it 'has more than 10 stack frames' do | ||
expect { subject } | ||
.to change { io.string } | ||
.from('') | ||
.to(match(%r{^ 11\. })) | ||
end | ||
|
||
context 'not verbose' do | ||
let(:verbose) { false } | ||
it 'does not contain a see-more explanation' do | ||
subject | ||
expect(io.string).not_to match(/crash\.log/) | ||
end | ||
end | ||
|
||
it 'starts with zero' do | ||
expect { subject } | ||
.to change { io.string } | ||
.from('') | ||
.to(start_with(' 0. ')) | ||
end | ||
context 'not verbose' do | ||
let(:verbose) { false } | ||
|
||
it 'has more recent stack frames at the top' do | ||
expect { subject } | ||
.to change { io.string } | ||
.from('') | ||
.to(match(%r{^ 0\. /.+/spec/nanoc/cli/stack_trace_writer_spec\.rb:\d+.*$\n 1\. /.+/spec/nanoc/cli/stack_trace_writer_spec\.rb:\d}m)) | ||
end | ||
it 'starts with zero' do | ||
expect { subject } | ||
.to change { io.string } | ||
.from('') | ||
.to(start_with(' 0. ')) | ||
end | ||
|
||
it 'has more recent stack frames at the top' do | ||
expect { subject } | ||
.to change { io.string } | ||
.from('') | ||
.to(match(%r{^ 0\. /.+/spec/nanoc/cli/stack_trace_writer_spec\.rb:\d+.*$\n 1\. /.+/spec/nanoc/cli/stack_trace_writer_spec\.rb:\d}m)) | ||
end | ||
|
||
it 'has not more than 10 stack frames' do | ||
subject | ||
expect(io.string).not_to match(/^ 11\. /) | ||
it 'has not more than 10 stack frames' do | ||
subject | ||
expect(io.string).not_to match(/^ 11\. /) | ||
end | ||
|
||
it 'does not contain a see-more explanation' do | ||
subject | ||
expect(io.string).to include(" lines omitted (see crash.log for details)\n") | ||
end | ||
end | ||
end | ||
|
||
it 'does not contain a see-more explanation' do | ||
subject | ||
expect(io.string).to include(" lines omitted (see crash.log for details)\n") | ||
context 'forwards' do | ||
let(:forwards) { true } | ||
|
||
context 'verbose' do | ||
let(:verbose) { true } | ||
|
||
it 'ends with most recent line' do | ||
expect { subject } | ||
.to change { io.string } | ||
.from('') | ||
.to(match(%r{^ 1\. from /.+/spec/nanoc/cli/stack_trace_writer_spec\.rb:\d+.*$\n /.+/spec/nanoc/cli}m)) | ||
end | ||
|
||
it 'has more recent stack frames at the bottom' do | ||
expect { subject } | ||
.to change { io.string } | ||
.from('') | ||
.to(match(%r{^ 2\. from /.+/spec/nanoc/cli/stack_trace_writer_spec\.rb:\d+.*$\n 1\. from /.+/spec/nanoc/cli/stack_trace_writer_spec\.rb:\d}m)) | ||
end | ||
|
||
it 'has more than 10 stack frames' do | ||
expect { subject } | ||
.to change { io.string } | ||
.from('') | ||
.to(match(%r{^ 11\. from })) | ||
end | ||
|
||
it 'does not contain a see-more explanation' do | ||
subject | ||
expect(io.string).not_to match(/crash\.log/) | ||
end | ||
end | ||
|
||
context 'not verbose' do | ||
let(:verbose) { false } | ||
|
||
it 'ends with most recent line' do | ||
expect { subject } | ||
.to change { io.string } | ||
.from('') | ||
.to(match(%r{^ 1\. from /.+/spec/nanoc/cli/stack_trace_writer_spec\.rb:\d+.*$\n /.+/spec/nanoc/cli}m)) | ||
end | ||
|
||
it 'has more recent stack frames at the top' do | ||
expect { subject } | ||
.to change { io.string } | ||
.from('') | ||
.to(match(%r{^ 2\. from /.+/spec/nanoc/cli/stack_trace_writer_spec\.rb:\d+.*$\n 1\. from /.+/spec/nanoc/cli/stack_trace_writer_spec\.rb:\d}m)) | ||
end | ||
|
||
it 'has not more than 10 stack frames' do | ||
subject | ||
expect(io.string).not_to match(/^ 11\. from /) | ||
end | ||
|
||
it 'does not contain a see-more explanation' do | ||
subject | ||
expect(io.string).to include(" lines omitted (see crash.log for details)\n") | ||
end | ||
end | ||
end | ||
end | ||
end |