- Notifications
You must be signed in to change notification settings - Fork 64
Check exit status in ruby_exe #49
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
Conversation
lib/mspec/helpers/ruby_exe.rb Outdated
| output = `#{ruby_cmd(code, opts)}` | ||
| | ||
| if !$?.success? && exception | ||
| raise "Ruby command failed. Exit status #{$?.exitstatus}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message should show the command that failed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW
$ ruby -e 'system "exit 3", exception: true' Traceback (most recent call last): 1: from -e:1:in `<main>' -e:1:in `system': Command failed with exit 3: exit 3 (RuntimeError) But I find it rather unclear.
So I'm thinking something like:
"ruby_exe(#{command.inspect}) failed: {$?.inspect}"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| We should make sure all cases in ruby/spec are fixed before merging this to not break the CI there. (maybe we should do a run of ruby/spec here to make sure mspec changes don't break ruby/spec) |
|
| I was hesitating for the name of the keyword argument (e.g. |
Will work on it soon. |
lib/mspec/helpers/ruby_exe.rb Outdated
| output = `#{ruby_cmd(code, opts)}` | ||
| | ||
| if !$?.success? && exception | ||
| raise "ruby_exe(#{code}, #{opts}) failed: #{$?.inspect}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would show the created command here, because it's easier to read and we need it anyway.
command = ruby_cmd(code, opts) output = `#{command}` if !$?.success? && exception raise "ruby_exe(#{command.inspect}) failed: #{$?.inspect}"There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That has the advantage that if there is some issue behavior in ruby_cmd it should be obvious from the output, and make it easier to run the command on its own.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| I wonder if the option should be something like That way, we would always test the exit code, rather than |
| Another advantage compared to One issue with that approach is it might not be easy to give an exact exit code, e.g. for So we could accept |
| Yeah, I see. It definitely makes sense to check result exit code (if it's the same on different platforms). But I would also consider separating 1) helper ( I mean something like this: result = ruby_exe(command, options) result.should have_execution_output('') result.should be_successful_execution result.should be_failed_execution result.should have_execution_exit_status(0) result.should have_execution_signal(9) |
Yes they should be the same, because either the program is successful (then it's 0), an exception reached the top level (then it's 1), or there is some explicit
Yes, that's an important concern. it "foo" do ruby_exe("bar") endstill says "no expectations in example". It's true that keeping Also, something related, in case the command fails, it's very useful if we can show the output of stderr, instead of having to search that through the log. This is potentially something So, I think |
| Regarding naming, I'm happy with either |
| I see. Will try. |
| @andrykonchin Could you try the exit_code/exit_status approach? I'd be happy to merge your work here :) |
| Yes, sure. I will work on it. Hope this week. Sorry for delaying. |
52c429e to 385acd6 Compare | @eregon I added the So now we can safely merge ruby/spec#819 and then ensure this PR passes the CI checks on the new RubySpec master branch. The only issue I noticed is that exit status is checked explicitly in some tests: before :each do ruby_exe("exit(42)", exit_status: 42) end it "returns the process exit code" do $?.exitstatus.should == 42 endI noticed such checks in the following files:
|
| @andrykonchin Looks great, thank you! |
385acd6 to 7eb52cc Compare | (I amended and pushed the last commit to rerun CI) |
Raise RuntimeError when
ruby_exerun Ruby script and it exits with failed status.Close ruby/spec#767
Example