Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exit with different status codes when scenarios failed (1) and when... #845

Merged
merged 1 commit into from
May 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion features/docs/getting_started.feature
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Feature: Getting started
puts 'this will not be shown'
"""
When I run `cucumber`
Then the exit status should be 1
Then the exit status should be 2
And the output should not contain:
"""
this will not be shown
Expand Down
2 changes: 1 addition & 1 deletion features/docs/raketask.feature
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ Feature: Raketask

Scenario: Failing feature
When I run `bundle exec rake fail`
Then the exit status should not be 0
Then the exit status should be 1
But the output should not contain "rake aborted!"
19 changes: 11 additions & 8 deletions lib/cucumber/cli/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,30 @@ def execute!(existing_runtime = nil)
end

runtime.run!
failure = runtime.failure? || Cucumber.wants_to_quit
@kernel.exit(failure ? 1 : 0)
if Cucumber.wants_to_quit
@kernel.exit(2)
else
@kernel.exit(runtime.failure? ? 1 : 0)
end
rescue FileNotFoundException => e
@err.puts(e.message)
@err.puts("Couldn't open #{e.path}")
@kernel.exit(1)
@kernel.exit(2)
rescue FeatureFolderNotFoundException => e
@err.puts(e.message + ". You can use `cucumber --init` to get started.")
@kernel.exit(1)
@kernel.exit(2)
rescue ProfilesNotDefinedError, YmlLoadError, ProfileNotFound => e
@err.puts(e.message)
@kernel.exit(1)
@kernel.exit(2)
rescue SystemExit => e
@kernel.exit(e.status)
rescue Errno::EACCES, Errno::ENOENT => e
@err.puts("#{e.message} (#{e.class})")
@kernel.exit(1)
@kernel.exit(2)
rescue Exception => e
@err.puts("#{e.message} (#{e.class})")
@err.puts(e.backtrace.join("\n"))
@kernel.exit(1)
@kernel.exit(2)
end

def configuration
Expand All @@ -70,7 +73,7 @@ def configuration

def trap_interrupt
trap('INT') do
exit!(1) if Cucumber.wants_to_quit
exit!(2) if Cucumber.wants_to_quit
Cucumber.wants_to_quit = true
STDERR.puts "\nExiting... Interrupt again to exit immediately."
end
Expand Down
6 changes: 3 additions & 3 deletions spec/cucumber/cli/main_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ def do_execute
Cucumber.wants_to_quit = false
end

it "registers as a failure" do
it "exits with error code" do
results = double('results', :failure? => false)

allow_any_instance_of(Runtime).to receive(:run!)
allow_any_instance_of(Runtime).to receive(:results) { results }

Cucumber.wants_to_quit = true

expect(kernel).to receive(:exit).with(1)
expect(kernel).to receive(:exit).with(2)

subject.execute!
end
Expand Down Expand Up @@ -93,7 +93,7 @@ def do_execute

allow(Configuration).to receive(:new) { configuration }
allow(configuration).to receive(:parse!).and_raise(exception_klass.new("error message"))
allow(kernel).to receive(:exit).with(1)
allow(kernel).to receive(:exit).with(2)

subject.execute!

Expand Down