Skip to content

Commit

Permalink
Use the --bisect flag value rather than ENV var for verbose mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
myronmarston committed Apr 9, 2015
1 parent 1f11351 commit 2666401
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 34 deletions.
6 changes: 3 additions & 3 deletions features/command_line/bisect.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Feature: Bisect

At any point during the bisect run, you can hit ctrl-c to abort and it will provide you with the most minimal reproduction command it has discovered so far.

To get more detailed output (particularly useful if you want to report a bug with bisect), you can set the `DEBUG_RSPEC_BISECT` environment variable.
To get more detailed output (particularly useful if you want to report a bug with bisect), use `--bisect=verbose`.

Background:
Given a file named "lib/calculator.rb" with:
Expand Down Expand Up @@ -88,8 +88,8 @@ Feature: Bisect
When I run `rspec ./spec/calculator_10_spec.rb[1:1] ./spec/calculator_1_spec.rb[1:1] ./spec/calculator_3_spec.rb[1:1] --seed 1234`
Then the output should contain "3 examples, 1 failure"

Scenario: Use DEBUG_RSPEC_BISECT=1 to enable verbose debug mode for more detail
When I run `rspec --seed 1234 --bisect` with `DEBUG_RSPEC_BISECT=1` set
Scenario: Use `--bisect=verbose` to enable verbose debug mode for more detail
When I run `rspec --seed 1234 --bisect=verbose`
Then bisect should succeed with output like:
"""
Bisect started using options: "--seed 1234"
Expand Down
5 changes: 0 additions & 5 deletions features/step_definitions/additional_cli_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,6 @@
expect(actual.sub(/\n+\Z/, '')).to eq(expected)
end

When(/^I run `([^`]+)` with `([^=]+)=([^`]+)` set$/) do |cmd, env_key, env_value|
set_env(env_key, env_value)
step "I run `#{cmd}`"
end

When(/^I run `([^`]+)` and abort in the middle with ctrl\-c$/) do |cmd|
set_env('RUBYOPT', ENV['RUBYOPT'] + " -r#{File.expand_path("../../support/send_sigint_during_bisect.rb", __FILE__)}")
step "I run `#{cmd}`"
Expand Down
13 changes: 5 additions & 8 deletions lib/rspec/core/bisect/coordinator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@ module Bisect
# - Formatters::BisectProgressFormatter: provides progress updates
# to the user.
class Coordinator
def self.bisect_with(original_cli_args, configuration)
new(original_cli_args, configuration).bisect
def self.bisect_with(original_cli_args, configuration, formatter)
new(original_cli_args, configuration, formatter).bisect
end

def initialize(original_cli_args, configuration)
def initialize(original_cli_args, configuration, formatter)
@original_cli_args = original_cli_args
@configuration = configuration
@formatter = formatter
end

def bisect
@configuration.add_formatter bisect_formatter
@configuration.add_formatter @formatter

reporter.close_after do
repro = Server.run do |server|
Expand All @@ -52,10 +53,6 @@ def reporter
@configuration.reporter
end

def bisect_formatter
ENV['DEBUG_RSPEC_BISECT'] ? Formatters::BisectDebugFormatter : Formatters::BisectProgressFormatter
end

def gracefully_abort_on_sigint(minimizer)
trap('INT') do
repro = minimizer.repro_command_for_currently_needed_ids
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/core/bisect/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Runner

def initialize(server, original_cli_args)
@server = server
@original_cli_args = original_cli_args - ["--bisect"]
@original_cli_args = original_cli_args.reject { |arg| arg.start_with?("--bisect") }
end

def run(locations)
Expand Down
21 changes: 16 additions & 5 deletions lib/rspec/core/option_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ def parser(options)
options[:order] = "rand:#{seed}"
end

parser.on('--bisect', 'Repeatedly runs the suite in order to isolate the failures to the ',
' smallest reproducible case.') do
bisect_and_exit
parser.on('--bisect [verbose]', 'Repeatedly runs the suite in order to isolate the failures to the ',
' smallest reproducible case.') do |argument|
bisect_and_exit(argument)
end

parser.on('--[no-]fail-fast', 'Abort the run on first failure.') do |value|
Expand Down Expand Up @@ -268,12 +268,23 @@ def initialize_project_and_exit
exit
end

def bisect_and_exit
def bisect_and_exit(argument)
RSpec::Support.require_rspec_core "bisect/coordinator"
success = Bisect::Coordinator.bisect_with(original_args, RSpec.configuration)

success = Bisect::Coordinator.bisect_with(
original_args,
RSpec.configuration,
bisect_formatter_for(argument)
)

exit(success ? 0 : 1)
end

def bisect_formatter_for(argument)
return Formatters::BisectDebugFormatter if argument == "verbose"
Formatters::BisectProgressFormatter
end

def print_version_and_exit
puts RSpec::Core::Version::STRING
exit
Expand Down
14 changes: 6 additions & 8 deletions spec/rspec/core/bisect/coordinator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ module RSpec::Core
)
end

def find_minimal_repro(output)
def find_minimal_repro(output, formatter=Formatters::BisectProgressFormatter)
allow(Bisect::Server).to receive(:run).and_yield(instance_double(Bisect::Server))
allow(Bisect::Runner).to receive(:new).and_return(fake_runner)

RSpec.configuration.output_stream = output
Bisect::Coordinator.bisect_with([], RSpec.configuration)
Bisect::Coordinator.bisect_with([], RSpec.configuration, formatter)
ensure
RSpec.reset # so that RSpec.configuration.output_stream isn't closed
end
Expand Down Expand Up @@ -47,7 +47,7 @@ def find_minimal_repro(output)

it 'can use the bisect debug formatter to get detailed progress' do
output = StringIO.new
with_env_vars('DEBUG_RSPEC_BISECT' => '1') { find_minimal_repro(output) }
find_minimal_repro(output, Formatters::BisectDebugFormatter)
output = normalize_durations(output.string)

expect(output).to eq(<<-EOS.gsub(/^\s+\|/, ''))
Expand Down Expand Up @@ -95,8 +95,8 @@ def find_minimal_repro(output)
end

context "when the user aborst the bisect with ctrl-c" do
before do
formatter_subclass = Class.new(Formatters::BisectProgressFormatter) do
let(:aborting_formatter) do
Class.new(Formatters::BisectProgressFormatter) do
Formatters.register self

def bisect_round_finished(notification)
Expand All @@ -111,14 +111,12 @@ def bisect_round_finished(notification)
sleep 5
end
end

stub_const(Formatters::BisectProgressFormatter.name, formatter_subclass)
end

it "prints the most minimal repro command it has found so far" do
output = StringIO.new
expect {
find_minimal_repro(output)
find_minimal_repro(output, aborting_formatter)
}.to raise_error(an_object_having_attributes(
:class => SystemExit,
:status => 1
Expand Down
10 changes: 6 additions & 4 deletions spec/rspec/core/bisect/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,12 @@ def command_for(locations, options={})
expect(cmd.scan("--drb-port").count).to eq(1)
end

it 'ignores the `--bisect` option since that would infinitely recurse' do
original_cli_args << "--bisect"
cmd = command_for([])
expect(cmd).to exclude("--bisect")
%w[ --bisect --bisect=verbose --bisect=blah ].each do |value|
it "ignores a `#{value}` option since that would infinitely recurse" do
original_cli_args << value
cmd = command_for([])
expect(cmd).to exclude(value)
end
end

it 'uses the bisect formatter' do
Expand Down

0 comments on commit 2666401

Please sign in to comment.