summaryrefslogtreecommitdiff
path: root/test/ruby/test_require.rb
AgeCommit message (Collapse)Author
2021-09-18Revert "Do not load file with same realpath twice when requiring"Jeremy Evans
This reverts commit ddb85c5d2bdf75a83eb163856508691a7436b446. This commit causes unexpected warnings in TestTranscode#test_loading_race occasionally in CI.
2021-09-18Do not load file with same realpath twice when requiringJeremy Evans
This fixes issues with paths being loaded twice in certain cases when symlinks are used. It took me multiple attempts to get this working. My original attempt tried to convert paths to realpaths before adding them to $LOADED_FEATURES. Unfortunately, this doesn't work well with the loaded feature index, which is based off load paths and not realpaths. While I was able to get require working, I'm fairly sure the loaded feature index was not being used as expected, which would have significant performance implications. Additionally, I was never able to get that approach working with autoload when autoloading a non-realpath file. It also broke some specs. This takes a more conservative approach. Directly before loading the file, if the file with the same realpath has been required, the loading of the file is skipped. The realpaths are stored as fstrings in a hidden hash. When rebuilding the loaded feature index, the hash of realpaths is also rebuilt. I'm guessing this makes rebuilding process slower, but I don think that is a hot path. In general, modifying loaded features is only done when reloading, and that tends to be in non-production environments. Change test_require_with_loaded_features_pop test to use 30 threads and 300 iterations, instead of 4 threads and 1000 iterations. I saw only sporadic failures with 4/1000, but consistent failures 30/300 threads. These failures were due to the fact that the concurrent deletions from $LOADED_FEATURES in other threads can result in rb_ary_entry returning nil when rebuilding the loaded features index. To avoid concurrency issues when rebuilding the loaded features index, the building of the index itself is left alone, and afterwards, a separate loop is done on a copy of the loaded feature snapshot in order to rebuild the realpaths hash. Fixes [Bug #17885] Notes: Merged: https://github.com/ruby/ruby/pull/4615
2021-09-16[Bug #18173] Update loaded_features_indexNobuyoshi Nakada
If $LOADED_FEATURES is changed in the just required file, also the index table needs to be updated before loaded_features_snapshot is reset. If the snapshot is reset without updating the table, the name of the added feature will not be found. Notes: Merged: https://github.com/ruby/ruby/pull/4849
2021-04-05Get rid of multibyte prefix to tmpdirNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/4354
2021-02-16`$LOAD_PATH.resolve_feature_path` should not raiseDavid Rodríguez
I think it's more friendly and easier to work with to return `nil` when the feature is not found in the $LOAD_PATH. Notes: Merged: https://github.com/ruby/ruby/pull/2317
2020-04-19Skip TestRequire#test_loading_fifo_fd_leak on AndroidYusuke Endoh
The test fails due to unknown reason. Need to debug in future, but tentatively skipped.
2020-03-01require enc/trans/single_byte in advance.Koichi Sasada
enc/trans/single_byte is needed to run some tests, however it will fail to require because $: is empty.
2020-02-04Add the loaded feature after no exception raisedNobuyoshi Nakada
Retrying after rescued `require` should try to load the same library again. [Bug #16607] Notes: Merged: https://github.com/ruby/ruby/pull/2879
2020-01-29restore $LOADED_FEATURES.Koichi Sasada
Dir.tmpdir can return same directory because of rand() value, so we shouldn't rely on different name.
2019-12-11Do not load files in build directoryKazuhiro NISHIYAMA
related https://bugs.ruby-lang.org/issues/16177 Notes: Merged: https://github.com/ruby/ruby/pull/2736
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-12test/ruby/test_require.rb: Remove the tests of require with $SAFEYusuke Endoh
The taint mechanism is decided to be removed at 2.7. [Feature #16131] So, this change removes the tests that expects a SecurityError when requiring a file under $SAFE >= 1. The reason why they should be removed in advance is because the upstream of rubygems has already removed a call to "untaint" method, which makes the tests fail.
2019-08-17Use the original require for test_race_exceptionHiroshi SHIBATA
The extension for require method with rubygems affects this test case. We need to keep this test for the original method.
2019-08-09Should require without wrapper moduleNobuyoshi Nakada
2019-08-08Reduce unnecessary EXEC_TAG in requireNobuyoshi Nakada
2019-08-04Revert "Skip test_race_exception on MJIT for now"Takashi Kokubun
This reverts commit 7a75baa6e294473f02da512c99f7ef1f76b2d83c. Revert "Defer skip to avoid errors on ensure" This reverts commit adfc8d6dbadbccef27d6ec78022650840c7604cc. because 76e2370f132f83c16c9de39a0a9356579f364527 is hoped to fix the problem.
2019-08-04Defer skip to avoid errors on ensureTakashi Kokubun
2019-08-04Skip test_race_exception on MJIT for nowTakashi Kokubun
somehow the test fails only on Wercker in CIs triggered by GitHub. Actually rubyci and ci.rvm.jp also have issues too, though.
2019-07-11$LOAD_PATH.resolve_feature_pathNobuyoshi Nakada
Moved from RubyVM. [Feature #15903]
2019-06-30Suppress void context warnings in verbose modeNobuyoshi Nakada
2019-05-25Avoid to show warning message with unused variable.Hiroshi SHIBATA
2018-12-31load.c: resolve_feature_pathnobu
* load.c (rb_resolve_feature_path): search the path for already loaded feature. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66661 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-09-21load.c: real path to loadnobu
* load.c (rb_construct_expanded_load_path): expand load paths to real paths to get rid of duplicate loading from symbolic-linked directories. [Feature #10222] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59984 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-04test_require.rb: fix expected pathnobu
* test/ruby/test_require.rb (test_require_with_unc): remove extra slash. the result of File.expand_path has a slash just follows the drive letter. https://github.com/ruby/ruby/commit/4ef849bd9014746821402e21053a53ea61b3690d#commitcomment-22391133 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59012 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-03test_require.rb: ignore EPERM at UNCnobu
* test/ruby/test_require.rb (test_require_with_unc): ignore EPERM. GetFileAttributes and CreateFile with backup semantics fail at a symlink in a shared folder to another shared folder. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59009 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-03file.c: preserve encodingnobu
* file.c (path_check_0): preserve encoding of path name in warning message. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59008 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-03test/ruby/test_require.rb: remove duplicate assertionnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59005 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-03test_require.rb: untouch default internal encodingnobu
* test/ruby/test_require.rb (assert_require_insecure_path): get rid of setting Encoding.default_internal, which affects load path conversion. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59004 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-02test_require.rb: assert_require_insecure_pathnobu
* test/ruby/test_require.rb (assert_require_insecure_path): more tests for loading insecure path. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58999 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-02test_require.rb: fallback encodingnobu
* test/ruby/test_require.rb (assert_require_nonascii_path): fallback when LANG=C. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58998 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-02test_require.rb: filesystem encodingnobu
* test/ruby/test_require.rb (assert_require_nonascii_path): the path in error message is converted to filesystem encoding. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58997 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-02file.c: preserve encodingnobu
* file.c (rb_find_file_safe): preserve encoding of path in SecurityError messages. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58996 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-11test/ruby/test_require.rb: use squiggly heredocsnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57835 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-07Extend timeout for Solaris unstable10s.shugo
http://rubyci.org/logs/rubyci.s3.amazonaws.com/unstable10s/ruby-trunk/log/20161206T181910Z.fail.html.gz git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57010 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-05Don't insert an entry to loading_tbl if another thread succeed to load.shugo
If rb_thread_shield_wait() returns Qfalse, the file has been successfully loaded by another thread, so there is no need to insert a new entry into loading_tbl. [ruby-core:78464] [Bug #12999] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56985 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-04Increase timeout of TestRequire#test_require_with_loaded_features_popnaruse
unstable10s fails it because of timeout http://rubyci.s3.amazonaws.com/unstable10s/ruby-trunk/log/20161201T161908Z.fail.html.gz git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56982 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-21test_require.rb: reduce GCnobu
* test/ruby/test_require.rb (test_loading_fifo_fd_leak): invoke GC only when FDs exhausted to reduce the test time. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56462 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-10ruby.c: bind fd before waitingnobu
* ruby.c (open_load_file): bind the open fd to an IO instance before waiting FIFO, not to leak the fd if interrupted. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56388 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-10test_require.rb: use assert_separatelynobu
* test/ruby/test_require.rb (test_loading_fifo_threading_raise): use assert_separately. * test/ruby/test_require.rb (test_loading_fifo_threading_success): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56387 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-06load.c: setup syntax error backtracenobu
* load.c (rb_require_safe): SyntaxError created by the parser just has the mesage and needs to set up the backtrace. [ruby-core:77491] [Bug #12811] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56363 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-06load.c: fix load/require contextnobu
* load.c (rb_load_internal0): load/require is not the main script. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56362 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-08* test/ruby/test_require.rb (test_require_with_loaded_features_pop):headius
Only remove PATH so threads don't accidentally double-pop. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54037 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-10-18* ruby/test_require.rb (loading_fifo): checking by defined? is meaningless aboutusa
notimplemented method. such methods are defined, but not respond_to?. this fixes test failures introduced at r52172. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52187 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-18test_require.rb: no guarantees to load FIFOnobu
* test/ruby/test_require.rb (loading_fifo): loading from FIFO is not guaranteed, it just should not block the whole process. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52173 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-18test_require.rb: test conditionsnobu
* test/ruby/test_require.rb (loading_fifo): check by if FIFO is available or not, instead of platform names. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52172 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-17* ruby.c (open_load_file): reset O_NONBLOCK after open.kosaki
Even if S_ISREG() is true, the file may be file on FUSE filesystem or something. We can't assume O_NONBLOCK is safe. Moreover, we should wait if the path is point to FIFO. That's FIFO semantics. GVL should be transparent from ruby script. Thus, just reopen without O_NONBLOCK for filling the requirements. [Bug #11060][Bug #11559] * ruby.c (loadopen_func): new for the above. * file.c (ruby_is_fd_loadable): new. for checks loadable file type of not. * file.c (rb_file_load_ok): use ruby_is_fd_loadble() * internal.h: add ruby_is_fd_loadble() * common.mk: now, ruby.o depend on thread.h. * test/ruby/test_require.rb (TestRequire#test_loading_fifo_threading_success): new test. This test successful case that loading from FIFO. * test/ruby/test_require.rb (TestRequire#test_loading_fifo_threading_raise): rename from test_loading_fifo_threading. You souldn't rescue an exception if you test raise or not. Moreover, this case should be caught IOError because load(FIFO) should be blocked until given any input. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52151 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-16file.c: non-blocking opennobu
* file.c (rb_file_load_ok): open in non-blocking mode withoout releasing GVL. don't care about others than regular files and directories. [ruby-dev:49272] [Bug #11559] * ruby.c (load_file_internal): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52139 b2dd03c8-39d4-4d8f-98ff-823fe69b080e