summaryrefslogtreecommitdiff
path: root/test/ruby/test_proc.rb
AgeCommit message (Collapse)Author
2020-06-19Implement Proc#== and #eql?Jeremy Evans
Previously, these were not implemented, and Object#== and #eql? were used. This tries to check the proc internals to make sure that procs created from separate blocks are treated as not equal, but procs created from the same block are treated as equal, even when the lazy proc allocation optimization is used. Implements [Feature #14267] Notes: Merged: https://github.com/ruby/ruby/pull/3174
2020-06-10Make proc/Proc.new without block an error instead of warningJeremy Evans
The warning for these was added in 2.7. Notes: Merged: https://github.com/ruby/ruby/pull/3208
2020-03-08Do not autosplat when calling procs that accept rest and keywordsJeremy Evans
When providing a single array to a block that takes a splat, pass the array as one argument of the splat instead of as the splat itself, even if the block also accepts keyword arguments. Previously, this behavior was only used for blocks that did not accept keywords. Implements [Feature#16166] Notes: Merged: https://github.com/ruby/ruby/pull/2502
2020-01-28support multi-run for test/ruby/test_proc.rbKoichi Sasada
Mysterious error: `remove_method(:foo) if method_defined?(:foo)` raise an exception `method `foo' not defined in #<Class:#<TestProc:0x000055d12ff154e0>>` This patch rename the method name foo to foo_arity to solve it.
2020-01-24Do not autosplat when calling proc with empty keyword splatJeremy Evans
With the removal of the splatted argument when using an empty keyword splat, the autosplat code considered an empty keyword splat the same as no argument at all. However, that results in autosplat behavior changing dependent on the content of the splatted hash, which is not what anyone would expect or want. This change always skips an autosplat if keywords were provided. Fixes [Bug #16560] Notes: Merged: https://github.com/ruby/ruby/pull/2861
2020-01-02Update tests for full keyword argument separationJeremy Evans
Notes: Merged: https://github.com/ruby/ruby/pull/2794
2020-01-02Fully separate positional arguments and keyword argumentsJeremy Evans
This removes the warnings added in 2.7, and changes the behavior so that a final positional hash is not treated as keywords or vice-versa. To handle the arg_setup_block splat case correctly with keyword arguments, we need to check if we are taking a keyword hash. That case didn't have a test, but it affects real-world code, so add a test for it. This removes rb_empty_keyword_given_p() and related code, as that is not needed in Ruby 3. The empty keyword case is the same as the no keyword case in Ruby 3. This changes rb_scan_args to implement keyword argument separation for C functions when the : character is used. For backwards compatibility, it returns a duped hash. This is a bad idea for performance, but not duping the hash breaks at least Enumerator::ArithmeticSequence#inspect. Instead of having RB_PASS_CALLED_KEYWORDS be a number, simplify the code by just making it be rb_keyword_given_p(). Notes: Merged: https://github.com/ruby/ruby/pull/2794
2019-12-30Decide lambdaness of (f << g) using g (#2729)Alan Wu
* Deciding lambdaness of (f << g) using g * Use version guards for spec changes Notes: Merged-By: XrXr
2019-12-23Reword keyword arguments warning messages to convey these are deprecation ↵Marc-Andre Lafortune
warnings
2019-12-20vm_args.c: rephrase the warning message of keyword argument separationYusuke Endoh
(old) test.rb:4: warning: The last argument is used as the keyword parameter test.rb:1: warning: for `foo' defined here; maybe ** should be added to the call? (new) test.rb:4: warning: The last argument is used as keyword parameters; maybe ** should be added to the call test.rb:1: warning: The called method `foo' is defined here
2019-11-18Deprecate taint/trust and related methods, and make the methods no-opsJeremy Evans
This removes the related tests, and puts the related specs behind version guards. This affects all code in lib, including some libraries that may want to support older versions of Ruby. Notes: Merged: https://github.com/ruby/ruby/pull/2476
2019-11-18Warn on access/modify of $SAFE, and remove effects of modifying $SAFEJeremy Evans
This removes the security features added by $SAFE = 1, and warns for access or modification of $SAFE from Ruby-level, as well as warning when calling all public C functions related to $SAFE. This modifies some internal functions that took a safe level argument to no longer take the argument. rb_require_safe now warns, rb_require_string has been added as a version that takes a VALUE and does not warn. One public C function that still takes a safe level argument and that this doesn't warn for is rb_eval_cmd. We may want to consider adding an alternative method that does not take a safe level argument, and warn for rb_eval_cmd. Notes: Merged: https://github.com/ruby/ruby/pull/2476
2019-11-14test/ruby/test_proc.rb: suppress "method redefined" warningsYusuke Endoh
2019-11-12Show the name `Kernel#proc` in the warning messageNobuyoshi Nakada
2019-09-26Fix more keyword separation issuesJeremy Evans
This fixes instance_exec and similar methods. It also fixes Enumerator::Yielder#yield, rb_yield_block, and a couple of cases with Proc#{<<,>>}. This support requires the addition of rb_yield_values_kw, similar to rb_yield_values2, for passing the keyword flag. Unlike earlier attempts at this, this does not modify the rb_block_call_func type or add a separate function type. The functions of type rb_block_call_func are called by Ruby with a separate VM frame, and we can get the keyword flag information from the VM frame flags, so it doesn't need to be passed as a function argument. These changes require the following VM functions accept a keyword flag: * vm_yield_with_cref * vm_yield * vm_yield_with_block Notes: Merged: https://github.com/ruby/ruby/pull/2493
2019-09-26Fix keyword argument separation issues in Proc#{<<,>>}Jeremy Evans
This requires adding rb_proc_call_with_block_kw. Notes: Merged: https://github.com/ruby/ruby/pull/2484
2019-08-14change Proc#to_s format ('@...' -> ' ...') (#2362)Koichi Sasada
Now Proc#to_s returns "#<Proc:0x00000237a0f5f170@t.rb:1>". However, it is convenient to select a file name by (double-)clicking on some terminals by separating ' ' instead of '@' like "#<Proc:0x00000237a0f5f170 t.rb:1>" [Feature #16101]
2019-07-15add tests for orphan/not-orphan proc/lambda.Tanaka Akira
2019-06-30Suppress unused variable warningsNobuyoshi Nakada
2019-04-26Hide internal IDsNobuyoshi Nakada
* parse.y (internal_id): number the ID serial for internal use by counting down from the neary maximum value, not to accidentally match permanent IDs. [Bug #15768] Notes: Fixed: [Bug #15786]
2019-01-10proc.c: proc without blocknobu
* proc.c (proc_new): promoted lambda/proc/Proc.new with no block in a method called with a block to a warning/error. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66772 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-10proc.c: check if callablenobu
* proc.c: check the argument at composition, expect a Proc, Method, or callable object. [ruby-core:90591] [Bug #15428] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66769 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-22Proc#<< and Proc#>>nobu
[Feature #6284] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-22proc.c: Support any callable when composing Procsnobu
* proc.c (proc_compose): support any object with a call method rather than supporting only procs. [Feature #6284] * proc.c (compose): use the function call on the given object rather than rb_proc_call_with_block in order to support any object. * test/ruby/test_proc.rb: Add test cases for composing Procs with callable objects. * test/ruby/test_method.rb: Add test cases for composing Methods with callable objects. From: Paul Mucur <paul@altmetric.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65913 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-22proc.c: Implement Proc#* for Proc compositionnobu
* proc.c (proc_compose): Implement Proc#* for Proc composition, enabling composition of Procs and Methods. [Feature #6284] * test/ruby/test_proc.rb: Add test cases for Proc composition. From: Paul Mucur <mudge@mudge.name> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65911 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-23remove VM_ENV_DATA_INDEX_ENV_PROC.ko1
* vm_core.h (VM_ENV_DATA_INDEX_ENV_PROC): ep[VM_ENV_DATA_INDEX_ENV_PROC] is allocated to mark a Proc which is created from iseq block. However, `lep[0]` keeps Proc object itself as a block handler (Proc). So we don't need to keep it. * vm_core.h (VM_ENV_PROCVAL): ditto. * vm.c (vm_make_env_each): do not need to keep blockprocval as special value. * vm.c (vm_block_handler_escape): simply return Proc value. * proc.c (proc_new): we don't need to check Env because a Proc type block handler is a Proc object itself. [Bug #14782] * test/ruby/test_proc.rb: add a test for [Bug #14782] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63494 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-18extend timeout morenaruse
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61902 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-17extend timeoutnaruse
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61892 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-08vm.c: respect redefinition of Proc#callnobu
* vm.c (vm_redefinition_check_method_type): hoist out method definition type to check redefinition. * vm.c (rb_vm_check_redefinition_opt_method): should check optimized method too. * vm.c (vm_init_redefined_flag): check Proc#call. * vm_insnhelper.c (vm_call_opt_block_call): search proper method if redefined. [Bug #14335] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61680 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-05extend timeout to 15 seconds for ARMv8 environmentnaruse
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61625 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-28`$SAFE` as a process global state. [Feature #14250]ko1
* vm_core.h (rb_vm_t): move `rb_execution_context_t::safe_level` to `rb_vm_t::safe_level_` because `$SAFE` is a process (VM) global state. * vm_core.h (rb_proc_t): remove `rb_proc_t::safe_level` because `Proc` objects don't need to keep `$SAFE` at the creation. Also make `is_from_method` and `is_lambda` as 1 bit fields. * cont.c (cont_restore_thread): no need to keep `$SAFE` for Continuation. * eval.c (ruby_cleanup): use `rb_set_safe_level_force()` instead of access `vm->safe_level_` directly. * eval_jump.c: End procs `END{}` doesn't keep `$SAFE`. * proc.c (proc_dup): removed and introduce `rb_proc_dup` in vm.c. * safe.c (rb_set_safe_level): don't check `$SAFE` 1 -> 0 changes. * safe.c (safe_setter): use `rb_set_safe_level()`. * thread.c (rb_thread_safe_level): `Thread#safe_level` returns `$SAFE`. It should be obsolete. * transcode.c (load_transcoder_entry): `rb_safe_level()` only returns 0 or 1 so that this check is not needed. * vm.c (vm_proc_create_from_captured): don't need to keep `$SAFE` for Proc. * vm.c (rb_proc_create): renamed to `proc_create`. * vm.c (rb_proc_dup): moved from proc.c. * vm.c (vm_invoke_proc): do not need to set and restore `$SAFE` for `Proc#call`. * vm_eval.c (rb_eval_cmd): rename a local variable to represent clearer meaning. * lib/drb/drb.rb: restore `$SAFE`. * lib/erb.rb: restore `$SAFE`, too. * test/lib/leakchecker.rb: check `$SAFE == 0` at the end of tests. * test/rubygems/test_gem.rb: do not set `$SAFE = 1`. * bootstraptest/test_proc.rb: catch up this change. * spec/ruby/optional/capi/string_spec.rb: ditto. * test/bigdecimal/test_bigdecimal.rb: ditto. * test/fiddle/test_func.rb: ditto. * test/fiddle/test_handle.rb: ditto. * test/net/imap/test_imap_response_parser.rb: ditto. * test/pathname/test_pathname.rb: ditto. * test/readline/test_readline.rb: ditto. * test/ruby/test_file.rb: ditto. * test/ruby/test_optimization.rb: ditto. * test/ruby/test_proc.rb: ditto. * test/ruby/test_require.rb: ditto. * test/ruby/test_thread.rb: ditto. * test/rubygems/test_gem_specification.rb: ditto. * test/test_tempfile.rb: ditto. * test/test_tmpdir.rb: ditto. * test/win32ole/test_win32ole.rb: ditto. * test/win32ole/test_win32ole_event.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61510 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-26test_proc.rb: remove duplicate test_source_locationnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61485 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-26test/ruby/test_proc.rb: Add a test for Binding#source_locationmame
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61481 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-12* proc.c (get_local_variable_ptr): return found env ptr. Returned envko1
will be used by write barrier at `bind_local_variable_set()'. [Bug #13605] * test/ruby/test_proc.rb: add a test for this issue. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59063 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-08proc.c: preserve class name encoding in Proc#to_snobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57808 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-20test_proc.rb: improve curry testsnobu
* test/ruby/test_proc.rb (test_curry): split. * test/ruby/test_proc.rb (test_curry_passed_block): simplify the assertion. * test/ruby/test_proc.rb (test_curry_with_trace): run all curry tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56457 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-08test_proc.rb: test_lambda?nobu
* test/ruby/test_proc.rb (test_lambda?): lambda-ness should be preserved across proc, lambda, and Proc.new. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55321 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-02-19test/ruby: suppress parser warningsnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53872 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-01-12fix test to follow r53503naruse
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53507 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-16* vm.c: fix mark miss for proc given as passed block.ko1
[Bug #11750] * vm.c (vm_make_proc_from_block): should return a Proc object if block is given. Previous implementation returns a Proc object only when corresponding Proc object is not available. * vm.c (vm_make_env_each): ditto. * test/ruby/test_proc.rb: add a test for this bug. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53144 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-16Add frozen_string_literal: false for all filesnaruse
When you change this to true, you may need to add more tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53141 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-29test_proc.rb: test_curry_bindingnobu
* test/ruby/test_proc.rb (test_curry_binding): rename test_binding2. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50109 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-15* test/ruby/test_proc.rb: Fix typo signle -> singlegogotanaka
[fix GH-852][ci skip] Patch by @hanachin git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49974 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-16proc.c: fix method proc binding locationnobu
* proc.c (proc_binding): use the original iseq on a binding from proc from method object to get the location. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48466 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-13* test/lib/envutil.rb: Moved from test/ruby/.akr
* test/lib/find_executable.rb: Ditto. * test/lib/memory_status.rb: Ditto. * test/lib/test/unit.rb: require envutil. * test/: Don't require envutil in test files. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48409 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-10-27proc.c: fix method proc binding receivernobu
* proc.c (method_proc): the receiver of binding from method should be same as the receiver of the method. [ruby-core:65917] [Bug #10432] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48160 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-01vm.c: rb_vm_env_local_variablesnobu
* vm.c (rb_vm_env_local_variables): returns array of local variable name symbols in the environment by envval. * proc.c (bind_local_variables): use rb_vm_env_local_variables. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46648 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-01proc.c: Binding#receivernobu
* proc.c (bind_receiver): new method to return the bound receiver of the binding object. [ruby-dev:47613] [Feature #8779] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46646 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-01proc.c: fix infinite loopnobu
* proc.c (bind_local_variables): update env from envval for each iterations. [ruby-dev:48351] [Bug #10001] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46645 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-01test_proc.rb: test_local_variablesnobu
* test/ruby/test_proc.rb (test_local_variables): missing test for Binding#local_variables. [Feature #8773] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46644 b2dd03c8-39d4-4d8f-98ff-823fe69b080e