summaryrefslogtreecommitdiff
path: root/test/ruby
AgeCommit message (Collapse)Author
2021-05-08Fix Math.cbrt(0.0) on glibcJeremy Evans
This should return 0, but on glibc it returned NaN. Fixes [Bug #17804] Notes: Merged: https://github.com/ruby/ruby/pull/4425
2021-04-28test/ruby/test_fiber.rb: reduce the count of object creation to cause GCYusuke Endoh
... on Solaris. This is the same as 547887138f19959f649b1c0dbcde5659ae3878ed. http://rubyci.s3.amazonaws.com/solaris10-gcc/ruby-master/log/20210427T160003Z.fail.html.gz ``` [ 7667/20965] TestFiber#test_fork_from_fiber/export/home/users/chkbuild/cb-gcc/tmp/build/20210427T160003Z/ruby/test/ruby/test_fiber.rb:397:in `transfer': can't alloc machine stack to fiber (1 x 139264 bytes): Not enough space (FiberError) from /export/home/users/chkbuild/cb-gcc/tmp/build/20210427T160003Z/ruby/test/ruby/test_fiber.rb:397:in `block (6 levels) in test_fork_from_fiber' from /export/home/users/chkbuild/cb-gcc/tmp/build/20210427T160003Z/ruby/test/ruby/test_fiber.rb:396:in `times' from /export/home/users/chkbuild/cb-gcc/tmp/build/20210427T160003Z/ruby/test/ruby/test_fiber.rb:396:in `block (5 levels) in test_fork_from_fiber' from /export/home/users/chkbuild/cb-gcc/tmp/build/20210427T160003Z/ruby/test/ruby/test_fiber.rb:392:in `fork' from /export/home/users/chkbuild/cb-gcc/tmp/build/20210427T160003Z/ruby/test/ruby/test_fiber.rb:392:in `block (4 levels) in test_fork_from_fiber' = 0.88 s ... 1) Failure: TestFiber#test_fork_from_fiber [/export/home/users/chkbuild/cb-gcc/tmp/build/20210427T160003Z/ruby/test/ruby/test_fiber.rb:409]: [ruby-core:41456]. <0> expected but was <1>. ```
2021-04-27test/ruby/test_exception.rb: suppress "warning: statement not reached"Yusuke Endoh
2021-04-26node.c (rb_ast_new): imemo_ast is WB-unprotectedYusuke Endoh
Previously imemo_ast was handled as WB-protected which caused a segfault of the following code: # shareable_constant_value: literal M0 = {} M1 = {} ... M100000 = {} My analysis is here: `shareable_constant_value: literal` creates many Hash instances during parsing, and add them to node_buffer of imemo_ast. However, the contents are missed because imemo_ast is incorrectly WB-protected. This changeset makes imemo_ast as WB-unprotected. Notes: Merged: https://github.com/ruby/ruby/pull/4416
2021-04-26Remove test of removed reverse VM instructionKazuhiro NISHIYAMA
since 5512353d97250e85c13bf10b9b32e750478cf474
2021-04-26Fix some typos by spell checkerRyuta Kamizono
Notes: Merged: https://github.com/ruby/ruby/pull/4414
2021-04-23Add back checks for empty kw splat with tests (#4405)Alan Wu
This reverts commit a224ce8150f2bc687cf79eb415c931d87a4cd247. Turns out the checks are needed to handle splatting an array with an empty ruby2 keywords hash. Notes: Merged-By: XrXr
2021-04-23Fix setting method visibility for a refinement without an origin classJeremy Evans
If a class has been refined but does not have an origin class, there is a single method entry marked with VM_METHOD_TYPE_REFINED, but it contains the original method entry. If the original method entry is present, we shouldn't skip the method when searching even when skipping refined methods. Fixes [Bug #17519] Notes: Merged: https://github.com/ruby/ruby/pull/4357
2021-04-23test/ruby/test_assignment.rb: Avoid "assigned but unused variable"Yusuke Endoh
2021-04-23Suppress warnings for unsued variableHiroshi SHIBATA
2021-04-22fix raise in exception with jumpKoichi Sasada
add_ensure_iseq() adds ensure block to the end of jump such as next/redo/return. However, if the rescue cause are in the body, this rescue catches the exception in ensure clause. iter do next rescue R ensure raise end In this case, R should not be executed, but executed without this patch. Fixes [Bug #13930] Fixes [Bug #16618] A part of tests are written by @jeremyevans https://github.com/ruby/ruby/pull/4291 Notes: Merged: https://github.com/ruby/ruby/pull/4399
2021-04-21Evaluate multiple assignment left hand side before right hand sideJeremy Evans
In regular assignment, Ruby evaluates the left hand side before the right hand side. For example: ```ruby foo[0] = bar ``` Calls `foo`, then `bar`, then `[]=` on the result of `foo`. Previously, multiple assignment didn't work this way. If you did: ```ruby abc.def, foo[0] = bar, baz ``` Ruby would previously call `bar`, then `baz`, then `abc`, then `def=` on the result of `abc`, then `foo`, then `[]=` on the result of `foo`. This change makes multiple assignment similar to single assignment, changing the evaluation order of the above multiple assignment code to calling `abc`, then `foo`, then `bar`, then `baz`, then `def=` on the result of `abc`, then `[]=` on the result of `foo`. Implementing this is challenging with the stack-based virtual machine. We need to keep track of all of the left hand side attribute setter receivers and setter arguments, and then keep track of the stack level while handling the assignment processing, so we can issue the appropriate topn instructions to get the receiver. Here's an example of how the multiple assignment is executed, showing the stack and instructions: ``` self # putself abc # send abc, self # putself abc, foo # send abc, foo, 0 # putobject 0 abc, foo, 0, [bar, baz] # evaluate RHS abc, foo, 0, [bar, baz], baz, bar # expandarray abc, foo, 0, [bar, baz], baz, bar, abc # topn 5 abc, foo, 0, [bar, baz], baz, abc, bar # swap abc, foo, 0, [bar, baz], baz, def= # send abc, foo, 0, [bar, baz], baz # pop abc, foo, 0, [bar, baz], baz, foo # topn 3 abc, foo, 0, [bar, baz], baz, foo, 0 # topn 3 abc, foo, 0, [bar, baz], baz, foo, 0, baz # topn 2 abc, foo, 0, [bar, baz], baz, []= # send abc, foo, 0, [bar, baz], baz # pop abc, foo, 0, [bar, baz] # pop [bar, baz], foo, 0, [bar, baz] # setn 3 [bar, baz], foo, 0 # pop [bar, baz], foo # pop [bar, baz] # pop ``` As multiple assignment must deal with splats, post args, and any level of nesting, it gets quite a bit more complex than this in non-trivial cases. To handle this, struct masgn_state is added to keep track of the overall state of the mass assignment, which stores a linked list of struct masgn_attrasgn, one for each assigned attribute. This adds a new optimization that replaces a topn 1/pop instruction combination with a single swap instruction for multiple assignment to non-aref attributes. This new approach isn't compatible with one of the optimizations previously used, in the case where the multiple assignment return value was not needed, there was no lhs splat, and one of the left hand side used an attribute setter. This removes that optimization. Removing the optimization allowed for removing the POP_ELEMENT and adjust_stack functions. This adds a benchmark to measure how much slower multiple assignment is with the correct evaluation order. This benchmark shows: * 4-9% decrease for attribute sets * 14-23% decrease for array member sets * Basically same speed for local variable sets Importantly, it shows no significant difference between the popped (where return value of the multiple assignment is not needed) and !popped (where return value of the multiple assignment is needed) cases for attribute and array member sets. This indicates the previous optimization, which was dropped in the evaluation order fix and only affected the popped case, is not important to performance. Fixes [Bug #4443] Notes: Merged: https://github.com/ruby/ruby/pull/4390 Merged-By: jeremyevans <code@jeremyevans.net>
2021-04-21array.c (rb_ary_zip): take only as many as needed from an Enumerator (#4389)Yusuke Endoh
[Bug #17814] Notes: Merged-By: mame <mame@ruby-lang.org>
2021-04-16Add Array#intersect?Travis Hunter
Notes: Merged: https://github.com/ruby/ruby/pull/1972
2021-04-09test/ruby/test_gc_compact.rb: Use assert_separately for debuggingYusuke Endoh
... the following timeout failure. http://rubyci.s3.amazonaws.com/rhel_zlinux/ruby-master/log/20210408T213303Z.fail.html.gz ``` [ 8871/21204] TestGCCompact#test_ast_compactstimeout: output interval exceeds 600.0 seconds. timeout: the process group 28416 is alive. PSOUT PGID PID ELAPSED %CPU VSZ COMMAND COMMAND PSOUT 28416 28416 12:46 0.0 108120 gmake gmake TESTS=--hide-skip -v RUBYOPT=-w test-all PSOUT 28416 28423 12:46 88.2 1446124 ruby ./test/runner.rb: TestGCCompact#test_ast_compacts timeout: INT signal sent. timeout: INT signal sent. timeout: TERM signal sent. timeout: TERM signal sent. timeout: KILL signal sent. ``` This error repeatedly occurs on RHEL s390x. This change sends SEGV when timeout occurs so that it should dump the backtrace.
2021-04-07[Bug #17780] Fix Method#super_method for module aliasPeter Zhu
Method#super_method crashes for aliased module methods because they are not defined on a class. This bug was introduced in c60aaed1856b2b6f90de0992c34771830019e021 as part of bug #17130. Notes: Merged: https://github.com/ruby/ruby/pull/4364
2021-04-05Get rid of multibyte prefix to tmpdirNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/4354
2021-04-04test/ruby/test_lambda.rb: Remove "warning: assigned but unused variable"Yusuke Endoh
2021-04-02fix return from orphan Proc in lambdaKoichi Sasada
A "return" statement in a Proc in a lambda like: `lambda{ proc{ return }.call }` should return outer lambda block. However, the inner Proc can become orphan Proc from the lambda block. This "return" escape outer-scope like method, but this behavior was decieded as a bug. [Bug #17105] This patch raises LocalJumpError by checking the proc is orphan or not from lambda blocks before escaping by "return". Most of tests are written by Jeremy Evans https://github.com/ruby/ruby/pull/4223 Notes: Merged: https://github.com/ruby/ruby/pull/4347
2021-03-29Add more tests for defined? with method callsJeremy Evans
Notes: Merged: https://github.com/ruby/ruby/pull/4213
2021-03-28Keep non evaluated keys in `Hash#transform_keys!` [Bug #17735]Kenichi Kamiya
Notes: Merged: https://github.com/ruby/ruby/pull/4294 Merged-By: nobu <nobu@ruby-lang.org>
2021-03-28Fix segmentation fault when `Module#name` returns non string value [Bug #17754]Kenichi Kamiya
* Add test for NoMethodError#to_s does not segfault * Ensure no segfault even if Module#name is overridden Notes: Merged: https://github.com/ruby/ruby/pull/4328 Merged-By: nobu <nobu@ruby-lang.org>
2021-03-27Fix Enumerable#tally with some arguments pattern [Feature #17744]Kenichi Kamiya
* Add test cases for Enumerable#tally with hash argument * Add ruby/spec for Enumerable#tally with hash argument * Fix Enumerable#tally does not update given frozen hash * Add test cases for Enumerable#tally with hash convertible arguments * Fix SEGV when Enumerable#tally takes non Hash convertible * FIx cosmetic damage enum.c Notes: Merged: https://github.com/ruby/ruby/pull/4327 Merged-By: nobu <nobu@ruby-lang.org>
2021-03-26Enumerable#tally with the resulting hash [Feature #17744]Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/4318 Merged-By: nobu <nobu@ruby-lang.org>
2021-03-24Change heap walking to be safe for object allocationPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/4263
2021-03-24Ensure that caller respects the start argumentJeremy Evans
Previously, if there were ignored frames (iseq without pc), we could go beyond the requested start frame. This has two changes: 1) Ensure that we don't look beyond the start frame by using last_cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(last_cfp) until the desired start frame is reached. 2) To fix the failures caused by change 1), which occur when a limited number of frames is requested, scan the VM stack before allocating backtrace frames, looking for ignored frames. This is complicated if there are ignored frames before and after the start, in which case we need to scan until the start frame, and then scan backwards, decrementing the start value until we get to the point where start will result in the number of requested frames. This fixes a Rails test failure. Jean Boussier was able to to produce a failing test case outside of Rails. Co-authored-by: Jean Boussier <jean.boussier@gmail.com> Notes: Merged: https://github.com/ruby/ruby/pull/4237
2021-03-23Ignore useless separators preceding a file encoding commentNobuyoshi Nakada
2021-03-23Assertion for colon-separated encoding pragmaNobuyoshi Nakada
2021-03-23Refined failure messages in TestFileExhaustive#test_testNobuyoshi Nakada
2021-03-23test/ruby/test_fiber.rb: relax timeout on SolarisYusuke Endoh
... of test_many_fibers_with_threads because the test seems to take about 180 sec. on Solaris. This change extends the limit to 300 sec on Solaris. BTW, 180 sec. is too long for other normal environments, so this reverts Related to 6ab7d439f8d43234004e1760aa88a98c29129006 for them.
2021-03-22Hash#transform_values! ensures receiver modifiable in block [Bug #17736]Kenichi Kamiya
Notes: Merged: https://github.com/ruby/ruby/pull/4302 Merged-By: nobu <nobu@ruby-lang.org>
2021-03-21Pattern matching pin operator against expression [Feature #17411]Kazuki Tsujimoto
This commit is based on the patch by @nobu.
2021-03-21Ensure the receiver hash modifiable before updating [Bug #17736]Nobuyoshi Nakada
Close https://github.com/ruby/ruby/pull/4298 Notes: Merged: https://github.com/ruby/ruby/pull/4299
2021-03-21Add Hash#{update, merge!} test to ensure receiver modifiable in blockKenichi Kamiya
Notes: Merged: https://github.com/ruby/ruby/pull/4299
2021-03-20Some Hash destructive methods ensure the receiver modifiable [Bug #17736]Kenichi Kamiya
refs: * https://bugs.ruby-lang.org/issues/17736 * https://github.com/ruby/ruby/pull/4296 This commit aims to cover following methods * Hash#select! * Hash#filter! * Hash#keep_if * Hash#reject! * Hash#delete_if I think these are not all. --- * Ensure the receiver is modifiable or not * Assert the receiver is not modified Notes: Merged: https://github.com/ruby/ruby/pull/4297
2021-03-20Ensure the receiver is modifiable before shrinking [Bug #17736]Nobuyoshi Nakada
* Ensure the receiver is modifiable before shinking [Bug #17736] * Assert the receivers are not modified Notes: Merged: https://github.com/ruby/ruby/pull/4296 Merged-By: nobu <nobu@ruby-lang.org>
2021-03-19Fix Enumerable#inject with high negative fixnums [Bug #17731]Marc-Andre Lafortune
Notes: Merged: https://github.com/ruby/ruby/pull/4288
2021-03-19Fix infinite loop at illegal sequence [Bug #17729]Nobuyoshi Nakada
As mblen returns -1 on failure, skip the first byte and try the succeeding bytes in that case. Close https://github.com/ruby/ruby/pull/4281 Notes: Merged: https://github.com/ruby/ruby/pull/4284
2021-03-18Avoid rehashing in Hash#replace/dup/initialize_copy [Bug #16996]Marc-Andre Lafortune
2021-03-18Avoid rehashing in Hash#select/reject [Bug #16996]Marc-Andre Lafortune
2021-03-16Skip refined method when exporting methods with changed visibilityJeremy Evans
Previously, attempting to change the visibility of a method in a singleton class for a class/module that is prepended to and refined would raise a NoMethodError. Fixes [Bug #17519] Notes: Merged: https://github.com/ruby/ruby/pull/4200
2021-03-16test/ruby/test_regexp.rb: Avoid "ambiguity between regexp and two divisions"Yusuke Endoh
2021-03-15File.dirname optional levelNobuyoshi Nakada
* file.c (rb_file_dirname_n): chomp N level of base names. [Feature #12194] Notes: Merged: https://github.com/ruby/ruby/pull/4111
2021-03-15Check backref number buffer overrun [Bug #16376]xtkoba (Tee KOBAYASHI)
2021-03-12Fix integer/float remainder with infinity argument of opposite signJeremy Evans
Previously, the result was incorrect: 4.remainder(-Float::INFINITY) Before: => NaN After: => 4 4.2.remainder(-Float::INFINITY) Before: => NaN After: => 4.2 Fixes [Bug #6120] Notes: Merged: https://github.com/ruby/ruby/pull/4257
2021-03-11Create the test file under the created temporary directoryNobuyoshi Nakada
Fixes https://github.com/ruby/ruby/pull/4255
2021-03-10Remove cvar overtaken classes at end of test methodsJeremy Evans
Fixes issues when the same tests are executed more than once, which some CI machines do.
2021-03-10Add cvar overtaken testseileencodes
While working on another project we noticed that there were no tests for the cvar overtaken exception when using classes. This change adds a test for cvar overtaken with classes and moves the cvar overtaken test for modules into the new file. Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org> Notes: Merged: https://github.com/ruby/ruby/pull/4251
2021-03-08test/ruby/test_string.rb: make GitHub syntax-highlight correctlyYusuke Endoh
It looks like GitHub syntax-highlighting does not support an empty heredoc. This change adds a newline to make GitHub can handle the syntax appropriately. https://bugs.ruby-lang.org/issues/17662
2021-03-06Undef Enumerator::Chain#{feed,next,next_values,peek,peek_values}Jeremy Evans
Previously these methods were defined but raised TypeError, which seems worse. Notes: Merged: https://github.com/ruby/ruby/pull/3811