-
-
Notifications
You must be signed in to change notification settings - Fork 383
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
Add specs for top-level return #530
Add specs for top-level return #530
Conversation
The build for Ruby 2.4 on AppVeyor is failed because Ruby 2.4.1p111 is used. Top level So I don't know the right solution. I see two ways
|
In general, it's better to update to latest releases if possible. This is odd, AppVeyor should use 2.4.2 according to https://www.appveyor.com/docs/build-environment/#ruby. |
Appveyor just updated from 2.4.1 to 2.4.2 yesterday 22-Oct-17. For current Appveyor info, I've got a run of ruby related info at appveyor-ruby. It's run twice a day, shows info on all the minor versions. It also shows all the MSYS2 / MinGW packages, which are used to build both ruby and extension gems. I'm not sure about 2.2.8 or 2.3.5, as they haven't been released yet. FYI, 2.3 and earlier were/are built with a proprietary system based on RubyInstaller (MSYS / MingW). 2.4 forward (and my trunk build) are built with MSYS2 / MinGW, and utilize the RubyInstaller2 runtime. Probably more info than you were looking for... Thanks. |
I looked recently, and noticed that Travis ruby-head and Appeyor trunk were both failing on 'Mock.verify_count' issues and one array spec. I may have a go at it, but probably won't be for a few days... |
@eregon looks like we need just to re-run build on AppVeyor. I still don't have permissions. Could somebody do it? |
I restarted the build. For some reason, AppVeyor is on my personal GitHub account, so I guess I'm the only one with permissions. I should try to fix that. |
@MSP-Greg Ah that explains why, thanks for the info! Re ruby-head/trunk, it is expected to fail, as basically we are testing latest of ruby/ruby with latest of ruby/spec and they are only synchronized ~once a month. Maybe we should just remove those from CI as they are only useful when I do synchronization (and even then, the Travis ruby-head build is often old). |
Should ruby-head specs go to ruby/spec/ruby ? I ask since I'm currently writing specs that differ between 2.4.2 and ruby-head and am writing them together to save effort. Perhaps an event can be setup to notify of changes made to ruby/spec/ruby so they can be tested (travis head as currently) and pulled into here more easily? |
Either is fine (ruby/ruby or ruby/spec), it's OK to add them here, but of course test locally with latest ruby-trunk then.
Automatically importing specs changes from ruby/ruby would be nice indeed. I guess it's not so trivial, particularly when there are conflicts (rare overall but still occasionally happens). |
@eregon will do |
No reason to have surprises once things are moved to ruby/spec/ruby. I suppose test frameworks are messy in that two different types of work are done, one to make the tests more complete for existing functionality, and second, to add more testing for new trunk functionality. As long as everyone working in here is aware of trunk test breakage while WIP, shouldn't be an issue... Thanks. |
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.
These are nicely readable specs!
Could you try removing those ruby_exe
? They make specs slower and don't seem needed here.
language/return_spec.rb
Outdated
|
||
ruby_exe(<<-END_OF_CODE).should == "before return\n" | ||
load "#{temp.path}" | ||
END_OF_CODE |
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 file needs to be removed after the end of the spec.
It's also better to use the tmp("loaded_file.rb")
and rm_r
helpers as they avoid creating any file outside the rubyspec_temp directory.
puts "after return" | ||
END_OF_CODE | ||
|
||
$?.exitstatus.should == 0 |
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.
ruby_exe
is powerful but has the cost of spawning a new Ruby process every time.
This is particularly bad on some implementations where it can take anywhere from 10ms to a couple seconds.
I think those specs do not need ruby_exe
, instead they could use a tmp("top_return")
file (in a before :each
block), File.write()
the code in it and just call Kernel#load
.
Then the puts should be replaced with ScratchPad << "before return"
and ScratchPad.recorded.should == ...
language/return_spec.rb
Outdated
after do | ||
rm_r @filename | ||
end | ||
|
||
it "stops file execution" do | ||
ruby_exe(<<-END_OF_CODE).should == "before return\n" |
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.
@eregon
I left ruby_exe
here intentionally to test terminating the ruby process
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.
Good idea, it's worth testing this also works for the main script.
language/return_spec.rb
Outdated
|
||
$?.exitstatus.should == 0 | ||
it "does not fire ensure block before returning while loads file" do |
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.
@eregon it looks like a Ruby bug and I am not sure this case should be present. Previous not changed case illustrates the feature
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 looks like a bug indeed. I reported it at https://bugs.ruby-lang.org/issues/14061.
Please annotate it with ruby_bug "#14061", "2.4"
and specify the opposite behavior inside, i.e., the expected non-buggy behavior.
@eregon done |
language/return_spec.rb
Outdated
|
||
->() { | ||
load @filename | ||
}.should_not raise_error |
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.
Minor, but should_not raise_error
is not so useful, leaving outside the lambda would be clear it's expected to not raise an error. I'll remove it.
I actually want to remove all should_not raise_error
in ruby/spec, because positive expectations are much more precise, but there are quite a few of them.
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.
@eregon should_not raise_error
expresses the test case intention here. If feature is broken and exception propagates with such raise_error
expectation test will fail. Without raise_error
expectation test will considered as just broken/outdated.
It's a minor issue and if you consider should_not raise_error
expectation as excessive - I will remove it.
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.
Yes, it makes a difference between an error
and failure
in mspec.
I personally see no value to that difference. I see it as either the spec passes or it does not.
If the spec fails because of a method returning a different value or because it raises an exception it's the same to me, it doesn't pass and needs fixing :)
If the spec raises an exception, the interpreter is behaving wrong whether it's an "error" or "failure" (or the spec is broken of course).
language/return_spec.rb
Outdated
end | ||
|
||
describe "return with argument" do | ||
it "does not affect exit status" do |
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.
This seems also a bug, filed as https://bugs.ruby-lang.org/issues/14062.
It seems OK to keep the spec like this for now though, could you just add a comment with the bug URL above?
@eregon done |
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.
Thank you for the new specs and congrats for finding 2 bugs in one PR!
Top-level return is now allowed. Feature #4840
Based on Ruby tests in trunk
Related issue #473
Following test cases aren't based on feature discussion or ruby tests and just describe current behavior so I am not sure they should be added:
"within if"
"within while loop"
"within a block"
"within a class"
Moreover according to discussion using of
return
keyword in class and block is incorrect but it works for Ruby 2.4.2