summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/-ext-/arith_seq/test_arith_seq_beg_len_step.rb52
-rw-r--r--test/-ext-/bug_reporter/test_bug_reporter.rb9
-rw-r--r--test/-ext-/debug/test_profile_frames.rb24
-rw-r--r--test/-ext-/eval/test_eval.rb12
-rw-r--r--test/-ext-/symbol/test_type.rb9
-rw-r--r--test/-ext-/test_abi.rb8
-rw-r--r--test/-ext-/thread/test_instrumentation_api.rb91
-rw-r--r--test/cgi/test_cgi_util.rb1
-rw-r--r--test/coverage/test_coverage.rb21
-rw-r--r--test/date/test_date_conv.rb17
-rw-r--r--test/did_you_mean/core_ext/test_name_error_extension.rb16
-rw-r--r--test/did_you_mean/helper.rb10
-rw-r--r--test/did_you_mean/spell_checking/test_key_name_check.rb14
-rw-r--r--test/did_you_mean/spell_checking/test_method_name_check.rb20
-rw-r--r--test/did_you_mean/spell_checking/test_pattern_key_name_check.rb2
-rw-r--r--test/did_you_mean/spell_checking/test_require_path_check.rb6
-rw-r--r--test/did_you_mean/spell_checking/test_variable_name_check.rb24
-rw-r--r--test/did_you_mean/test_ractor_compatibility.rb8
-rw-r--r--test/digest/test_digest_extend.rb13
-rw-r--r--test/digest/test_ractor.rb6
-rw-r--r--test/error_highlight/test_error_highlight.rb41
-rw-r--r--test/excludes/Psych/TestDateTime.rb1
-rw-r--r--test/fileutils/test_fileutils.rb24
-rw-r--r--test/io/console/test_io_console.rb2
-rw-r--r--test/io/wait/test_io_wait.rb28
-rw-r--r--test/irb/test_context.rb288
-rw-r--r--test/json/json_parser_test.rb4
-rw-r--r--test/lib/jit_support.rb4
-rw-r--r--test/net/http/test_httpheader.rb21
-rw-r--r--test/objspace/test_objspace.rb25
-rw-r--r--test/openssl/test_ocsp.rb2
-rw-r--r--test/openssl/test_ssl.rb103
-rw-r--r--test/optparse/test_placearg.rb6
-rw-r--r--test/psych/helper.rb6
-rw-r--r--test/psych/test_array.rb16
-rw-r--r--test/psych/test_hash.rb64
-rw-r--r--test/psych/test_merge_keys.rb2
-rw-r--r--test/psych/test_object.rb13
-rw-r--r--test/psych/test_safe_load.rb31
-rw-r--r--test/rdoc/test_rdoc_any_method.rb14
-rw-r--r--test/rdoc/test_rdoc_markdown.rb1
-rw-r--r--test/rdoc/test_rdoc_markup_to_html.rb20
-rw-r--r--test/rdoc/test_rdoc_parser_c.rb145
-rw-r--r--test/rdoc/test_rdoc_ri_driver.rb32
-rw-r--r--test/reline/test_config.rb15
-rw-r--r--test/reline/test_reline.rb29
-rw-r--r--test/rinda/test_rinda.rb7
-rw-r--r--test/ripper/test_lexer.rb14
-rw-r--r--test/ripper/test_parser_events.rb38
-rw-r--r--test/ruby/test_argf.rb11
-rw-r--r--test/ruby/test_array.rb90
-rw-r--r--test/ruby/test_ast.rb19
-rw-r--r--test/ruby/test_autoload.rb38
-rw-r--r--test/ruby/test_bignum.rb9
-rw-r--r--test/ruby/test_clone.rb46
-rw-r--r--test/ruby/test_dup.rb110
-rw-r--r--test/ruby/test_enumerator.rb38
-rw-r--r--test/ruby/test_env.rb56
-rw-r--r--test/ruby/test_file_exhaustive.rb4
-rw-r--r--test/ruby/test_frozen.rb30
-rw-r--r--test/ruby/test_gc.rb1
-rw-r--r--test/ruby/test_gc_compact.rb129
-rw-r--r--test/ruby/test_hash.rb35
-rw-r--r--test/ruby/test_integer.rb17
-rw-r--r--test/ruby/test_io.rb25
-rw-r--r--test/ruby/test_io_m17n.rb10
-rw-r--r--test/ruby/test_method.rb53
-rw-r--r--test/ruby/test_mjit.rb48
-rw-r--r--test/ruby/test_module.rb11
-rw-r--r--test/ruby/test_objectspace.rb5
-rw-r--r--test/ruby/test_parse.rb46
-rw-r--r--test/ruby/test_pattern_matching.rb22
-rw-r--r--test/ruby/test_range.rb29
-rw-r--r--test/ruby/test_refinement.rb35
-rw-r--r--test/ruby/test_regexp.rb76
-rw-r--r--test/ruby/test_require.rb2
-rw-r--r--test/ruby/test_rubyoptions.rb21
-rw-r--r--test/ruby/test_rubyvm_mjit.rb19
-rw-r--r--test/ruby/test_settracefunc.rb84
-rw-r--r--test/ruby/test_string.rb22
-rw-r--r--test/ruby/test_symbol.rb13
-rw-r--r--test/ruby/test_syntax.rb24
-rw-r--r--test/ruby/test_thread.rb29
-rw-r--r--test/ruby/test_thread_queue.rb37
-rw-r--r--test/ruby/test_time.rb2
-rw-r--r--test/ruby/test_yjit.rb184
-rw-r--r--test/ruby/test_yjit_exit_locations.rb110
-rw-r--r--test/rubygems/data/excon-0.7.7.gemspec.rzbin0 -> 388 bytes
-rw-r--r--test/rubygems/data/null-type.gemspec.rzbin504 -> 0 bytes
-rw-r--r--test/rubygems/data/pry-0.4.7.gemspec.rzbin0 -> 433 bytes
-rw-r--r--test/rubygems/helper.rb274
-rw-r--r--test/rubygems/installer_test_case.rb26
-rw-r--r--test/rubygems/package/tar_test_case.rb4
-rw-r--r--test/rubygems/plugin/exception/rubygems_plugin.rb2
-rw-r--r--test/rubygems/plugin/standarderror/rubygems_plugin.rb2
-rw-r--r--test/rubygems/rubygems_plugin.rb4
-rw-r--r--test/rubygems/specifications/rubyforge-0.0.1.gemspec8
-rw-r--r--test/rubygems/test_bundled_ca.rb22
-rw-r--r--test/rubygems/test_config.rb6
-rw-r--r--test/rubygems/test_deprecate.rb6
-rw-r--r--test/rubygems/test_exit.rb10
-rw-r--r--test/rubygems/test_gem.rb684
-rw-r--r--test/rubygems/test_gem_available_set.rb42
-rw-r--r--test/rubygems/test_gem_bundler_version_finder.rb4
-rw-r--r--test/rubygems/test_gem_command.rb88
-rw-r--r--test/rubygems/test_gem_command_manager.rb58
-rw-r--r--test/rubygems/test_gem_commands_build_command.rb126
-rw-r--r--test/rubygems/test_gem_commands_cert_command.rb196
-rw-r--r--test/rubygems/test_gem_commands_check_command.rb8
-rw-r--r--test/rubygems/test_gem_commands_cleanup_command.rb80
-rw-r--r--test/rubygems/test_gem_commands_contents_command.rb54
-rw-r--r--test/rubygems/test_gem_commands_dependency_command.rb72
-rw-r--r--test/rubygems/test_gem_commands_environment_command.rb52
-rw-r--r--test/rubygems/test_gem_commands_fetch_command.rb74
-rw-r--r--test/rubygems/test_gem_commands_generate_index_command.rb14
-rw-r--r--test/rubygems/test_gem_commands_help_command.rb26
-rw-r--r--test/rubygems/test_gem_commands_info_command.rb4
-rw-r--r--test/rubygems/test_gem_commands_install_command.rb262
-rw-r--r--test/rubygems/test_gem_commands_list_command.rb8
-rw-r--r--test/rubygems/test_gem_commands_lock_command.rb20
-rw-r--r--test/rubygems/test_gem_commands_mirror.rb4
-rw-r--r--test/rubygems/test_gem_commands_open_command.rb8
-rw-r--r--test/rubygems/test_gem_commands_outdated_command.rb18
-rw-r--r--test/rubygems/test_gem_commands_owner_command.rb82
-rw-r--r--test/rubygems/test_gem_commands_pristine_command.rb185
-rw-r--r--test/rubygems/test_gem_commands_push_command.rb108
-rw-r--r--test/rubygems/test_gem_commands_query_command.rb146
-rw-r--r--test/rubygems/test_gem_commands_search_command.rb4
-rw-r--r--test/rubygems/test_gem_commands_server_command.rb4
-rw-r--r--test/rubygems/test_gem_commands_setup_command.rb204
-rw-r--r--test/rubygems/test_gem_commands_signin_command.rb76
-rw-r--r--test/rubygems/test_gem_commands_signout_command.rb6
-rw-r--r--test/rubygems/test_gem_commands_sources_command.rb99
-rw-r--r--test/rubygems/test_gem_commands_specification_command.rb64
-rw-r--r--test/rubygems/test_gem_commands_stale_command.rb8
-rw-r--r--test/rubygems/test_gem_commands_uninstall_command.rb150
-rw-r--r--test/rubygems/test_gem_commands_unpack_command.rb62
-rw-r--r--test/rubygems/test_gem_commands_update_command.rb226
-rw-r--r--test/rubygems/test_gem_commands_which_command.rb12
-rw-r--r--test/rubygems/test_gem_commands_yank_command.rb80
-rw-r--r--test/rubygems/test_gem_config_file.rb174
-rw-r--r--test/rubygems/test_gem_dependency.rb146
-rw-r--r--test/rubygems/test_gem_dependency_installer.rb330
-rw-r--r--test/rubygems/test_gem_dependency_list.rb94
-rw-r--r--test/rubygems/test_gem_dependency_resolution_error.rb8
-rw-r--r--test/rubygems/test_gem_doctor.rb52
-rw-r--r--test/rubygems/test_gem_ext_builder.rb118
-rw-r--r--test/rubygems/test_gem_ext_cargo_builder.rb99
-rw-r--r--test/rubygems/test_gem_ext_cargo_builder/custom_name/Cargo.lock225
-rw-r--r--test/rubygems/test_gem_ext_cargo_builder/custom_name/Cargo.toml4
-rw-r--r--test/rubygems/test_gem_ext_cargo_builder/custom_name/build.rb20
-rw-r--r--test/rubygems/test_gem_ext_cargo_builder/custom_name/custom_name.gemspec2
-rw-r--r--test/rubygems/test_gem_ext_cargo_builder/custom_name/src/lib.rs3
-rw-r--r--test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/Cargo.lock225
-rw-r--r--test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/Cargo.toml4
-rw-r--r--test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/build.rb16
-rw-r--r--test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/src/lib.rs3
-rw-r--r--test/rubygems/test_gem_ext_cargo_builder_link_flag_converter.rb33
-rw-r--r--test/rubygems/test_gem_ext_cargo_builder_unit.rb75
-rw-r--r--test/rubygems/test_gem_ext_cmake_builder.rb30
-rw-r--r--test/rubygems/test_gem_ext_configure_builder.rb26
-rw-r--r--test/rubygems/test_gem_ext_ext_conf_builder.rb103
-rw-r--r--test/rubygems/test_gem_ext_rake_builder.rb30
-rw-r--r--test/rubygems/test_gem_gem_runner.rb14
-rw-r--r--test/rubygems/test_gem_gemcutter_utilities.rb132
-rw-r--r--test/rubygems/test_gem_impossible_dependencies_error.rb8
-rw-r--r--test/rubygems/test_gem_indexer.rb100
-rw-r--r--test/rubygems/test_gem_install_update_options.rb32
-rw-r--r--test/rubygems/test_gem_installer.rb603
-rw-r--r--test/rubygems/test_gem_local_remote_options.rb20
-rw-r--r--test/rubygems/test_gem_name_tuple.rb8
-rw-r--r--test/rubygems/test_gem_package.rb438
-rw-r--r--test/rubygems/test_gem_package_old.rb26
-rw-r--r--test/rubygems/test_gem_package_tar_header.rb84
-rw-r--r--test/rubygems/test_gem_package_tar_reader.rb16
-rw-r--r--test/rubygems/test_gem_package_tar_reader_entry.rb20
-rw-r--r--test/rubygems/test_gem_package_tar_writer.rb152
-rw-r--r--test/rubygems/test_gem_package_task.rb36
-rw-r--r--test/rubygems/test_gem_path_support.rb28
-rw-r--r--test/rubygems/test_gem_platform.rb444
-rw-r--r--test/rubygems/test_gem_rdoc.rb28
-rw-r--r--test/rubygems/test_gem_remote_fetcher.rb298
-rw-r--r--test/rubygems/test_gem_request.rb110
-rw-r--r--test/rubygems/test_gem_request_connection_pools.rb58
-rw-r--r--test/rubygems/test_gem_request_set.rb198
-rw-r--r--test/rubygems/test_gem_request_set_gem_dependency_api.rb410
-rw-r--r--test/rubygems/test_gem_request_set_lockfile.rb172
-rw-r--r--test/rubygems/test_gem_request_set_lockfile_parser.rb112
-rw-r--r--test/rubygems/test_gem_request_set_lockfile_tokenizer.rb124
-rw-r--r--test/rubygems/test_gem_requirement.rb88
-rw-r--r--test/rubygems/test_gem_resolver.rb196
-rw-r--r--test/rubygems/test_gem_resolver_activation_request.rb12
-rw-r--r--test/rubygems/test_gem_resolver_api_set.rb66
-rw-r--r--test/rubygems/test_gem_resolver_api_specification.rb94
-rw-r--r--test/rubygems/test_gem_resolver_best_set.rb44
-rw-r--r--test/rubygems/test_gem_resolver_composed_set.rb2
-rw-r--r--test/rubygems/test_gem_resolver_conflict.rb24
-rw-r--r--test/rubygems/test_gem_resolver_dependency_request.rb30
-rw-r--r--test/rubygems/test_gem_resolver_git_set.rb42
-rw-r--r--test/rubygems/test_gem_resolver_git_specification.rb42
-rw-r--r--test/rubygems/test_gem_resolver_index_set.rb24
-rw-r--r--test/rubygems/test_gem_resolver_index_specification.rb32
-rw-r--r--test/rubygems/test_gem_resolver_installed_specification.rb10
-rw-r--r--test/rubygems/test_gem_resolver_installer_set.rb112
-rw-r--r--test/rubygems/test_gem_resolver_local_specification.rb14
-rw-r--r--test/rubygems/test_gem_resolver_lock_set.rb24
-rw-r--r--test/rubygems/test_gem_resolver_lock_specification.rb34
-rw-r--r--test/rubygems/test_gem_resolver_requirement_list.rb2
-rw-r--r--test/rubygems/test_gem_resolver_specification.rb16
-rw-r--r--test/rubygems/test_gem_resolver_vendor_set.rb12
-rw-r--r--test/rubygems/test_gem_resolver_vendor_specification.rb20
-rw-r--r--test/rubygems/test_gem_security.rb134
-rw-r--r--test/rubygems/test_gem_security_policy.rb124
-rw-r--r--test/rubygems/test_gem_security_signer.rb56
-rw-r--r--test/rubygems/test_gem_security_trust_dir.rb12
-rw-r--r--test/rubygems/test_gem_silent_ui.rb70
-rw-r--r--test/rubygems/test_gem_source.rb88
-rw-r--r--test/rubygems/test_gem_source_fetch_problem.rb18
-rw-r--r--test/rubygems/test_gem_source_git.rb118
-rw-r--r--test/rubygems/test_gem_source_installed.rb32
-rw-r--r--test/rubygems/test_gem_source_list.rb10
-rw-r--r--test/rubygems/test_gem_source_local.rb28
-rw-r--r--test/rubygems/test_gem_source_lock.rb62
-rw-r--r--test/rubygems/test_gem_source_specific_file.rb34
-rw-r--r--test/rubygems/test_gem_source_subpath_problem.rb14
-rw-r--r--test/rubygems/test_gem_source_vendor.rb26
-rw-r--r--test/rubygems/test_gem_spec_fetcher.rb144
-rw-r--r--test/rubygems/test_gem_specification.rb926
-rw-r--r--test/rubygems/test_gem_stream_ui.rb38
-rw-r--r--test/rubygems/test_gem_stub_specification.rb64
-rw-r--r--test/rubygems/test_gem_text.rb2
-rw-r--r--test/rubygems/test_gem_uninstaller.rb224
-rw-r--r--test/rubygems/test_gem_unsatisfiable_dependency_error.rb6
-rw-r--r--test/rubygems/test_gem_uri.rb8
-rw-r--r--test/rubygems/test_gem_uri_formatter.rb28
-rw-r--r--test/rubygems/test_gem_util.rb46
-rw-r--r--test/rubygems/test_gem_validator.rb16
-rw-r--r--test/rubygems/test_gem_version.rb37
-rw-r--r--test/rubygems/test_gem_version_option.rb30
-rw-r--r--test/rubygems/test_kernel.rb78
-rw-r--r--test/rubygems/test_project_sanity.rb2
-rw-r--r--test/rubygems/test_remote_fetch_error.rb12
-rw-r--r--test/rubygems/test_require.rb90
-rw-r--r--test/rubygems/test_rubygems.rb31
-rw-r--r--test/rubygems/utilities.rb38
-rw-r--r--test/stringio/test_stringio.rb73
-rw-r--r--test/test_pstore.rb32
-rw-r--r--test/test_set.rb2
248 files changed, 9029 insertions, 6836 deletions
diff --git a/test/-ext-/arith_seq/test_arith_seq_beg_len_step.rb b/test/-ext-/arith_seq/test_arith_seq_beg_len_step.rb
new file mode 100644
index 0000000000..4320c1f20d
--- /dev/null
+++ b/test/-ext-/arith_seq/test_arith_seq_beg_len_step.rb
@@ -0,0 +1,52 @@
+# frozen_string_literal: false
+require 'test/unit'
+
+class Test_ArithSeq < Test::Unit::TestCase
+ def test_beg_len_step
+ assert_separately([], <<-"end;") #do
+ require '-test-/arith_seq/beg_len_step'
+
+ r, = Enumerator::ArithmeticSequence.__beg_len_step__([1, 2, 3], 0, 0)
+ assert_equal(false, r)
+
+ r, = Enumerator::ArithmeticSequence.__beg_len_step__([1, 2, 3], 1, 0)
+ assert_equal(false, r)
+
+ r, = Enumerator::ArithmeticSequence.__beg_len_step__([1, 2, 3], 3, 0)
+ assert_equal(false, r)
+
+ r, = Enumerator::ArithmeticSequence.__beg_len_step__(1..3, 0, 0)
+ assert_equal(nil, r)
+
+ r = Enumerator::ArithmeticSequence.__beg_len_step__(1..3, 1, 0)
+ assert_equal([true, 1, 0, 1], r)
+
+ r = Enumerator::ArithmeticSequence.__beg_len_step__(1..3, 2, 0)
+ assert_equal([true, 1, 1, 1], r)
+
+ r = Enumerator::ArithmeticSequence.__beg_len_step__(1..3, 3, 0)
+ assert_equal([true, 1, 2, 1], r)
+
+ r = Enumerator::ArithmeticSequence.__beg_len_step__(1..3, 4, 0)
+ assert_equal([true, 1, 3, 1], r)
+
+ r = Enumerator::ArithmeticSequence.__beg_len_step__(1..3, 5, 0)
+ assert_equal([true, 1, 3, 1], r)
+
+ r = Enumerator::ArithmeticSequence.__beg_len_step__((-10..10).step(2), 24, 0)
+ assert_equal([true, 14, 0, 2], r)
+
+ r = Enumerator::ArithmeticSequence.__beg_len_step__((-10..10).step(3), 24, 0)
+ assert_equal([true, 14, 0, 3], r)
+
+ r = Enumerator::ArithmeticSequence.__beg_len_step__((-10..10).step(3), 22, 0)
+ assert_equal([true, 12, 0, 3], r)
+
+ r = Enumerator::ArithmeticSequence.__beg_len_step__((-10..10).step(-3), 22, 0)
+ assert_equal([true, 10, 3, -3], r)
+
+ r = Enumerator::ArithmeticSequence.__beg_len_step__(1..3, 0, 1)
+ assert_equal([true, 1, 3, 1], r)
+ end;
+ end
+end
diff --git a/test/-ext-/bug_reporter/test_bug_reporter.rb b/test/-ext-/bug_reporter/test_bug_reporter.rb
index 990b6a2cc5..81d2ca4674 100644
--- a/test/-ext-/bug_reporter/test_bug_reporter.rb
+++ b/test/-ext-/bug_reporter/test_bug_reporter.rb
@@ -1,14 +1,18 @@
# frozen_string_literal: false
require 'test/unit'
require 'tmpdir'
+require_relative '../../lib/jit_support'
class TestBugReporter < Test::Unit::TestCase
+ def yjit_enabled?
+ defined?(RubyVM::YJIT.enabled?) && RubyVM::YJIT.enabled?
+ end
+
def test_bug_reporter_add
omit if ENV['RUBY_ON_BUG']
description = RUBY_DESCRIPTION
- description = description.sub(/\+MJIT /, '') if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled?
- description = description.sub(/\+YJIT /, '') if defined?(RubyVM::YJIT.enabled?) && RubyVM::YJIT.enabled?
+ description = description.sub(/\+MJIT /, '') unless JITSupport.mjit_force_enabled?
expected_stderr = [
:*,
/\[BUG\]\sSegmentation\sfault.*\n/,
@@ -22,6 +26,7 @@ class TestBugReporter < Test::Unit::TestCase
no_core = "Process.setrlimit(Process::RLIMIT_CORE, 0); " if defined?(Process.setrlimit) && defined?(Process::RLIMIT_CORE)
args = ["--disable-gems", "-r-test-/bug_reporter",
"-C", tmpdir]
+ args.push("--yjit") if yjit_enabled? # We want the printed description to match this process's RUBY_DESCRIPTION
stdin = "#{no_core}register_sample_bug_reporter(12345); Process.kill :SEGV, $$"
assert_in_out_err(args, stdin, [], expected_stderr, encoding: "ASCII-8BIT")
ensure
diff --git a/test/-ext-/debug/test_profile_frames.rb b/test/-ext-/debug/test_profile_frames.rb
index e0152247e7..d6ae953dd2 100644
--- a/test/-ext-/debug/test_profile_frames.rb
+++ b/test/-ext-/debug/test_profile_frames.rb
@@ -137,6 +137,30 @@ class TestProfileFrames < Test::Unit::TestCase
}
end
+ def test_matches_backtrace_locations_main_thread
+ assert_equal(Thread.current, Thread.main)
+
+ # Keep these in the same line, so the backtraces match exactly
+ backtrace_locations, profile_frames = [Thread.current.backtrace_locations, Bug::Debug.profile_frames(0, 100)]
+
+ assert_equal(backtrace_locations.size, profile_frames.size)
+
+ # The first entries are not going to match, since one is #backtrace_locations and the other #profile_frames
+ backtrace_locations.shift
+ profile_frames.shift
+
+ # The rest of the stack is expected to look the same...
+ backtrace_locations.zip(profile_frames).each.with_index do |(location, (path, absolute_path, _, base_label, _, _, _, _, _, _, lineno)), i|
+ next if absolute_path == "<cfunc>" # ...except for cfunc frames
+
+ err_msg = "#{i}th frame"
+ assert_equal(location.absolute_path, absolute_path, err_msg)
+ assert_equal(location.base_label, base_label, err_msg)
+ assert_equal(location.lineno, lineno, err_msg)
+ assert_equal(location.path, path, err_msg)
+ end
+ end
+
def test_ifunc_frame
bug11851 = '[ruby-core:72409] [Bug #11851]'
assert_ruby_status([], <<~'end;', bug11851) # do
diff --git a/test/-ext-/eval/test_eval.rb b/test/-ext-/eval/test_eval.rb
new file mode 100644
index 0000000000..27952996e2
--- /dev/null
+++ b/test/-ext-/eval/test_eval.rb
@@ -0,0 +1,12 @@
+# frozen_string_literal: false
+require 'test/unit'
+require "-test-/eval"
+
+class EvalTest < Test::Unit::TestCase
+ def test_rb_eval_string
+ a = 1
+ assert_equal [self, 1, __method__], rb_eval_string(%q{
+ [self, a, __method__]
+ })
+ end
+end
diff --git a/test/-ext-/symbol/test_type.rb b/test/-ext-/symbol/test_type.rb
index 7cb3c7b6ef..fdee692fe4 100644
--- a/test/-ext-/symbol/test_type.rb
+++ b/test/-ext-/symbol/test_type.rb
@@ -93,16 +93,16 @@ module Test_Symbol
assert_symtype("@foo=", :attrset?)
assert_symtype("@@foo=", :attrset?)
assert_symtype("$foo=", :attrset?)
- assert_symtype("0=", :attrset?)
- assert_symtype("@=", :attrset?)
- assert_symtype("@@=", :attrset?)
+ assert_not_symtype("0=", :attrset?)
+ assert_not_symtype("@=", :attrset?)
+ assert_not_symtype("@@=", :attrset?)
assert_not_symtype("foo", :attrset?)
assert_not_symtype("Foo", :attrset?)
assert_not_symtype("@foo", :attrset?)
assert_not_symtype("@@foo", :attrset?)
assert_not_symtype("$foo", :attrset?)
assert_not_symtype("[foo]", :attrset?)
- assert_symtype("[foo]=", :attrset?)
+ assert_not_symtype("[foo]=", :attrset?)
assert_equal(:"foo=", Bug::Symbol.attrset("foo"))
assert_symtype(Bug::Symbol.attrset("foo"), :attrset?)
assert_equal(:"Foo=", Bug::Symbol.attrset("Foo"))
@@ -114,7 +114,6 @@ module Test_Symbol
assert_equal(:"$foo=", Bug::Symbol.attrset("$foo"))
assert_symtype(Bug::Symbol.attrset("$foo"), :attrset?)
assert_equal(:"[foo]=", Bug::Symbol.attrset("[foo]"))
- assert_symtype(Bug::Symbol.attrset("[foo]"), :attrset?)
assert_equal(:[]=, Bug::Symbol.attrset(:[]))
assert_symtype(Bug::Symbol.attrset("foo?="), :attrset?)
assert_equal(:"foo?=", Bug::Symbol.attrset(:foo?))
diff --git a/test/-ext-/test_abi.rb b/test/-ext-/test_abi.rb
index ec2050ecad..d3ea6bb9b1 100644
--- a/test/-ext-/test_abi.rb
+++ b/test/-ext-/test_abi.rb
@@ -1,12 +1,15 @@
# frozen_string_literal: true
+return unless RUBY_PATCHLEVEL < 0
+
class TestABI < Test::Unit::TestCase
def test_require_lib_with_incorrect_abi_on_dev_ruby
omit "ABI is not checked" unless abi_checking_supported?
assert_separately [], <<~RUBY
err = assert_raise(LoadError) { require "-test-/abi" }
- assert_match(/ABI version of binary is incompatible with this Ruby/, err.message)
+ assert_match(/incompatible ABI version/, err.message)
+ assert_include err.message, "/-test-/abi."
RUBY
end
@@ -23,7 +26,8 @@ class TestABI < Test::Unit::TestCase
assert_separately [{ "RUBY_ABI_CHECK" => "1" }], <<~RUBY
err = assert_raise(LoadError) { require "-test-/abi" }
- assert_match(/ABI version of binary is incompatible with this Ruby/, err.message)
+ assert_match(/incompatible ABI version/, err.message)
+ assert_include err.message, "/-test-/abi."
RUBY
end
diff --git a/test/-ext-/thread/test_instrumentation_api.rb b/test/-ext-/thread/test_instrumentation_api.rb
new file mode 100644
index 0000000000..dd620e7380
--- /dev/null
+++ b/test/-ext-/thread/test_instrumentation_api.rb
@@ -0,0 +1,91 @@
+# frozen_string_literal: false
+require 'envutil'
+
+class TestThreadInstrumentation < Test::Unit::TestCase
+ def setup
+ pend("No windows support") if /mswin|mingw|bccwin/ =~ RUBY_PLATFORM
+
+ require '-test-/thread/instrumentation'
+
+ Thread.list.each do |thread|
+ if thread != Thread.current
+ thread.kill
+ thread.join rescue nil
+ end
+ end
+ assert_equal [Thread.current], Thread.list
+
+ Bug::ThreadInstrumentation.reset_counters
+ Bug::ThreadInstrumentation::register_callback
+ end
+
+ def teardown
+ return if /mswin|mingw|bccwin/ =~ RUBY_PLATFORM
+ Bug::ThreadInstrumentation::unregister_callback
+ end
+
+ THREADS_COUNT = 3
+
+ def test_thread_instrumentation
+ threads = threaded_cpu_work
+ assert_equal [false] * THREADS_COUNT, threads.map(&:status)
+ counters = Bug::ThreadInstrumentation.counters
+ assert_join_counters(counters)
+ assert_global_join_counters(counters)
+ end
+
+ def test_join_counters # Bug #18900
+ thr = Thread.new { fib(30) }
+ Bug::ThreadInstrumentation.reset_counters
+ thr.join
+ assert_join_counters(Bug::ThreadInstrumentation.local_counters)
+ end
+
+ def test_thread_instrumentation_fork_safe
+ skip "No fork()" unless Process.respond_to?(:fork)
+
+ thread_statuses = counters = nil
+ IO.popen("-") do |read_pipe|
+ if read_pipe
+ thread_statuses = Marshal.load(read_pipe)
+ counters = Marshal.load(read_pipe)
+ else
+ Bug::ThreadInstrumentation.reset_counters
+ threads = threaded_cpu_work
+ Marshal.dump(threads.map(&:status), STDOUT)
+ Marshal.dump(Bug::ThreadInstrumentation.counters, STDOUT)
+ end
+ end
+ assert_predicate $?, :success?
+
+ assert_equal [false] * THREADS_COUNT, thread_statuses
+ assert_join_counters(counters)
+ assert_global_join_counters(counters)
+ end
+
+ def test_thread_instrumentation_unregister
+ Bug::ThreadInstrumentation::unregister_callback
+ assert Bug::ThreadInstrumentation::register_and_unregister_callbacks
+ end
+
+ private
+
+ def fib(n = 20)
+ return n if n <= 1
+ fib(n-1) + fib(n-2)
+ end
+
+ def threaded_cpu_work(size = 20)
+ THREADS_COUNT.times.map { Thread.new { fib(size) } }.each(&:join)
+ end
+
+ def assert_join_counters(counters)
+ counters.each_with_index do |c, i|
+ assert_operator c, :>, 0, "Call counters[#{i}]: #{counters.inspect}"
+ end
+ end
+
+ def assert_global_join_counters(counters)
+ assert_equal THREADS_COUNT, counters.first
+ end
+end
diff --git a/test/cgi/test_cgi_util.rb b/test/cgi/test_cgi_util.rb
index 5a2d07b328..5baf87db75 100644
--- a/test/cgi/test_cgi_util.rb
+++ b/test/cgi/test_cgi_util.rb
@@ -105,6 +105,7 @@ class CGIUtilTest < Test::Unit::TestCase
end
def test_cgi_escape_html_large
+ return if RUBY_ENGINE == 'jruby'
ulong_max, size_max = RbConfig::LIMITS.values_at("ULONG_MAX", "SIZE_MAX")
return unless ulong_max < size_max # Platforms not concerned
diff --git a/test/coverage/test_coverage.rb b/test/coverage/test_coverage.rb
index 882368363a..eefe7e7da6 100644
--- a/test/coverage/test_coverage.rb
+++ b/test/coverage/test_coverage.rb
@@ -181,6 +181,27 @@ class TestCoverage < Test::Unit::TestCase
end;
end
+ def test_coverage_ensure_if_return
+ result = {
+ :branches => {
+ [:if, 0, 3, 1, 6, 4] => {
+ [:then, 1, 3, 6, 3, 6] => 0,
+ [:else, 2, 5, 3, 5, 9] => 1,
+ },
+ },
+ }
+ assert_coverage(<<~"end;", { branches: true }, result)
+ def flush
+ ensure
+ if $!
+ else
+ return
+ end
+ end
+ flush
+ end;
+ end
+
def assert_coverage(code, opt, stdout)
stdout = [stdout] unless stdout.is_a?(Array)
stdout = stdout.map {|s| s.to_s }
diff --git a/test/date/test_date_conv.rb b/test/date/test_date_conv.rb
index d41ff45d85..ed478b41bb 100644
--- a/test/date/test_date_conv.rb
+++ b/test/date/test_date_conv.rb
@@ -77,6 +77,11 @@ class TestDateConv < Test::Unit::TestCase
assert_equal([2004, 9, 19, 1, 2, 3, 456789],
[t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.usec])
+ d = DateTime.new(1582, 10, 3, 1, 2, 3, 0) + 456789.to_r/86400000000
+ t = d.to_time.utc
+ assert_equal([1582, 10, 13, 1, 2, 3, 456789],
+ [t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.usec])
+
if Time.allocate.respond_to?(:nsec)
d = DateTime.new(2004, 9, 19, 1, 2, 3, 0) + 456789123.to_r/86400000000000
t = d.to_time.utc
@@ -100,6 +105,10 @@ class TestDateConv < Test::Unit::TestCase
t = Time.utc(2004, 9, 19, 1, 2, 3, 456789)
d = t.to_date
assert_equal([2004, 9, 19, 0], [d.year, d.mon, d.mday, d.day_fraction])
+
+ t = Time.utc(1582, 10, 13, 1, 2, 3, 456789)
+ d = t.to_date # using ITALY
+ assert_equal([1582, 10, 3, 0], [d.year, d.mon, d.mday, d.day_fraction])
end
def test_to_date__from_date
@@ -136,6 +145,14 @@ class TestDateConv < Test::Unit::TestCase
[d.year, d.mon, d.mday, d.hour, d.min, d.sec,
d.sec_fraction, d.offset])
+ t = Time.utc(1582, 10, 13, 1, 2, 3, 456789)
+ d = t.to_datetime # using ITALY
+ assert_equal([1582, 10, 3, 1, 2, 3,
+ 456789.to_r/1000000,
+ 0],
+ [d.year, d.mon, d.mday, d.hour, d.min, d.sec,
+ d.sec_fraction, d.offset])
+
t = Time.now
d = t.to_datetime
require 'time'
diff --git a/test/did_you_mean/core_ext/test_name_error_extension.rb b/test/did_you_mean/core_ext/test_name_error_extension.rb
index 91871cda9a..1fdbd4510f 100644
--- a/test/did_you_mean/core_ext/test_name_error_extension.rb
+++ b/test/did_you_mean/core_ext/test_name_error_extension.rb
@@ -1,6 +1,8 @@
require_relative '../helper'
class NameErrorExtensionTest < Test::Unit::TestCase
+ include DidYouMean::TestHelper
+
SPELL_CHECKERS = DidYouMean.spell_checkers
class TestSpellChecker
@@ -20,8 +22,12 @@ class NameErrorExtensionTest < Test::Unit::TestCase
end
def test_message
- assert_match(/Did you mean\? does_exist/, @error.to_s)
- assert_match(/Did you mean\? does_exist/, @error.message)
+ if Exception.method_defined?(:detailed_message)
+ assert_match(/Did you mean\? does_exist/, @error.detailed_message)
+ else
+ assert_match(/Did you mean\? does_exist/, @error.to_s)
+ assert_match(/Did you mean\? does_exist/, @error.message)
+ end
end
def test_to_s_does_not_make_disruptive_changes_to_error_message
@@ -29,8 +35,8 @@ class NameErrorExtensionTest < Test::Unit::TestCase
raise NameError, "uninitialized constant Object"
end
- error.to_s
- assert_equal 1, error.to_s.scan("Did you mean?").count
+ get_message(error)
+ assert_equal 1, get_message(error).scan("Did you mean?").count
end
def test_correctable_error_objects_are_dumpable
@@ -41,7 +47,7 @@ class NameErrorExtensionTest < Test::Unit::TestCase
e
end
- error.to_s
+ get_message(error)
assert_equal "undefined method `sizee' for #<File:test_name_error_extension.rb (closed)>",
Marshal.load(Marshal.dump(error)).original_message
diff --git a/test/did_you_mean/helper.rb b/test/did_you_mean/helper.rb
index 7cb7b10282..d40d58d95d 100644
--- a/test/did_you_mean/helper.rb
+++ b/test/did_you_mean/helper.rb
@@ -29,5 +29,15 @@ module DidYouMean
def assert_correction(expected, array)
assert_equal Array(expected), array, "Expected #{array.inspect} to only include #{expected.inspect}"
end
+
+ def get_message(err)
+ if err.respond_to?(:detailed_message)
+ err.detailed_message(highlight: false)
+ else
+ err.to_s
+ end
+ end
+
+ module_function :get_message
end
end
diff --git a/test/did_you_mean/spell_checking/test_key_name_check.rb b/test/did_you_mean/spell_checking/test_key_name_check.rb
index ea05ff69e4..2f246f04d7 100644
--- a/test/did_you_mean/spell_checking/test_key_name_check.rb
+++ b/test/did_you_mean/spell_checking/test_key_name_check.rb
@@ -8,11 +8,11 @@ class KeyNameCheckTest < Test::Unit::TestCase
error = assert_raise(KeyError) { hash.fetch(:bax) }
assert_correction ":bar", error.corrections
- assert_match "Did you mean? :bar", error.to_s
+ assert_match "Did you mean? :bar", get_message(error)
error = assert_raise(KeyError) { hash.fetch("fooo") }
assert_correction %("foo"), error.corrections
- assert_match %(Did you mean? "foo"), error.to_s
+ assert_match %(Did you mean? "foo"), get_message(error)
end
def test_corrects_hash_key_name_with_fetch_values
@@ -20,11 +20,11 @@ class KeyNameCheckTest < Test::Unit::TestCase
error = assert_raise(KeyError) { hash.fetch_values("foo", :bar, :bax) }
assert_correction ":bar", error.corrections
- assert_match "Did you mean? :bar", error.to_s
+ assert_match "Did you mean? :bar", get_message(error)
error = assert_raise(KeyError) { hash.fetch_values("foo", :bar, "fooo") }
assert_correction %("foo"), error.corrections
- assert_match %(Did you mean? "foo"), error.to_s
+ assert_match %(Did you mean? "foo"), get_message(error)
end
def test_correct_symbolized_hash_keys_with_string_value
@@ -32,13 +32,13 @@ class KeyNameCheckTest < Test::Unit::TestCase
error = assert_raise(KeyError) { hash.fetch('foo_1') }
assert_correction %(:foo_1), error.corrections
- assert_match %(Did you mean? :foo_1), error.to_s
+ assert_match %(Did you mean? :foo_1), get_message(error)
end
def test_corrects_sprintf_key_name
error = assert_raise(KeyError) { sprintf("%<foo>d", {fooo: 1}) }
assert_correction ":fooo", error.corrections
- assert_match "Did you mean? :fooo", error.to_s
+ assert_match "Did you mean? :fooo", get_message(error)
end
def test_corrects_env_key_name
@@ -46,7 +46,7 @@ class KeyNameCheckTest < Test::Unit::TestCase
ENV["BAR"] = "2"
error = assert_raise(KeyError) { ENV.fetch("BAX") }
assert_correction %("BAR"), error.corrections
- assert_match %(Did you mean? "BAR"), error.to_s
+ assert_match %(Did you mean? "BAR"), get_message(error)
ensure
ENV.delete("FOO")
ENV.delete("BAR")
diff --git a/test/did_you_mean/spell_checking/test_method_name_check.rb b/test/did_you_mean/spell_checking/test_method_name_check.rb
index 6e14e6acc4..d2e46d58f3 100644
--- a/test/did_you_mean/spell_checking/test_method_name_check.rb
+++ b/test/did_you_mean/spell_checking/test_method_name_check.rb
@@ -41,28 +41,28 @@ class MethodNameCheckTest < Test::Unit::TestCase
error = assert_raise(NoMethodError){ @user.flrst_name }
assert_correction :first_name, error.corrections
- assert_match "Did you mean? first_name", error.to_s
+ assert_match "Did you mean? first_name", get_message(error)
end
def test_corrections_include_private_method
error = assert_raise(NoMethodError){ @user.friend }
assert_correction :friends, error.corrections
- assert_match "Did you mean? friends", error.to_s
+ assert_match "Did you mean? friends", get_message(error)
end
def test_corrections_include_method_from_module
error = assert_raise(NoMethodError){ @user.fr0m_module }
assert_correction :from_module, error.corrections
- assert_match "Did you mean? from_module", error.to_s
+ assert_match "Did you mean? from_module", get_message(error)
end
def test_corrections_include_class_method
error = assert_raise(NoMethodError){ User.l0ad }
assert_correction :load, error.corrections
- assert_match "Did you mean? load", error.to_s
+ assert_match "Did you mean? load", get_message(error)
end
def test_private_methods_should_not_be_suggested
@@ -77,7 +77,7 @@ class MethodNameCheckTest < Test::Unit::TestCase
error = assert_raise(NoMethodError){ @user.call_incorrect_private_method }
assert_correction :raise, error.corrections
- assert_match "Did you mean? raise", error.to_s
+ assert_match "Did you mean? raise", get_message(error)
end
def test_exclude_methods_on_nil
@@ -104,7 +104,7 @@ class MethodNameCheckTest < Test::Unit::TestCase
end
end
- assert_equal 1, error.to_s.scan(/Did you mean/).count
+ assert_equal 1, get_message(error).scan(/Did you mean/).count
end
def test_does_not_append_suggestions_three_times
@@ -116,7 +116,7 @@ class MethodNameCheckTest < Test::Unit::TestCase
end
end
- assert_equal 1, error.to_s.scan(/Did you mean/).count
+ assert_equal 1, get_message(error).scan(/Did you mean/).count
end
def test_suggests_corrections_on_nested_error
@@ -128,20 +128,20 @@ class MethodNameCheckTest < Test::Unit::TestCase
end
end
- assert_equal 1, error.to_s.scan(/Did you mean/).count
+ assert_equal 1, get_message(error).scan(/Did you mean/).count
end
def test_suggests_yield
error = assert_raise(NoMethodError) { yeild(1) }
assert_correction :yield, error.corrections
- assert_match "Did you mean? yield", error.to_s
+ assert_match "Did you mean? yield", get_message(error)
end
def test_does_not_suggest_yield
error = assert_raise(NoMethodError) { 1.yeild }
assert_correction [], error.corrections
- assert_not_match(/Did you mean\? +yield/, error.to_s)
+ assert_not_match(/Did you mean\? +yield/, get_message(error))
end if RUBY_ENGINE != "jruby"
end
diff --git a/test/did_you_mean/spell_checking/test_pattern_key_name_check.rb b/test/did_you_mean/spell_checking/test_pattern_key_name_check.rb
index 2b0752a56a..10f973802b 100644
--- a/test/did_you_mean/spell_checking/test_pattern_key_name_check.rb
+++ b/test/did_you_mean/spell_checking/test_pattern_key_name_check.rb
@@ -15,6 +15,6 @@ class PatternKeyNameCheckTest < Test::Unit::TestCase
end
assert_correction ":foo", error.corrections
- assert_match "Did you mean? :foo", error.to_s
+ assert_match "Did you mean? :foo", get_message(error)
end
end
diff --git a/test/did_you_mean/spell_checking/test_require_path_check.rb b/test/did_you_mean/spell_checking/test_require_path_check.rb
index f67fab0568..d6c06e9999 100644
--- a/test/did_you_mean/spell_checking/test_require_path_check.rb
+++ b/test/did_you_mean/spell_checking/test_require_path_check.rb
@@ -11,7 +11,7 @@ class RequirePathCheckTest < Test::Unit::TestCase
end
assert_correction 'ostruct', error.corrections
- assert_match "Did you mean? ostruct", error.to_s
+ assert_match "Did you mean? ostruct", get_message(error)
end
def test_load_error_from_require_for_nested_files_has_suggestions
@@ -20,13 +20,13 @@ class RequirePathCheckTest < Test::Unit::TestCase
end
assert_correction 'net/http', error.corrections
- assert_match "Did you mean? net/http", error.to_s
+ assert_match "Did you mean? net/http", get_message(error)
error = assert_raise LoadError do
require 'net-http'
end
assert_correction ['net/http', 'net/https'], error.corrections
- assert_match "Did you mean? net/http", error.to_s
+ assert_match "Did you mean? net/http", get_message(error)
end
end
diff --git a/test/did_you_mean/spell_checking/test_variable_name_check.rb b/test/did_you_mean/spell_checking/test_variable_name_check.rb
index 193e2b7520..9d8b86eb5b 100644
--- a/test/did_you_mean/spell_checking/test_variable_name_check.rb
+++ b/test/did_you_mean/spell_checking/test_variable_name_check.rb
@@ -39,7 +39,7 @@ class VariableNameCheckTest < Test::Unit::TestCase
end
assert_correction :first_name, error.corrections
- assert_match "Did you mean? first_name", error.to_s
+ assert_match "Did you mean? first_name", get_message(error)
end
def test_corrections_include_method_from_module
@@ -48,7 +48,7 @@ class VariableNameCheckTest < Test::Unit::TestCase
end
assert_correction :from_module, error.corrections
- assert_match "Did you mean? from_module", error.to_s
+ assert_match "Did you mean? from_module", get_message(error)
end
def test_corrections_include_local_variable_name
@@ -57,7 +57,7 @@ class VariableNameCheckTest < Test::Unit::TestCase
error = (eprson rescue $!) # Do not use @assert_raise here as it changes a scope.
assert_correction :person, error.corrections
- assert_match "Did you mean? person", error.to_s
+ assert_match "Did you mean? person", get_message(error)
end
end
@@ -81,30 +81,30 @@ class VariableNameCheckTest < Test::Unit::TestCase
end
assert_correction :false, false_error.corrections
- assert_match "Did you mean? false", false_error.to_s
+ assert_match "Did you mean? false", get_message(false_error)
assert_correction :true, true_error.corrections
- assert_match "Did you mean? true", true_error.to_s
+ assert_match "Did you mean? true", get_message(true_error)
assert_correction :nil, nil_error.corrections
- assert_match "Did you mean? nil", nil_error.to_s
+ assert_match "Did you mean? nil", get_message(nil_error)
assert_correction :__FILE__, file_error.corrections
- assert_match "Did you mean? __FILE__", file_error.to_s
+ assert_match "Did you mean? __FILE__", get_message(file_error)
end
def test_suggests_yield
error = assert_raise(NameError) { yeild }
assert_correction :yield, error.corrections
- assert_match "Did you mean? yield", error.to_s
+ assert_match "Did you mean? yield", get_message(error)
end
def test_corrections_include_instance_variable_name
error = assert_raise(NameError){ @user.to_s }
assert_correction :@email_address, error.corrections
- assert_match "Did you mean? @email_address", error.to_s
+ assert_match "Did you mean? @email_address", get_message(error)
end
def test_corrections_include_private_method
@@ -113,7 +113,7 @@ class VariableNameCheckTest < Test::Unit::TestCase
end
assert_correction :cia_codename, error.corrections
- assert_match "Did you mean? cia_codename", error.to_s
+ assert_match "Did you mean? cia_codename", get_message(error)
end
@@does_exist = true
@@ -122,7 +122,7 @@ class VariableNameCheckTest < Test::Unit::TestCase
error = assert_raise(NameError){ @@doesnt_exist }
assert_correction :@@does_exist, error.corrections
- assert_match "Did you mean? @@does_exist", error.to_s
+ assert_match "Did you mean? @@does_exist", get_message(error)
end
def test_struct_name_error
@@ -130,7 +130,7 @@ class VariableNameCheckTest < Test::Unit::TestCase
error = assert_raise(NameError){ value[:doesnt_exist] }
assert_correction [:does_exist, :does_exist=], error.corrections
- assert_match "Did you mean? does_exist", error.to_s
+ assert_match "Did you mean? does_exist", get_message(error)
end
def test_exclude_typical_incorrect_suggestions
diff --git a/test/did_you_mean/test_ractor_compatibility.rb b/test/did_you_mean/test_ractor_compatibility.rb
index f66a1a9d62..7385f10612 100644
--- a/test/did_you_mean/test_ractor_compatibility.rb
+++ b/test/did_you_mean/test_ractor_compatibility.rb
@@ -35,7 +35,7 @@ class RactorCompatibilityTest < Test::Unit::TestCase
}.take
assert_correction ":bar", error.corrections
- assert_match "Did you mean? :bar", error.to_s
+ assert_match "Did you mean? :bar", get_message(error)
CODE
end
@@ -52,7 +52,7 @@ class RactorCompatibilityTest < Test::Unit::TestCase
}.take
assert_correction :to_s, error.corrections
- assert_match "Did you mean? to_s", error.to_s
+ assert_match "Did you mean? to_s", get_message(error)
CODE
end
@@ -74,7 +74,7 @@ class RactorCompatibilityTest < Test::Unit::TestCase
}.take
assert_correction ":foo", error.corrections
- assert_match "Did you mean? :foo", error.to_s
+ assert_match "Did you mean? :foo", get_message(error)
CODE
end
end
@@ -111,7 +111,7 @@ class RactorCompatibilityTest < Test::Unit::TestCase
}.take
assert_correction :in_ractor, error.corrections
- assert_match "Did you mean? in_ractor", error.to_s
+ assert_match "Did you mean? in_ractor", get_message(error)
CODE
end
end
diff --git a/test/digest/test_digest_extend.rb b/test/digest/test_digest_extend.rb
index bd599f2d20..a66b896e1e 100644
--- a/test/digest/test_digest_extend.rb
+++ b/test/digest/test_digest_extend.rb
@@ -6,6 +6,11 @@ require_relative '../lib/with_different_ofs'
class TestDigestExtend < Test::Unit::TestCase
extend DifferentOFS
+ TEST_DIGEST = %w[SHA1024 SHA512 SHA384 SHA256 SHA1].find do |n|
+ break Digest.const_get(n)
+ rescue LoadError
+ end
+
class MyDigest < Digest::Class
def initialize(*arg)
super
@@ -54,7 +59,7 @@ class TestDigestExtend < Test::Unit::TestCase
end
def test_class_reset
- a = Digest::SHA1.new
+ a = TEST_DIGEST.new
base = a.to_s
assert_equal(base, a.reset.to_s)
b = a.new
@@ -62,7 +67,7 @@ class TestDigestExtend < Test::Unit::TestCase
b.update('1')
assert_not_equal(base, b.to_s)
assert_equal(base, b.reset.to_s)
- end
+ end if TEST_DIGEST
def test_digest
assert_equal("\3", MyDigest.digest("foo"))
@@ -83,7 +88,7 @@ class TestDigestExtend < Test::Unit::TestCase
end
def test_new
- a = Digest::SHA1.new
+ a = TEST_DIGEST.new
b = a.new
obj = a.to_s
assert_equal(obj, a.to_s)
@@ -91,7 +96,7 @@ class TestDigestExtend < Test::Unit::TestCase
a.update('1')
assert_not_equal(obj, a.to_s)
assert_equal(obj, b.to_s)
- end
+ end if TEST_DIGEST
def test_digest_hexdigest
[:digest, :hexdigest].each do |m|
diff --git a/test/digest/test_ractor.rb b/test/digest/test_ractor.rb
index 0dbdcb9c8c..b34a3653b4 100644
--- a/test/digest/test_ractor.rb
+++ b/test/digest/test_ractor.rb
@@ -13,10 +13,6 @@ module TestDigestRactor
Data1 = "abc"
Data2 = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
- def setup
- pend unless defined?(Ractor)
- end
-
def test_s_hexdigest
assert_in_out_err([], <<-"end;", ["true", "true"], [])
$VERBOSE = nil
@@ -98,4 +94,4 @@ module TestDigestRactor
Data2 => "12a053384a9c0c88e405a06c27dcf49ada62eb2b",
}
end if defined?(Digest::RMD160)
-end
+end if defined?(Ractor)
diff --git a/test/error_highlight/test_error_highlight.rb b/test/error_highlight/test_error_highlight.rb
index a3cc7aa149..c4a998092b 100644
--- a/test/error_highlight/test_error_highlight.rb
+++ b/test/error_highlight/test_error_highlight.rb
@@ -23,9 +23,16 @@ class ErrorHighlightTest < Test::Unit::TestCase
end
end
- def assert_error_message(klass, expected_msg, &blk)
- err = assert_raise(klass, &blk)
- assert_equal(expected_msg.chomp, err.message)
+ if Exception.method_defined?(:detailed_message)
+ def assert_error_message(klass, expected_msg, &blk)
+ err = assert_raise(klass, &blk)
+ assert_equal(expected_msg.chomp, err.detailed_message(highlight: false).sub(/ \((?:NoMethod|Name)Error\)/, ""))
+ end
+ else
+ def assert_error_message(klass, expected_msg, &blk)
+ err = assert_raise(klass, &blk)
+ assert_equal(expected_msg.chomp, err.message)
+ end
end
def test_CALL_noarg_1
@@ -1143,7 +1150,7 @@ nil can't be coerced into Integer
def test_custom_formatter
custom_formatter = Object.new
def custom_formatter.message_for(spot)
- "\n\n" + spot.inspect
+ "\n\n" + spot.except(:script_lines).inspect
end
original_formatter, ErrorHighlight.formatter = ErrorHighlight.formatter, custom_formatter
@@ -1224,4 +1231,30 @@ undefined method `foo' for nil:NilClass
end
end
end
+
+ def raise_name_error
+ 1.time
+ end
+
+ def test_spot_with_backtrace_location
+ lineno = __LINE__
+ begin
+ raise_name_error
+ rescue NameError => exc
+ end
+
+ spot = ErrorHighlight.spot(exc).except(:script_lines)
+ assert_equal(lineno - 4, spot[:first_lineno])
+ assert_equal(lineno - 4, spot[:last_lineno])
+ assert_equal(5, spot[:first_column])
+ assert_equal(10, spot[:last_column])
+ assert_equal(" 1.time\n", spot[:snippet])
+
+ spot = ErrorHighlight.spot(exc, backtrace_location: exc.backtrace_locations[1]).except(:script_lines)
+ assert_equal(lineno + 2, spot[:first_lineno])
+ assert_equal(lineno + 2, spot[:last_lineno])
+ assert_equal(6, spot[:first_column])
+ assert_equal(22, spot[:last_column])
+ assert_equal(" raise_name_error\n", spot[:snippet])
+ end
end
diff --git a/test/excludes/Psych/TestDateTime.rb b/test/excludes/Psych/TestDateTime.rb
new file mode 100644
index 0000000000..1188b4d4a6
--- /dev/null
+++ b/test/excludes/Psych/TestDateTime.rb
@@ -0,0 +1 @@
+exclude(:test_new_datetime, "Psych loses the start date")
diff --git a/test/fileutils/test_fileutils.rb b/test/fileutils/test_fileutils.rb
index 36b5d6ef50..e1e2a829c3 100644
--- a/test/fileutils/test_fileutils.rb
+++ b/test/fileutils/test_fileutils.rb
@@ -317,7 +317,7 @@ class TestFileUtils < Test::Unit::TestCase
def test_cp_preserve_permissions
bug4507 = '[ruby-core:35518]'
touch 'tmp/cptmp'
- chmod 0755, 'tmp/cptmp'
+ chmod 0o755, 'tmp/cptmp'
cp 'tmp/cptmp', 'tmp/cptmp2'
assert_equal_filemode('tmp/cptmp', 'tmp/cptmp2', bug4507, mask: ~File.umask)
@@ -327,9 +327,9 @@ class TestFileUtils < Test::Unit::TestCase
bug7246 = '[ruby-core:48603]'
mkdir 'tmp/cptmp'
mkdir 'tmp/cptmp/d1'
- chmod 0745, 'tmp/cptmp/d1'
+ chmod 0o745, 'tmp/cptmp/d1'
mkdir 'tmp/cptmp/d2'
- chmod 0700, 'tmp/cptmp/d2'
+ chmod 0o700, 'tmp/cptmp/d2'
cp_r 'tmp/cptmp', 'tmp/cptmp2', :preserve => true
assert_equal_filemode('tmp/cptmp/d1', 'tmp/cptmp2/d1', bug7246)
assert_equal_filemode('tmp/cptmp/d2', 'tmp/cptmp2/d2', bug7246)
@@ -823,7 +823,7 @@ class TestFileUtils < Test::Unit::TestCase
if File.sticky?('tmp/tmpdir')
Dir.mkdir 'tmp/tmpdir/d', 0
assert_raise(Errno::EACCES) {remove_entry_secure 'tmp/tmpdir/d'}
- File.chmod 0777, 'tmp/tmpdir/d'
+ File.chmod 0o777, 'tmp/tmpdir/d'
Dir.rmdir 'tmp/tmpdir/d'
end
end
@@ -1227,9 +1227,9 @@ class TestFileUtils < Test::Unit::TestCase
check_singleton :chmod
touch 'tmp/a'
- chmod 0700, 'tmp/a'
+ chmod 0o700, 'tmp/a'
assert_filemode 0700, 'tmp/a'
- chmod 0500, 'tmp/a'
+ chmod 0o500, 'tmp/a'
assert_filemode 0500, 'tmp/a'
end if have_file_perm?
@@ -1333,9 +1333,9 @@ class TestFileUtils < Test::Unit::TestCase
assert_output_lines(["chmod 700 tmp/a", "chmod 500 tmp/a"]) {
touch 'tmp/a'
- chmod 0700, 'tmp/a', verbose: true
+ chmod 0o700, 'tmp/a', verbose: true
assert_filemode 0700, 'tmp/a', mask: 0777
- chmod 0500, 'tmp/a', verbose: true
+ chmod 0o500, 'tmp/a', verbose: true
assert_filemode 0500, 'tmp/a', mask: 0777
}
end if have_file_perm?
@@ -1343,7 +1343,7 @@ class TestFileUtils < Test::Unit::TestCase
def test_s_chmod_verbose
assert_output_lines(["chmod 700 tmp/a"], FileUtils) {
touch 'tmp/a'
- FileUtils.chmod 0700, 'tmp/a', verbose: true
+ FileUtils.chmod 0o700, 'tmp/a', verbose: true
assert_filemode 0700, 'tmp/a', mask: 0777
}
end if have_file_perm?
@@ -1656,7 +1656,7 @@ class TestFileUtils < Test::Unit::TestCase
def test_remove_file_file_perm
File.open('data/tmp', 'w') {|f| f.puts 'dummy' }
- File.chmod 0, 'data/tmp'
+ File.chmod 0o000, 'data/tmp'
remove_file 'data/tmp'
assert_file_not_exist 'data/tmp'
end if have_file_perm?
@@ -1671,7 +1671,7 @@ class TestFileUtils < Test::Unit::TestCase
def test_remove_dir_file_perm
Dir.mkdir 'data/tmpdir'
- File.chmod 0555, 'data/tmpdir'
+ File.chmod 0o555, 'data/tmpdir'
remove_dir 'data/tmpdir'
assert_file_not_exist 'data/tmpdir'
end if have_file_perm?
@@ -1790,7 +1790,7 @@ cd -
return if /mswin|mingw/ =~ RUBY_PLATFORM
mkdir 'tmpdatadir'
- chmod 700, 'tmpdatadir'
+ chmod 0o700, 'tmpdatadir'
rm_rf 'tmpdatadir'
assert_file_not_exist 'tmpdatadir'
diff --git a/test/io/console/test_io_console.rb b/test/io/console/test_io_console.rb
index f6e46fe112..b5382555f5 100644
--- a/test/io/console/test_io_console.rb
+++ b/test/io/console/test_io_console.rb
@@ -395,7 +395,7 @@ defined?(PTY) and defined?(IO.console) and TestIO_Console.class_eval do
assert_ctrl("#{cc.ord}", cc, r, w)
assert_ctrl("#{cc.ord}", cc, r, w)
end
- if cc = ctrl["lnext"]
+ if (cc = ctrl["lnext"]) && /freebsd/ !~ RUBY_PLATFORM
assert_ctrl("#{cc.ord}", cc, r, w)
assert_ctrl("#{cc.ord}", cc, r, w)
assert_ctrl("#{cc.ord}", cc, r, w)
diff --git a/test/io/wait/test_io_wait.rb b/test/io/wait/test_io_wait.rb
index 6b4722e1be..fb42b6a700 100644
--- a/test/io/wait/test_io_wait.rb
+++ b/test/io/wait/test_io_wait.rb
@@ -161,6 +161,34 @@ class TestIOWait < Test::Unit::TestCase
assert_equal @w, @w.wait(0.01, :read_write)
end
+ def test_wait_mask_writable
+ omit("Missing IO::WRITABLE!") unless IO.const_defined?(:WRITABLE)
+ assert_equal IO::WRITABLE, @w.wait(IO::WRITABLE, 0)
+ end
+
+ def test_wait_mask_readable
+ omit("Missing IO::READABLE!") unless IO.const_defined?(:READABLE)
+ @w.write("Hello World\n" * 3)
+ assert_equal IO::READABLE, @r.wait(IO::READABLE, 0)
+
+ @r.gets
+ assert_equal IO::READABLE, @r.wait(IO::READABLE, 0)
+ end
+
+ def test_wait_mask_zero
+ omit("Missing IO::WRITABLE!") unless IO.const_defined?(:WRITABLE)
+ assert_raise(ArgumentError) do
+ @w.wait(0, 0)
+ end
+ end
+
+ def test_wait_mask_negative
+ omit("Missing IO::WRITABLE!") unless IO.const_defined?(:WRITABLE)
+ assert_raise(ArgumentError) do
+ @w.wait(-6, 0)
+ end
+ end
+
private
def fill_pipe
diff --git a/test/irb/test_context.rb b/test/irb/test_context.rb
index 42f82fc37e..b3fc49e7e3 100644
--- a/test/irb/test_context.rb
+++ b/test/irb/test_context.rb
@@ -30,10 +30,6 @@ module TestIRB
def reset
@line_no = 0
end
-
- def winsize
- [10, 20]
- end
end
def setup
@@ -135,30 +131,54 @@ module TestIRB
], out)
end
- def test_eval_object_without_inspect_method
- verbose, $VERBOSE = $VERBOSE, nil
- all_assertions do |all|
- IRB::Inspector::INSPECTORS.invert.each_value do |mode|
- all.for(mode) do
- input = TestInputMethod.new([
- "[BasicObject.new, Class.new]\n",
- ])
- irb = IRB::Irb.new(IRB::WorkSpace.new(Object.new), input)
- irb.context.inspect_mode = mode
- out, err = capture_output do
- irb.eval_input
- end
- assert_empty err
- assert_match(/\(Object doesn't support #inspect\)\n(=> )?\n/, out)
+ def test_output_to_pipe
+ require 'stringio'
+ input = TestInputMethod.new(["n=1"])
+ input.instance_variable_set(:@stdout, StringIO.new)
+ irb = IRB::Irb.new(IRB::WorkSpace.new(Object.new), input)
+ irb.context.echo_on_assignment = :truncate
+ irb.context.prompt_mode = :DEFAULT
+ out, err = capture_output do
+ irb.eval_input
+ end
+ assert_empty err
+ assert_equal "=> 1\n", out
+ end
+
+ {
+ successful: [
+ [false, "class Foo < Struct.new(:bar); end; Foo.new(123)\n", /#<struct bar=123>/],
+ [:p, "class Foo < Struct.new(:bar); end; Foo.new(123)\n", /#<struct bar=123>/],
+ [true, "class Foo < Struct.new(:bar); end; Foo.new(123)\n", /#<struct #<Class:.*>::Foo bar=123>/],
+ [:yaml, "123", /--- 123\n/],
+ [:marshal, "123", Marshal.dump(123)],
+ ],
+ failed: [
+ [false, "BasicObject.new", /\(Object doesn't support #inspect\)\n(=> )?\n/],
+ [:p, "class Foo; undef inspect ;end; Foo.new", /\(Object doesn't support #inspect\)\n(=> )?\n/],
+ [true, "BasicObject.new", /\(Object doesn't support #inspect\)\n(=> )?\n/],
+ [:yaml, "BasicObject.new", /\(Object doesn't support #inspect\)\n(=> )?\n/],
+ [:marshal, "[Object.new, Class.new]", /\(Object doesn't support #inspect\)\n(=> )?\n/]
+ ]
+ }.each do |scenario, cases|
+ cases.each do |inspect_mode, input, expected|
+ define_method "test_#{inspect_mode}_inspect_mode_#{scenario}" do
+ pend if RUBY_ENGINE == 'truffleruby'
+ verbose, $VERBOSE = $VERBOSE, nil
+ irb = IRB::Irb.new(IRB::WorkSpace.new(Object.new), TestInputMethod.new([input]))
+ irb.context.inspect_mode = inspect_mode
+ out, err = capture_output do
+ irb.eval_input
end
+ assert_empty err
+ assert_match(expected, out)
+ ensure
+ $VERBOSE = verbose
end
end
- ensure
- $VERBOSE = verbose
end
def test_default_config
- assert_equal(true, @context.use_colorize?)
assert_equal(true, @context.use_autocomplete?)
end
@@ -259,7 +279,6 @@ module TestIRB
end
def test_omit_on_assignment
- IRB.conf[:USE_COLORIZE] = false
input = TestInputMethod.new([
"a = [1] * 100\n",
"a\n",
@@ -323,101 +342,103 @@ module TestIRB
end
def test_omit_multiline_on_assignment
- IRB.conf[:USE_COLORIZE] = false
- input = TestInputMethod.new([
- "class A; def inspect; ([?* * 1000] * 3).join(%{\\n}); end; end; a = A.new\n",
- "a\n"
- ])
- value = ([?* * 1000] * 3).join(%{\n})
- value_first_line = (?* * 1000).to_s
- irb = IRB::Irb.new(IRB::WorkSpace.new(Object.new), input)
- irb.context.return_format = "=> %s\n"
-
- irb.context.echo = true
- irb.context.echo_on_assignment = false
- out, err = capture_output do
- irb.eval_input
- end
- assert_empty err
- assert_equal("=> \n#{value}\n", out)
- irb.context.evaluate('A.remove_method(:inspect)', 0)
-
- input.reset
- irb.context.echo = true
- irb.context.echo_on_assignment = :truncate
- out, err = capture_output do
- irb.eval_input
- end
- assert_empty err
- assert_equal("=> #{value_first_line[0..(input.winsize.last - 9)]}...\n=> \n#{value}\n", out)
- irb.context.evaluate('A.remove_method(:inspect)', 0)
-
- input.reset
- irb.context.echo = true
- irb.context.echo_on_assignment = true
- out, err = capture_output do
- irb.eval_input
- end
- assert_empty err
- assert_equal("=> \n#{value}\n=> \n#{value}\n", out)
- irb.context.evaluate('A.remove_method(:inspect)', 0)
-
- input.reset
- irb.context.echo = false
- irb.context.echo_on_assignment = false
- out, err = capture_output do
- irb.eval_input
- end
- assert_empty err
- assert_equal("", out)
- irb.context.evaluate('A.remove_method(:inspect)', 0)
-
- input.reset
- irb.context.echo = false
- irb.context.echo_on_assignment = :truncate
- out, err = capture_output do
- irb.eval_input
- end
- assert_empty err
- assert_equal("", out)
- irb.context.evaluate('A.remove_method(:inspect)', 0)
-
- input.reset
- irb.context.echo = false
- irb.context.echo_on_assignment = true
- out, err = capture_output do
- irb.eval_input
+ without_colorize do
+ input = TestInputMethod.new([
+ "class A; def inspect; ([?* * 1000] * 3).join(%{\\n}); end; end; a = A.new\n",
+ "a\n"
+ ])
+ value = ([?* * 1000] * 3).join(%{\n})
+ value_first_line = (?* * 1000).to_s
+ irb = IRB::Irb.new(IRB::WorkSpace.new(Object.new), input)
+ irb.context.return_format = "=> %s\n"
+
+ irb.context.echo = true
+ irb.context.echo_on_assignment = false
+ out, err = capture_output do
+ irb.eval_input
+ end
+ assert_empty err
+ assert_equal("=> \n#{value}\n", out)
+ irb.context.evaluate('A.remove_method(:inspect)', 0)
+
+ input.reset
+ irb.context.echo = true
+ irb.context.echo_on_assignment = :truncate
+ out, err = capture_output do
+ irb.eval_input
+ end
+ assert_empty err
+ assert_equal("=> #{value_first_line[0..(input.winsize.last - 9)]}...\n=> \n#{value}\n", out)
+ irb.context.evaluate('A.remove_method(:inspect)', 0)
+
+ input.reset
+ irb.context.echo = true
+ irb.context.echo_on_assignment = true
+ out, err = capture_output do
+ irb.eval_input
+ end
+ assert_empty err
+ assert_equal("=> \n#{value}\n=> \n#{value}\n", out)
+ irb.context.evaluate('A.remove_method(:inspect)', 0)
+
+ input.reset
+ irb.context.echo = false
+ irb.context.echo_on_assignment = false
+ out, err = capture_output do
+ irb.eval_input
+ end
+ assert_empty err
+ assert_equal("", out)
+ irb.context.evaluate('A.remove_method(:inspect)', 0)
+
+ input.reset
+ irb.context.echo = false
+ irb.context.echo_on_assignment = :truncate
+ out, err = capture_output do
+ irb.eval_input
+ end
+ assert_empty err
+ assert_equal("", out)
+ irb.context.evaluate('A.remove_method(:inspect)', 0)
+
+ input.reset
+ irb.context.echo = false
+ irb.context.echo_on_assignment = true
+ out, err = capture_output do
+ irb.eval_input
+ end
+ assert_empty err
+ assert_equal("", out)
+ irb.context.evaluate('A.remove_method(:inspect)', 0)
end
- assert_empty err
- assert_equal("", out)
- irb.context.evaluate('A.remove_method(:inspect)', 0)
end
def test_echo_on_assignment_conf
# Default
IRB.conf[:ECHO] = nil
IRB.conf[:ECHO_ON_ASSIGNMENT] = nil
- IRB.conf[:USE_COLORIZE] = false
- input = TestInputMethod.new()
- irb = IRB::Irb.new(IRB::WorkSpace.new(Object.new), input)
+ without_colorize do
+ input = TestInputMethod.new()
+ irb = IRB::Irb.new(IRB::WorkSpace.new(Object.new), input)
- assert(irb.context.echo?, "echo? should be true by default")
- assert_equal(:truncate, irb.context.echo_on_assignment?, "echo_on_assignment? should be :truncate by default")
+ assert(irb.context.echo?, "echo? should be true by default")
+ assert_equal(:truncate, irb.context.echo_on_assignment?, "echo_on_assignment? should be :truncate by default")
- # Explicitly set :ECHO to false
- IRB.conf[:ECHO] = false
- irb = IRB::Irb.new(IRB::WorkSpace.new(Object.new), input)
+ # Explicitly set :ECHO to false
+ IRB.conf[:ECHO] = false
+ irb = IRB::Irb.new(IRB::WorkSpace.new(Object.new), input)
- refute(irb.context.echo?, "echo? should be false when IRB.conf[:ECHO] is set to false")
- assert_equal(:truncate, irb.context.echo_on_assignment?, "echo_on_assignment? should be :truncate by default")
+ refute(irb.context.echo?, "echo? should be false when IRB.conf[:ECHO] is set to false")
+ assert_equal(:truncate, irb.context.echo_on_assignment?, "echo_on_assignment? should be :truncate by default")
- # Explicitly set :ECHO_ON_ASSIGNMENT to true
- IRB.conf[:ECHO] = nil
- IRB.conf[:ECHO_ON_ASSIGNMENT] = false
- irb = IRB::Irb.new(IRB::WorkSpace.new(Object.new), input)
+ # Explicitly set :ECHO_ON_ASSIGNMENT to true
+ IRB.conf[:ECHO] = nil
+ IRB.conf[:ECHO_ON_ASSIGNMENT] = false
+ irb = IRB::Irb.new(IRB::WorkSpace.new(Object.new), input)
- assert(irb.context.echo?, "echo? should be true by default")
- refute(irb.context.echo_on_assignment?, "echo_on_assignment? should be false when IRB.conf[:ECHO_ON_ASSIGNMENT] is set to false")
+ assert(irb.context.echo?, "echo? should be true by default")
+ refute(irb.context.echo_on_assignment?, "echo_on_assignment? should be false when IRB.conf[:ECHO_ON_ASSIGNMENT] is set to false")
+ end
end
def test_multiline_output_on_default_inspector
@@ -425,31 +446,32 @@ module TestIRB
def main.inspect
"abc\ndef"
end
- IRB.conf[:USE_COLORIZE] = false
- input = TestInputMethod.new([
- "self"
- ])
- irb = IRB::Irb.new(IRB::WorkSpace.new(main), input)
- irb.context.return_format = "=> %s\n"
- # The default
- irb.context.newline_before_multiline_output = true
- out, err = capture_output do
- irb.eval_input
- end
- assert_empty err
- assert_equal("=> \nabc\ndef\n",
- out)
+ without_colorize do
+ input = TestInputMethod.new([
+ "self"
+ ])
+ irb = IRB::Irb.new(IRB::WorkSpace.new(main), input)
+ irb.context.return_format = "=> %s\n"
- # No newline before multiline output
- input.reset
- irb.context.newline_before_multiline_output = false
- out, err = capture_output do
- irb.eval_input
+ # The default
+ irb.context.newline_before_multiline_output = true
+ out, err = capture_output do
+ irb.eval_input
+ end
+ assert_empty err
+ assert_equal("=> \nabc\ndef\n",
+ out)
+
+ # No newline before multiline output
+ input.reset
+ irb.context.newline_before_multiline_output = false
+ out, err = capture_output do
+ irb.eval_input
+ end
+ assert_empty err
+ assert_equal("=> abc\ndef\n", out)
end
- assert_empty err
- assert_equal("=> abc\ndef\n",
- out)
end
def test_default_return_format
@@ -622,5 +644,15 @@ module TestIRB
:*, /\b6\n/,
], out)
end
+
+ private
+
+ def without_colorize
+ original_value = IRB.conf[:USE_COLORIZE]
+ IRB.conf[:USE_COLORIZE] = false
+ yield
+ ensure
+ IRB.conf[:USE_COLORIZE] = original_value
+ end
end
end
diff --git a/test/json/json_parser_test.rb b/test/json/json_parser_test.rb
index 00b254fc6a..146ff7c047 100644
--- a/test/json/json_parser_test.rb
+++ b/test/json/json_parser_test.rb
@@ -115,6 +115,10 @@ class JSONParserTest < Test::Unit::TestCase
assert_equal(BigDecimal("0.901234567890123456789E1"),JSON.parse('{"foo": 9.01234567890123456789}', decimal_class: BigDecimal)["foo"] )
end
+ def test_parse_string_mixed_unicode
+ assert_equal(["éé"], JSON.parse("[\"\\u00e9é\"]"))
+ end
+
if Array.method_defined?(:permutation)
def test_parse_more_complex_arrays
a = [ nil, false, true, "foßbar", [ "n€st€d", true ], { "nested" => true, "n€ßt€ð2" => {} }]
diff --git a/test/lib/jit_support.rb b/test/lib/jit_support.rb
index c7618e03a0..e607df4cab 100644
--- a/test/lib/jit_support.rb
+++ b/test/lib/jit_support.rb
@@ -96,4 +96,8 @@ module JITSupport
RbConfig::CONFIG['CC'].start_with?('gcc') &&
stderr.include?("error trying to exec 'cc1': execvp: No such file or directory")
end
+
+ def mjit_force_enabled?
+ "#{RbConfig::CONFIG['CFLAGS']} #{RbConfig::CONFIG['CPPFLAGS']}".match?(/(\A|\s)-D ?MJIT_FORCE_ENABLE\b/)
+ end
end
diff --git a/test/net/http/test_httpheader.rb b/test/net/http/test_httpheader.rb
index cfbe36bcfd..b1ca9e8225 100644
--- a/test/net/http/test_httpheader.rb
+++ b/test/net/http/test_httpheader.rb
@@ -308,6 +308,18 @@ class HTTPHeaderTest < Test::Unit::TestCase
end
def test_content_range
+ @c['Content-Range'] = "bytes 0-499/1000"
+ assert_equal 0..499, @c.content_range
+ @c['Content-Range'] = "bytes 1-500/1000"
+ assert_equal 1..500, @c.content_range
+ @c['Content-Range'] = "bytes 1-1/1000"
+ assert_equal 1..1, @c.content_range
+ @c['Content-Range'] = "tokens 1-1/1000"
+ assert_equal nil, @c.content_range
+
+ try_invalid_content_range "invalid"
+ try_invalid_content_range "bytes 123-abc"
+ try_invalid_content_range "bytes abc-123"
end
def test_range_length
@@ -317,6 +329,15 @@ class HTTPHeaderTest < Test::Unit::TestCase
assert_equal 500, @c.range_length
@c['Content-Range'] = "bytes 1-1/1000"
assert_equal 1, @c.range_length
+ @c['Content-Range'] = "tokens 1-1/1000"
+ assert_equal nil, @c.range_length
+
+ try_invalid_content_range "bytes 1-1/abc"
+ end
+
+ def try_invalid_content_range(s)
+ @c['Content-Range'] = "#{s}"
+ assert_raise(Net::HTTPHeaderSyntaxError, s){ @c.content_range }
end
def test_chunked?
diff --git a/test/objspace/test_objspace.rb b/test/objspace/test_objspace.rb
index ed9c998597..3b90319858 100644
--- a/test/objspace/test_objspace.rb
+++ b/test/objspace/test_objspace.rb
@@ -486,6 +486,16 @@ class TestObjSpace < Test::Unit::TestCase
end
end
+ def test_dump_string_coderange
+ assert_includes ObjectSpace.dump("TEST STRING"), '"coderange":"7bit"'
+ unknown = "TEST STRING".dup.force_encoding(Encoding::BINARY)
+ 2.times do # ensure that dumping the string doesn't mutate it
+ assert_includes ObjectSpace.dump(unknown), '"coderange":"unknown"'
+ end
+ assert_includes ObjectSpace.dump("Fée"), '"coderange":"valid"'
+ assert_includes ObjectSpace.dump("\xFF"), '"coderange":"broken"'
+ end
+
def test_dump_escapes_method_name
method_name = "foo\"bar"
klass = Class.new do
@@ -715,4 +725,19 @@ class TestObjSpace < Test::Unit::TestCase
assert_equal '42', out[2]
end
end
+
+ def test_utf8_method_names
+ name = "utf8_❨╯°□°❩╯︵┻━┻"
+ obj = ObjectSpace.trace_object_allocations do
+ __send__(name)
+ end
+ dump = ObjectSpace.dump(obj)
+ assert_equal name, JSON.parse(dump)["method"], dump
+ end
+
+ private
+
+ def utf8_❨╯°□°❩╯︵┻━┻
+ "1#{2}"
+ end
end
diff --git a/test/openssl/test_ocsp.rb b/test/openssl/test_ocsp.rb
index ef7321abd6..85f133752c 100644
--- a/test/openssl/test_ocsp.rb
+++ b/test/openssl/test_ocsp.rb
@@ -99,7 +99,7 @@ class OpenSSL::TestOCSP < OpenSSL::TestCase
request.sign(@cert, @cert_key, [@ca_cert], 0)
asn1 = OpenSSL::ASN1.decode(request.to_der)
assert_equal cid.to_der, asn1.value[0].value.find { |a| a.tag_class == :UNIVERSAL }.value[0].value[0].to_der
- assert_equal OpenSSL::ASN1.ObjectId("sha1WithRSAEncryption").to_der, asn1.value[1].value[0].value[0].value[0].to_der
+ assert_equal OpenSSL::ASN1.ObjectId("sha256WithRSAEncryption").to_der, asn1.value[1].value[0].value[0].value[0].to_der
assert_equal @cert.to_der, asn1.value[1].value[0].value[2].value[0].value[0].to_der
assert_equal @ca_cert.to_der, asn1.value[1].value[0].value[2].value[0].value[1].to_der
assert_equal asn1.to_der, OpenSSL::OCSP::Request.new(asn1.to_der).to_der
diff --git a/test/openssl/test_ssl.rb b/test/openssl/test_ssl.rb
index a7607da073..5679ae77d7 100644
--- a/test/openssl/test_ssl.rb
+++ b/test/openssl/test_ssl.rb
@@ -676,10 +676,16 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase
# buzz.example.net, respectively). ...
assert_equal(true, OpenSSL::SSL.verify_certificate_identity(
create_cert_with_san('DNS:baz*.example.com'), 'baz1.example.com'))
+
+ # LibreSSL 3.5.0+ doesn't support other wildcard certificates
+ # (it isn't required to, as RFC states MAY, not MUST)
+ return if libressl?(3, 5, 0)
+
assert_equal(true, OpenSSL::SSL.verify_certificate_identity(
create_cert_with_san('DNS:*baz.example.com'), 'foobaz.example.com'))
assert_equal(true, OpenSSL::SSL.verify_certificate_identity(
create_cert_with_san('DNS:b*z.example.com'), 'buzz.example.com'))
+
# Section 6.4.3 of RFC6125 states that client should NOT match identifier
# where wildcard is other than left-most label.
#
@@ -1563,6 +1569,103 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase
end
end
+ def test_ciphersuites_method_tls_connection
+ ssl_ctx = OpenSSL::SSL::SSLContext.new
+ if !tls13_supported? || !ssl_ctx.respond_to?(:ciphersuites=)
+ pend 'TLS 1.3 not supported'
+ end
+
+ csuite = ['TLS_AES_128_GCM_SHA256', 'TLSv1.3', 128, 128]
+ inputs = [csuite[0], [csuite[0]], [csuite]]
+
+ start_server do |port|
+ inputs.each do |input|
+ cli_ctx = OpenSSL::SSL::SSLContext.new
+ cli_ctx.min_version = cli_ctx.max_version = OpenSSL::SSL::TLS1_3_VERSION
+ cli_ctx.ciphersuites = input
+
+ server_connect(port, cli_ctx) do |ssl|
+ assert_equal('TLSv1.3', ssl.ssl_version)
+ if libressl?(3, 4, 0) && !libressl?(3, 5, 0)
+ assert_equal("AEAD-AES128-GCM-SHA256", ssl.cipher[0])
+ else
+ assert_equal(csuite[0], ssl.cipher[0])
+ end
+ ssl.puts('abc'); assert_equal("abc\n", ssl.gets)
+ end
+ end
+ end
+ end
+
+ def test_ciphersuites_method_nil_argument
+ ssl_ctx = OpenSSL::SSL::SSLContext.new
+ pend 'ciphersuites= method is missing' unless ssl_ctx.respond_to?(:ciphersuites=)
+
+ assert_nothing_raised { ssl_ctx.ciphersuites = nil }
+ end
+
+ def test_ciphersuites_method_frozen_object
+ ssl_ctx = OpenSSL::SSL::SSLContext.new
+ pend 'ciphersuites= method is missing' unless ssl_ctx.respond_to?(:ciphersuites=)
+
+ ssl_ctx.freeze
+ assert_raise(FrozenError) { ssl_ctx.ciphersuites = 'TLS_AES_256_GCM_SHA384' }
+ end
+
+ def test_ciphersuites_method_bogus_csuite
+ ssl_ctx = OpenSSL::SSL::SSLContext.new
+ pend 'ciphersuites= method is missing' unless ssl_ctx.respond_to?(:ciphersuites=)
+
+ assert_raise_with_message(
+ OpenSSL::SSL::SSLError,
+ /SSL_CTX_set_ciphersuites: no cipher match/i
+ ) { ssl_ctx.ciphersuites = 'BOGUS' }
+ end
+
+ def test_ciphers_method_tls_connection
+ csuite = ['ECDHE-RSA-AES256-GCM-SHA384', 'TLSv1.2', 256, 256]
+ inputs = [csuite[0], [csuite[0]], [csuite]]
+
+ start_server do |port|
+ inputs.each do |input|
+ cli_ctx = OpenSSL::SSL::SSLContext.new
+ cli_ctx.min_version = cli_ctx.max_version = OpenSSL::SSL::TLS1_2_VERSION
+ cli_ctx.ciphers = input
+
+ server_connect(port, cli_ctx) do |ssl|
+ assert_equal('TLSv1.2', ssl.ssl_version)
+ assert_equal(csuite[0], ssl.cipher[0])
+ ssl.puts('abc'); assert_equal("abc\n", ssl.gets)
+ end
+ end
+ end
+ end
+
+ def test_ciphers_method_nil_argument
+ ssl_ctx = OpenSSL::SSL::SSLContext.new
+ assert_nothing_raised { ssl_ctx.ciphers = nil }
+ end
+
+ def test_ciphers_method_frozen_object
+ ssl_ctx = OpenSSL::SSL::SSLContext.new
+
+ ssl_ctx.freeze
+ assert_raise(FrozenError) { ssl_ctx.ciphers = 'ECDHE-RSA-AES128-SHA' }
+ end
+
+ def test_ciphers_method_bogus_csuite
+ omit "Old #{OpenSSL::OPENSSL_LIBRARY_VERSION}" if
+ year = OpenSSL::OPENSSL_LIBRARY_VERSION[/\A OpenSSL\s+[01]\..*\s\K\d+\z/x] and
+ year.to_i <= 2018
+
+ ssl_ctx = OpenSSL::SSL::SSLContext.new
+
+ assert_raise_with_message(
+ OpenSSL::SSL::SSLError,
+ /SSL_CTX_set_cipher_list: no cipher match/i
+ ) { ssl_ctx.ciphers = 'BOGUS' }
+ end
+
def test_connect_works_when_setting_dh_callback_to_nil
ctx_proc = -> ctx {
ctx.max_version = :TLS1_2
diff --git a/test/optparse/test_placearg.rb b/test/optparse/test_placearg.rb
index 94cfb0e819..ed0e4d3e6c 100644
--- a/test/optparse/test_placearg.rb
+++ b/test/optparse/test_placearg.rb
@@ -18,6 +18,8 @@ class TestOptionParserPlaceArg < TestOptionParser
def test_short
assert_equal(%w"", no_error {@opt.parse!(%w"-x -n")})
assert_equal(nil, @flag)
+ assert_equal(%w"", no_error {@opt.parse!(%w"-x -")})
+ assert_equal("-", @flag)
@flag = false
assert_equal(%w"", no_error {@opt.parse!(%w"-x foo")})
assert_equal("foo", @flag)
@@ -30,6 +32,8 @@ class TestOptionParserPlaceArg < TestOptionParser
def test_abbrev
assert_equal(%w"", no_error {@opt.parse!(%w"-o -n")})
assert_equal(nil, @flag)
+ assert_equal(%w"", no_error {@opt.parse!(%w"-o -")})
+ assert_equal("-", @flag)
@flag = false
assert_equal(%w"", no_error {@opt.parse!(%w"-o foo")})
assert_equal("foo", @flag)
@@ -42,6 +46,8 @@ class TestOptionParserPlaceArg < TestOptionParser
def test_long
assert_equal(%w"", no_error {@opt.parse!(%w"--opt -n")})
assert_equal(nil, @flag)
+ assert_equal(%w"", no_error {@opt.parse!(%w"--opt -")})
+ assert_equal("-", @flag)
assert_equal(%w"foo", no_error {@opt.parse!(%w"--opt= foo")})
assert_equal("", @flag)
assert_equal(%w"", no_error {@opt.parse!(%w"--opt=foo")})
diff --git a/test/psych/helper.rb b/test/psych/helper.rb
index 0643139d8c..4e82887c6d 100644
--- a/test/psych/helper.rb
+++ b/test/psych/helper.rb
@@ -51,7 +51,7 @@ module Psych
:UseVersion => true, :UseHeader => true, :SortKeys => true
)
))
- rescue Psych::DisallowedClass, Psych::BadAlias
+ rescue Psych::DisallowedClass, Psych::BadAlias, Psych::AliasesNotEnabled
assert_to_yaml obj, yaml, :unsafe_load
end
@@ -61,7 +61,7 @@ module Psych
def assert_parse_only( obj, yaml )
begin
assert_equal obj, Psych::load( yaml )
- rescue Psych::DisallowedClass, Psych::BadAlias
+ rescue Psych::DisallowedClass, Psych::BadAlias, Psych::AliasesNotEnabled
assert_equal obj, Psych::unsafe_load( yaml )
end
assert_equal obj, Psych::parse( yaml ).transform
@@ -79,7 +79,7 @@ module Psych
assert_equal(obj, Psych.load(v.tree.yaml))
assert_equal(obj, Psych::load(Psych.dump(obj)))
assert_equal(obj, Psych::load(obj.to_yaml))
- rescue Psych::DisallowedClass, Psych::BadAlias
+ rescue Psych::DisallowedClass, Psych::BadAlias, Psych::AliasesNotEnabled
assert_equal(obj, Psych.unsafe_load(v.tree.yaml))
assert_equal(obj, Psych::unsafe_load(Psych.dump(obj)))
assert_equal(obj, Psych::unsafe_load(obj.to_yaml))
diff --git a/test/psych/test_array.rb b/test/psych/test_array.rb
index 28b76da785..0dc82439d4 100644
--- a/test/psych/test_array.rb
+++ b/test/psych/test_array.rb
@@ -57,6 +57,22 @@ module Psych
assert_cycle(@list)
end
+ def test_recursive_array
+ @list << @list
+
+ loaded = Psych.load(Psych.dump(@list), aliases: true)
+
+ assert_same loaded, loaded.last
+ end
+
+ def test_recursive_array_uses_alias
+ @list << @list
+
+ assert_raise(AliasesNotEnabled) do
+ Psych.load(Psych.dump(@list), aliases: false)
+ end
+ end
+
def test_cycle
assert_cycle(@list)
end
diff --git a/test/psych/test_hash.rb b/test/psych/test_hash.rb
index 5374781339..31eba8580b 100644
--- a/test/psych/test_hash.rb
+++ b/test/psych/test_hash.rb
@@ -102,26 +102,66 @@ module Psych
end
def test_ref_append
- hash = Psych.unsafe_load(<<-eoyml)
----
-foo: &foo
- hello: world
-bar:
- <<: *foo
-eoyml
+ hash = Psych.unsafe_load(<<~eoyml)
+ ---
+ foo: &foo
+ hello: world
+ bar:
+ <<: *foo
+ eoyml
assert_equal({"foo"=>{"hello"=>"world"}, "bar"=>{"hello"=>"world"}}, hash)
end
+ def test_anchor_reuse
+ hash = Psych.unsafe_load(<<~eoyml)
+ ---
+ foo: &foo
+ hello: world
+ bar: *foo
+ eoyml
+ assert_equal({"foo"=>{"hello"=>"world"}, "bar"=>{"hello"=>"world"}}, hash)
+ assert_same(hash.fetch("foo"), hash.fetch("bar"))
+ end
+
+ def test_raises_if_anchor_not_defined
+ assert_raise(Psych::AnchorNotDefined) do
+ Psych.unsafe_load(<<~eoyml)
+ ---
+ foo: &foo
+ hello: world
+ bar: *not_foo
+ eoyml
+ end
+ end
+
+ def test_recursive_hash
+ h = { }
+ h["recursive_reference"] = h
+
+ loaded = Psych.load(Psych.dump(h), aliases: true)
+
+ assert_same loaded, loaded.fetch("recursive_reference")
+ end
+
+ def test_recursive_hash_uses_alias
+ h = { }
+ h["recursive_reference"] = h
+
+ assert_raise(AliasesNotEnabled) do
+ Psych.load(Psych.dump(h), aliases: false)
+ end
+ end
+
def test_key_deduplication
unless String.method_defined?(:-@) && (-("a" * 20)).equal?((-("a" * 20)))
pend "This Ruby implementation doesn't support string deduplication"
end
- hashes = Psych.load(<<-eoyml)
----
-- unique_identifier: 1
-- unique_identifier: 2
-eoyml
+ hashes = Psych.load(<<~eoyml)
+ ---
+ - unique_identifier: 1
+ - unique_identifier: 2
+ eoyml
assert_same hashes[0].keys.first, hashes[1].keys.first
end
diff --git a/test/psych/test_merge_keys.rb b/test/psych/test_merge_keys.rb
index dcf4f1fce3..2f55a1ed8e 100644
--- a/test/psych/test_merge_keys.rb
+++ b/test/psych/test_merge_keys.rb
@@ -117,7 +117,7 @@ development:
bar:
<< : *foo
eoyml
- exp = assert_raise(Psych::BadAlias) { Psych.load yaml }
+ exp = assert_raise(Psych::AnchorNotDefined) { Psych.load(yaml, aliases: true) }
assert_match 'foo', exp.message
end
diff --git a/test/psych/test_object.rb b/test/psych/test_object.rb
index 0faf6b244d..21c27794ea 100644
--- a/test/psych/test_object.rb
+++ b/test/psych/test_object.rb
@@ -36,10 +36,19 @@ module Psych
def test_cyclic_references
foo = Foo.new(nil)
foo.parent = foo
- loaded = Psych.unsafe_load Psych.dump foo
+ loaded = Psych.load(Psych.dump(foo), permitted_classes: [Foo], aliases: true)
assert_instance_of(Foo, loaded)
- assert_equal loaded, loaded.parent
+ assert_same loaded, loaded.parent
+ end
+
+ def test_cyclic_reference_uses_alias
+ foo = Foo.new(nil)
+ foo.parent = foo
+
+ assert_raise(AliasesNotEnabled) do
+ Psych.load(Psych.dump(foo), permitted_classes: [Foo], aliases: false)
+ end
end
end
end
diff --git a/test/psych/test_safe_load.rb b/test/psych/test_safe_load.rb
index b52d6048b3..a9ed737528 100644
--- a/test/psych/test_safe_load.rb
+++ b/test/psych/test_safe_load.rb
@@ -19,18 +19,31 @@ module Psych
end
end
- def test_no_recursion
- x = []
- x << x
- assert_raise(Psych::BadAlias) do
- Psych.safe_load Psych.dump(x)
+ def test_raises_when_alias_found_if_alias_parsing_not_enabled
+ yaml_with_aliases = <<~YAML
+ ---
+ a: &ABC
+ k1: v1
+ k2: v2
+ b: *ABC
+ YAML
+
+ assert_raise(Psych::AliasesNotEnabled) do
+ Psych.safe_load(yaml_with_aliases)
end
end
- def test_explicit_recursion
- x = []
- x << x
- assert_equal(x, Psych.safe_load(Psych.dump(x), permitted_classes: [], permitted_symbols: [], aliases: true))
+ def test_aliases_are_parsed_when_alias_parsing_is_enabled
+ yaml_with_aliases = <<~YAML
+ ---
+ a: &ABC
+ k1: v1
+ k2: v2
+ b: *ABC
+ YAML
+
+ result = Psych.safe_load(yaml_with_aliases, aliases: true)
+ assert_same result.fetch("a"), result.fetch("b")
end
def test_permitted_symbol
diff --git a/test/rdoc/test_rdoc_any_method.rb b/test/rdoc/test_rdoc_any_method.rb
index 826ef1c8d8..6915b466f0 100644
--- a/test/rdoc/test_rdoc_any_method.rb
+++ b/test/rdoc/test_rdoc_any_method.rb
@@ -51,6 +51,20 @@ method(a, b) { |c, d| ... }
assert_equal 'foo', m.call_seq
end
+ def test_call_seq_alias_for
+ a = RDoc::AnyMethod.new nil, "each"
+ m = RDoc::AnyMethod.new nil, "each_line"
+
+ a.call_seq = <<-CALLSEQ
+each(foo)
+each_line(foo)
+ CALLSEQ
+
+ m.is_alias_for = a
+
+ assert_equal "each_line(foo)", m.call_seq
+ end
+
def test_full_name
assert_equal 'C1::m', @c1.method_list.first.full_name
end
diff --git a/test/rdoc/test_rdoc_markdown.rb b/test/rdoc/test_rdoc_markdown.rb
index c223c44c12..ca76c34f43 100644
--- a/test/rdoc/test_rdoc_markdown.rb
+++ b/test/rdoc/test_rdoc_markdown.rb
@@ -761,7 +761,6 @@ with inline notes^[like this]
and an extra note.[^2]
[^1]: With a footnote
-
[^2]: Which should be numbered correctly
MD
diff --git a/test/rdoc/test_rdoc_markup_to_html.rb b/test/rdoc/test_rdoc_markup_to_html.rb
index e5d7a35710..a5927dccae 100644
--- a/test/rdoc/test_rdoc_markup_to_html.rb
+++ b/test/rdoc/test_rdoc_markup_to_html.rb
@@ -812,6 +812,26 @@ EXPECTED
assert_equal expected, @m.convert(str, @to)
end
+ def test_block_quote_in_verbatim
+ str = "BlockQuote\n >>>\n"
+
+ expected = <<-EXPECTED
+<p>BlockQuote</p>
+<pre>&gt;&gt;&gt;</pre>
+ EXPECTED
+
+ assert_equal expected, @m.convert(str, @to).gsub(/^\n/, "")
+
+ str = "BlockQuote\n >>> word\n"
+
+ expected = <<-EXPECTED
+<p>BlockQuote</p>
+<pre>&gt;&gt;&gt; word</pre>
+ EXPECTED
+
+ assert_equal expected, @m.convert(str, @to).gsub(/^\n/, "")
+ end
+
def test_parseable_eh
valid_syntax = [
'def x() end',
diff --git a/test/rdoc/test_rdoc_parser_c.rb b/test/rdoc/test_rdoc_parser_c.rb
index d3138d23aa..b65561b2bb 100644
--- a/test/rdoc/test_rdoc_parser_c.rb
+++ b/test/rdoc/test_rdoc_parser_c.rb
@@ -101,6 +101,31 @@ class TestRDocParserC < RDoc::TestCase
end
end
+ def test_known_classes
+ RDoc::KNOWN_CLASSES.each do |var, name|
+ case name
+ when "Refinement"
+ next unless defined?(Refinement)
+ when "RubyVM"
+ next unless defined?(RubyVM)
+ when "Bignum", "Fixnum", "Data", "Socket", /\A(?![A-Z])/
+ next
+ end
+ obj = Object.const_get(name)
+ assert_equal obj.name, name
+ case var
+ when /\Arb_c/
+ assert_kind_of Class, obj
+ when /\Arb_m/
+ assert_kind_of Module, obj
+ when /\Arb_e/
+ assert_operator obj, :<=, Exception
+ else
+ raise "unknown prefix: #{var} => #{name}"
+ end
+ end
+ end
+
def test_initialize
some_ext = @top_level.add_class RDoc::NormalClass, 'SomeExt'
@top_level.add_class RDoc::SingleClass, 'SomeExtSingle'
@@ -132,51 +157,7 @@ class TestRDocParserC < RDoc::TestCase
assert_equal expected, known_classes
end
- def test_do_attr_rb_attr
- content = <<-EOF
-void Init_Blah(void) {
- cBlah = rb_define_class("Blah", rb_cObject);
-
- /*
- * This is an accessor
- */
- rb_attr(cBlah, rb_intern("accessor"), 1, 1, Qfalse);
-
- /*
- * This is a reader
- */
- rb_attr(cBlah, rb_intern("reader"), 1, 0, Qfalse);
-
- /*
- * This is a writer
- */
- rb_attr(cBlah, rb_intern("writer"), 0, 1, Qfalse);
-}
- EOF
-
- klass = util_get_class content, 'cBlah'
-
- attrs = klass.attributes
- assert_equal 3, attrs.length, attrs.inspect
-
- accessor = attrs.shift
- assert_equal 'accessor', accessor.name
- assert_equal 'RW', accessor.rw
- assert_equal 'This is an accessor', accessor.comment.text
- assert_equal @top_level, accessor.file
-
- reader = attrs.shift
- assert_equal 'reader', reader.name
- assert_equal 'R', reader.rw
- assert_equal 'This is a reader', reader.comment.text
-
- writer = attrs.shift
- assert_equal 'writer', writer.name
- assert_equal 'W', writer.rw
- assert_equal 'This is a writer', writer.comment.text
- end
-
- def test_do_attr_rb_attr_2
+ def assert_do_attr(flags)
content = <<-EOF
void Init_Blah(void) {
cBlah = rb_define_class("Blah", rb_cObject);
@@ -184,17 +165,17 @@ void Init_Blah(void) {
/*
* This is an accessor
*/
- rb_attr(cBlah, rb_intern_const("accessor"), 1, 1, Qfalse);
+ #{yield "cBlah", "accessor", flags[1], flags[1]};
/*
* This is a reader
*/
- rb_attr(cBlah, rb_intern_const("reader"), 1, 0, Qfalse);
+ #{yield "cBlah", "reader", flags[1], flags[0]};
/*
* This is a writer
*/
- rb_attr(cBlah, rb_intern_const("writer"), 0, 1, Qfalse);
+ #{yield "cBlah", "writer", flags[0], flags[1]};
}
EOF
@@ -220,28 +201,21 @@ void Init_Blah(void) {
assert_equal 'This is a writer', writer.comment.text
end
- def test_do_attr_rb_define_attr
- content = <<-EOF
-void Init_Blah(void) {
- cBlah = rb_define_class("Blah", rb_cObject);
-
- /*
- * This is an accessor
- */
- rb_define_attr(cBlah, "accessor", 1, 1);
-}
- EOF
-
- klass = util_get_class content, 'cBlah'
-
- attrs = klass.attributes
- assert_equal 1, attrs.length, attrs.inspect
-
- accessor = attrs.shift
- assert_equal 'accessor', accessor.name
- assert_equal 'RW', accessor.rw
- assert_equal 'This is an accessor', accessor.comment.text
- assert_equal @top_level, accessor.file
+ {
+ num: %w[0 1],
+ macro: %w[FALSE TRUE],
+ ruby: %w[Qfalse Qtrue],
+ bool: %w[false true],
+ }.each_pair do |name, values|
+ define_method("test_do_attr:rb_attr:intern:#{name}") do
+ assert_do_attr(values) {|c, name, r, w| %[rb_attr(#{c}, rb_intern("#{name}"), #{r}, #{w}, Qfalse)]}
+ end
+ define_method("test_do_attr:rb_attr:intern_const:#{name}") do
+ assert_do_attr(values) {|c, name, r, w| %[rb_attr(#{c}, rb_intern_const("#{name}"), #{r}, #{w}, Qfalse)]}
+ end
+ define_method("test_do_attr:rb_define_attr:#{name}") do
+ assert_do_attr(values) {|c, name, r, w| %[rb_define_attr(#{c}, "#{name}", #{r}, #{w})]}
+ end
end
def test_do_aliases
@@ -362,6 +336,12 @@ VALUE cFoo = rb_struct_define(
klass = util_get_class content, 'cFoo'
assert_equal "this is the Foo class", klass.comment.text
+
+ attributes = klass.attributes
+ assert_equal 3, attributes.size, -> {attributes}
+ ["some", "various", "fields"].zip(attributes) do |name, attr|
+ assert_equal RDoc::Attr.new("", name, "RW", ""), attr
+ end
end
def test_do_classes_struct_under
@@ -377,6 +357,12 @@ VALUE cFoo = rb_struct_define_under(
klass = util_get_class content, 'cFoo'
assert_equal 'Kernel::Foo', klass.full_name
assert_equal "this is the Foo class under Kernel", klass.comment.text
+
+ attributes = klass.attributes
+ assert_equal 3, attributes.size, -> {attributes}
+ ["some", "various", "fields"].zip(attributes) do |name, attr|
+ assert_equal RDoc::Attr.new("", name, "RW", ""), attr
+ end
end
def test_do_classes_struct_without_accessor
@@ -391,6 +377,7 @@ VALUE cFoo = rb_struct_define_without_accessor(
klass = util_get_class content, 'cFoo'
assert_equal "this is the Foo class", klass.comment.text
+ assert_empty klass.attributes
end
def test_do_classes_struct_without_accessor_under
@@ -406,6 +393,7 @@ VALUE cFoo = rb_struct_define_without_accessor_under(
klass = util_get_class content, 'cFoo'
assert_equal 'Kernel::Foo', klass.full_name
assert_equal "this is the Foo class under Kernel", klass.comment.text
+ assert_empty klass.attributes
end
def test_do_classes_class_under
@@ -908,6 +896,23 @@ Init_Foo(void) {
assert_equal "a comment for class Foo", klass.comment.text
end
+
+ def test_find_class_comment_initvm
+ content = <<-EOF
+/*
+ * a comment for class Foo
+ */
+void
+InitVM_Foo(void) {
+ VALUE foo = rb_define_class("Foo", rb_cObject);
+}
+ EOF
+
+ klass = util_get_class content, 'foo'
+
+ assert_equal "a comment for class Foo", klass.comment.text
+ end
+
def test_find_class_comment_define_class
content = <<-EOF
/*
diff --git a/test/rdoc/test_rdoc_ri_driver.rb b/test/rdoc/test_rdoc_ri_driver.rb
index 5f3468c368..fc15c25cea 100644
--- a/test/rdoc/test_rdoc_ri_driver.rb
+++ b/test/rdoc/test_rdoc_ri_driver.rb
@@ -38,7 +38,12 @@ class TestRDocRIDriver < RDoc::TestCase
super
end
- DUMMY_PAGER = ":;\n"
+ case RUBY_PLATFORM
+ when /mswin|mingw/
+ DUMMY_PAGER = "type nul"
+ else
+ DUMMY_PAGER = "true"
+ end
def with_dummy_pager
pager_env, ENV['RI_PAGER'] = ENV['RI_PAGER'], DUMMY_PAGER
@@ -1091,23 +1096,6 @@ Foo::Bar#bother
assert_instance_of @RM::ToBs, driver.formatter(StringIO.new)
end
- def test_in_path_eh
- path = ENV['PATH']
-
- test_path = File.expand_path '..', __FILE__
-
- temp_dir do |dir|
- nonexistent = File.join dir, 'nonexistent'
- refute @driver.in_path?(nonexistent)
-
- ENV['PATH'] = test_path
-
- assert @driver.in_path?(File.basename(__FILE__))
- end
- ensure
- ENV['PATH'] = path
- end
-
def test_method_type
assert_equal :both, @driver.method_type(nil)
assert_equal :both, @driver.method_type('.')
@@ -1246,7 +1234,7 @@ Foo::Bar#bother
assert_equal '(unknown)#inherit', method.full_name
end
- def _test_page # this test doesn't do anything anymore :(
+ def test_page
@driver.use_stdout = false
with_dummy_pager do
@@ -1260,9 +1248,7 @@ Foo::Bar#bother
refute @driver.paging?
end
- # this test is too fragile. Perhaps using Process.spawn will make this
- # reliable
- def _test_page_in_presence_of_child_status
+ def test_page_in_presence_of_child_status
@driver.use_stdout = false
with_dummy_pager do
@@ -1425,7 +1411,7 @@ Foo::Bar#bother
end
end
- def _test_setup_pager # this test doesn't do anything anymore :(
+ def test_setup_pager # this test doesn't do anything anymore :(
@driver.use_stdout = false
pager = with_dummy_pager do @driver.setup_pager end
diff --git a/test/reline/test_config.rb b/test/reline/test_config.rb
index 99d190d246..6b4dca0b28 100644
--- a/test/reline/test_config.rb
+++ b/test/reline/test_config.rb
@@ -408,4 +408,19 @@ class Reline::Config::Test < Reline::TestCase
ENV['XDG_CONFIG_HOME'] = xdg_config_home_backup
ENV['HOME'] = home_backup
end
+
+ def test_dialog_configurations
+ @config.read_lines(<<~LINES.lines)
+ set dialog-default-bg-color white
+ set dialog-highlight-bg-color black
+ set dialog-default-fg-color cyan
+ set dialog-highlight-fg-color magenta
+ LINES
+
+ assert_equal :white, @config.dialog_default_bg_color
+ assert_equal :black, @config.dialog_highlight_bg_color
+ assert_equal :cyan, @config.dialog_default_fg_color
+ assert_equal :magenta, @config.dialog_highlight_fg_color
+ end
end
+
diff --git a/test/reline/test_reline.rb b/test/reline/test_reline.rb
index 0d45c5da54..8828e41985 100644
--- a/test/reline/test_reline.rb
+++ b/test/reline/test_reline.rb
@@ -46,6 +46,35 @@ class Reline::Test < Reline::TestCase
Reline.completion_append_character = completion_append_character
end
+ def test_dialog_color_configuration
+ # defaults
+ assert_equal(:cyan, Reline.dialog_default_bg_color)
+ assert_equal(:white, Reline.dialog_default_fg_color)
+ assert_equal(:magenta, Reline.dialog_highlight_bg_color)
+ assert_equal(:white, Reline.dialog_highlight_fg_color)
+
+ Reline.dialog_default_bg_color = :black
+ assert_equal(:black, Reline.dialog_default_bg_color)
+ assert_equal(40, Reline.dialog_default_bg_color_sequence)
+
+ Reline.dialog_default_fg_color = :white
+ assert_equal(:white, Reline.dialog_default_fg_color)
+ assert_equal(37, Reline.dialog_default_fg_color_sequence)
+
+ Reline.dialog_highlight_bg_color = :white
+ assert_equal(:white, Reline.dialog_highlight_bg_color)
+ assert_equal(47, Reline.dialog_highlight_bg_color_sequence)
+
+ Reline.dialog_highlight_fg_color = :black
+ assert_equal(:black, Reline.dialog_highlight_fg_color)
+ assert_equal(30, Reline.dialog_highlight_fg_color_sequence)
+
+ # test value validation
+ assert_raise(ArgumentError) do
+ Reline.dialog_highlight_fg_color = :foo
+ end
+ end
+
def test_basic_word_break_characters
basic_word_break_characters = Reline.basic_word_break_characters
diff --git a/test/rinda/test_rinda.rb b/test/rinda/test_rinda.rb
index d937cd0f45..d8340e0fc4 100644
--- a/test/rinda/test_rinda.rb
+++ b/test/rinda/test_rinda.rb
@@ -496,6 +496,10 @@ class TupleSpaceProxyTest < Test::Unit::TestCase
include TupleSpaceTestModule
def setup
+ if RUBY_PLATFORM.match?(/mingw/)
+ @omitted = true
+ omit 'This test seems to randomly hang on GitHub Actions MinGW UCRT64'
+ end
super
ThreadGroup.new.add(Thread.current)
@ts_base = Rinda::TupleSpace.new(1)
@@ -503,6 +507,9 @@ class TupleSpaceProxyTest < Test::Unit::TestCase
@server = DRb.start_service("druby://localhost:0")
end
def teardown
+ return if @omitted
+ @omitted = false
+
# implementation-dependent
@ts_base.instance_eval{
if th = @keeper
diff --git a/test/ripper/test_lexer.rb b/test/ripper/test_lexer.rb
index 83130668be..4f3f4657ef 100644
--- a/test/ripper/test_lexer.rb
+++ b/test/ripper/test_lexer.rb
@@ -100,6 +100,20 @@ class TestRipper::Lexer < Test::Unit::TestCase
assert_equal expect, Ripper.lex(src).map {|e| e[1]}
end
+ def test_end_of_script_char
+ all_assertions do |all|
+ ["a", %w"[a ]", %w"{, }", "if"].each do |src, append|
+ expected = Ripper.lex(src).map {|e| e[1]}
+ ["\0b", "\4b", "\32b"].each do |eof|
+ c = "#{src}#{eof}#{append}"
+ all.for(c) do
+ assert_equal expected, Ripper.lex(c).map {|e| e[1]}
+ end
+ end
+ end
+ end
+ end
+
def test_slice
assert_equal "string\#{nil}\n",
Ripper.slice(%(<<HERE\nstring\#{nil}\nHERE), "heredoc_beg .*? nl $(.*?) heredoc_end", 1)
diff --git a/test/ripper/test_parser_events.rb b/test/ripper/test_parser_events.rb
index 5bb8f120f2..1ea8d23378 100644
--- a/test/ripper/test_parser_events.rb
+++ b/test/ripper/test_parser_events.rb
@@ -155,6 +155,44 @@ class TestRipper::ParserEvents < Test::Unit::TestCase
end
end
+ def test_anonymous_block_forwarding
+ thru_args_add_block = false
+ parse('def b(&); c(&); end', :on_args_add_block) {thru_args_add_block = true}
+ assert_equal true, thru_args_add_block
+ assert_match "no anonymous block parameter", compile_error('def b; c(&); end')
+ end
+
+ def test_anonymous_rest_forwarding
+ [
+ 'c(*)',
+ 'c(*, *)',
+ ].each do |code|
+ thru_args_add_star = false
+ src = "def b(*); #{code} end"
+ parse(src, :on_args_add_star) {thru_args_add_star = true}
+ assert_equal true, thru_args_add_star, src
+
+ src = "def b; #{code} end"
+ assert_match "no anonymous rest parameter", compile_error(src), src
+ end
+ end
+
+ def test_anonymous_keyword_rest_forwarding
+ [
+ 'c(**)',
+ 'c(k: 1, **)',
+ 'c(**, k: 1)',
+ ].each do |code|
+ thru_assoc_splat = false
+ src = "def b(**); #{code} end"
+ parse(src, :on_assoc_splat) {thru_assoc_splat = true}
+ assert_equal true, thru_assoc_splat, src
+
+ src = "def b; #{code} end"
+ assert_match "no anonymous keyword rest parameter", compile_error(src), src
+ end
+ end
+
def test_arg_paren
# FIXME
end
diff --git a/test/ruby/test_argf.rb b/test/ruby/test_argf.rb
index dbffd24370..12f7d6485a 100644
--- a/test/ruby/test_argf.rb
+++ b/test/ruby/test_argf.rb
@@ -143,6 +143,17 @@ class TestArgf < Test::Unit::TestCase
};
end
+ def test_lineno_after_shebang
+ expected = %w"1 1 1 2 2 2 3 3 1 4 4 2"
+ assert_in_out_err(["--enable=gems", "-", @t1.path, @t2.path], "#{<<~"{#"}\n#{<<~'};'}", expected)
+ #!/usr/bin/env ruby
+ {#
+ ARGF.each do |line|
+ puts [$., ARGF.lineno, ARGF.file.lineno]
+ end
+ };
+ end
+
def test_new_lineno_each
f = ARGF.class.new(@t1.path, @t2.path, @t3.path)
result = []
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb
index e376d76a16..6ee468eaef 100644
--- a/test/ruby/test_array.rb
+++ b/test/ruby/test_array.rb
@@ -1580,6 +1580,96 @@ class TestArray < Test::Unit::TestCase
assert_equal_instance(a.values_at(*idx), a.slice((3..90)%2))
idx = 90.step(3, -2).to_a
assert_equal_instance(a.values_at(*idx), a.slice((90 .. 3)% -2))
+
+ a = [0, 1, 2, 3, 4, 5]
+ assert_equal([2, 1, 0], a.slice((2..).step(-1)))
+ assert_equal([2, 0], a.slice((2..).step(-2)))
+ assert_equal([2], a.slice((2..).step(-3)))
+ assert_equal([2], a.slice((2..).step(-4)))
+
+ assert_equal([3, 2, 1, 0], a.slice((-3..).step(-1)))
+ assert_equal([3, 1], a.slice((-3..).step(-2)))
+ assert_equal([3, 0], a.slice((-3..).step(-3)))
+ assert_equal([3], a.slice((-3..).step(-4)))
+ assert_equal([3], a.slice((-3..).step(-5)))
+
+ assert_equal([5, 4, 3, 2, 1, 0], a.slice((..0).step(-1)))
+ assert_equal([5, 3, 1], a.slice((..0).step(-2)))
+ assert_equal([5, 2], a.slice((..0).step(-3)))
+ assert_equal([5, 1], a.slice((..0).step(-4)))
+ assert_equal([5, 0], a.slice((..0).step(-5)))
+ assert_equal([5], a.slice((..0).step(-6)))
+ assert_equal([5], a.slice((..0).step(-7)))
+
+ assert_equal([5, 4, 3, 2, 1], a.slice((...0).step(-1)))
+ assert_equal([5, 3, 1], a.slice((...0).step(-2)))
+ assert_equal([5, 2], a.slice((...0).step(-3)))
+ assert_equal([5, 1], a.slice((...0).step(-4)))
+ assert_equal([5], a.slice((...0).step(-5)))
+ assert_equal([5], a.slice((...0).step(-6)))
+
+ assert_equal([5, 4, 3, 2], a.slice((...1).step(-1)))
+ assert_equal([5, 3], a.slice((...1).step(-2)))
+ assert_equal([5, 2], a.slice((...1).step(-3)))
+ assert_equal([5], a.slice((...1).step(-4)))
+ assert_equal([5], a.slice((...1).step(-5)))
+
+ assert_equal([5, 4, 3, 2, 1], a.slice((..-5).step(-1)))
+ assert_equal([5, 3, 1], a.slice((..-5).step(-2)))
+ assert_equal([5, 2], a.slice((..-5).step(-3)))
+ assert_equal([5, 1], a.slice((..-5).step(-4)))
+ assert_equal([5], a.slice((..-5).step(-5)))
+ assert_equal([5], a.slice((..-5).step(-6)))
+
+ assert_equal([5, 4, 3, 2], a.slice((...-5).step(-1)))
+ assert_equal([5, 3], a.slice((...-5).step(-2)))
+ assert_equal([5, 2], a.slice((...-5).step(-3)))
+ assert_equal([5], a.slice((...-5).step(-4)))
+ assert_equal([5], a.slice((...-5).step(-5)))
+
+ assert_equal([4, 3, 2, 1], a.slice((4..1).step(-1)))
+ assert_equal([4, 2], a.slice((4..1).step(-2)))
+ assert_equal([4, 1], a.slice((4..1).step(-3)))
+ assert_equal([4], a.slice((4..1).step(-4)))
+ assert_equal([4], a.slice((4..1).step(-5)))
+
+ assert_equal([4, 3, 2], a.slice((4...1).step(-1)))
+ assert_equal([4, 2], a.slice((4...1).step(-2)))
+ assert_equal([4], a.slice((4...1).step(-3)))
+ assert_equal([4], a.slice((4...1).step(-4)))
+
+ assert_equal([4, 3, 2, 1], a.slice((-2..1).step(-1)))
+ assert_equal([4, 2], a.slice((-2..1).step(-2)))
+ assert_equal([4, 1], a.slice((-2..1).step(-3)))
+ assert_equal([4], a.slice((-2..1).step(-4)))
+ assert_equal([4], a.slice((-2..1).step(-5)))
+
+ assert_equal([4, 3, 2], a.slice((-2...1).step(-1)))
+ assert_equal([4, 2], a.slice((-2...1).step(-2)))
+ assert_equal([4], a.slice((-2...1).step(-3)))
+ assert_equal([4], a.slice((-2...1).step(-4)))
+
+ assert_equal([4, 3, 2, 1], a.slice((4..-5).step(-1)))
+ assert_equal([4, 2], a.slice((4..-5).step(-2)))
+ assert_equal([4, 1], a.slice((4..-5).step(-3)))
+ assert_equal([4], a.slice((4..-5).step(-4)))
+ assert_equal([4], a.slice((4..-5).step(-5)))
+
+ assert_equal([4, 3, 2], a.slice((4...-5).step(-1)))
+ assert_equal([4, 2], a.slice((4...-5).step(-2)))
+ assert_equal([4], a.slice((4...-5).step(-3)))
+ assert_equal([4], a.slice((4...-5).step(-4)))
+
+ assert_equal([4, 3, 2, 1], a.slice((-2..-5).step(-1)))
+ assert_equal([4, 2], a.slice((-2..-5).step(-2)))
+ assert_equal([4, 1], a.slice((-2..-5).step(-3)))
+ assert_equal([4], a.slice((-2..-5).step(-4)))
+ assert_equal([4], a.slice((-2..-5).step(-5)))
+
+ assert_equal([4, 3, 2], a.slice((-2...-5).step(-1)))
+ assert_equal([4, 2], a.slice((-2...-5).step(-2)))
+ assert_equal([4], a.slice((-2...-5).step(-3)))
+ assert_equal([4], a.slice((-2...-5).step(-4)))
end
def test_slice_out_of_range
diff --git a/test/ruby/test_ast.rb b/test/ruby/test_ast.rb
index cd96027654..d28d7e1fab 100644
--- a/test/ruby/test_ast.rb
+++ b/test/ruby/test_ast.rb
@@ -542,6 +542,25 @@ dummy
assert_equal("def test_keep_script_lines_for_of\n", node_method.source.lines.first)
end
+ def test_encoding_with_keep_script_lines
+ # Stop a warning "possibly useless use of a literal in void context"
+ verbose_bak, $VERBOSE = $VERBOSE, nil
+
+ enc = Encoding::EUC_JP
+ code = "__ENCODING__".encode(enc)
+
+ assert_equal(enc, eval(code))
+
+ node = RubyVM::AbstractSyntaxTree.parse(code, keep_script_lines: false)
+ assert_equal(enc, node.children[2].children[0])
+
+ node = RubyVM::AbstractSyntaxTree.parse(code, keep_script_lines: true)
+ assert_equal(enc, node.children[2].children[0])
+
+ ensure
+ $VERBOSE = verbose_bak
+ end
+
def test_e_option
assert_in_out_err(["-e", "def foo; end; pp RubyVM::AbstractSyntaxTree.of(method(:foo)).type"],
"", [":SCOPE"], [])
diff --git a/test/ruby/test_autoload.rb b/test/ruby/test_autoload.rb
index f6183f5ee2..1528fdd97a 100644
--- a/test/ruby/test_autoload.rb
+++ b/test/ruby/test_autoload.rb
@@ -150,6 +150,7 @@ p Foo::Bar
end
def test_nameerror_when_autoload_did_not_define_the_constant
+ verbose_bak, $VERBOSE = $VERBOSE, nil
Tempfile.create(['autoload', '.rb']) {|file|
file.puts ''
file.close
@@ -162,6 +163,8 @@ p Foo::Bar
remove_autoload_constant
end
}
+ ensure
+ $VERBOSE = verbose_bak
end
def test_override_autoload
@@ -443,6 +446,23 @@ p Foo::Bar
end
end
+ def test_source_location_after_require
+ bug = "Bug18624"
+ Dir.mktmpdir('autoload') do |tmpdir|
+ path = "#{tmpdir}/test-#{bug}.rb"
+ File.write(path, "C::#{bug} = __FILE__\n")
+ assert_separately(%W[-I #{tmpdir}], "#{<<-"begin;"}\n#{<<-"end;"}")
+ begin;
+ class C; end
+ C.autoload(:Bug18624, #{path.dump})
+ require #{path.dump}
+ assert_equal [#{path.dump}, 1], C.const_source_location(#{bug.dump})
+ assert_equal #{path.dump}, C.const_get(#{bug.dump})
+ assert_equal [#{path.dump}, 1], C.const_source_location(#{bug.dump})
+ end;
+ end
+ end
+
def test_no_memory_leak
assert_no_memory_leak([], '', "#{<<~"begin;"}\n#{<<~'end;'}", 'many autoloads', timeout: 60)
begin;
@@ -462,6 +482,7 @@ p Foo::Bar
File.write(autoload_path, '')
assert_separately(%W[-I #{tmpdir}], <<-RUBY)
+ $VERBOSE = nil
path = #{File.realpath(autoload_path).inspect}
autoload :X, path
assert_equal(path, Object.autoload?(:X))
@@ -529,6 +550,7 @@ p Foo::Bar
t2 = Thread.new {Bar}
t1.join
+ GC.start # force GC.
t2.join
Object.send(:remove_const, :Foo)
@@ -539,4 +561,20 @@ p Foo::Bar
RUBY
end
end
+
+ def test_autoload_parent_namespace
+ Dir.mktmpdir('autoload') do |tmpdir|
+ autoload_path = File.join(tmpdir, "some_const.rb")
+ File.write(autoload_path, 'class SomeConst; end')
+
+ assert_separately(%W[-I #{tmpdir}], <<-RUBY)
+ module SomeNamespace
+ autoload :SomeConst, #{File.realpath(autoload_path).inspect}
+ assert_warning(%r{/some_const\.rb to define SomeNamespace::SomeConst but it didn't}) do
+ assert_not_nil SomeConst
+ end
+ end
+ RUBY
+ end
+ end
end
diff --git a/test/ruby/test_bignum.rb b/test/ruby/test_bignum.rb
index 53a2b20cc8..065a944853 100644
--- a/test/ruby/test_bignum.rb
+++ b/test/ruby/test_bignum.rb
@@ -203,6 +203,15 @@ class TestBignum < Test::Unit::TestCase
assert_equal(00_02, '00_02'.to_i)
end
+ def test_very_big_str_to_inum
+ assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
+ begin;
+ digits = [["3", 700], ["0", 2700], ["1", 1], ["0", 26599]]
+ num = digits.inject("") {|s,(c,n)|s << c*n}.to_i
+ assert_equal digits.sum {|c,n|n}, num.to_s.size
+ end;
+ end
+
def test_to_s2
assert_raise(ArgumentError) { T31P.to_s(37) }
assert_equal("9" * 32768, (10**32768-1).to_s)
diff --git a/test/ruby/test_clone.rb b/test/ruby/test_clone.rb
index 321feb07c7..216eaa39d2 100644
--- a/test/ruby/test_clone.rb
+++ b/test/ruby/test_clone.rb
@@ -27,6 +27,52 @@ class TestClone < Test::Unit::TestCase
assert_equal([M003, M002, M001], M003.ancestors)
end
+ def test_frozen_properties_retained_on_clone
+ obj = Object.new.freeze
+ cloned_obj = obj.clone
+
+ assert_predicate(obj, :frozen?)
+ assert_predicate(cloned_obj, :frozen?)
+ end
+
+ def test_ivar_retained_on_clone
+ obj = Object.new
+ obj.instance_variable_set(:@a, 1)
+ cloned_obj = obj.clone
+
+ assert_equal(obj.instance_variable_get(:@a), 1)
+ assert_equal(cloned_obj.instance_variable_get(:@a), 1)
+ end
+
+ def test_ivars_retained_on_extended_obj_clone
+ ivars = { :@a => 1, :@b => 2, :@c => 3, :@d => 4 }
+ obj = Object.new
+ ivars.each do |ivar_name, val|
+ obj.instance_variable_set(ivar_name, val)
+ end
+
+ cloned_obj = obj.clone
+
+ ivars.each do |ivar_name, val|
+ assert_equal(obj.instance_variable_get(ivar_name), val)
+ assert_equal(cloned_obj.instance_variable_get(ivar_name), val)
+ end
+ end
+
+ def test_frozen_properties_and_ivars_retained_on_clone_with_ivar
+ obj = Object.new
+ obj.instance_variable_set(:@a, 1)
+ obj.freeze
+
+ cloned_obj = obj.clone
+
+ assert_predicate(obj, :frozen?)
+ assert_equal(obj.instance_variable_get(:@a), 1)
+
+ assert_predicate(cloned_obj, :frozen?)
+ assert_equal(cloned_obj.instance_variable_get(:@a), 1)
+ end
+
def test_user_flags
assert_separately([], <<-EOS)
#
diff --git a/test/ruby/test_dup.rb b/test/ruby/test_dup.rb
new file mode 100644
index 0000000000..75c4fc0339
--- /dev/null
+++ b/test/ruby/test_dup.rb
@@ -0,0 +1,110 @@
+# frozen_string_literal: false
+require 'test/unit'
+
+class TestDup < Test::Unit::TestCase
+ module M001; end
+ module M002; end
+ module M003; include M002; end
+ module M002; include M001; end
+ module M003; include M002; end
+
+ def test_dup
+ foo = Object.new
+ def foo.test
+ "test"
+ end
+ bar = foo.dup
+ def bar.test2
+ "test2"
+ end
+
+ assert_equal("test2", bar.test2)
+ assert_raise(NoMethodError) { bar.test }
+ assert_equal("test", foo.test)
+
+ assert_raise(NoMethodError) {foo.test2}
+
+ assert_equal([M003, M002, M001], M003.ancestors)
+ end
+
+ def test_frozen_properties_not_retained_on_dup
+ obj = Object.new.freeze
+ duped_obj = obj.dup
+
+ assert_predicate(obj, :frozen?)
+ refute_predicate(duped_obj, :frozen?)
+ end
+
+ def test_ivar_retained_on_dup
+ obj = Object.new
+ obj.instance_variable_set(:@a, 1)
+ duped_obj = obj.dup
+
+ assert_equal(obj.instance_variable_get(:@a), 1)
+ assert_equal(duped_obj.instance_variable_get(:@a), 1)
+ end
+
+ def test_ivars_retained_on_extended_obj_dup
+ ivars = { :@a => 1, :@b => 2, :@c => 3, :@d => 4 }
+ obj = Object.new
+ ivars.each do |ivar_name, val|
+ obj.instance_variable_set(ivar_name, val)
+ end
+
+ duped_obj = obj.dup
+
+ ivars.each do |ivar_name, val|
+ assert_equal(obj.instance_variable_get(ivar_name), val)
+ assert_equal(duped_obj.instance_variable_get(ivar_name), val)
+ end
+ end
+
+ def test_frozen_properties_not_retained_on_dup_with_ivar
+ obj = Object.new
+ obj.instance_variable_set(:@a, 1)
+ obj.freeze
+
+ duped_obj = obj.dup
+
+ assert_predicate(obj, :frozen?)
+ assert_equal(obj.instance_variable_get(:@a), 1)
+
+ refute_predicate(duped_obj, :frozen?)
+ assert_equal(duped_obj.instance_variable_get(:@a), 1)
+ end
+
+ def test_user_flags
+ assert_separately([], <<-EOS)
+ #
+ class Array
+ undef initialize_copy
+ def initialize_copy(*); end
+ end
+ x = [1, 2, 3].dup
+ assert_equal [], x, '[Bug #14847]'
+ EOS
+
+ assert_separately([], <<-EOS)
+ #
+ class Array
+ undef initialize_copy
+ def initialize_copy(*); end
+ end
+ x = [1,2,3,4,5,6,7][1..-2].dup
+ x.push(1,1,1,1,1)
+ assert_equal [1, 1, 1, 1, 1], x, '[Bug #14847]'
+ EOS
+
+ assert_separately([], <<-EOS)
+ #
+ class Hash
+ undef initialize_copy
+ def initialize_copy(*); end
+ end
+ h = {}
+ h.default_proc = proc { raise }
+ h = h.dup
+ assert_equal nil, h[:not_exist], '[Bug #14847]'
+ EOS
+ end
+end
diff --git a/test/ruby/test_enumerator.rb b/test/ruby/test_enumerator.rb
index c823b79c6d..3ca33126d5 100644
--- a/test/ruby/test_enumerator.rb
+++ b/test/ruby/test_enumerator.rb
@@ -906,4 +906,42 @@ class TestEnumerator < Test::Unit::TestCase
e.chain.each(&->{})
assert_equal(true, e.is_lambda)
end
+
+ def test_product
+ e = Enumerator::Product.new
+ assert_instance_of(Enumerator::Product, e)
+ assert_kind_of(Enumerator, e)
+ assert_equal(1, e.size)
+ elts = []
+ e.each { |*x| elts << x }
+ assert_equal [[]], elts
+
+ e = Enumerator::Product.new(1..3, %w[a b])
+ assert_instance_of(Enumerator::Product, e)
+ assert_kind_of(Enumerator, e)
+ assert_equal(3 * 2, e.size)
+ elts = []
+ e.each { |*x| elts << x }
+ assert_equal [[1, "a"], [1, "b"], [2, "a"], [2, "b"], [3, "a"], [3, "b"]], elts
+
+ e = Enumerator.product(1..3, %w[a b])
+ assert_instance_of(Enumerator::Product, e)
+
+ elts = []
+ ret = Enumerator.product(1..3, %w[a b]) { |*x| elts << x }
+ assert_instance_of(Enumerator::Product, ret)
+ assert_equal [[1, "a"], [1, "b"], [2, "a"], [2, "b"], [3, "a"], [3, "b"]], elts
+
+ e = Enumerator.product(1.., 'a'..'c')
+ assert_equal(Float::INFINITY, e.size)
+ assert_equal [[1, "a"], [1, "b"], [1, "c"], [2, "a"]], e.take(4)
+
+ e = Enumerator.product(1.., Enumerator.new { |y| y << 'a' << 'b' })
+ assert_equal(Float::INFINITY, e.size)
+ assert_equal [[1, "a"], [1, "b"], [2, "a"], [2, "b"]], e.take(4)
+
+ e = Enumerator.product(1..3, Enumerator.new { |y| y << 'a' << 'b' })
+ assert_equal(nil, e.size)
+ assert_equal [[1, "a"], [1, "b"], [2, "a"], [2, "b"]], e.take(4)
+ end
end
diff --git a/test/ruby/test_env.rb b/test/ruby/test_env.rb
index 87ccd5102b..cdadeac148 100644
--- a/test/ruby/test_env.rb
+++ b/test/ruby/test_env.rb
@@ -69,25 +69,20 @@ class TestEnv < Test::Unit::TestCase
end
def test_clone
- warning = /ENV\.clone is deprecated; use ENV\.to_h instead/
- clone = assert_deprecated_warning(warning) {
+ message = /Cannot clone ENV/
+ assert_raise_with_message(TypeError, message) {
ENV.clone
}
- assert_same(ENV, clone)
-
- clone = assert_deprecated_warning(warning) {
+ assert_raise_with_message(TypeError, message) {
ENV.clone(freeze: false)
}
- assert_same(ENV, clone)
-
- clone = assert_deprecated_warning(warning) {
+ assert_raise_with_message(TypeError, message) {
ENV.clone(freeze: nil)
}
- assert_same(ENV, clone)
-
- assert_raise(TypeError) {
+ assert_raise_with_message(TypeError, message) {
ENV.clone(freeze: true)
}
+
assert_raise(ArgumentError) {
ENV.clone(freeze: 1)
}
@@ -494,12 +489,20 @@ class TestEnv < Test::Unit::TestCase
ENV["baz"] = "qux"
ENV.update({"baz"=>"quux","a"=>"b"})
check(ENV.to_hash.to_a, [%w(foo bar), %w(baz quux), %w(a b)])
+ ENV.update
+ check(ENV.to_hash.to_a, [%w(foo bar), %w(baz quux), %w(a b)])
+ ENV.update({"foo"=>"zot"}, {"c"=>"d"})
+ check(ENV.to_hash.to_a, [%w(foo zot), %w(baz quux), %w(a b), %w(c d)])
ENV.clear
ENV["foo"] = "bar"
ENV["baz"] = "qux"
ENV.update({"baz"=>"quux","a"=>"b"}) {|k, v1, v2| k + "_" + v1 + "_" + v2 }
check(ENV.to_hash.to_a, [%w(foo bar), %w(baz baz_qux_quux), %w(a b)])
+ ENV.update {|k, v1, v2| k + "_" + v1 + "_" + v2 }
+ check(ENV.to_hash.to_a, [%w(foo bar), %w(baz baz_qux_quux), %w(a b)])
+ ENV.update({"foo"=>"zot"}, {"c"=>"d"}) {|k, v1, v2| k + "_" + v1 + "_" + v2 }
+ check(ENV.to_hash.to_a, [%w(foo foo_bar_zot), %w(baz baz_qux_quux), %w(a b), %w(c d)])
end
def test_huge_value
@@ -680,37 +683,6 @@ class TestEnv < Test::Unit::TestCase
end;
end
- def test_clone_in_ractor
- assert_ractor(<<-"end;")
- r = Ractor.new do
- original_warning_state = Warning[:deprecated]
- Warning[:deprecated] = false
-
- begin
- Ractor.yield ENV.clone.object_id
- Ractor.yield ENV.clone(freeze: false).object_id
- Ractor.yield ENV.clone(freeze: nil).object_id
-
- #{str_for_yielding_exception_class("ENV.clone(freeze: true)")}
- #{str_for_yielding_exception_class("ENV.clone(freeze: 1)")}
- #{str_for_yielding_exception_class("ENV.clone(foo: false)")}
- #{str_for_yielding_exception_class("ENV.clone(1)")}
- #{str_for_yielding_exception_class("ENV.clone(1, foo: false)")}
-
- ensure
- Warning[:deprecated] = original_warning_state
- end
- end
- assert_equal(ENV.object_id, r.take)
- assert_equal(ENV.object_id, r.take)
- assert_equal(ENV.object_id, r.take)
- #{str_for_assert_raise_on_yielded_exception_class(TypeError, "r")}
- 4.times do
- #{str_for_assert_raise_on_yielded_exception_class(ArgumentError, "r")}
- end
- end;
- end
-
def test_has_value_in_ractor
assert_ractor(<<-"end;")
r = Ractor.new do
diff --git a/test/ruby/test_file_exhaustive.rb b/test/ruby/test_file_exhaustive.rb
index 579e4d77a9..8cd020533b 100644
--- a/test/ruby/test_file_exhaustive.rb
+++ b/test/ruby/test_file_exhaustive.rb
@@ -1407,6 +1407,8 @@ class TestFileExhaustive < Test::Unit::TestCase
end
def test_flock_exclusive
+ omit "[Bug #18613]" if /freebsd/ =~ RUBY_PLATFORM
+
timeout = EnvUtil.apply_timeout_scale(0.1).to_s
File.open(regular_file, "r+") do |f|
f.flock(File::LOCK_EX)
@@ -1436,6 +1438,8 @@ class TestFileExhaustive < Test::Unit::TestCase
end
def test_flock_shared
+ omit "[Bug #18613]" if /freebsd/ =~ RUBY_PLATFORM
+
timeout = EnvUtil.apply_timeout_scale(0.1).to_s
File.open(regular_file, "r+") do |f|
f.flock(File::LOCK_SH)
diff --git a/test/ruby/test_frozen.rb b/test/ruby/test_frozen.rb
new file mode 100644
index 0000000000..2918a2afd8
--- /dev/null
+++ b/test/ruby/test_frozen.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: false
+require 'test/unit'
+
+class TestFrozen < Test::Unit::TestCase
+ def test_setting_ivar_on_frozen_obj
+ obj = Object.new
+ obj.freeze
+ assert_raise(FrozenError) { obj.instance_variable_set(:@a, 1) }
+ end
+
+ def test_setting_ivar_on_frozen_obj_with_ivars
+ obj = Object.new
+ obj.instance_variable_set(:@a, 1)
+ obj.freeze
+ assert_raise(FrozenError) { obj.instance_variable_set(:@b, 1) }
+ end
+
+ def test_setting_ivar_on_frozen_string
+ str = "str"
+ str.freeze
+ assert_raise(FrozenError) { str.instance_variable_set(:@a, 1) }
+ end
+
+ def test_setting_ivar_on_frozen_string_with_ivars
+ str = "str"
+ str.instance_variable_set(:@a, 1)
+ str.freeze
+ assert_raise(FrozenError) { str.instance_variable_set(:@b, 1) }
+ end
+end
diff --git a/test/ruby/test_gc.rb b/test/ruby/test_gc.rb
index b081e9fa78..a5d7f4dbaa 100644
--- a/test/ruby/test_gc.rb
+++ b/test/ruby/test_gc.rb
@@ -160,6 +160,7 @@ class TestGc < Test::Unit::TestCase
assert_operator stat_heap[:heap_tomb_slots], :>=, 0
assert_operator stat_heap[:total_allocated_pages], :>=, 0
assert_operator stat_heap[:total_freed_pages], :>=, 0
+ assert_operator stat_heap[:force_major_gc_count], :>=, 0
end
GC.stat_heap(0, stat_heap)
diff --git a/test/ruby/test_gc_compact.rb b/test/ruby/test_gc_compact.rb
index da0023e6f3..92a2be1174 100644
--- a/test/ruby/test_gc_compact.rb
+++ b/test/ruby/test_gc_compact.rb
@@ -11,16 +11,7 @@ end
class TestGCCompact < Test::Unit::TestCase
module CompactionSupportInspector
def supports_auto_compact?
- return false if /wasm/ =~ RUBY_PLATFORM
- return true unless defined?(Etc::SC_PAGE_SIZE)
-
- begin
- return GC::INTERNAL_CONSTANTS[:HEAP_PAGE_SIZE] % Etc.sysconf(Etc::SC_PAGE_SIZE) == 0
- rescue NotImplementedError
- rescue ArgumentError
- end
-
- true
+ GC::OPTS.include?("GC_COMPACTION_SUPPORTED")
end
end
@@ -175,7 +166,7 @@ class TestGCCompact < Test::Unit::TestCase
hash = list_of_objects.hash
GC.verify_compaction_references(toward: :empty)
assert_equal hash, list_of_objects.hash
- GC.verify_compaction_references(double_heap: false)
+ GC.verify_compaction_references(expand_heap: false)
assert_equal hash, list_of_objects.hash
end
@@ -200,4 +191,120 @@ class TestGCCompact < Test::Unit::TestCase
GC.compact
assert_equal count + 1, GC.stat(:compact_count)
end
+
+ def test_compacting_from_trace_point
+ obj = Object.new
+ def obj.tracee
+ :ret # expected to emit both line and call event from one instruction
+ end
+
+ results = []
+ TracePoint.new(:call, :line) do |tp|
+ results << tp.event
+ GC.verify_compaction_references
+ end.enable(target: obj.method(:tracee)) do
+ obj.tracee
+ end
+
+ assert_equal([:call, :line], results)
+ end
+
+ def test_moving_arrays_down_size_pools
+ omit if !GC.using_rvargc?
+ assert_separately([], "#{<<~"begin;"}\n#{<<~"end;"}", timeout: 10, signal: :SEGV)
+ begin;
+ ARY_COUNT = 500
+
+ GC.verify_compaction_references(expand_heap: true, toward: :empty)
+
+ arys = ARY_COUNT.times.map do
+ ary = "abbbbbbbbbb".chars
+ ary.uniq!
+ end
+
+ stats = GC.verify_compaction_references(expand_heap: true, toward: :empty)
+ assert_operator(stats.dig(:moved_down, :T_ARRAY), :>=, ARY_COUNT)
+ assert(arys) # warning: assigned but unused variable - arys
+ end;
+ end
+
+ def test_moving_arrays_up_size_pools
+ omit if !GC.using_rvargc?
+ assert_separately([], "#{<<~"begin;"}\n#{<<~"end;"}", timeout: 10, signal: :SEGV)
+ begin;
+ ARY_COUNT = 500
+
+ GC.verify_compaction_references(expand_heap: true, toward: :empty)
+
+ ary = "hello".chars
+ arys = ARY_COUNT.times.map do
+ x = []
+ ary.each { |e| x << e }
+ x
+ end
+
+ stats = GC.verify_compaction_references(expand_heap: true, toward: :empty)
+ assert_operator(stats.dig(:moved_up, :T_ARRAY), :>=, ARY_COUNT)
+ assert(arys) # warning: assigned but unused variable - arys
+ end;
+ end
+
+ def test_moving_objects_between_size_pools
+ assert_separately([], "#{<<~"begin;"}\n#{<<~"end;"}", timeout: 10, signal: :SEGV)
+ begin;
+ class Foo
+ def add_ivars
+ 10.times do |i|
+ instance_variable_set("@foo" + i.to_s, 0)
+ end
+ end
+ end
+
+ OBJ_COUNT = 500
+
+ GC.verify_compaction_references(expand_heap: true, toward: :empty)
+
+ ary = OBJ_COUNT.times.map { Foo.new }
+ ary.each(&:add_ivars)
+
+ stats = GC.verify_compaction_references(expand_heap: true, toward: :empty)
+
+ assert_operator(stats[:moved_up][:T_OBJECT], :>=, OBJ_COUNT)
+ end;
+ end
+
+ def test_moving_strings_up_size_pools
+ omit if !GC.using_rvargc?
+ assert_separately([], "#{<<~"begin;"}\n#{<<~"end;"}", timeout: 10, signal: :SEGV)
+ begin;
+ STR_COUNT = 500
+
+ GC.verify_compaction_references(expand_heap: true, toward: :empty)
+
+ str = "a" * GC::INTERNAL_CONSTANTS[:BASE_SLOT_SIZE]
+ ary = STR_COUNT.times.map { "" << str }
+
+ stats = GC.verify_compaction_references(expand_heap: true, toward: :empty)
+
+ assert_operator(stats[:moved_up][:T_STRING], :>=, STR_COUNT)
+ assert(ary) # warning: assigned but unused variable - ary
+ end;
+ end
+
+ def test_moving_strings_down_size_pools
+ omit if !GC.using_rvargc?
+ assert_separately([], "#{<<~"begin;"}\n#{<<~"end;"}", timeout: 10, signal: :SEGV)
+ begin;
+ STR_COUNT = 500
+
+ GC.verify_compaction_references(expand_heap: true, toward: :empty)
+
+ ary = STR_COUNT.times.map { ("a" * GC::INTERNAL_CONSTANTS[:BASE_SLOT_SIZE]).squeeze! }
+
+ stats = GC.verify_compaction_references(expand_heap: true, toward: :empty)
+
+ assert_operator(stats[:moved_down][:T_STRING], :>=, STR_COUNT)
+ assert(ary) # warning: assigned but unused variable - ary
+ end;
+ end
end
diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb
index 073a0dabe8..83d16d462e 100644
--- a/test/ruby/test_hash.rb
+++ b/test/ruby/test_hash.rb
@@ -304,6 +304,20 @@ class TestHash < Test::Unit::TestCase
assert_equal before, ObjectSpace.count_objects[:T_STRING]
end
+ def test_AREF_fstring_key_default_proc
+ assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
+ begin;
+ h = Hash.new do |h, k|
+ k.frozen?
+ end
+
+ str = "foo"
+ refute str.frozen? # assumes this file is frozen_string_literal: false
+ refute h[str]
+ refute h["foo"]
+ end;
+ end
+
def test_ASET_fstring_key
a, b = {}, {}
assert_equal 1, a["abc"] = 1
@@ -2166,6 +2180,27 @@ class TestHash < Test::Unit::TestCase
end
end
+ # Previously this test would fail because rb_hash inside opt_aref would look
+ # at the current method name
+ def test_hash_recursion_independent_of_mid
+ o = Class.new do
+ def hash(h, k)
+ h[k]
+ end
+
+ def any_other_name(h, k)
+ h[k]
+ end
+ end.new
+
+ rec = []; rec << rec
+
+ h = @cls[]
+ h[rec] = 1
+ assert o.hash(h, rec)
+ assert o.any_other_name(h, rec)
+ end
+
def test_any_hash_fixable
20.times do
assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
diff --git a/test/ruby/test_integer.rb b/test/ruby/test_integer.rb
index a2b181c642..c3e11498be 100644
--- a/test/ruby/test_integer.rb
+++ b/test/ruby/test_integer.rb
@@ -704,4 +704,21 @@ class TestInteger < Test::Unit::TestCase
def o.to_int; Object.new; end
assert_raise_with_message(TypeError, /can't convert Object to Integer/) {Integer.try_convert(o)}
end
+
+ def test_ceildiv
+ assert_equal(0, 0.ceildiv(3))
+ assert_equal(1, 1.ceildiv(3))
+ assert_equal(1, 3.ceildiv(3))
+ assert_equal(2, 4.ceildiv(3))
+
+ assert_equal(-1, 4.ceildiv(-3))
+ assert_equal(-1, -4.ceildiv(3))
+ assert_equal(2, -4.ceildiv(-3))
+
+ assert_equal(3, 3.ceildiv(1.2))
+ assert_equal(3, 3.ceildiv(6/5r))
+
+ assert_equal(10, (10**100-11).ceildiv(10**99-1))
+ assert_equal(11, (10**100-9).ceildiv(10**99-1))
+ end
end
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb
index ed0198321d..6a3d7594cf 100644
--- a/test/ruby/test_io.rb
+++ b/test/ruby/test_io.rb
@@ -312,7 +312,7 @@ class TestIO < Test::Unit::TestCase
w.print "a\n\nb\n\n"
w.close
end, proc do |r|
- assert_equal "a\n\nb\n", r.gets(nil, chomp: true)
+ assert_equal("a\n\nb\n\n", r.gets(nil, chomp: true), "[Bug #18770]")
assert_nil r.gets("")
r.close
end)
@@ -1894,6 +1894,20 @@ class TestIO < Test::Unit::TestCase
assert_equal("baz\n", e.next)
assert_raise(StopIteration) { e.next }
end)
+
+ pipe(proc do |w|
+ w.write "foo\n"
+ w.close
+ end, proc do |r|
+ assert_equal(["foo\n"], r.each_line(nil, chomp: true).to_a, "[Bug #18770]")
+ end)
+
+ pipe(proc do |w|
+ w.write "foo\n"
+ w.close
+ end, proc do |r|
+ assert_equal(["fo", "o\n"], r.each_line(nil, 2, chomp: true).to_a, "[Bug #18770]")
+ end)
end
def test_each_byte2
@@ -2596,6 +2610,8 @@ class TestIO < Test::Unit::TestCase
assert_raise_with_message(IOError, /not opened for reading/, bug6054) do
IO.foreach(t.path, mode:"w").next
end
+
+ assert_raise(ArgumentError, "[Bug #18771] [ruby-core:108503]") {IO.foreach(t, "\n", 10, true){}}
}
end
@@ -2605,6 +2621,7 @@ class TestIO < Test::Unit::TestCase
assert_equal(["foo\nb", "ar\nb", "az\n"], IO.readlines(t.path, "b"))
assert_equal(["fo", "o\n", "ba", "r\n", "ba", "z\n"], IO.readlines(t.path, 2))
assert_equal(["fo", "o\n", "b", "ar", "\nb", "az", "\n"], IO.readlines(t.path, "b", 2))
+ assert_raise(ArgumentError, "[Bug #18771] [ruby-core:108503]") {IO.readlines(t, "\n", 10, true){}}
}
end
@@ -3097,6 +3114,8 @@ __END__
end
def test_cross_thread_close_stdio
+ omit "[Bug #18613]" if /freebsd/ =~ RUBY_PLATFORM
+
assert_separately([], <<-'end;')
IO.pipe do |r,w|
$stdin.reopen(r)
@@ -3765,6 +3784,8 @@ __END__
end
def test_race_closed_stream
+ omit "[Bug #18613]" if /freebsd/ =~ RUBY_PLATFORM
+
assert_separately([], "#{<<-"begin;"}\n#{<<-"end;"}")
begin;
bug13158 = '[ruby-core:79262] [Bug #13158]'
@@ -3859,6 +3880,8 @@ __END__
end
def test_closed_stream_in_rescue
+ omit "[Bug #18613]" if /freebsd/ =~ RUBY_PLATFORM
+
assert_separately([], "#{<<-"begin;"}\n#{<<~"end;"}")
begin;
10.times do
diff --git a/test/ruby/test_io_m17n.rb b/test/ruby/test_io_m17n.rb
index 27b16a2a36..9c14087eba 100644
--- a/test/ruby/test_io_m17n.rb
+++ b/test/ruby/test_io_m17n.rb
@@ -1142,8 +1142,18 @@ EOT
IO.pipe do |r, w|
assert_nothing_raised(bug5567) do
assert_warning(/Unsupported/, bug5567) {r.set_encoding("fffffffffffxx")}
+ w.puts("foo")
+ assert_equal("foo\n", r.gets)
assert_warning(/Unsupported/, bug5567) {r.set_encoding("fffffffffffxx", "us-ascii")}
+ w.puts("bar")
+ assert_equal("bar\n", r.gets)
assert_warning(/Unsupported/, bug5567) {r.set_encoding("us-ascii", "fffffffffffxx")}
+ w.puts("zot")
+ begin
+ assert_equal("zot\n", r.gets)
+ rescue Encoding::ConverterNotFoundError => e
+ assert_match(/\((\S+) to \1\)/, e.message)
+ end
end
end
end
diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb
index 83e499913a..56e94493d9 100644
--- a/test/ruby/test_method.rb
+++ b/test/ruby/test_method.rb
@@ -199,11 +199,6 @@ class TestMethod < Test::Unit::TestCase
assert_equal(o.method(:foo), o.method(:foo))
assert_equal(o.method(:foo), o.method(:bar))
assert_not_equal(o.method(:foo), o.method(:baz))
-
- class << o
- private :bar
- end
- assert_not_equal(o.method(:foo), o.method(:bar))
end
def test_hash
@@ -330,8 +325,8 @@ class TestMethod < Test::Unit::TestCase
def PUBLIC_SINGLETON_TEST.def; end
end
def test_define_singleton_method_public
- assert_equal(true, PUBLIC_SINGLETON_TEST.method(:dsm).public?)
- assert_equal(true, PUBLIC_SINGLETON_TEST.method(:def).public?)
+ assert_nil(PUBLIC_SINGLETON_TEST.dsm)
+ assert_nil(PUBLIC_SINGLETON_TEST.def)
end
def test_define_singleton_method_no_proc
@@ -1197,50 +1192,6 @@ class TestMethod < Test::Unit::TestCase
assert_nil(super_method)
end
- def test_method_visibility_predicates
- v = Visibility.new
- assert_equal(true, v.method(:mv1).public?)
- assert_equal(true, v.method(:mv2).private?)
- assert_equal(true, v.method(:mv3).protected?)
- assert_equal(false, v.method(:mv2).public?)
- assert_equal(false, v.method(:mv3).private?)
- assert_equal(false, v.method(:mv1).protected?)
- end
-
- def test_unbound_method_visibility_predicates
- assert_equal(true, Visibility.instance_method(:mv1).public?)
- assert_equal(true, Visibility.instance_method(:mv2).private?)
- assert_equal(true, Visibility.instance_method(:mv3).protected?)
- assert_equal(false, Visibility.instance_method(:mv2).public?)
- assert_equal(false, Visibility.instance_method(:mv3).private?)
- assert_equal(false, Visibility.instance_method(:mv1).protected?)
- end
-
- class VisibilitySub < Visibility
- protected :mv1
- public :mv2
- private :mv3
- end
-
- def test_method_visibility_predicates_with_subclass_visbility_change
- v = VisibilitySub.new
- assert_equal(false, v.method(:mv1).public?)
- assert_equal(false, v.method(:mv2).private?)
- assert_equal(false, v.method(:mv3).protected?)
- assert_equal(true, v.method(:mv2).public?)
- assert_equal(true, v.method(:mv3).private?)
- assert_equal(true, v.method(:mv1).protected?)
- end
-
- def test_unbound_method_visibility_predicates_with_subclass_visbility_change
- assert_equal(false, VisibilitySub.instance_method(:mv1).public?)
- assert_equal(false, VisibilitySub.instance_method(:mv2).private?)
- assert_equal(false, VisibilitySub.instance_method(:mv3).protected?)
- assert_equal(true, VisibilitySub.instance_method(:mv2).public?)
- assert_equal(true, VisibilitySub.instance_method(:mv3).private?)
- assert_equal(true, VisibilitySub.instance_method(:mv1).protected?)
- end
-
def rest_parameter(*rest)
rest
end
diff --git a/test/ruby/test_mjit.rb b/test/ruby/test_mjit.rb
index 30c5659c14..02be88aa32 100644
--- a/test/ruby/test_mjit.rb
+++ b/test/ruby/test_mjit.rb
@@ -620,6 +620,16 @@ class TestMJIT < Test::Unit::TestCase
end;
end
+ def test_compile_opt_pc
+ assert_eval_with_jit("#{<<~"begin;"}\n#{<<~"end;"}", stdout: 'hello', success_count: 1)
+ begin;
+ def test(arg = 'hello')
+ print arg
+ end
+ test
+ end;
+ end
+
def test_mjit_output
out, err = eval_with_jit('5.times { puts "MJIT" }', verbose: 1, min_calls: 5)
assert_equal("MJIT\n" * 5, out)
@@ -710,10 +720,12 @@ class TestMJIT < Test::Unit::TestCase
if RUBY_PLATFORM.match?(/mswin/)
# "Permission Denied" error is preventing to remove so file on AppVeyor/RubyCI.
omit 'Removing so file is randomly failing on AppVeyor/RubyCI mswin due to Permission Denied.'
- else
- # verify .c files are deleted on unload_units
- assert_send([Dir, :empty?, dir], debug_info)
end
+ if RUBY_PLATFORM.match?(/darwin/)
+ omit '.bundle.dSYM directory is left but removing it is not supported for now'
+ end
+ # verify .c files are deleted on unload_units
+ assert_send([Dir, :empty?, dir], debug_info)
end
end
@@ -957,23 +969,24 @@ class TestMJIT < Test::Unit::TestCase
end
def test_heap_promotion_of_ivar_in_the_middle_of_jit
+ omit if GC.using_rvargc?
+
assert_eval_with_jit("#{<<~"begin;"}\n#{<<~"end;"}", stdout: "true\ntrue\n", success_count: 2, min_calls: 2)
begin;
class A
def initialize
@iv0 = nil
@iv1 = []
- @iv2 = nil
end
def test(add)
@iv0.nil?
- @iv2.nil?
add_ivar if add
@iv1.empty?
end
def add_ivar
+ @iv2 = nil
@iv3 = nil
end
end
@@ -998,10 +1011,13 @@ class TestMJIT < Test::Unit::TestCase
if RUBY_PLATFORM.match?(/mswin/)
omit 'Removing so file is randomly failing on AppVeyor/RubyCI mswin due to Permission Denied.'
end
+ if RUBY_PLATFORM.match?(/darwin/)
+ omit '.bundle.dSYM directory is left but removing it is not supported for now'
+ end
Dir.mktmpdir("jit_test_clean_so_") do |dir|
code = "x = 0; 10.times {|i|x+=i}"
eval_with_jit({"TMPDIR"=>dir}, code)
- assert_send([Dir, :empty?, dir])
+ assert_send([Dir, :empty?, dir], "Directory #{dir} was not empty:\n#{Dir.glob("#{dir}/*").join("\n")}\n")
eval_with_jit({"TMPDIR"=>dir}, code, save_temps: true)
assert_not_send([Dir, :empty?, dir])
end
@@ -1012,6 +1028,9 @@ class TestMJIT < Test::Unit::TestCase
# TODO: check call stack and close handle of code which is not on stack, and remove objects on best-effort basis
omit 'Removing so file being used does not work on Windows'
end
+ if RUBY_PLATFORM.match?(/darwin/)
+ omit '.bundle.dSYM directory is left but removing it is not supported for now'
+ end
Dir.mktmpdir("jit_test_clean_objects_on_exec_") do |dir|
eval_with_jit({"TMPDIR"=>dir}, "#{<<~"begin;"}\n#{<<~"end;"}", min_calls: 1)
begin;
@@ -1173,10 +1192,25 @@ class TestMJIT < Test::Unit::TestCase
assert_equal("Successful MJIT finish\n" * 2, err.gsub(/^#{JIT_SUCCESS_PREFIX}:[^\n]+\n/, ''), debug_info)
# ensure objects are deleted
+ if RUBY_PLATFORM.match?(/darwin/)
+ omit '.bundle.dSYM directory is left but removing it is not supported for now'
+ end
assert_send([Dir, :empty?, dir], debug_info)
end
end if defined?(fork)
+ def test_jit_failure
+ _, err = eval_with_jit("#{<<~"begin;"}\n#{<<~"end;"}", min_calls: 1, verbose: 1)
+ begin;
+ 1.times do
+ class A
+ end
+ end
+ end;
+ assert_match(/^MJIT warning: .+ unsupported instruction: defineclass/, err)
+ assert_match(/^JIT failure: block in <main>/, err)
+ end
+
private
# The shortest way to test one proc
@@ -1195,7 +1229,7 @@ class TestMJIT < Test::Unit::TestCase
success_actual = err.scan(/^#{JIT_SUCCESS_PREFIX}:/).size
recompile_actual = err.scan(/^#{JIT_RECOMPILE_PREFIX}:/).size
# Add --mjit-verbose=2 logs for cl.exe because compiler's error message is suppressed
- # for cl.exe with --mjit-verbose=1. See `start_process` in mjit_worker.c.
+ # for cl.exe with --mjit-verbose=1. See `start_process` in mjit.c.
if RUBY_PLATFORM.match?(/mswin/) && success_count != success_actual
out2, err2 = eval_with_jit(script, verbose: 2, min_calls: min_calls, max_cache: max_cache)
end
diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb
index c7245ab2db..137da09bc3 100644
--- a/test/ruby/test_module.rb
+++ b/test/ruby/test_module.rb
@@ -994,6 +994,15 @@ class TestModule < Test::Unit::TestCase
assert_equal([:bClass1], BClass.public_instance_methods(false))
end
+ def test_undefined_instance_methods
+ assert_equal([], AClass.undefined_instance_methods)
+ assert_equal([], BClass.undefined_instance_methods)
+ c = Class.new(AClass) {undef aClass}
+ assert_equal([:aClass], c.undefined_instance_methods)
+ c = Class.new(c)
+ assert_equal([], c.undefined_instance_methods)
+ end
+
def test_s_public
o = (c = Class.new(AClass)).new
assert_raise(NoMethodError, /private method/) {o.aClass1}
@@ -1319,8 +1328,6 @@ class TestModule < Test::Unit::TestCase
end
end
include LangModuleSpecInObject
- module LangModuleTop
- end
puts "ok" if LangModuleSpecInObject::LangModuleTop == LangModuleTop
INPUT
diff --git a/test/ruby/test_objectspace.rb b/test/ruby/test_objectspace.rb
index e0f9eecd11..3c912fe300 100644
--- a/test/ruby/test_objectspace.rb
+++ b/test/ruby/test_objectspace.rb
@@ -65,6 +65,11 @@ End
assert_raise_with_message(TypeError, msg) {ObjectSpace._id2ref(Object.new)}
end
+ def test_id2ref_invalid_symbol_id
+ msg = /is not symbol id value/
+ assert_raise_with_message(RangeError, msg) { ObjectSpace._id2ref(:a.object_id + 40) }
+ end
+
def test_count_objects
h = {}
ObjectSpace.count_objects(h)
diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb
index 2841e20f6d..4488ea620e 100644
--- a/test/ruby/test_parse.rb
+++ b/test/ruby/test_parse.rb
@@ -1359,6 +1359,52 @@ x = __ENCODING__
end;
end
+ def test_if_after_class
+ assert_valid_syntax('module if true; Object end::Kernel; end')
+ assert_valid_syntax('module while true; break Object end::Kernel; end')
+ assert_valid_syntax('class if true; Object end::Kernel; end')
+ assert_valid_syntax('class while true; break Object end::Kernel; end')
+ end
+
+ def test_escaped_space
+ assert_syntax_error('x = \ 42', /escaped space/)
+ end
+
+ def test_label
+ expected = {:foo => 1}
+
+ code = '{"foo": 1}'
+ assert_valid_syntax(code)
+ assert_equal(expected, eval(code))
+
+ code = '{foo: 1}'
+ assert_valid_syntax(code)
+ assert_equal(expected, eval(code))
+
+ class << (obj = Object.new)
+ attr_reader :arg
+ def set(arg)
+ @arg = arg
+ end
+ end
+
+ assert_valid_syntax(code = "#{<<~"do;"}\n#{<<~'end;'}")
+ do;
+ obj.set foo:
+ 1
+ end;
+ assert_equal(expected, eval(code))
+ assert_equal(expected, obj.arg)
+
+ assert_valid_syntax(code = "#{<<~"do;"}\n#{<<~'end;'}")
+ do;
+ obj.set "foo":
+ 1
+ end;
+ assert_equal(expected, eval(code))
+ assert_equal(expected, obj.arg)
+ end
+
=begin
def test_past_scope_variable
assert_warning(/past scope/) {catch {|tag| eval("BEGIN{throw tag}; tap {a = 1}; a")}}
diff --git a/test/ruby/test_pattern_matching.rb b/test/ruby/test_pattern_matching.rb
index 7531466f91..36731e14f9 100644
--- a/test/ruby/test_pattern_matching.rb
+++ b/test/ruby/test_pattern_matching.rb
@@ -1155,6 +1155,28 @@ END
end
end
+ bug18890 = assert_warning(/(?:.*:[47]: warning: unused literal ignored\n){2}/) do
+ eval("#{<<~';;;'}")
+ proc do |i|
+ case i
+ in a:
+ 0 # line 4
+ a
+ in "b":
+ 0 # line 7
+ b
+ else
+ false
+ end
+ end
+ ;;;
+ end
+ [{a: 42}, {b: 42}].each do |i|
+ assert_block('newline should be significant after pattern label') do
+ bug18890.call(i)
+ end
+ end
+
assert_syntax_error(%q{
case _
in a:, a:
diff --git a/test/ruby/test_range.rb b/test/ruby/test_range.rb
index 8789eca749..0df0a985ad 100644
--- a/test/ruby/test_range.rb
+++ b/test/ruby/test_range.rb
@@ -670,6 +670,35 @@ class TestRange < Test::Unit::TestCase
assert_not_operator(1..10, :cover?, 3...3)
assert_not_operator('aa'..'zz', :cover?, 'aa'...'zzz')
assert_not_operator(1..10, :cover?, 1...10.1)
+
+ assert_operator(..2, :cover?, 1)
+ assert_operator(..2, :cover?, 2)
+ assert_not_operator(..2, :cover?, 3)
+ assert_not_operator(...2, :cover?, 2)
+ assert_not_operator(..2, :cover?, "2")
+ assert_operator(..2, :cover?, ..2)
+ assert_operator(..2, :cover?, ...2)
+ assert_not_operator(..2, :cover?, .."2")
+ assert_not_operator(...2, :cover?, ..2)
+
+ assert_not_operator(2.., :cover?, 1)
+ assert_operator(2.., :cover?, 2)
+ assert_operator(2..., :cover?, 3)
+ assert_operator(2.., :cover?, 2)
+ assert_not_operator(2.., :cover?, "2")
+ assert_operator(2.., :cover?, 2..)
+ assert_operator(2.., :cover?, 2...)
+ assert_not_operator(2.., :cover?, "2"..)
+ assert_not_operator(2..., :cover?, 2..)
+ assert_operator(2..., :cover?, 3...)
+ assert_not_operator(2..., :cover?, 3..)
+ assert_not_operator(3.., :cover?, 2..)
+
+ assert_operator(nil..., :cover?, Object.new)
+ assert_operator(nil..., :cover?, nil...)
+ assert_operator(nil.., :cover?, nil...)
+ assert_not_operator(nil..., :cover?, nil..)
+ assert_not_operator(nil..., :cover?, 1..)
end
def test_beg_len
diff --git a/test/ruby/test_refinement.rb b/test/ruby/test_refinement.rb
index c0754d8cf0..56f33ae00a 100644
--- a/test/ruby/test_refinement.rb
+++ b/test/ruby/test_refinement.rb
@@ -1206,6 +1206,41 @@ class TestRefinement < Test::Unit::TestCase
INPUT
end
+ def test_refined_protected_methods
+ assert_separately([], <<-"end;")
+ bug18806 = '[ruby-core:108705] [Bug #18806]'
+ class C; end
+
+ module R
+ refine C do
+ def refined_call_foo = foo
+ def refined_call_foo_on(other) = other.foo
+
+ protected
+
+ def foo = :foo
+ end
+ end
+
+ class C
+ using R
+
+ def call_foo = foo
+ def call_foo_on(other) = other.foo
+ end
+
+ c = C.new
+ assert_equal :foo, c.call_foo, bug18806
+ assert_equal :foo, c.call_foo_on(c), bug18806
+ assert_equal :foo, c.call_foo_on(C.new), bug18806
+
+ using R
+ assert_equal :foo, c.refined_call_foo, bug18806
+ assert_equal :foo, c.refined_call_foo_on(c), bug18806
+ assert_equal :foo, c.refined_call_foo_on(C.new), bug18806
+ end;
+ end
+
def test_refine_basic_object
assert_separately([], <<-"end;")
bug10106 = '[ruby-core:64166] [Bug #10106]'
diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb
index 84687c5380..1d93d1a5b1 100644
--- a/test/ruby/test_regexp.rb
+++ b/test/ruby/test_regexp.rb
@@ -91,6 +91,59 @@ class TestRegexp < Test::Unit::TestCase
assert_warn('', '[ruby-core:82328] [Bug #13798]') {re.to_s}
end
+ def test_extended_comment_invalid_escape_bug_18294
+ assert_separately([], <<-RUBY)
+ re = / C:\\\\[a-z]{5} # e.g. C:\\users /x
+ assert_match(re, 'C:\\users')
+ assert_not_match(re, 'C:\\user')
+
+ re = /
+ foo # \\M-ca
+ bar
+ /x
+ assert_match(re, 'foobar')
+ assert_not_match(re, 'foobaz')
+
+ re = /
+ f[#o]o # \\M-ca
+ bar
+ /x
+ assert_match(re, 'foobar')
+ assert_not_match(re, 'foobaz')
+
+ re = /
+ f[[:alnum:]#]o # \\M-ca
+ bar
+ /x
+ assert_match(re, 'foobar')
+ assert_not_match(re, 'foobaz')
+
+ re = /
+ f(?# \\M-ca)oo # \\M-ca
+ bar
+ /x
+ assert_match(re, 'foobar')
+ assert_not_match(re, 'foobaz')
+
+ re = /f(?# \\M-ca)oobar/
+ assert_match(re, 'foobar')
+ assert_not_match(re, 'foobaz')
+
+ re = /[-(?# fca)]oobar/
+ assert_match(re, 'foobar')
+ assert_not_match(re, 'foobaz')
+
+ re = /f(?# ca\0\\M-ca)oobar/
+ assert_match(re, 'foobar')
+ assert_not_match(re, 'foobaz')
+ RUBY
+
+ assert_raise(SyntaxError) {eval "/\\users/x"}
+ assert_raise(SyntaxError) {eval "/[\\users]/x"}
+ assert_raise(SyntaxError) {eval "/(?<\\users)/x"}
+ assert_raise(SyntaxError) {eval "/# \\users/"}
+ end
+
def test_union
assert_equal :ok, begin
Regexp.union(
@@ -575,6 +628,29 @@ class TestRegexp < Test::Unit::TestCase
assert_raise(RegexpError) { Regexp.new("((?<v>))\\g<0>") }
end
+ def test_initialize_bool_warning
+ assert_warning(/expected true or false as ignorecase/) do
+ Regexp.new("foo", :i)
+ end
+ end
+
+ def test_initialize_option
+ assert_equal(//i, Regexp.new("", "i"))
+ assert_equal(//m, Regexp.new("", "m"))
+ assert_equal(//x, Regexp.new("", "x"))
+ assert_equal(//imx, Regexp.new("", "imx"))
+ assert_equal(//, Regexp.new("", ""))
+ assert_equal(//imx, Regexp.new("", "mimix"))
+
+ assert_raise(ArgumentError) { Regexp.new("", "e") }
+ assert_raise(ArgumentError) { Regexp.new("", "n") }
+ assert_raise(ArgumentError) { Regexp.new("", "s") }
+ assert_raise(ArgumentError) { Regexp.new("", "u") }
+ assert_raise(ArgumentError) { Regexp.new("", "o") }
+ assert_raise(ArgumentError) { Regexp.new("", "j") }
+ assert_raise(ArgumentError) { Regexp.new("", "xmen") }
+ end
+
def test_match_control_meta_escape
assert_equal(0, /\c\xFF/ =~ "\c\xFF")
assert_equal(0, /\c\M-\xFF/ =~ "\c\M-\xFF")
diff --git a/test/ruby/test_require.rb b/test/ruby/test_require.rb
index 5a24cb1ba5..604ddf09d8 100644
--- a/test/ruby/test_require.rb
+++ b/test/ruby/test_require.rb
@@ -824,6 +824,8 @@ class TestRequire < Test::Unit::TestCase
end if File.respond_to?(:mkfifo)
def test_loading_fifo_threading_success
+ omit "[Bug #18613]" if /freebsd/=~ RUBY_PLATFORM
+
Tempfile.create(%w'fifo .rb') {|f|
f.close
File.unlink(f.path)
diff --git a/test/ruby/test_rubyoptions.rb b/test/ruby/test_rubyoptions.rb
index ab15006e4c..ed2bc3538c 100644
--- a/test/ruby/test_rubyoptions.rb
+++ b/test/ruby/test_rubyoptions.rb
@@ -7,12 +7,13 @@ require 'tempfile'
require_relative '../lib/jit_support'
class TestRubyOptions < Test::Unit::TestCase
+ def self.mjit_enabled? = defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled?
def self.yjit_enabled? = defined?(RubyVM::YJIT.enabled?) && RubyVM::YJIT.enabled?
NO_JIT_DESCRIPTION =
- if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? # checking -DMJIT_FORCE_ENABLE
+ if mjit_enabled?
RUBY_DESCRIPTION.sub(/\+MJIT /, '')
- elsif yjit_enabled? # checking -DYJIT_FORCE_ENABLE
+ elsif yjit_enabled?
RUBY_DESCRIPTION.sub(/\+YJIT /, '')
else
RUBY_DESCRIPTION
@@ -148,7 +149,7 @@ class TestRubyOptions < Test::Unit::TestCase
def test_verbose
assert_in_out_err([{'RUBY_YJIT_ENABLE' => nil}, "-vve", ""]) do |r, e|
assert_match(VERSION_PATTERN, r[0])
- if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? && !mjit_force_enabled? # checking -DMJIT_FORCE_ENABLE
+ if self.class.mjit_enabled? && !JITSupport.mjit_force_enabled?
assert_equal(NO_JIT_DESCRIPTION, r[0])
elsif self.class.yjit_enabled? && !yjit_force_enabled? # checking -DYJIT_FORCE_ENABLE
assert_equal(NO_JIT_DESCRIPTION, r[0])
@@ -216,7 +217,7 @@ class TestRubyOptions < Test::Unit::TestCase
assert_match(VERSION_PATTERN, r[0])
if ENV['RUBY_YJIT_ENABLE'] == '1'
assert_equal(NO_JIT_DESCRIPTION, r[0])
- elsif defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? || self.class.yjit_enabled? # checking -D(M|Y)JIT_FORCE_ENABLE
+ elsif self.class.mjit_enabled? || self.class.yjit_enabled? # checking -D(M|Y)JIT_FORCE_ENABLE
assert_equal(EnvUtil.invoke_ruby(['-e', 'print RUBY_DESCRIPTION'], '', true).first, r[0])
else
assert_equal(RUBY_DESCRIPTION, r[0])
@@ -257,7 +258,7 @@ class TestRubyOptions < Test::Unit::TestCase
].each do |args|
assert_in_out_err([env] + args) do |r, e|
assert_match(VERSION_PATTERN_WITH_JIT, r[0])
- if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? # checking -DMJIT_FORCE_ENABLE
+ if JITSupport.mjit_force_enabled?
assert_equal(RUBY_DESCRIPTION, r[0])
else
assert_equal(EnvUtil.invoke_ruby([env, '--mjit', '-e', 'print RUBY_DESCRIPTION'], '', true).first, r[0])
@@ -740,7 +741,7 @@ class TestRubyOptions < Test::Unit::TestCase
-e:(?:1:)?\s\[BUG\]\sSegmentation\sfault.*\n
)x,
%r(
- #{ Regexp.quote(NO_JIT_DESCRIPTION) }\n\n
+ #{ Regexp.quote((TestRubyOptions.mjit_enabled? && !JITSupport.mjit_force_enabled?) ? NO_JIT_DESCRIPTION : RUBY_DESCRIPTION) }\n\n
)x,
%r(
(?:--\s(?:.+\n)*\n)?
@@ -777,6 +778,10 @@ class TestRubyOptions < Test::Unit::TestCase
def assert_segv(args, message=nil)
omit if ENV['RUBY_ON_BUG']
+ # We want YJIT to be enabled in the subprocess if it's enabled for us
+ # so that the Ruby description matches.
+ args.unshift("--yjit") if self.class.yjit_enabled?
+
test_stdin = ""
opt = SEGVTest::ExecOptions.dup
list = SEGVTest::ExpectedStderrList
@@ -1132,10 +1137,6 @@ class TestRubyOptions < Test::Unit::TestCase
private
- def mjit_force_enabled?
- "#{RbConfig::CONFIG['CFLAGS']} #{RbConfig::CONFIG['CPPFLAGS']}".match?(/(\A|\s)-D ?MJIT_FORCE_ENABLE\b/)
- end
-
def yjit_force_enabled?
"#{RbConfig::CONFIG['CFLAGS']} #{RbConfig::CONFIG['CPPFLAGS']}".match?(/(\A|\s)-D ?YJIT_FORCE_ENABLE\b/)
end
diff --git a/test/ruby/test_rubyvm_mjit.rb b/test/ruby/test_rubyvm_mjit.rb
index 94b773c4e6..8ca0fb9ef2 100644
--- a/test/ruby/test_rubyvm_mjit.rb
+++ b/test/ruby/test_rubyvm_mjit.rb
@@ -51,6 +51,19 @@ class TestRubyVMMJIT < Test::Unit::TestCase
) unless RUBY_PLATFORM.match?(/mswin|mingw/) # compaction is not supported on Windows yet
end
+ def test_pause_after_waitall
+ out, err = eval_with_jit(<<~'EOS', verbose: 1, min_calls: 1, wait: false)
+ def test() = nil
+ test
+ Process.waitall
+ print RubyVM::MJIT.pause
+ EOS
+ assert_equal(
+ 1, err.scan(/#{JITSupport::JIT_SUCCESS_PREFIX}/).size,
+ "unexpected stdout:\n```\n#{out}```\n\nstderr:\n```\n#{err}```",
+ )
+ end
+
def test_pause_does_not_hang_on_full_units
out, _ = eval_with_jit(<<~'EOS', verbose: 1, min_calls: 1, max_cache: 10, wait: false)
i = 0
@@ -74,7 +87,11 @@ class TestRubyVMMJIT < Test::Unit::TestCase
print RubyVM::MJIT.pause(wait: false)
EOS
assert_equal('truefalse', out)
- assert_equal(true, err.scan(/#{JITSupport::JIT_SUCCESS_PREFIX}/).size < 10)
+ if RUBY_PLATFORM.match?(/mswin|mingw/) # MJIT synchronously compiles methods on Windows
+ assert_equal(10, err.scan(/#{JITSupport::JIT_SUCCESS_PREFIX}/).size)
+ else
+ assert_equal(true, err.scan(/#{JITSupport::JIT_SUCCESS_PREFIX}/).size < 10)
+ end
end
def test_resume
diff --git a/test/ruby/test_settracefunc.rb b/test/ruby/test_settracefunc.rb
index b43f9c114d..31946c8b71 100644
--- a/test/ruby/test_settracefunc.rb
+++ b/test/ruby/test_settracefunc.rb
@@ -2140,17 +2140,16 @@ CODE
m2t_q.push 1
t.join
- assert_equal ["c-return", base_line + 31], events[0]
- assert_equal ["line", base_line + 32], events[1]
- assert_equal ["line", base_line + 33], events[2]
- assert_equal ["call", base_line + -6], events[3]
- assert_equal ["return", base_line + -4], events[4]
- assert_equal ["line", base_line + 34], events[5]
- assert_equal ["line", base_line + 35], events[6]
- assert_equal ["c-call", base_line + 35], events[7] # Thread.current
- assert_equal ["c-return", base_line + 35], events[8] # Thread.current
- assert_equal ["c-call", base_line + 35], events[9] # Thread#set_trace_func
- assert_equal nil, events[10]
+ assert_equal ["line", base_line + 32], events[0]
+ assert_equal ["line", base_line + 33], events[1]
+ assert_equal ["call", base_line + -6], events[2]
+ assert_equal ["return", base_line + -4], events[3]
+ assert_equal ["line", base_line + 34], events[4]
+ assert_equal ["line", base_line + 35], events[5]
+ assert_equal ["c-call", base_line + 35], events[6] # Thread.current
+ assert_equal ["c-return", base_line + 35], events[7] # Thread.current
+ assert_equal ["c-call", base_line + 35], events[8] # Thread#set_trace_func
+ assert_equal nil, events[9]
end
def test_lineno_in_optimized_insn
@@ -2364,6 +2363,28 @@ CODE
assert_equal [:tp1, 1, 2, :tp2, 3], events
end
+ def test_multiple_tracepoints_same_bmethod
+ events = []
+ tp1 = TracePoint.new(:return) do |tp|
+ events << :tp1
+ end
+ tp2 = TracePoint.new(:return) do |tp|
+ events << :tp2
+ end
+
+ obj = Object.new
+ obj.define_singleton_method(:foo) {}
+ bmethod = obj.method(:foo)
+
+ tp1.enable(target: bmethod) do
+ tp2.enable(target: bmethod) do
+ obj.foo
+ end
+ end
+
+ assert_equal([:tp2, :tp1], events, '[Bug #18031]')
+ end
+
def test_script_compiled
events = []
tp = TracePoint.new(:script_compiled){|tp|
@@ -2561,6 +2582,20 @@ CODE
end
bar
EOS
+
+ assert_normal_exit(<<-EOS, 'Bug #18730')
+ def bar
+ 42
+ end
+ tp_line = TracePoint.new(:line) do |tp0|
+ tp_multi1 = TracePoint.new(:return, :b_return, :line) do |tp|
+ tp0.disable
+ end
+ tp_multi1.enable
+ end
+ tp_line.enable(target: method(:bar))
+ bar
+ EOS
end
def test_stat_exists
@@ -2620,4 +2655,31 @@ CODE
TracePoint.allow_reentry{}
end
end
+
+ def test_raising_from_b_return_tp_tracing_bmethod
+ assert_normal_exit(<<~RUBY, '[Bug #18060]', timeout: 3)
+ class Foo
+ define_singleton_method(:foo) { return } # a bmethod
+ end
+
+ TracePoint.trace(:b_return) do |tp|
+ raise
+ end
+
+ Foo.foo
+ RUBY
+
+ # Same thing but with a target
+ assert_normal_exit(<<~RUBY, '[Bug #18060]', timeout: 3)
+ class Foo
+ define_singleton_method(:foo) { return } # a bmethod
+ end
+
+ TracePoint.new(:b_return) do |tp|
+ raise
+ end.enable(target: Foo.method(:foo))
+
+ Foo.foo
+ RUBY
+ end
end
diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb
index d96e8dff22..ab14a3c17b 100644
--- a/test/ruby/test_string.rb
+++ b/test/ruby/test_string.rb
@@ -1121,14 +1121,19 @@ CODE
assert_equal(S("world"), res[1])
res = []
- S("hello\n\n\nworld").each_line(S(''), chomp: true) {|x| res << x}
- assert_equal(S("hello\n"), res[0])
- assert_equal(S("world"), res[1])
+ S("hello\n\n\nworld\n").each_line(S(''), chomp: true) {|x| res << x}
+ assert_equal(S("hello"), res[0])
+ assert_equal(S("world\n"), res[1])
res = []
- S("hello\r\n\r\nworld").each_line(S(''), chomp: true) {|x| res << x}
- assert_equal(S("hello\r\n"), res[0])
- assert_equal(S("world"), res[1])
+ S("hello\r\n\r\nworld\r\n").each_line(S(''), chomp: true) {|x| res << x}
+ assert_equal(S("hello"), res[0])
+ assert_equal(S("world\r\n"), res[1])
+
+ res = []
+ S("hello\r\n\n\nworld").each_line(S(''), chomp: true) {|x| res << x}
+ assert_equal(S("hello"), res[0])
+ assert_equal(S("world"), res[1])
res = []
S("hello!world").each_line(S('!'), chomp: true) {|x| res << x}
@@ -2609,6 +2614,11 @@ CODE
assert_equal '"\x0012"', s.inspect, bug8290
end
+ def test_inspect_next_line
+ bug16842 = '[ruby-core:98231]'
+ assert_equal '"\\u0085"', 0x85.chr(Encoding::UTF_8).inspect, bug16842
+ end
+
def test_partition
assert_equal(%w(he l lo), S("hello").partition(/l/))
assert_equal(%w(he l lo), S("hello").partition("l"))
diff --git a/test/ruby/test_symbol.rb b/test/ruby/test_symbol.rb
index f7f17b8d67..1d2a18d734 100644
--- a/test/ruby/test_symbol.rb
+++ b/test/ruby/test_symbol.rb
@@ -36,6 +36,19 @@ class TestSymbol < Test::Unit::TestCase
assert_eval_inspected(:"@@1", false)
assert_eval_inspected(:"@", false)
assert_eval_inspected(:"@@", false)
+ assert_eval_inspected(:"[]=")
+ assert_eval_inspected(:"[][]", false)
+ assert_eval_inspected(:"[][]=", false)
+ assert_eval_inspected(:"@=", false)
+ assert_eval_inspected(:"@@=", false)
+ assert_eval_inspected(:"@x=", false)
+ assert_eval_inspected(:"@@x=", false)
+ assert_eval_inspected(:"$$=", false)
+ assert_eval_inspected(:"$==", false)
+ assert_eval_inspected(:"$x=", false)
+ assert_eval_inspected(:"$$$=", false)
+ assert_eval_inspected(:"foo?=", false)
+ assert_eval_inspected(:"foo!=", false)
end
def assert_inspect_evaled(n)
diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb
index b1fa3e5227..b0ad012131 100644
--- a/test/ruby/test_syntax.rb
+++ b/test/ruby/test_syntax.rb
@@ -66,6 +66,15 @@ class TestSyntax < Test::Unit::TestCase
f&.close!
end
+ def test_script_lines_encoding
+ require 'tmpdir'
+ Dir.mktmpdir do |dir|
+ File.write(File.join(dir, "script_lines.rb"), "SCRIPT_LINES__ = {}\n")
+ assert_in_out_err(%w"-r./script_lines -w -Ke", "puts __ENCODING__.name",
+ %w"EUC-JP", /-K is specified/, chdir: dir)
+ end
+ end
+
def test_anonymous_block_forwarding
assert_syntax_error("def b; c(&); end", /no anonymous block parameter/)
assert_separately([], "#{<<-"begin;"}\n#{<<-'end;'}")
@@ -1898,6 +1907,21 @@ eom
assert_equal 0...1, exp.call(a: 0)
end
+ def test_class_module_Object_ancestors
+ assert_separately([], <<-RUBY)
+ m = Module.new
+ m::Bug18832 = 1
+ include m
+ class Bug18832; end
+ RUBY
+ assert_separately([], <<-RUBY)
+ m = Module.new
+ m::Bug18832 = 1
+ include m
+ module Bug18832; end
+ RUBY
+ end
+
def test_cdhash
assert_separately([], <<-RUBY)
n = case 1 when 2r then false else true end
diff --git a/test/ruby/test_thread.rb b/test/ruby/test_thread.rb
index ddb4516b3c..f6156a16fd 100644
--- a/test/ruby/test_thread.rb
+++ b/test/ruby/test_thread.rb
@@ -29,13 +29,19 @@ class TestThread < Test::Unit::TestCase
end
def test_inspect
+ m = Thread::Mutex.new
+ m.lock
line = __LINE__+1
- th = Module.new {break module_eval("class C\u{30b9 30ec 30c3 30c9} < Thread; self; end")}.start{}
+ th = Module.new {break module_eval("class C\u{30b9 30ec 30c3 30c9} < Thread; self; end")}.start do
+ m.synchronize {}
+ end
+ Thread.pass until th.stop?
s = th.inspect
assert_include(s, "::C\u{30b9 30ec 30c3 30c9}:")
assert_include(s, " #{__FILE__}:#{line} ")
assert_equal(s, th.to_s)
ensure
+ m.unlock
th.join
end
@@ -966,6 +972,8 @@ _eom
end
def test_thread_timer_and_interrupt
+ omit "[Bug #18613]" if /freebsd/ =~ RUBY_PLATFORM
+
bug5757 = '[ruby-dev:44985]'
pid = nil
cmd = 'Signal.trap(:INT, "DEFAULT"); pipe=IO.pipe; Thread.start {Thread.pass until Thread.main.stop?; puts; STDOUT.flush}; pipe[0].read'
@@ -1244,6 +1252,20 @@ q.pop
assert_predicate(status, :success?, bug9751)
end if Process.respond_to?(:fork)
+ def test_fork_value
+ bug18902 = "[Bug #18902]"
+ th = Thread.start { sleep 2 }
+ begin
+ pid = fork do
+ th.value
+ end
+ _, status = Process.wait2(pid)
+ assert_predicate(status, :success?, bug18902)
+ ensure
+ th.kill
+ end
+ end if Process.respond_to?(:fork)
+
def test_fork_while_locked
m = Thread::Mutex.new
thrs = []
@@ -1442,6 +1464,11 @@ q.pop
omit "can't trap a signal from another process on Windows"
# opt = {new_pgroup: true}
end
+
+ if /freebsd/ =~ RUBY_PLATFORM
+ omit "[Bug #18613]"
+ end
+
assert_separately([], "#{<<~"{#"}\n#{<<~'};'}", timeout: 120)
{#
n = 1000
diff --git a/test/ruby/test_thread_queue.rb b/test/ruby/test_thread_queue.rb
index 69cb40711c..1c852474b4 100644
--- a/test/ruby/test_thread_queue.rb
+++ b/test/ruby/test_thread_queue.rb
@@ -111,6 +111,23 @@ class TestThreadQueue < Test::Unit::TestCase
assert_equal(0, q.num_waiting)
end
+ def test_queue_pop_timeout
+ q = Thread::Queue.new
+ q << 1
+ assert_equal 1, q.pop(timeout: 1)
+
+ t1 = Thread.new { q.pop(timeout: 1) }
+ assert_equal t1, t1.join(2)
+ assert_nil t1.value
+
+ t2 = Thread.new { q.pop(timeout: 0.1) }
+ assert_equal t2, t2.join(1)
+ assert_nil t2.value
+ ensure
+ t1&.kill&.join
+ t2&.kill&.join
+ end
+
def test_queue_pop_non_block
q = Thread::Queue.new
assert_raise_with_message(ThreadError, /empty/) do
@@ -126,6 +143,24 @@ class TestThreadQueue < Test::Unit::TestCase
assert_equal(0, q.num_waiting)
end
+ def test_sized_queue_pop_timeout
+ q = Thread::SizedQueue.new(1)
+
+ q << 1
+ assert_equal 1, q.pop(timeout: 1)
+
+ t1 = Thread.new { q.pop(timeout: 1) }
+ assert_equal t1, t1.join(2)
+ assert_nil t1.value
+
+ t2 = Thread.new { q.pop(timeout: 0.1) }
+ assert_equal t2, t2.join(1)
+ assert_nil t2.value
+ ensure
+ t1&.kill&.join
+ t2&.kill&.join
+ end
+
def test_sized_queue_pop_non_block
q = Thread::SizedQueue.new(1)
assert_raise_with_message(ThreadError, /empty/) do
@@ -151,6 +186,8 @@ class TestThreadQueue < Test::Unit::TestCase
end
def test_thr_kill
+ omit "[Bug #18613]" if /freebsd/ =~ RUBY_PLATFORM
+
bug5343 = '[ruby-core:39634]'
Dir.mktmpdir {|d|
timeout = EnvUtil.apply_timeout_scale(60)
diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb
index 8300681fe5..4af4cf5474 100644
--- a/test/ruby/test_time.rb
+++ b/test/ruby/test_time.rb
@@ -53,6 +53,8 @@ class TestTime < Test::Unit::TestCase
assert_raise_with_message(ArgumentError, msg) { Time.new(2021, 1, 1, "+09:99") }
assert_raise_with_message(ArgumentError, msg) { Time.new(2021, 1, "+09:99") }
assert_raise_with_message(ArgumentError, msg) { Time.new(2021, "+09:99") }
+
+ assert_equal([0, 0, 0, 2, 1, 2000], Time.new(2000, 1, 1, 24, 0, 0, "-00:00").to_a[0, 6])
end
def test_time_add()
diff --git a/test/ruby/test_yjit.rb b/test/ruby/test_yjit.rb
index 1d93ac9b59..37e72dcafa 100644
--- a/test/ruby/test_yjit.rb
+++ b/test/ruby/test_yjit.rb
@@ -513,6 +513,183 @@ class TestYJIT < Test::Unit::TestCase
RUBY
end
+ def test_getblockparamproxy_with_no_block
+ # Currently side exits on the send
+ assert_compiles(<<~'RUBY', insns: [:getblockparamproxy], exits: { send: 2 })
+ def bar
+ end
+
+ def foo &blk
+ bar(&blk)
+ bar(&blk)
+ end
+
+ foo
+ foo
+ RUBY
+ end
+
+ def test_send_splat
+ assert_compiles(<<~'RUBY', result: "3#1,2,3/P", exits: {})
+ def internal_method(*args)
+ "#{args.size}##{args.join(",")}"
+ end
+
+ def jit_method
+ send(:internal_method, *[1, 2, 3]) + "/P"
+ end
+
+ jit_method
+ RUBY
+ end
+
+ def test_send_multiarg
+ assert_compiles(<<~'RUBY', result: "3#1,2,3/Q")
+ def internal_method(*args)
+ "#{args.size}##{args.join(",")}"
+ end
+
+ def jit_method
+ send(:internal_method, 1, 2, 3) + "/Q"
+ end
+
+ jit_method
+ RUBY
+ end
+
+ def test_send_kwargs
+ # For now, this side-exits when calls include keyword args
+ assert_compiles(<<~'RUBY', result: "2#a:1,b:2/A", exits: {opt_send_without_block: 1})
+ def internal_method(**kw)
+ "#{kw.size}##{kw.keys.map { |k| "#{k}:#{kw[k]}" }.join(",")}"
+ end
+
+ def jit_method
+ send(:internal_method, a: 1, b: 2) + "/A"
+ end
+ jit_method
+ RUBY
+ end
+
+ def test_send_kwargs_in_receiver_only
+ assert_compiles(<<~'RUBY', result: "0/RK", exits: {})
+ def internal_method(**kw)
+ "#{kw.size}"
+ end
+
+ def jit_method
+ send(:internal_method) + "/RK"
+ end
+ jit_method
+ RUBY
+ end
+
+ def test_send_with_underscores
+ assert_compiles(<<~'RUBY', result: "0/RK", exits: {})
+ def internal_method(**kw)
+ "#{kw.size}"
+ end
+
+ def jit_method
+ __send__(:internal_method) + "/RK"
+ end
+ jit_method
+ RUBY
+ end
+
+ def test_send_kwargs_splat
+ # For now, this side-exits when calling with a splat
+ assert_compiles(<<~'RUBY', result: "2#a:1,b:2/B", exits: {opt_send_without_block: 1})
+ def internal_method(**kw)
+ "#{kw.size}##{kw.keys.map { |k| "#{k}:#{kw[k]}" }.join(",")}"
+ end
+
+ def jit_method
+ send(:internal_method, **{ a: 1, b: 2 }) + "/B"
+ end
+ jit_method
+ RUBY
+ end
+
+ def test_send_block
+ # Setlocal_wc_0 sometimes side-exits on write barrier
+ assert_compiles(<<~'RUBY', result: "b:n/b:y/b:y/b:n", exits: { :setlocal_WC_0 => 0..1 })
+ def internal_method(&b)
+ "b:#{block_given? ? "y" : "n"}"
+ end
+
+ def jit_method
+ b7 = proc { 7 }
+ [
+ send(:internal_method),
+ send(:internal_method, &b7),
+ send(:internal_method) { 7 },
+ send(:internal_method, &nil),
+ ].join("/")
+ end
+ jit_method
+ RUBY
+ end
+
+ def test_send_block_calling
+ assert_compiles(<<~'RUBY', result: "1a2", exits: {})
+ def internal_method
+ out = yield
+ "1" + out + "2"
+ end
+
+ def jit_method
+ __send__(:internal_method) { "a" }
+ end
+ jit_method
+ RUBY
+ end
+
+ def test_send_block_only_receiver
+ assert_compiles(<<~'RUBY', result: "b:n", exits: {})
+ def internal_method(&b)
+ "b:#{block_given? ? "y" : "n"}"
+ end
+
+ def jit_method
+ send(:internal_method)
+ end
+ jit_method
+ RUBY
+ end
+
+ def test_send_block_only_sender
+ assert_compiles(<<~'RUBY', result: "Y/Y/Y/Y", exits: {})
+ def internal_method
+ "Y"
+ end
+
+ def jit_method
+ b7 = proc { 7 }
+ [
+ send(:internal_method),
+ send(:internal_method, &b7),
+ send(:internal_method) { 7 },
+ send(:internal_method, &nil),
+ ].join("/")
+ end
+ jit_method
+ RUBY
+ end
+
+ def test_multisend
+ assert_compiles(<<~'RUBY', result: "77")
+ def internal_method
+ "7"
+ end
+
+ def jit_method
+ send(:send, :internal_method) + send(:send, :send, :internal_method)
+ end
+ jit_method
+ RUBY
+ end
+
def test_getivar_opt_plus
assert_no_exits(<<~RUBY)
class TheClass
@@ -708,7 +885,12 @@ class TestYJIT < Test::Unit::TestCase
recorded_exits = recorded_exits.reject { |k, v| v == 0 }
recorded_exits.transform_keys! { |k| k.to_s.gsub("exit_", "").to_sym }
- if exits != :any && exits != recorded_exits
+ # Exits can be specified as a hash of stat-name symbol to integer for exact exits.
+ # or stat-name symbol to range if the number of side exits might vary (e.g. write
+ # barriers, cache misses.)
+ if exits != :any &&
+ exits != recorded_exits &&
+ !exits.all? { |k, v| v === recorded_exits[k] } # triple-equal checks range membership or integer equality
flunk "Expected #{exits.empty? ? "no" : exits.inspect} exits" \
", but got\n#{recorded_exits.inspect}"
end
diff --git a/test/ruby/test_yjit_exit_locations.rb b/test/ruby/test_yjit_exit_locations.rb
new file mode 100644
index 0000000000..9bafe392d5
--- /dev/null
+++ b/test/ruby/test_yjit_exit_locations.rb
@@ -0,0 +1,110 @@
+# frozen_string_literal: true
+#
+# This set of tests can be run with:
+# make test-all TESTS='test/ruby/test_yjit_exit_locations.rb' RUN_OPTS="--yjit-call-threshold=1"
+
+require 'test/unit'
+require 'envutil'
+require 'tmpdir'
+require_relative '../lib/jit_support'
+
+return unless defined?(RubyVM::YJIT) && RubyVM::YJIT.enabled?
+
+# Tests for YJIT with assertions on tracing exits
+# insipired by the MJIT tests in test/ruby/test_yjit.rb
+class TestYJITExitLocations < Test::Unit::TestCase
+ def test_yjit_trace_exits_and_v_no_error
+ _stdout, stderr, _status = EnvUtil.invoke_ruby(%w(-v --yjit-trace-exits), '', true, true)
+ refute_includes(stderr, "NoMethodError")
+ end
+
+ def test_trace_exits_setclassvariable
+ script = 'class Foo; def self.foo; @@foo = 1; end; end; Foo.foo'
+ assert_exit_locations(script)
+ end
+
+ def test_trace_exits_putobject
+ assert_exit_locations('true')
+ assert_exit_locations('123')
+ assert_exit_locations(':foo')
+ end
+
+ def test_trace_exits_opt_not
+ assert_exit_locations('!false')
+ assert_exit_locations('!nil')
+ assert_exit_locations('!true')
+ assert_exit_locations('![]')
+ end
+
+ private
+
+ def assert_exit_locations(test_script)
+ write_results = <<~RUBY
+ IO.open(3).write Marshal.dump({
+ enabled: RubyVM::YJIT.trace_exit_locations_enabled?,
+ exit_locations: RubyVM::YJIT.exit_locations
+ })
+ RUBY
+
+ script = <<~RUBY
+ _test_proc = -> {
+ #{test_script}
+ }
+ result = _test_proc.call
+ #{write_results}
+ RUBY
+
+ run_script = eval_with_jit(script)
+ # If stats are disabled when configuring, --yjit-exit-locations
+ # can't be true. We don't want to check if exit_locations hash
+ # is not empty because that could indicate a bug in the exit
+ # locations collection.
+ return unless run_script[:enabled]
+ exit_locations = run_script[:exit_locations]
+
+ assert exit_locations.key?(:raw)
+ assert exit_locations.key?(:frames)
+ assert exit_locations.key?(:lines)
+ assert exit_locations.key?(:samples)
+ assert exit_locations.key?(:missed_samples)
+ assert exit_locations.key?(:gc_samples)
+
+ assert_equal 0, exit_locations[:missed_samples]
+ assert_equal 0, exit_locations[:gc_samples]
+
+ assert_not_empty exit_locations[:raw]
+ assert_not_empty exit_locations[:frames]
+ assert_not_empty exit_locations[:lines]
+
+ exit_locations[:frames].each do |frame_id, frame|
+ assert frame.key?(:name)
+ assert frame.key?(:file)
+ assert frame.key?(:samples)
+ assert frame.key?(:total_samples)
+ assert frame.key?(:edges)
+ end
+ end
+
+ def eval_with_jit(script)
+ args = [
+ "--disable-gems",
+ "--yjit-call-threshold=1",
+ "--yjit-trace-exits"
+ ]
+ args << "-e" << script_shell_encode(script)
+ stats_r, stats_w = IO.pipe
+ _out, _err, _status = EnvUtil.invoke_ruby(args,
+ '', true, true, timeout: 1000, ios: { 3 => stats_w }
+ )
+ stats_w.close
+ stats = stats_r.read
+ stats = Marshal.load(stats) if !stats.empty?
+ stats_r.close
+ stats
+ end
+
+ def script_shell_encode(s)
+ # We can't pass utf-8-encoded characters directly in a shell arg. But we can use Ruby \u constants.
+ s.chars.map { |c| c.ascii_only? ? c : "\\u%x" % c.codepoints[0] }.join
+ end
+end
diff --git a/test/rubygems/data/excon-0.7.7.gemspec.rz b/test/rubygems/data/excon-0.7.7.gemspec.rz
new file mode 100644
index 0000000000..159bd4bb1c
--- /dev/null
+++ b/test/rubygems/data/excon-0.7.7.gemspec.rz
Binary files differ
diff --git a/test/rubygems/data/null-type.gemspec.rz b/test/rubygems/data/null-type.gemspec.rz
deleted file mode 100644
index 2134fcde29..0000000000
--- a/test/rubygems/data/null-type.gemspec.rz
+++ /dev/null
Binary files differ
diff --git a/test/rubygems/data/pry-0.4.7.gemspec.rz b/test/rubygems/data/pry-0.4.7.gemspec.rz
new file mode 100644
index 0000000000..58fc1ed8a0
--- /dev/null
+++ b/test/rubygems/data/pry-0.4.7.gemspec.rz
Binary files differ
diff --git a/test/rubygems/helper.rb b/test/rubygems/helper.rb
index c03ce7e6c6..cb0177adb2 100644
--- a/test/rubygems/helper.rb
+++ b/test/rubygems/helper.rb
@@ -1,9 +1,9 @@
# frozen_string_literal: true
-require 'rubygems'
+require "rubygems"
# If bundler gemspec exists, add to stubs
-bundler_gemspec = File.expand_path('../../bundler/bundler.gemspec', __dir__)
+bundler_gemspec = File.expand_path("../../bundler/bundler.gemspec", __dir__)
if File.exist?(bundler_gemspec)
Gem::Specification.dirs.unshift File.dirname(bundler_gemspec)
Gem::Specification.class_variable_set :@@stubs, nil
@@ -12,32 +12,32 @@ if File.exist?(bundler_gemspec)
end
begin
- gem 'test-unit', '~> 3.0'
+ gem "test-unit", "~> 3.0"
rescue Gem::LoadError
end
if File.exist?(bundler_gemspec)
- require_relative '../../bundler/lib/bundler'
+ require_relative "../../bundler/lib/bundler"
else
- require 'bundler'
+ require "bundler"
end
-require 'test/unit'
+require "test/unit"
ENV["JARS_SKIP"] = "true" if Gem.java_platform? # avoid unnecessary and noisy `jar-dependencies` post install hook
-require 'rubygems/deprecate'
+require "rubygems/deprecate"
-require 'fileutils'
-require 'pathname'
-require 'pp'
-require 'rubygems/package'
-require 'shellwords'
-require 'tmpdir'
-require 'uri'
-require 'zlib'
-require 'benchmark' # stdlib
-require 'rubygems/mock_gem_ui'
+require "fileutils"
+require "pathname"
+require "pp"
+require "rubygems/package"
+require "shellwords"
+require "tmpdir"
+require "uri"
+require "zlib"
+require "benchmark" # stdlib
+require "rubygems/mock_gem_ui"
module Gem
@@ -119,6 +119,12 @@ class Gem::TestCase < Test::Unit::TestCase
assert File.directory?(path), msg
end
+ def refute_directory_exists(path, msg = nil)
+ msg = build_message(msg, "Expected path '#{path}' not to be a directory")
+ assert_path_not_exist path
+ refute File.directory?(path), msg
+ end
+
# https://github.com/seattlerb/minitest/blob/21d9e804b63c619f602f3f4ece6c71b48974707a/lib/minitest/assertions.rb#L188
def _synchronize
yield
@@ -159,15 +165,15 @@ class Gem::TestCase < Test::Unit::TestCase
# the original value when the block ends
def enable_shared(value)
- enable_shared = RbConfig::CONFIG['ENABLE_SHARED']
- RbConfig::CONFIG['ENABLE_SHARED'] = value
+ enable_shared = RbConfig::CONFIG["ENABLE_SHARED"]
+ RbConfig::CONFIG["ENABLE_SHARED"] = value
yield
ensure
if enable_shared
- RbConfig::CONFIG['enable_shared'] = enable_shared
+ RbConfig::CONFIG["ENABLE_SHARED"] = enable_shared
else
- RbConfig::CONFIG.delete 'enable_shared'
+ RbConfig::CONFIG.delete "ENABLE_SHARED"
end
end
@@ -176,20 +182,20 @@ class Gem::TestCase < Test::Unit::TestCase
# original value when the block ends
#
def vendordir(value)
- vendordir = RbConfig::CONFIG['vendordir']
+ vendordir = RbConfig::CONFIG["vendordir"]
if value
- RbConfig::CONFIG['vendordir'] = value
+ RbConfig::CONFIG["vendordir"] = value
else
- RbConfig::CONFIG.delete 'vendordir'
+ RbConfig::CONFIG.delete "vendordir"
end
yield
ensure
if vendordir
- RbConfig::CONFIG['vendordir'] = vendordir
+ RbConfig::CONFIG["vendordir"] = vendordir
else
- RbConfig::CONFIG.delete 'vendordir'
+ RbConfig::CONFIG.delete "vendordir"
end
end
@@ -199,21 +205,21 @@ class Gem::TestCase < Test::Unit::TestCase
#
def bindir(value)
with_clean_path_to_ruby do
- bindir = RbConfig::CONFIG['bindir']
+ bindir = RbConfig::CONFIG["bindir"]
if value
- RbConfig::CONFIG['bindir'] = value
+ RbConfig::CONFIG["bindir"] = value
else
- RbConfig::CONFIG.delete 'bindir'
+ RbConfig::CONFIG.delete "bindir"
end
begin
yield
ensure
if bindir
- RbConfig::CONFIG['bindir'] = bindir
+ RbConfig::CONFIG["bindir"] = bindir
else
- RbConfig::CONFIG.delete 'bindir'
+ RbConfig::CONFIG.delete "bindir"
end
end
end
@@ -224,20 +230,20 @@ class Gem::TestCase < Test::Unit::TestCase
# original value when the block ends
#
def exeext(value)
- exeext = RbConfig::CONFIG['EXEEXT']
+ exeext = RbConfig::CONFIG["EXEEXT"]
if value
- RbConfig::CONFIG['EXEEXT'] = value
+ RbConfig::CONFIG["EXEEXT"] = value
else
- RbConfig::CONFIG.delete 'EXEEXT'
+ RbConfig::CONFIG.delete "EXEEXT"
end
yield
ensure
if exeext
- RbConfig::CONFIG['EXEEXT'] = exeext
+ RbConfig::CONFIG["EXEEXT"] = exeext
else
- RbConfig::CONFIG.delete 'EXEEXT'
+ RbConfig::CONFIG.delete "EXEEXT"
end
end
@@ -258,23 +264,23 @@ class Gem::TestCase < Test::Unit::TestCase
end
end
- targets << '' if targets.empty?
+ targets << "" if targets.empty?
targets
end
def assert_contains_make_command(target, output, msg = nil)
- if output.match(/\n/)
+ if output.include?("\n")
msg = build_message(msg,
"Expected output containing make command \"%s\", but was \n\nBEGIN_OF_OUTPUT\n%sEND_OF_OUTPUT" % [
- ('%s %s' % [make_command, target]).rstrip,
+ ("%s %s" % [make_command, target]).rstrip,
output,
]
)
else
msg = build_message(msg,
'Expected make command "%s", but was "%s"' % [
- ('%s %s' % [make_command, target]).rstrip,
+ ("%s %s" % [make_command, target]).rstrip,
output,
]
)
@@ -311,13 +317,13 @@ class Gem::TestCase < Test::Unit::TestCase
@tempdir = Dir.mktmpdir("test_rubygems_", @tmp)
@tempdir.tap(&Gem::UNTAINT)
- ENV['GEM_VENDOR'] = nil
- ENV['GEMRC'] = nil
- ENV['XDG_CACHE_HOME'] = nil
- ENV['XDG_CONFIG_HOME'] = nil
- ENV['XDG_DATA_HOME'] = nil
- ENV['SOURCE_DATE_EPOCH'] = nil
- ENV['BUNDLER_VERSION'] = nil
+ ENV["GEM_VENDOR"] = nil
+ ENV["GEMRC"] = nil
+ ENV["XDG_CACHE_HOME"] = nil
+ ENV["XDG_CONFIG_HOME"] = nil
+ ENV["XDG_DATA_HOME"] = nil
+ ENV["SOURCE_DATE_EPOCH"] = nil
+ ENV["BUNDLER_VERSION"] = nil
@current_dir = Dir.pwd
@fetcher = nil
@@ -333,19 +339,19 @@ class Gem::TestCase < Test::Unit::TestCase
@orig_SYSTEM_WIDE_CONFIG_FILE = Gem::ConfigFile::SYSTEM_WIDE_CONFIG_FILE
Gem::ConfigFile.send :remove_const, :SYSTEM_WIDE_CONFIG_FILE
Gem::ConfigFile.send :const_set, :SYSTEM_WIDE_CONFIG_FILE,
- File.join(@tempdir, 'system-gemrc')
+ File.join(@tempdir, "system-gemrc")
- @gemhome = File.join @tempdir, 'gemhome'
- @userhome = File.join @tempdir, 'userhome'
- ENV["GEM_SPEC_CACHE"] = File.join @tempdir, 'spec_cache'
+ @gemhome = File.join @tempdir, "gemhome"
+ @userhome = File.join @tempdir, "userhome"
+ ENV["GEM_SPEC_CACHE"] = File.join @tempdir, "spec_cache"
- @orig_ruby = if ENV['RUBY']
+ @orig_ruby = if ENV["RUBY"]
ruby = Gem.ruby
- Gem.ruby = ENV['RUBY']
+ Gem.ruby = ENV["RUBY"]
ruby
end
- @git = ENV['GIT'] || (win_platform? ? 'git.exe' : 'git')
+ @git = ENV["GIT"] || (win_platform? ? "git.exe" : "git")
Gem.ensure_gem_subdirectories @gemhome
Gem.ensure_default_gem_subdirectories @gemhome
@@ -366,7 +372,7 @@ class Gem::TestCase < Test::Unit::TestCase
Dir.chdir @tempdir
- ENV['HOME'] = @userhome
+ ENV["HOME"] = @userhome
Gem.instance_variable_set :@config_file, nil
Gem.instance_variable_set :@user_home, nil
Gem.instance_variable_set :@config_home, nil
@@ -378,12 +384,12 @@ class Gem::TestCase < Test::Unit::TestCase
FileUtils.mkdir_p @userhome
- ENV['GEM_PRIVATE_KEY_PASSPHRASE'] = PRIVATE_KEY_PASSPHRASE
+ ENV["GEM_PRIVATE_KEY_PASSPHRASE"] = PRIVATE_KEY_PASSPHRASE
Gem.instance_variable_set(:@default_specifications_dir, nil)
if Gem.java_platform?
- @orig_default_gem_home = RbConfig::CONFIG['default_gem_home']
- RbConfig::CONFIG['default_gem_home'] = @gemhome
+ @orig_default_gem_home = RbConfig::CONFIG["default_gem_home"]
+ RbConfig::CONFIG["default_gem_home"] = @gemhome
else
Gem.instance_variable_set(:@default_dir, @gemhome)
end
@@ -419,12 +425,12 @@ class Gem::TestCase < Test::Unit::TestCase
Gem.searcher = nil
Gem::SpecFetcher.fetcher = nil
- @orig_arch = RbConfig::CONFIG['arch']
+ @orig_arch = RbConfig::CONFIG["arch"]
if win_platform?
- util_set_arch 'i386-mswin32'
+ util_set_arch "i386-mswin32"
else
- util_set_arch 'i686-darwin8.10.1'
+ util_set_arch "i686-darwin8.10.1"
end
%w[post_install_hooks done_installing_hooks post_uninstall_hooks pre_uninstall_hooks pre_install_hooks pre_reset_hooks post_reset_hooks post_build_hooks].each do |name|
@@ -451,7 +457,7 @@ class Gem::TestCase < Test::Unit::TestCase
end
end
- RbConfig::CONFIG['arch'] = @orig_arch
+ RbConfig::CONFIG["arch"] = @orig_arch
if defined? Gem::RemoteFetcher
Gem::RemoteFetcher.fetcher = nil
@@ -469,13 +475,13 @@ class Gem::TestCase < Test::Unit::TestCase
Gem.ruby = @orig_ruby if @orig_ruby
- RbConfig::CONFIG['mandir'] = @orig_mandir
- RbConfig::CONFIG['sitelibdir'] = @orig_sitelibdir
- RbConfig::CONFIG['bindir'] = @orig_bindir
+ RbConfig::CONFIG["mandir"] = @orig_mandir
+ RbConfig::CONFIG["sitelibdir"] = @orig_sitelibdir
+ RbConfig::CONFIG["bindir"] = @orig_bindir
Gem.instance_variable_set :@default_specifications_dir, nil
if Gem.java_platform?
- RbConfig::CONFIG['default_gem_home'] = @orig_default_gem_home
+ RbConfig::CONFIG["default_gem_home"] = @orig_default_gem_home
else
Gem.instance_variable_set :@default_dir, nil
end
@@ -491,9 +497,9 @@ class Gem::TestCase < Test::Unit::TestCase
end
def credential_setup
- @temp_cred = File.join(@userhome, '.gem', 'credentials')
+ @temp_cred = File.join(@userhome, ".gem", "credentials")
FileUtils.mkdir_p File.dirname(@temp_cred)
- File.write @temp_cred, ':rubygems_api_key: 701229f217cdf23b1344c7b4b54ca97'
+ File.write @temp_cred, ":rubygems_api_key: 701229f217cdf23b1344c7b4b54ca97"
File.chmod 0600, @temp_cred
end
@@ -548,10 +554,10 @@ class Gem::TestCase < Test::Unit::TestCase
#
# Yields the +specification+ to the block, if given
- def git_gem(name = 'a', version = 1)
+ def git_gem(name = "a", version = 1)
have_git?
- directory = File.join 'git', name
+ directory = File.join "git", name
directory = File.expand_path directory
git_spec = Gem::Specification.new name, version do |specification|
@@ -562,22 +568,22 @@ class Gem::TestCase < Test::Unit::TestCase
gemspec = "#{name}.gemspec"
- File.open File.join(directory, gemspec), 'w' do |io|
+ File.open File.join(directory, gemspec), "w" do |io|
io.write git_spec.to_ruby
end
head = nil
Dir.chdir directory do
- unless File.exist? '.git'
- system @git, 'init', '--quiet'
- system @git, 'config', 'user.name', 'RubyGems Tests'
- system @git, 'config', 'user.email', 'rubygems@example'
+ unless File.exist? ".git"
+ system @git, "init", "--quiet"
+ system @git, "config", "user.name", "RubyGems Tests"
+ system @git, "config", "user.email", "rubygems@example"
end
- system @git, 'add', gemspec
- system @git, 'commit', '-a', '-m', 'a non-empty commit message', '--quiet'
- head = Gem::Util.popen(@git, 'rev-parse', 'master').strip
+ system @git, "add", gemspec
+ system @git, "commit", "-a", "-m", "a non-empty commit message", "--quiet"
+ head = Gem::Util.popen(@git, "rev-parse", "master").strip
end
return name, git_spec.version, directory, head
@@ -589,13 +595,13 @@ class Gem::TestCase < Test::Unit::TestCase
def have_git?
return if in_path? @git
- pend 'cannot find git executable, use GIT environment variable to set'
+ pend "cannot find git executable, use GIT environment variable to set"
end
def in_path?(executable) # :nodoc:
- return true if %r{\A([A-Z]:|/)} =~ executable and File.exist? executable
+ return true if %r{\A([A-Z]:|/)} =~ executable && File.exist?(executable)
- ENV['PATH'].split(File::PATH_SEPARATOR).any? do |directory|
+ ENV["PATH"].split(File::PATH_SEPARATOR).any? do |directory|
File.exist? File.join directory, executable
end
end
@@ -604,7 +610,7 @@ class Gem::TestCase < Test::Unit::TestCase
# Builds and installs the Gem::Specification +spec+
def install_gem(spec, options = {})
- require 'rubygems/installer'
+ require "rubygems/installer"
gem = spec.cache_file
@@ -631,7 +637,7 @@ class Gem::TestCase < Test::Unit::TestCase
##
# Uninstalls the Gem::Specification +spec+
def uninstall_gem(spec)
- require 'rubygems/uninstaller'
+ require "rubygems/uninstaller"
Class.new(Gem::Uninstaller) do
def ask_if_ok(spec)
@@ -654,7 +660,7 @@ class Gem::TestCase < Test::Unit::TestCase
# Reads a Marshal file at +path+
def read_cache(path)
- File.open path.dup.tap(&Gem::UNTAINT), 'rb' do |io|
+ File.open path.dup.tap(&Gem::UNTAINT), "rb" do |io|
Marshal.load io.read
end
end
@@ -674,7 +680,7 @@ class Gem::TestCase < Test::Unit::TestCase
dir = File.dirname path
FileUtils.mkdir_p dir unless File.directory? dir
- File.open path, 'wb' do |io|
+ File.open path, "wb" do |io|
yield io if block_given?
end
@@ -717,16 +723,16 @@ class Gem::TestCase < Test::Unit::TestCase
#
# Use this with #write_file to build an installed gem.
- def quick_gem(name, version='2')
- require 'rubygems/specification'
+ def quick_gem(name, version="2")
+ require "rubygems/specification"
spec = Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = name
s.version = version
- s.author = 'A User'
- s.email = 'example@example.com'
- s.homepage = 'http://example.com'
+ s.author = "A User"
+ s.email = "example@example.com"
+ s.homepage = "http://example.com"
s.summary = "this is a summary"
s.description = "This is a test description"
@@ -757,7 +763,7 @@ class Gem::TestCase < Test::Unit::TestCase
next if File.exist? file
FileUtils.mkdir_p File.dirname(file)
- File.open file, 'w' do |fp|
+ File.open file, "w" do |fp|
fp.puts "# #{file}"
end
end
@@ -843,15 +849,15 @@ class Gem::TestCase < Test::Unit::TestCase
# or a +block+ can be given for full customization of the specification.
def util_spec(name, version = 2, deps = nil, *files) # :yields: specification
- raise "deps or block, not both" if deps and block_given?
+ raise "deps or block, not both" if deps && block_given?
spec = Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = name
s.version = version
- s.author = 'A User'
- s.email = 'example@example.com'
- s.homepage = 'http://example.com'
+ s.author = "A User"
+ s.email = "example@example.com"
+ s.homepage = "http://example.com"
s.summary = "this is a summary"
s.description = "This is a test description"
@@ -862,7 +868,7 @@ class Gem::TestCase < Test::Unit::TestCase
if deps
deps.keys.each do |n|
- spec.add_dependency n, (deps[n] || '>= 0')
+ spec.add_dependency n, (deps[n] || ">= 0")
end
end
@@ -889,7 +895,7 @@ class Gem::TestCase < Test::Unit::TestCase
if deps
block = proc do |s|
deps.keys.each do |n|
- s.add_dependency n, (deps[n] || '>= 0')
+ s.add_dependency n, (deps[n] || ">= 0")
end
end
end
@@ -898,7 +904,7 @@ class Gem::TestCase < Test::Unit::TestCase
util_build_gem spec
- cache_file = File.join @tempdir, 'gems', "#{spec.original_name}.gem"
+ cache_file = File.join @tempdir, "gems", "#{spec.original_name}.gem"
FileUtils.mkdir_p File.dirname cache_file
FileUtils.mv spec.cache_file, cache_file
FileUtils.rm spec.spec_file
@@ -940,11 +946,11 @@ class Gem::TestCase < Test::Unit::TestCase
# TODO: nuke this and fix tests. this should speed up a lot
def util_make_gems(prerelease = false)
- @a1 = quick_gem 'a', '1' do |s|
+ @a1 = quick_gem "a", "1" do |s|
s.files = %w[lib/code.rb]
s.require_paths = %w[lib]
s.date = Gem::Specification::TODAY - 86400
- s.homepage = 'http://a.example.com'
+ s.homepage = "http://a.example.com"
s.email = %w[example@example.com example2@example.com]
s.authors = %w[Example Example2]
s.description = <<-DESC
@@ -961,27 +967,27 @@ Also, a list:
s.require_paths = %w[lib]
end
- @a2 = quick_gem('a', '2', &init)
- @a3a = quick_gem('a', '3.a', &init)
- @a_evil9 = quick_gem('a_evil', '9', &init)
- @b2 = quick_gem('b', '2', &init)
- @c1_2 = quick_gem('c', '1.2', &init)
- @x = quick_gem('x', '1', &init)
- @dep_x = quick_gem('dep_x', '1') do |s|
+ @a2 = quick_gem("a", "2", &init)
+ @a3a = quick_gem("a", "3.a", &init)
+ @a_evil9 = quick_gem("a_evil", "9", &init)
+ @b2 = quick_gem("b", "2", &init)
+ @c1_2 = quick_gem("c", "1.2", &init)
+ @x = quick_gem("x", "1", &init)
+ @dep_x = quick_gem("dep_x", "1") do |s|
s.files = %w[lib/code.rb]
s.require_paths = %w[lib]
- s.add_dependency 'x', '>= 1'
+ s.add_dependency "x", ">= 1"
end
- @pl1 = quick_gem 'pl', '1' do |s| # l for legacy
+ @pl1 = quick_gem "pl", "1" do |s| # l for legacy
s.files = %w[lib/code.rb]
s.require_paths = %w[lib]
- s.platform = Gem::Platform.new 'i386-linux'
- s.instance_variable_set :@original_platform, 'i386-linux'
+ s.platform = Gem::Platform.new "i386-linux"
+ s.instance_variable_set :@original_platform, "i386-linux"
end
if prerelease
- @a2_pre = quick_gem('a', '2.a', &init)
+ @a2_pre = quick_gem("a", "2.a", &init)
write_file File.join(*%W[gems #{@a2_pre.original_name} lib code.rb])
util_build_gem @a2_pre
end
@@ -1007,7 +1013,7 @@ Also, a list:
# Set the platform to +arch+
def util_set_arch(arch)
- RbConfig::CONFIG['arch'] = arch
+ RbConfig::CONFIG["arch"] = arch
platform = Gem::Platform.new arch
Gem.instance_variable_set :@platforms, nil
@@ -1176,7 +1182,7 @@ Also, a list:
# Borland) versus Cygwin, Mingw, etc.
def self.vc_windows?
- RUBY_PLATFORM.match('mswin')
+ RUBY_PLATFORM.match("mswin")
end
##
@@ -1184,14 +1190,14 @@ Also, a list:
# Borland) versus Cygwin, Mingw, etc.
def vc_windows?
- RUBY_PLATFORM.match('mswin')
+ RUBY_PLATFORM.match("mswin")
end
##
# Is this test being run on a ruby/ruby repository?
#
- def testing_ruby_repo?
+ def ruby_repo?
!ENV["GEM_COMMAND"].nil?
end
@@ -1201,7 +1207,7 @@ Also, a list:
# other platforms, including Cygwin, it will return 'make'.
def self.make_command
- ENV["make"] || ENV["MAKE"] || (vc_windows? ? 'nmake' : 'make')
+ ENV["make"] || ENV["MAKE"] || (vc_windows? ? "nmake" : "make")
end
##
@@ -1210,14 +1216,14 @@ Also, a list:
# other platforms, including Cygwin, it will return 'make'.
def make_command
- ENV["make"] || ENV["MAKE"] || (vc_windows? ? 'nmake' : 'make')
+ ENV["make"] || ENV["MAKE"] || (vc_windows? ? "nmake" : "make")
end
##
# Returns whether or not the nmake command could be found.
def nmake_found?
- system('nmake /? 1>NUL 2>&1')
+ system("nmake /? 1>NUL 2>&1")
end
# In case we're building docs in a background process, this method waits for
@@ -1273,10 +1279,10 @@ Also, a list:
rubyexe = "#{ruby}.exe"
3.times do
- if File.exist? ruby and File.executable? ruby and !File.directory? ruby
+ if File.exist?(ruby) && File.executable?(ruby) && !File.directory?(ruby)
return File.expand_path(ruby)
end
- if File.exist? rubyexe and File.executable? rubyexe
+ if File.exist?(rubyexe) && File.executable?(rubyexe)
return File.expand_path(rubyexe)
end
ruby = File.join("..", ruby)
@@ -1425,8 +1431,8 @@ Also, a list:
#
# Yields the +specification+ to the block, if given
- def vendor_gem(name = 'a', version = 1)
- directory = File.join 'vendor', name
+ def vendor_gem(name = "a", version = 1)
+ directory = File.join "vendor", name
FileUtils.mkdir_p directory
@@ -1439,12 +1445,12 @@ Also, a list:
#
# Yields the +specification+ to the block, if given
- def save_gemspec(name = 'a', version = 1, directory = '.')
+ def save_gemspec(name = "a", version = 1, directory = ".")
vendor_spec = Gem::Specification.new name, version do |specification|
yield specification if block_given?
end
- File.open File.join(directory, "#{name}.gemspec"), 'w' do |io|
+ File.open File.join(directory, "#{name}.gemspec"), "w" do |io|
io.write vendor_spec.to_ruby
end
@@ -1558,20 +1564,20 @@ Also, a list:
# :stopdoc:
# only available in RubyGems tests
- PRIVATE_KEY_PASSPHRASE = 'Foo bar'.freeze
+ PRIVATE_KEY_PASSPHRASE = "Foo bar".freeze
begin
- PRIVATE_KEY = load_key 'private'
- PRIVATE_KEY_PATH = key_path 'private'
+ PRIVATE_KEY = load_key "private"
+ PRIVATE_KEY_PATH = key_path "private"
# ENCRYPTED_PRIVATE_KEY is PRIVATE_KEY encrypted with PRIVATE_KEY_PASSPHRASE
- ENCRYPTED_PRIVATE_KEY = load_key 'encrypted_private', PRIVATE_KEY_PASSPHRASE
- ENCRYPTED_PRIVATE_KEY_PATH = key_path 'encrypted_private'
+ ENCRYPTED_PRIVATE_KEY = load_key "encrypted_private", PRIVATE_KEY_PASSPHRASE
+ ENCRYPTED_PRIVATE_KEY_PATH = key_path "encrypted_private"
PUBLIC_KEY = PRIVATE_KEY.public_key
- PUBLIC_CERT = load_cert 'public'
- PUBLIC_CERT_PATH = cert_path 'public'
+ PUBLIC_CERT = load_cert "public"
+ PUBLIC_CERT_PATH = cert_path "public"
rescue Errno::ENOENT
PRIVATE_KEY = nil
PUBLIC_KEY = nil
@@ -1586,7 +1592,7 @@ class Object
metaclass = class << self; self; end
- if respond_to? name and not methods.map(&:to_s).include? name.to_s
+ if respond_to?(name) && !methods.map(&:to_s).include?(name.to_s)
metaclass.send :define_method, name do |*args|
super(*args)
end
@@ -1613,4 +1619,4 @@ class Object
end unless method_defined?(:stub) # lib/resolv/test_dns.rb also has the same method definition
end
-require_relative 'utilities'
+require_relative "utilities"
diff --git a/test/rubygems/installer_test_case.rb b/test/rubygems/installer_test_case.rb
index 824ac53a82..6211cfff16 100644
--- a/test/rubygems/installer_test_case.rb
+++ b/test/rubygems/installer_test_case.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/installer'
+require_relative "helper"
+require "rubygems/installer"
class Gem::Installer
##
@@ -133,7 +133,7 @@ class Gem::InstallerTestCase < Gem::TestCase
# And returns it
def setup_base_spec
- quick_gem 'a' do |spec|
+ quick_gem "a" do |spec|
util_make_exec spec
end
end
@@ -154,7 +154,7 @@ class Gem::InstallerTestCase < Gem::TestCase
# And returns a Gem::Installer for the @user_spec that installs into Gem.user_dir
def setup_base_user_installer
- @user_spec = quick_gem 'b' do |spec|
+ @user_spec = quick_gem "b" do |spec|
util_make_exec spec
end
@@ -183,23 +183,23 @@ class Gem::InstallerTestCase < Gem::TestCase
# ext/a/mkrf_conf.rb
def util_setup_gem(ui = @ui, force = true)
- @spec.files << File.join('lib', 'code.rb')
- @spec.extensions << File.join('ext', 'a', 'mkrf_conf.rb')
+ @spec.files << File.join("lib", "code.rb")
+ @spec.extensions << File.join("ext", "a", "mkrf_conf.rb")
Dir.chdir @tempdir do
- FileUtils.mkdir_p 'bin'
- FileUtils.mkdir_p 'lib'
- FileUtils.mkdir_p File.join('ext', 'a')
+ FileUtils.mkdir_p "bin"
+ FileUtils.mkdir_p "lib"
+ FileUtils.mkdir_p File.join("ext", "a")
- File.open File.join('bin', 'executable'), 'w' do |f|
+ File.open File.join("bin", "executable"), "w" do |f|
f.puts "raise 'ran executable'"
end
- File.open File.join('lib', 'code.rb'), 'w' do |f|
- f.puts '1'
+ File.open File.join("lib", "code.rb"), "w" do |f|
+ f.puts "1"
end
- File.open File.join('ext', 'a', 'mkrf_conf.rb'), 'w' do |f|
+ File.open File.join("ext", "a", "mkrf_conf.rb"), "w" do |f|
f << <<-EOF
File.open 'Rakefile', 'w' do |rf| rf.puts "task :default" end
EOF
diff --git a/test/rubygems/package/tar_test_case.rb b/test/rubygems/package/tar_test_case.rb
index 4517f40730..6cee7f86dc 100644
--- a/test/rubygems/package/tar_test_case.rb
+++ b/test/rubygems/package/tar_test_case.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require_relative '../helper'
-require 'rubygems/package'
+require_relative "../helper"
+require "rubygems/package"
##
# A test case for Gem::Package::Tar* classes
diff --git a/test/rubygems/plugin/exception/rubygems_plugin.rb b/test/rubygems/plugin/exception/rubygems_plugin.rb
index 9a6f557b5c..f54e689d87 100644
--- a/test/rubygems/plugin/exception/rubygems_plugin.rb
+++ b/test/rubygems/plugin/exception/rubygems_plugin.rb
@@ -1,3 +1,3 @@
# frozen_string_literal: true
TestGem::TEST_PLUGIN_EXCEPTION = :loaded
-raise Exception.new('boom')
+raise Exception.new("boom")
diff --git a/test/rubygems/plugin/standarderror/rubygems_plugin.rb b/test/rubygems/plugin/standarderror/rubygems_plugin.rb
index 94cf4e8a52..0fcca28728 100644
--- a/test/rubygems/plugin/standarderror/rubygems_plugin.rb
+++ b/test/rubygems/plugin/standarderror/rubygems_plugin.rb
@@ -1,3 +1,3 @@
# frozen_string_literal: true
TestGem::TEST_PLUGIN_STANDARDERROR = :loaded
-raise StandardError.new('boom')
+raise StandardError.new("boom")
diff --git a/test/rubygems/rubygems_plugin.rb b/test/rubygems/rubygems_plugin.rb
index 2dc7836904..b538487bbf 100644
--- a/test/rubygems/rubygems_plugin.rb
+++ b/test/rubygems/rubygems_plugin.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require 'rubygems/command_manager'
+require "rubygems/command_manager"
##
# This is an example of exactly what NOT to do.
@@ -12,7 +12,7 @@ end
class Gem::Commands::InterruptCommand < Gem::Command
def initialize
- super('interrupt', 'Raises an Interrupt Exception', {})
+ super("interrupt", "Raises an Interrupt Exception", {})
end
def execute
diff --git a/test/rubygems/specifications/rubyforge-0.0.1.gemspec b/test/rubygems/specifications/rubyforge-0.0.1.gemspec
index c760a42073..e8d5030326 100644
--- a/test/rubygems/specifications/rubyforge-0.0.1.gemspec
+++ b/test/rubygems/specifications/rubyforge-0.0.1.gemspec
@@ -5,8 +5,8 @@ Gem::Specification.new do |s|
s.require_paths = ["lib"]
s.summary = "A very bar gem"
s.authors = ["unknown"]
- s.license = 'MIT'
- s.homepage = 'http://example.com'
- s.files = ['README.md']
- s.rubyforge_project = 'abc'
+ s.license = "MIT"
+ s.homepage = "http://example.com"
+ s.files = ["README.md"]
+ s.rubyforge_project = "abc"
end
diff --git a/test/rubygems/test_bundled_ca.rb b/test/rubygems/test_bundled_ca.rb
index fff5904aba..3d7f616519 100644
--- a/test/rubygems/test_bundled_ca.rb
+++ b/test/rubygems/test_bundled_ca.rb
@@ -1,13 +1,13 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'net/http'
-require 'rubygems/openssl'
+require_relative "helper"
+require "net/http"
+require "rubygems/openssl"
unless Gem::HAVE_OPENSSL
- warn 'Skipping bundled certificates tests. openssl not found.'
+ warn "Skipping bundled certificates tests. openssl not found."
end
-require 'rubygems/request'
+require "rubygems/request"
# = Testing Bundled CA
#
@@ -31,30 +31,30 @@ class TestBundledCA < Gem::TestCase
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
http.cert_store = bundled_certificate_store
- http.get('/')
+ http.get("/")
rescue Errno::ENOENT, Errno::ETIMEDOUT, SocketError
pend "#{host} seems offline, I can't tell whether ssl would work."
rescue OpenSSL::SSL::SSLError => e
# Only fail for certificate verification errors
- if e.message =~ /certificate verify failed/
+ if e.message.include?("certificate verify failed")
flunk "#{host} is not verifiable using the included certificates. Error was: #{e.message}"
end
raise
end
def test_accessing_rubygems
- assert_https('rubygems.org')
+ assert_https("rubygems.org")
end
def test_accessing_www_rubygems
- assert_https('www.rubygems.org')
+ assert_https("www.rubygems.org")
end
def test_accessing_staging
- assert_https('staging.rubygems.org')
+ assert_https("staging.rubygems.org")
end
def test_accessing_new_index
- assert_https('index.rubygems.org')
+ assert_https("index.rubygems.org")
end
end if Gem::HAVE_OPENSSL
diff --git a/test/rubygems/test_config.rb b/test/rubygems/test_config.rb
index fff539c816..d9e0f4dd9d 100644
--- a/test/rubygems/test_config.rb
+++ b/test/rubygems/test_config.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems'
-require 'shellwords'
+require_relative "helper"
+require "rubygems"
+require "shellwords"
class TestConfig < Gem::TestCase
def test_datadir
diff --git a/test/rubygems/test_deprecate.rb b/test/rubygems/test_deprecate.rb
index a619eccb37..dfcf8dea11 100644
--- a/test/rubygems/test_deprecate.rb
+++ b/test/rubygems/test_deprecate.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/deprecate'
+require_relative "helper"
+require "rubygems/deprecate"
class TestDeprecate < Gem::TestCase
def setup
@@ -123,7 +123,7 @@ class TestDeprecate < Gem::TestCase
end
def test_rubygems_deprecate_command
- require 'rubygems/command'
+ require "rubygems/command"
foo_command = Class.new(Gem::Command) do
extend Gem::Deprecate
diff --git a/test/rubygems/test_exit.rb b/test/rubygems/test_exit.rb
index 9557fe5d06..707150efaa 100644
--- a/test/rubygems/test_exit.rb
+++ b/test/rubygems/test_exit.rb
@@ -1,11 +1,17 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems'
+require_relative "helper"
+require "rubygems"
class TestExit < Gem::TestCase
def test_exit
system(*ruby_with_rubygems_in_load_path, "-e", "raise Gem::SystemExitException.new(2)")
assert_equal 2, $?.exitstatus
end
+
+ def test_status
+ exc = Gem::SystemExitException.new(42)
+ assert_equal 42, exc.status
+ assert_equal 42, exc.exit_code
+ end
end
diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb
index 4d9644d5c9..bbb3e6dd0a 100644
--- a/test/rubygems/test_gem.rb
+++ b/test/rubygems/test_gem.rb
@@ -1,16 +1,16 @@
# coding: US-ASCII
-require_relative 'helper'
-require 'rubygems'
-require 'rubygems/command'
-require 'rubygems/installer'
-require 'pathname'
-require 'tmpdir'
-require 'rbconfig'
+require_relative "helper"
+require "rubygems"
+require "rubygems/command"
+require "rubygems/installer"
+require "pathname"
+require "tmpdir"
+require "rbconfig"
class TestGem < Gem::TestCase
PLUGINS_LOADED = [] # rubocop:disable Style/MutableConstant
- PROJECT_DIR = File.expand_path('../..', __dir__).tap(&Gem::UNTAINT)
+ PROJECT_DIR = File.expand_path("../..", __dir__).tap(&Gem::UNTAINT)
def setup
super
@@ -89,32 +89,32 @@ class TestGem < Gem::TestCase
def test_self_install
spec_fetcher do |f|
- f.gem 'a', 1
- f.spec 'a', 2
+ f.gem "a", 1
+ f.spec "a", 2
end
gemhome2 = "#{@gemhome}2"
- installed = Gem.install 'a', '= 1', :install_dir => gemhome2
+ installed = Gem.install "a", "= 1", :install_dir => gemhome2
assert_equal %w[a-1], installed.map {|spec| spec.full_name }
- assert_path_exist File.join(gemhome2, 'gems', 'a-1')
+ assert_path_exist File.join(gemhome2, "gems", "a-1")
end
def test_self_install_in_rescue
spec_fetcher do |f|
- f.gem 'a', 1
- f.spec 'a', 2
+ f.gem "a", 1
+ f.spec "a", 2
end
gemhome2 = "#{@gemhome}2"
installed =
begin
- raise 'Error'
+ raise "Error"
rescue StandardError
- Gem.install 'a', '= 1', :install_dir => gemhome2
+ Gem.install "a", "= 1", :install_dir => gemhome2
end
assert_equal %w[a-1], installed.map {|spec| spec.full_name }
end
@@ -143,7 +143,7 @@ class TestGem < Gem::TestCase
def test_self_install_permissions_with_format_executable_and_non_standard_ruby_install_name
Gem::Installer.exec_format = nil
- ruby_install_name 'ruby27' do
+ ruby_install_name "ruby27" do
assert_self_install_permissions(format_executable: true)
end
ensure
@@ -160,35 +160,35 @@ class TestGem < Gem::TestCase
:format_executable => format_executable,
}
Dir.chdir @tempdir do
- Dir.mkdir 'bin'
- Dir.mkdir 'data'
+ Dir.mkdir "bin"
+ Dir.mkdir "data"
- File.write 'bin/foo', "#!/usr/bin/env ruby\n"
- File.chmod 0755, 'bin/foo'
+ File.write "bin/foo", "#!/usr/bin/env ruby\n"
+ File.chmod 0755, "bin/foo"
- File.write 'data/foo.txt', "blah\n"
+ File.write "data/foo.txt", "blah\n"
spec_fetcher do |f|
- f.gem 'foo', 1 do |s|
- s.executables = ['foo']
+ f.gem "foo", 1 do |s|
+ s.executables = ["foo"]
s.files = %w[bin/foo data/foo.txt]
end
end
- Gem.install 'foo', Gem::Requirement.default, options
+ Gem.install "foo", Gem::Requirement.default, options
end
prog_mode = (options[:prog_mode] & mask).to_s(8)
dir_mode = (options[:dir_mode] & mask).to_s(8)
data_mode = (options[:data_mode] & mask).to_s(8)
- prog_name = 'foo'
- prog_name = RbConfig::CONFIG['ruby_install_name'].sub('ruby', 'foo') if options[:format_executable]
+ prog_name = "foo"
+ prog_name = RbConfig::CONFIG["ruby_install_name"].sub("ruby", "foo") if options[:format_executable]
expected = {
"bin/#{prog_name}" => prog_mode,
- 'gems/foo-1' => dir_mode,
- 'gems/foo-1/bin' => dir_mode,
- 'gems/foo-1/data' => dir_mode,
- 'gems/foo-1/bin/foo' => prog_mode,
- 'gems/foo-1/data/foo.txt' => data_mode,
+ "gems/foo-1" => dir_mode,
+ "gems/foo-1/bin" => dir_mode,
+ "gems/foo-1/data" => dir_mode,
+ "gems/foo-1/bin/foo" => prog_mode,
+ "gems/foo-1/data/foo.txt" => data_mode,
}
# add Windows script
expected["bin/#{prog_name}.bat"] = mask.to_s(8) if win_platform?
@@ -200,7 +200,7 @@ class TestGem < Gem::TestCase
end
assert_equal(expected, result)
ensure
- File.chmod(0755, *Dir.glob(@gemhome + '/gems/**/').map {|path| path.tap(&Gem::UNTAINT) })
+ File.chmod(0755, *Dir.glob(@gemhome + "/gems/**/").map {|path| path.tap(&Gem::UNTAINT) })
end
def test_require_missing
@@ -222,57 +222,57 @@ class TestGem < Gem::TestCase
end
def test_self_bin_path_active
- a1 = util_spec 'a', '1' do |s|
- s.executables = ['exec']
+ a1 = util_spec "a", "1" do |s|
+ s.executables = ["exec"]
end
- util_spec 'a', '2' do |s|
- s.executables = ['exec']
+ util_spec "a", "2" do |s|
+ s.executables = ["exec"]
end
a1.activate
- assert_match 'a-1/bin/exec', Gem.bin_path('a', 'exec', '>= 0')
+ assert_match "a-1/bin/exec", Gem.bin_path("a", "exec", ">= 0")
end
def test_self_bin_path_picking_newest
- a1 = util_spec 'a', '1' do |s|
- s.executables = ['exec']
+ a1 = util_spec "a", "1" do |s|
+ s.executables = ["exec"]
end
- a2 = util_spec 'a', '2' do |s|
- s.executables = ['exec']
+ a2 = util_spec "a", "2" do |s|
+ s.executables = ["exec"]
end
install_specs a1, a2
- assert_match 'a-2/bin/exec', Gem.bin_path('a', 'exec', '>= 0')
+ assert_match "a-2/bin/exec", Gem.bin_path("a", "exec", ">= 0")
end
def test_self_activate_bin_path_no_exec_name
e = assert_raise ArgumentError do
- Gem.activate_bin_path 'a'
+ Gem.activate_bin_path "a"
end
- assert_equal 'you must supply exec_name', e.message
+ assert_equal "you must supply exec_name", e.message
end
def test_activate_bin_path_resolves_eagerly
- a1 = util_spec 'a', '1' do |s|
- s.executables = ['exec']
- s.add_dependency 'b'
+ a1 = util_spec "a", "1" do |s|
+ s.executables = ["exec"]
+ s.add_dependency "b"
end
- b1 = util_spec 'b', '1' do |s|
- s.add_dependency 'c', '2'
+ b1 = util_spec "b", "1" do |s|
+ s.add_dependency "c", "2"
end
- b2 = util_spec 'b', '2' do |s|
- s.add_dependency 'c', '1'
+ b2 = util_spec "b", "2" do |s|
+ s.add_dependency "c", "1"
end
- c1 = util_spec 'c', '1'
- c2 = util_spec 'c', '2'
+ c1 = util_spec "c", "1"
+ c2 = util_spec "c", "2"
install_specs c1, c2, b1, b2, a1
@@ -280,27 +280,27 @@ class TestGem < Gem::TestCase
# If we didn't eagerly resolve, this would activate c-2 and then the
# finish_resolve would cause a conflict
- gem 'c'
+ gem "c"
Gem.finish_resolve
assert_equal %w[a-1 b-2 c-1], loaded_spec_names
end
def test_activate_bin_path_does_not_error_if_a_gem_thats_not_finally_activated_has_orphaned_dependencies
- a1 = util_spec 'a', '1' do |s|
- s.executables = ['exec']
- s.add_dependency 'b'
+ a1 = util_spec "a", "1" do |s|
+ s.executables = ["exec"]
+ s.add_dependency "b"
end
- b1 = util_spec 'b', '1' do |s|
- s.add_dependency 'c', '1'
+ b1 = util_spec "b", "1" do |s|
+ s.add_dependency "c", "1"
end
- b2 = util_spec 'b', '2' do |s|
- s.add_dependency 'c', '2'
+ b2 = util_spec "b", "2" do |s|
+ s.add_dependency "c", "2"
end
- c2 = util_spec 'c', '2'
+ c2 = util_spec "c", "2"
install_specs c2, b1, b2, a1
@@ -312,20 +312,20 @@ class TestGem < Gem::TestCase
end
def test_activate_bin_path_raises_a_meaningful_error_if_a_gem_thats_finally_activated_has_orphaned_dependencies
- a1 = util_spec 'a', '1' do |s|
- s.executables = ['exec']
- s.add_dependency 'b'
+ a1 = util_spec "a", "1" do |s|
+ s.executables = ["exec"]
+ s.add_dependency "b"
end
- b1 = util_spec 'b', '1' do |s|
- s.add_dependency 'c', '1'
+ b1 = util_spec "b", "1" do |s|
+ s.add_dependency "c", "1"
end
- b2 = util_spec 'b', '2' do |s|
- s.add_dependency 'c', '2'
+ b2 = util_spec "b", "2" do |s|
+ s.add_dependency "c", "2"
end
- c1 = util_spec 'c', '1'
+ c1 = util_spec "c", "1"
install_specs c1, b1, b2, a1
@@ -339,8 +339,8 @@ class TestGem < Gem::TestCase
end
def test_activate_bin_path_in_debug_mode
- a1 = util_spec 'a', '1' do |s|
- s.executables = ['exec']
+ a1 = util_spec "a", "1" do |s|
+ s.executables = ["exec"]
end
install_specs a1
@@ -355,12 +355,12 @@ class TestGem < Gem::TestCase
end
def test_activate_bin_path_selects_exact_bundler_version_if_present
- bundler_latest = util_spec 'bundler', '2.0.1' do |s|
- s.executables = ['bundle']
+ bundler_latest = util_spec "bundler", "2.0.1" do |s|
+ s.executables = ["bundle"]
end
- bundler_previous = util_spec 'bundler', '2.0.0' do |s|
- s.executables = ['bundle']
+ bundler_previous = util_spec "bundler", "2.0.0" do |s|
+ s.executables = ["bundle"]
end
install_specs bundler_latest, bundler_previous
@@ -389,12 +389,12 @@ class TestGem < Gem::TestCase
end
def test_activate_bin_path_respects_underscore_selection_if_given
- bundler_latest = util_spec 'bundler', '2.0.1' do |s|
- s.executables = ['bundle']
+ bundler_latest = util_spec "bundler", "2.0.1" do |s|
+ s.executables = ["bundle"]
end
- bundler_previous = util_spec 'bundler', '1.17.3' do |s|
- s.executables = ['bundle']
+ bundler_previous = util_spec "bundler", "1.17.3" do |s|
+ s.executables = ["bundle"]
end
install_specs bundler_latest, bundler_previous
@@ -450,57 +450,57 @@ class TestGem < Gem::TestCase
def test_self_bin_path_no_exec_name
e = assert_raise ArgumentError do
- Gem.bin_path 'a'
+ Gem.bin_path "a"
end
- assert_equal 'you must supply exec_name', e.message
+ assert_equal "you must supply exec_name", e.message
end
def test_self_bin_path_bin_name
install_specs util_exec_gem
- assert_equal @abin_path, Gem.bin_path('a', 'abin')
+ assert_equal @abin_path, Gem.bin_path("a", "abin")
end
def test_self_bin_path_bin_name_version
install_specs util_exec_gem
- assert_equal @abin_path, Gem.bin_path('a', 'abin', '4')
+ assert_equal @abin_path, Gem.bin_path("a", "abin", "4")
end
def test_self_bin_path_nonexistent_binfile
- util_spec 'a', '2' do |s|
- s.executables = ['exec']
+ util_spec "a", "2" do |s|
+ s.executables = ["exec"]
end
assert_raise(Gem::GemNotFoundException) do
- Gem.bin_path('a', 'other', '2')
+ Gem.bin_path("a", "other", "2")
end
end
def test_self_bin_path_no_bin_file
- util_spec 'a', '1'
+ util_spec "a", "1"
assert_raise(ArgumentError) do
- Gem.bin_path('a', nil, '1')
+ Gem.bin_path("a", nil, "1")
end
end
def test_self_bin_path_not_found
assert_raise(Gem::GemNotFoundException) do
- Gem.bin_path('non-existent', 'blah')
+ Gem.bin_path("non-existent", "blah")
end
end
def test_self_bin_path_bin_file_gone_in_latest
install_specs util_exec_gem
- spec = util_spec 'a', '10' do |s|
+ spec = util_spec "a", "10" do |s|
s.executables = []
end
install_specs spec
- assert_equal @abin_path, Gem.bin_path('a', 'abin')
+ assert_equal @abin_path, Gem.bin_path("a", "abin")
end
def test_self_bindir
- assert_equal File.join(@gemhome, 'bin'), Gem.bindir
- assert_equal File.join(@gemhome, 'bin'), Gem.bindir(Gem.dir)
- assert_equal File.join(@gemhome, 'bin'), Gem.bindir(Pathname.new(Gem.dir))
+ assert_equal File.join(@gemhome, "bin"), Gem.bindir
+ assert_equal File.join(@gemhome, "bin"), Gem.bindir(Gem.dir)
+ assert_equal File.join(@gemhome, "bin"), Gem.bindir(Pathname.new(Gem.dir))
end
def test_self_bindir_default_dir
@@ -529,21 +529,21 @@ class TestGem < Gem::TestCase
foo = nil
Dir.chdir @tempdir do
- FileUtils.mkdir_p 'data'
- File.open File.join('data', 'foo.txt'), 'w' do |fp|
- fp.puts 'blah'
+ FileUtils.mkdir_p "data"
+ File.open File.join("data", "foo.txt"), "w" do |fp|
+ fp.puts "blah"
end
- foo = util_spec 'foo' do |s|
+ foo = util_spec "foo" do |s|
s.files = %w[data/foo.txt]
end
install_gem foo
end
- gem 'foo'
+ gem "foo"
- expected = File.join @gemhome, 'gems', foo.full_name, 'data', 'foo'
+ expected = File.join @gemhome, "gems", foo.full_name, "data", "foo"
assert_equal expected, Gem::Specification.find_by_name("foo").datadir
end
@@ -555,25 +555,25 @@ class TestGem < Gem::TestCase
end
def test_self_default_exec_format
- ruby_install_name 'ruby' do
- assert_equal '%s', Gem.default_exec_format
+ ruby_install_name "ruby" do
+ assert_equal "%s", Gem.default_exec_format
end
end
def test_self_default_exec_format_18
- ruby_install_name 'ruby18' do
- assert_equal '%s18', Gem.default_exec_format
+ ruby_install_name "ruby18" do
+ assert_equal "%s18", Gem.default_exec_format
end
end
def test_self_default_exec_format_jruby
- ruby_install_name 'jruby' do
- assert_equal 'j%s', Gem.default_exec_format
+ ruby_install_name "jruby" do
+ assert_equal "j%s", Gem.default_exec_format
end
end
def test_default_path
- vendordir(File.join(@tempdir, 'vendor')) do
+ vendordir(File.join(@tempdir, "vendor")) do
FileUtils.rm_rf Gem.user_home
expected = [Gem.default_dir]
@@ -593,7 +593,7 @@ class TestGem < Gem::TestCase
end
def test_default_path_user_home
- vendordir(File.join(@tempdir, 'vendor')) do
+ vendordir(File.join(@tempdir, "vendor")) do
expected = [Gem.user_dir, Gem.default_dir]
assert_equal expected, Gem.default_path
@@ -601,7 +601,7 @@ class TestGem < Gem::TestCase
end
def test_default_path_vendor_dir
- vendordir(File.join(@tempdir, 'vendor')) do
+ vendordir(File.join(@tempdir, "vendor")) do
FileUtils.mkdir_p Gem.vendor_dir
FileUtils.rm_rf Gem.user_home
@@ -617,14 +617,14 @@ class TestGem < Gem::TestCase
end
def test_self_use_gemdeps
- with_rubygems_gemdeps('-') do
- FileUtils.mkdir_p 'detect/a/b'
- FileUtils.mkdir_p 'detect/a/Isolate'
+ with_rubygems_gemdeps("-") do
+ FileUtils.mkdir_p "detect/a/b"
+ FileUtils.mkdir_p "detect/a/Isolate"
- FileUtils.touch 'detect/Isolate'
+ FileUtils.touch "detect/Isolate"
begin
- Dir.chdir 'detect/a/b'
+ Dir.chdir "detect/a/b"
Gem.use_gemdeps
@@ -645,12 +645,12 @@ class TestGem < Gem::TestCase
Gem.ensure_gem_subdirectories @gemhome
- assert_path_exist File.join @gemhome, 'build_info'
- assert_path_exist File.join @gemhome, 'cache'
- assert_path_exist File.join @gemhome, 'doc'
- assert_path_exist File.join @gemhome, 'extensions'
- assert_path_exist File.join @gemhome, 'gems'
- assert_path_exist File.join @gemhome, 'specifications'
+ assert_path_exist File.join @gemhome, "build_info"
+ assert_path_exist File.join @gemhome, "cache"
+ assert_path_exist File.join @gemhome, "doc"
+ assert_path_exist File.join @gemhome, "extensions"
+ assert_path_exist File.join @gemhome, "gems"
+ assert_path_exist File.join @gemhome, "specifications"
end
def test_self_ensure_gem_directories_permissions
@@ -680,9 +680,9 @@ class TestGem < Gem::TestCase
end unless win_platform?
def test_self_ensure_gem_directories_missing_parents
- gemdir = File.join @tempdir, 'a/b/c/gemdir'
- FileUtils.rm_rf File.join(@tempdir, 'a') rescue nil
- refute File.exist?(File.join(@tempdir, 'a')),
+ gemdir = File.join @tempdir, "a/b/c/gemdir"
+ FileUtils.rm_rf File.join(@tempdir, "a") rescue nil
+ refute File.exist?(File.join(@tempdir, "a")),
"manually remove #{File.join @tempdir, 'a'}, tests are broken"
Gem.use_paths gemdir
@@ -725,19 +725,19 @@ class TestGem < Gem::TestCase
end
def test_self_ensure_gem_directories_non_existent_paths
- Gem.ensure_gem_subdirectories '/proc/0123456789/bogus' # should not raise
- Gem.ensure_gem_subdirectories 'classpath:/bogus/x' # JRuby embed scenario
+ Gem.ensure_gem_subdirectories "/proc/0123456789/bogus" # should not raise
+ Gem.ensure_gem_subdirectories "classpath:/bogus/x" # JRuby embed scenario
end
end
def test_self_extension_dir_shared
- enable_shared 'yes' do
+ enable_shared "yes" do
assert_equal Gem.ruby_api_version, Gem.extension_api_version
end
end
def test_self_extension_dir_static
- enable_shared 'no' do
+ enable_shared "no" do
assert_equal "#{Gem.ruby_api_version}-static", Gem.extension_api_version
end
end
@@ -746,14 +746,14 @@ class TestGem < Gem::TestCase
cwd = File.expand_path("test/rubygems", PROJECT_DIR)
$LOAD_PATH.unshift cwd
- discover_path = File.join 'lib', 'sff', 'discover.rb'
+ discover_path = File.join "lib", "sff", "discover.rb"
foo1, foo2 = %w[1 2].map do |version|
- spec = quick_gem 'sff', version do |s|
+ spec = quick_gem "sff", version do |s|
s.files << discover_path
end
- write_file(File.join 'gems', spec.full_name, discover_path) do |fp|
+ write_file(File.join "gems", spec.full_name, discover_path) do |fp|
fp.puts "# #{spec.full_name}"
end
@@ -763,13 +763,13 @@ class TestGem < Gem::TestCase
Gem.refresh
expected = [
- File.expand_path('test/rubygems/sff/discover.rb', PROJECT_DIR),
+ File.expand_path("test/rubygems/sff/discover.rb", PROJECT_DIR),
File.join(foo2.full_gem_path, discover_path),
File.join(foo1.full_gem_path, discover_path),
]
- assert_equal expected, Gem.find_files('sff/discover')
- assert_equal expected, Gem.find_files('sff/**.rb'), '[ruby-core:31730]'
+ assert_equal expected, Gem.find_files("sff/discover")
+ assert_equal expected, Gem.find_files("sff/**.rb"), "[ruby-core:31730]"
ensure
assert_equal cwd, $LOAD_PATH.shift
end
@@ -778,14 +778,14 @@ class TestGem < Gem::TestCase
cwd = File.expand_path("test/rubygems", PROJECT_DIR)
actual_load_path = $LOAD_PATH.unshift(cwd).dup
- discover_path = File.join 'lib', 'sff', 'discover.rb'
+ discover_path = File.join "lib", "sff", "discover.rb"
foo1, _ = %w[1 2].map do |version|
- spec = quick_gem 'sff', version do |s|
+ spec = quick_gem "sff", version do |s|
s.files << discover_path
end
- write_file(File.join 'gems', spec.full_name, discover_path) do |fp|
+ write_file(File.join "gems", spec.full_name, discover_path) do |fp|
fp.puts "# #{spec.full_name}"
end
@@ -793,19 +793,19 @@ class TestGem < Gem::TestCase
end
Gem.refresh
- write_file(File.join Dir.pwd, 'Gemfile') do |fp|
+ write_file(File.join Dir.pwd, "Gemfile") do |fp|
fp.puts "source 'https://rubygems.org'"
fp.puts "gem '#{foo1.name}', '#{foo1.version}'"
end
- Gem.use_gemdeps(File.join Dir.pwd, 'Gemfile')
+ Gem.use_gemdeps(File.join Dir.pwd, "Gemfile")
expected = [
- File.expand_path('test/rubygems/sff/discover.rb', PROJECT_DIR),
+ File.expand_path("test/rubygems/sff/discover.rb", PROJECT_DIR),
File.join(foo1.full_gem_path, discover_path),
].sort
- assert_equal expected, Gem.find_files('sff/discover').sort
- assert_equal expected, Gem.find_files('sff/**.rb').sort, '[ruby-core:31730]'
+ assert_equal expected, Gem.find_files("sff/discover").sort
+ assert_equal expected, Gem.find_files("sff/**.rb").sort, "[ruby-core:31730]"
ensure
assert_equal cwd, actual_load_path.shift unless Gem.java_platform?
end
@@ -814,14 +814,14 @@ class TestGem < Gem::TestCase
cwd = File.expand_path("test/rubygems", PROJECT_DIR)
$LOAD_PATH.unshift cwd
- discover_path = File.join 'lib', 'sff', 'discover.rb'
+ discover_path = File.join "lib", "sff", "discover.rb"
_, foo2 = %w[1 2].map do |version|
- spec = quick_gem 'sff', version do |s|
+ spec = quick_gem "sff", version do |s|
s.files << discover_path
end
- write_file(File.join 'gems', spec.full_name, discover_path) do |fp|
+ write_file(File.join "gems", spec.full_name, discover_path) do |fp|
fp.puts "# #{spec.full_name}"
end
@@ -831,30 +831,30 @@ class TestGem < Gem::TestCase
Gem.refresh
expected = [
- File.expand_path('test/rubygems/sff/discover.rb', PROJECT_DIR),
+ File.expand_path("test/rubygems/sff/discover.rb", PROJECT_DIR),
File.join(foo2.full_gem_path, discover_path),
]
- assert_equal expected, Gem.find_latest_files('sff/discover')
- assert_equal expected, Gem.find_latest_files('sff/**.rb'), '[ruby-core:31730]'
+ assert_equal expected, Gem.find_latest_files("sff/discover")
+ assert_equal expected, Gem.find_latest_files("sff/**.rb"), "[ruby-core:31730]"
ensure
assert_equal cwd, $LOAD_PATH.shift
end
def test_self_latest_spec_for
gems = spec_fetcher do |fetcher|
- fetcher.spec 'a', 1
- fetcher.spec 'a', '3.a'
- fetcher.spec 'a', 2
+ fetcher.spec "a", 1
+ fetcher.spec "a", "3.a"
+ fetcher.spec "a", 2
end
- spec = Gem.latest_spec_for 'a'
+ spec = Gem.latest_spec_for "a"
- assert_equal gems['a-2'], spec
+ assert_equal gems["a-2"], spec
end
def test_self_latest_spec_for_multiple_sources
- uri = 'https://example.sample.com/'
+ uri = "https://example.sample.com/"
source = Gem::Source.new(uri)
source_list = Gem::SourceList.new
source_list << Gem::Source.new(@uri)
@@ -862,44 +862,44 @@ class TestGem < Gem::TestCase
Gem.sources.replace source_list
spec_fetcher(uri) do |fetcher|
- fetcher.spec 'a', 1.1
+ fetcher.spec "a", 1.1
end
gems = spec_fetcher do |fetcher|
- fetcher.spec 'a', 1
- fetcher.spec 'a', '3.a'
- fetcher.spec 'a', 2
+ fetcher.spec "a", 1
+ fetcher.spec "a", "3.a"
+ fetcher.spec "a", 2
end
- spec = Gem.latest_spec_for 'a'
- assert_equal gems['a-2'], spec
+ spec = Gem.latest_spec_for "a"
+ assert_equal gems["a-2"], spec
end
def test_self_latest_rubygems_version
spec_fetcher do |fetcher|
- fetcher.spec 'rubygems-update', '1.8.23'
- fetcher.spec 'rubygems-update', '1.8.24'
- fetcher.spec 'rubygems-update', '2.0.0.preview3'
+ fetcher.spec "rubygems-update", "1.8.23"
+ fetcher.spec "rubygems-update", "1.8.24"
+ fetcher.spec "rubygems-update", "2.0.0.preview3"
end
version = Gem.latest_rubygems_version
- assert_equal Gem::Version.new('1.8.24'), version
+ assert_equal Gem::Version.new("1.8.24"), version
end
def test_self_latest_version_for
spec_fetcher do |fetcher|
- fetcher.spec 'a', 1
- fetcher.spec 'a', 2
- fetcher.spec 'a', '3.a'
+ fetcher.spec "a", 1
+ fetcher.spec "a", 2
+ fetcher.spec "a", "3.a"
end
- version = Gem.latest_version_for 'a'
+ version = Gem.latest_version_for "a"
assert_equal Gem::Version.new(2), version
end
def test_self_latest_version_for_multiple_sources
- uri = 'https://example.sample.com/'
+ uri = "https://example.sample.com/"
source = Gem::Source.new(uri)
source_list = Gem::SourceList.new
source_list << Gem::Source.new(@uri)
@@ -907,27 +907,27 @@ class TestGem < Gem::TestCase
Gem.sources.replace source_list
spec_fetcher(uri) do |fetcher|
- fetcher.spec 'a', 1.1
+ fetcher.spec "a", 1.1
end
spec_fetcher do |fetcher|
- fetcher.spec 'a', 1
- fetcher.spec 'a', 2
- fetcher.spec 'a', '3.a'
+ fetcher.spec "a", 1
+ fetcher.spec "a", 2
+ fetcher.spec "a", "3.a"
end
- version = Gem.latest_version_for 'a'
+ version = Gem.latest_version_for "a"
assert_equal Gem::Version.new(2), version
end
def test_self_loaded_specs
- foo = util_spec 'foo'
+ foo = util_spec "foo"
install_gem foo
foo.activate
- assert_equal true, Gem.loaded_specs.keys.include?('foo')
+ assert_equal true, Gem.loaded_specs.keys.include?("foo")
end
def test_self_path
@@ -947,7 +947,7 @@ class TestGem < Gem::TestCase
path_count = Gem.path.size
Gem.clear_paths
- ENV['GEM_PATH'] = @additional.join(File::PATH_SEPARATOR)
+ ENV["GEM_PATH"] = @additional.join(File::PATH_SEPARATOR)
assert_equal @additional, Gem.path[0,2]
@@ -959,10 +959,10 @@ class TestGem < Gem::TestCase
def test_self_path_duplicate
Gem.clear_paths
util_ensure_gem_dirs
- dirs = @additional + [@gemhome] + [File.join(@tempdir, 'a')]
+ dirs = @additional + [@gemhome] + [File.join(@tempdir, "a")]
- ENV['GEM_HOME'] = @gemhome
- ENV['GEM_PATH'] = dirs.join File::PATH_SEPARATOR
+ ENV["GEM_HOME"] = @gemhome
+ ENV["GEM_PATH"] = dirs.join File::PATH_SEPARATOR
assert_equal @gemhome, Gem.dir
@@ -974,8 +974,8 @@ class TestGem < Gem::TestCase
Gem.clear_paths
util_ensure_gem_dirs
- ENV['GEM_HOME'] = @gemhome
- ENV['GEM_PATH'] = @additional.join(File::PATH_SEPARATOR)
+ ENV["GEM_HOME"] = @gemhome
+ ENV["GEM_PATH"] = @additional.join(File::PATH_SEPARATOR)
assert_equal @gemhome, Gem.dir
@@ -992,38 +992,38 @@ class TestGem < Gem::TestCase
end
def test_self_prefix_libdir
- orig_libdir = RbConfig::CONFIG['libdir']
- RbConfig::CONFIG['libdir'] = PROJECT_DIR
+ orig_libdir = RbConfig::CONFIG["libdir"]
+ RbConfig::CONFIG["libdir"] = PROJECT_DIR
assert_nil Gem.prefix
ensure
- RbConfig::CONFIG['libdir'] = orig_libdir
+ RbConfig::CONFIG["libdir"] = orig_libdir
end
def test_self_prefix_sitelibdir
- orig_sitelibdir = RbConfig::CONFIG['sitelibdir']
- RbConfig::CONFIG['sitelibdir'] = PROJECT_DIR
+ orig_sitelibdir = RbConfig::CONFIG["sitelibdir"]
+ RbConfig::CONFIG["sitelibdir"] = PROJECT_DIR
assert_nil Gem.prefix
ensure
- RbConfig::CONFIG['sitelibdir'] = orig_sitelibdir
+ RbConfig::CONFIG["sitelibdir"] = orig_sitelibdir
end
def test_self_read_binary
- File.open 'test', 'w' do |io|
+ File.open "test", "w" do |io|
io.write "\xCF\x80"
end
- assert_equal ["\xCF", "\x80"], Gem.read_binary('test').chars.to_a
+ assert_equal ["\xCF", "\x80"], Gem.read_binary("test").chars.to_a
- pend 'chmod not supported' if Gem.win_platform?
+ pend "chmod not supported" if Gem.win_platform?
begin
- File.chmod 0444, 'test'
+ File.chmod 0444, "test"
- assert_equal ["\xCF", "\x80"], Gem.read_binary('test').chars.to_a
+ assert_equal ["\xCF", "\x80"], Gem.read_binary("test").chars.to_a
ensure
- File.chmod 0644, 'test'
+ File.chmod 0644, "test"
end
end
@@ -1084,72 +1084,72 @@ class TestGem < Gem::TestCase
end
def test_self_ruby_api_version
- orig_ruby_version, RbConfig::CONFIG['ruby_version'] = RbConfig::CONFIG['ruby_version'], '1.2.3'
+ orig_ruby_version, RbConfig::CONFIG["ruby_version"] = RbConfig::CONFIG["ruby_version"], "1.2.3"
Gem.instance_variable_set :@ruby_api_version, nil
- assert_equal '1.2.3', Gem.ruby_api_version
+ assert_equal "1.2.3", Gem.ruby_api_version
ensure
Gem.instance_variable_set :@ruby_api_version, nil
- RbConfig::CONFIG['ruby_version'] = orig_ruby_version
+ RbConfig::CONFIG["ruby_version"] = orig_ruby_version
end
def test_self_env_requirement
- ENV["GEM_REQUIREMENT_FOO"] = '>= 1.2.3'
- ENV["GEM_REQUIREMENT_BAR"] = '1.2.3'
- ENV["GEM_REQUIREMENT_BAZ"] = 'abcd'
+ ENV["GEM_REQUIREMENT_FOO"] = ">= 1.2.3"
+ ENV["GEM_REQUIREMENT_BAR"] = "1.2.3"
+ ENV["GEM_REQUIREMENT_BAZ"] = "abcd"
- assert_equal Gem::Requirement.create('>= 1.2.3'), Gem.env_requirement('foo')
- assert_equal Gem::Requirement.create('1.2.3'), Gem.env_requirement('bAr')
- assert_raise(Gem::Requirement::BadRequirementError) { Gem.env_requirement('baz') }
- assert_equal Gem::Requirement.default, Gem.env_requirement('qux')
+ assert_equal Gem::Requirement.create(">= 1.2.3"), Gem.env_requirement("foo")
+ assert_equal Gem::Requirement.create("1.2.3"), Gem.env_requirement("bAr")
+ assert_raise(Gem::Requirement::BadRequirementError) { Gem.env_requirement("baz") }
+ assert_equal Gem::Requirement.default, Gem.env_requirement("qux")
end
def test_self_ruby_version_with_non_mri_implementations
- util_set_RUBY_VERSION '2.5.0', 0, 60928, 'jruby 9.2.0.0 (2.5.0) 2018-05-24 81156a8 OpenJDK 64-Bit Server VM 25.171-b11 on 1.8.0_171-8u171-b11-0ubuntu0.16.04.1-b11 [linux-x86_64]'
+ util_set_RUBY_VERSION "2.5.0", 0, 60928, "jruby 9.2.0.0 (2.5.0) 2018-05-24 81156a8 OpenJDK 64-Bit Server VM 25.171-b11 on 1.8.0_171-8u171-b11-0ubuntu0.16.04.1-b11 [linux-x86_64]"
- assert_equal Gem::Version.new('2.5.0'), Gem.ruby_version
+ assert_equal Gem::Version.new("2.5.0"), Gem.ruby_version
ensure
util_restore_RUBY_VERSION
end
def test_self_ruby_version_with_svn_prerelease
- util_set_RUBY_VERSION '2.6.0', -1, 63539, 'ruby 2.6.0preview2 (2018-05-31 trunk 63539) [x86_64-linux]'
+ util_set_RUBY_VERSION "2.6.0", -1, 63539, "ruby 2.6.0preview2 (2018-05-31 trunk 63539) [x86_64-linux]"
- assert_equal Gem::Version.new('2.6.0.preview2'), Gem.ruby_version
+ assert_equal Gem::Version.new("2.6.0.preview2"), Gem.ruby_version
ensure
util_restore_RUBY_VERSION
end
def test_self_ruby_version_with_git_prerelease
- util_set_RUBY_VERSION '2.7.0', -1, 'b563439274a402e33541f5695b1bfd4ac1085638', 'ruby 2.7.0preview3 (2019-11-23 master b563439274) [x86_64-linux]'
+ util_set_RUBY_VERSION "2.7.0", -1, "b563439274a402e33541f5695b1bfd4ac1085638", "ruby 2.7.0preview3 (2019-11-23 master b563439274) [x86_64-linux]"
- assert_equal Gem::Version.new('2.7.0.preview3'), Gem.ruby_version
+ assert_equal Gem::Version.new("2.7.0.preview3"), Gem.ruby_version
ensure
util_restore_RUBY_VERSION
end
def test_self_ruby_version_with_non_mri_implementations_with_mri_prerelase_compatibility
- util_set_RUBY_VERSION '2.6.0', -1, 63539, 'weirdjruby 9.2.0.0 (2.6.0preview2) 2018-05-24 81156a8 OpenJDK 64-Bit Server VM 25.171-b11 on 1.8.0_171-8u171-b11-0ubuntu0.16.04.1-b11 [linux-x86_64]', 'weirdjruby', '9.2.0.0'
+ util_set_RUBY_VERSION "2.6.0", -1, 63539, "weirdjruby 9.2.0.0 (2.6.0preview2) 2018-05-24 81156a8 OpenJDK 64-Bit Server VM 25.171-b11 on 1.8.0_171-8u171-b11-0ubuntu0.16.04.1-b11 [linux-x86_64]", "weirdjruby", "9.2.0.0"
- assert_equal Gem::Version.new('2.6.0.preview2'), Gem.ruby_version
+ assert_equal Gem::Version.new("2.6.0.preview2"), Gem.ruby_version
ensure
util_restore_RUBY_VERSION
end
def test_self_ruby_version_with_svn_trunk
- util_set_RUBY_VERSION '1.9.2', -1, 23493, 'ruby 1.9.2dev (2009-05-20 trunk 23493) [x86_64-linux]'
+ util_set_RUBY_VERSION "1.9.2", -1, 23493, "ruby 1.9.2dev (2009-05-20 trunk 23493) [x86_64-linux]"
- assert_equal Gem::Version.new('1.9.2.dev'), Gem.ruby_version
+ assert_equal Gem::Version.new("1.9.2.dev"), Gem.ruby_version
ensure
util_restore_RUBY_VERSION
end
def test_self_ruby_version_with_git_master
- util_set_RUBY_VERSION '2.7.0', -1, '5de284ec78220e75643f89b454ce999da0c1c195', 'ruby 2.7.0dev (2019-12-23T01:37:30Z master 5de284ec78) [x86_64-linux]'
+ util_set_RUBY_VERSION "2.7.0", -1, "5de284ec78220e75643f89b454ce999da0c1c195", "ruby 2.7.0dev (2019-12-23T01:37:30Z master 5de284ec78) [x86_64-linux]"
- assert_equal Gem::Version.new('2.7.0.dev'), Gem.ruby_version
+ assert_equal Gem::Version.new("2.7.0.dev"), Gem.ruby_version
ensure
util_restore_RUBY_VERSION
end
@@ -1159,7 +1159,7 @@ class TestGem < Gem::TestCase
end
def test_self_paths_eq
- other = File.join @tempdir, 'other'
+ other = File.join @tempdir, "other"
path = [@userhome, other].join File::PATH_SEPARATOR
#
@@ -1172,12 +1172,12 @@ class TestGem < Gem::TestCase
end
def test_self_paths_eq_nonexistent_home
- ENV['GEM_HOME'] = @gemhome
+ ENV["GEM_HOME"] = @gemhome
Gem.clear_paths
- other = File.join @tempdir, 'other'
+ other = File.join @tempdir, "other"
- ENV['HOME'] = other
+ ENV["HOME"] = other
Gem.paths = { "GEM_PATH" => other }
@@ -1256,43 +1256,43 @@ class TestGem < Gem::TestCase
end
def test_try_activate_returns_true_for_activated_specs
- b = util_spec 'b', '1.0' do |spec|
- spec.files << 'lib/b.rb'
+ b = util_spec "b", "1.0" do |spec|
+ spec.files << "lib/b.rb"
end
install_specs b
- assert Gem.try_activate('b'), 'try_activate should return true'
- assert Gem.try_activate('b'), 'try_activate should still return true'
+ assert Gem.try_activate("b"), "try_activate should return true"
+ assert Gem.try_activate("b"), "try_activate should still return true"
end
def test_spec_order_is_consistent
- b1 = util_spec 'b', '1.0'
- b2 = util_spec 'b', '2.0'
- b3 = util_spec 'b', '3.0'
+ b1 = util_spec "b", "1.0"
+ b2 = util_spec "b", "2.0"
+ b3 = util_spec "b", "3.0"
install_specs b1, b2, b3
- specs1 = Gem::Specification.stubs.find_all {|s| s.name == 'b' }
+ specs1 = Gem::Specification.stubs.find_all {|s| s.name == "b" }
Gem::Specification.reset
- specs2 = Gem::Specification.stubs_for('b')
+ specs2 = Gem::Specification.stubs_for("b")
assert_equal specs1.map(&:version), specs2.map(&:version)
end
def test_self_try_activate_missing_dep
- b = util_spec 'b', '1.0'
- a = util_spec 'a', '1.0', 'b' => '>= 1.0'
+ b = util_spec "b", "1.0"
+ a = util_spec "a", "1.0", "b" => ">= 1.0"
install_specs b, a
uninstall_gem b
- a_file = File.join a.gem_dir, 'lib', 'a_file.rb'
+ a_file = File.join a.gem_dir, "lib", "a_file.rb"
write_file a_file do |io|
- io.puts '# a_file.rb'
+ io.puts "# a_file.rb"
end
e = assert_raise Gem::MissingSpecError do
- Gem.try_activate 'a_file'
+ Gem.try_activate "a_file"
end
assert_match %r{Could not find 'b' }, e.message
@@ -1300,30 +1300,30 @@ class TestGem < Gem::TestCase
end
def test_self_try_activate_missing_prerelease
- b = util_spec 'b', '1.0rc1'
- a = util_spec 'a', '1.0rc1', 'b' => '1.0rc1'
+ b = util_spec "b", "1.0rc1"
+ a = util_spec "a", "1.0rc1", "b" => "1.0rc1"
install_specs b, a
uninstall_gem b
- a_file = File.join a.gem_dir, 'lib', 'a_file.rb'
+ a_file = File.join a.gem_dir, "lib", "a_file.rb"
write_file a_file do |io|
- io.puts '# a_file.rb'
+ io.puts "# a_file.rb"
end
e = assert_raise Gem::MissingSpecError do
- Gem.try_activate 'a_file'
+ Gem.try_activate "a_file"
end
assert_match %r{Could not find 'b' \(= 1.0rc1\)}, e.message
end
def test_self_try_activate_missing_extensions
- spec = util_spec 'ext', '1' do |s|
+ spec = util_spec "ext", "1" do |s|
s.extensions = %w[ext/extconf.rb]
s.mark_version
- s.installed_by_version = v('2.2')
+ s.installed_by_version = v("2.2")
end
# write the spec without install to simulate a failed install
@@ -1332,7 +1332,7 @@ class TestGem < Gem::TestCase
end
_, err = capture_output do
- refute Gem.try_activate 'nonexistent'
+ refute Gem.try_activate "nonexistent"
end
unless Gem.java_platform?
@@ -1344,43 +1344,43 @@ class TestGem < Gem::TestCase
end
def test_self_use_paths_with_nils
- orig_home = ENV.delete 'GEM_HOME'
- orig_path = ENV.delete 'GEM_PATH'
+ orig_home = ENV.delete "GEM_HOME"
+ orig_path = ENV.delete "GEM_PATH"
Gem.use_paths nil, nil
assert_equal Gem.default_dir, Gem.paths.home
path = (Gem.default_path + [Gem.paths.home]).uniq
assert_equal path, Gem.paths.path
ensure
- ENV['GEM_HOME'] = orig_home
- ENV['GEM_PATH'] = orig_path
+ ENV["GEM_HOME"] = orig_home
+ ENV["GEM_PATH"] = orig_path
end
def test_setting_paths_does_not_warn_about_unknown_keys
stdout, stderr = capture_output do
- Gem.paths = { 'foo' => [],
- 'bar' => Object.new,
- 'GEM_HOME' => Gem.paths.home,
- 'GEM_PATH' => 'foo' }
+ Gem.paths = { "foo" => [],
+ "bar" => Object.new,
+ "GEM_HOME" => Gem.paths.home,
+ "GEM_PATH" => "foo" }
end
- assert_equal ['foo', Gem.paths.home], Gem.paths.path
- assert_equal '', stderr
- assert_equal '', stdout
+ assert_equal ["foo", Gem.paths.home], Gem.paths.path
+ assert_equal "", stderr
+ assert_equal "", stdout
end
def test_setting_paths_does_not_mutate_parameter_object
- Gem.paths = { 'GEM_HOME' => Gem.paths.home,
- 'GEM_PATH' => 'foo' }.freeze
- assert_equal ['foo', Gem.paths.home], Gem.paths.path
+ Gem.paths = { "GEM_HOME" => Gem.paths.home,
+ "GEM_PATH" => "foo" }.freeze
+ assert_equal ["foo", Gem.paths.home], Gem.paths.path
end
def test_deprecated_paths=
stdout, stderr = capture_output do
- Gem.paths = { 'GEM_HOME' => Gem.paths.home,
- 'GEM_PATH' => [Gem.paths.home, 'foo'] }
+ Gem.paths = { "GEM_HOME" => Gem.paths.home,
+ "GEM_PATH" => [Gem.paths.home, "foo"] }
end
- assert_equal [Gem.paths.home, 'foo'], Gem.paths.path
+ assert_equal [Gem.paths.home, "foo"], Gem.paths.path
assert_match(/Array values in the parameter to `Gem.paths=` are deprecated.\nPlease use a String or nil/m, stderr)
- assert_equal '', stdout
+ assert_equal "", stdout
end
def test_self_use_paths
@@ -1393,8 +1393,8 @@ class TestGem < Gem::TestCase
end
def test_self_user_dir
- parts = [@userhome, '.gem', Gem.ruby_engine]
- parts << RbConfig::CONFIG['ruby_version'] unless RbConfig::CONFIG['ruby_version'].empty?
+ parts = [@userhome, ".gem", Gem.ruby_engine]
+ parts << RbConfig::CONFIG["ruby_version"] unless RbConfig::CONFIG["ruby_version"].empty?
FileUtils.mkdir_p File.join(parts)
@@ -1402,10 +1402,10 @@ class TestGem < Gem::TestCase
end
def test_self_user_home
- if ENV['HOME']
- assert_equal ENV['HOME'], Gem.user_home
+ if ENV["HOME"]
+ assert_equal ENV["HOME"], Gem.user_home
else
- assert true, 'count this test'
+ assert true, "count this test"
end
end
@@ -1430,7 +1430,7 @@ class TestGem < Gem::TestCase
a = util_spec "a", "1"
b = util_spec "b", "1", "c" => nil
c = util_spec "c", "2"
- d = util_spec "d", "1", { 'e' => '= 1' }, "lib/d#{$$}.rb"
+ d = util_spec "d", "1", { "e" => "= 1" }, "lib/d#{$$}.rb"
e = util_spec "e", "1"
install_specs a, c, b, e, d
@@ -1451,35 +1451,35 @@ class TestGem < Gem::TestCase
output = Gem::Util.gunzip input
- assert_equal 'hello', output
+ assert_equal "hello", output
assert_equal Encoding::BINARY, output.encoding
end
def test_self_gzip
- input = 'hello'
+ input = "hello"
output = Gem::Util.gzip input
zipped = StringIO.new output
- assert_equal 'hello', Zlib::GzipReader.new(zipped).read
+ assert_equal "hello", Zlib::GzipReader.new(zipped).read
assert_equal Encoding::BINARY, output.encoding
end
def test_self_vendor_dir
- vendordir(File.join(@tempdir, 'vendor')) do
+ vendordir(File.join(@tempdir, "vendor")) do
expected =
- File.join RbConfig::CONFIG['vendordir'], 'gems',
- RbConfig::CONFIG['ruby_version']
+ File.join RbConfig::CONFIG["vendordir"], "gems",
+ RbConfig::CONFIG["ruby_version"]
assert_equal expected, Gem.vendor_dir
end
end
def test_self_vendor_dir_ENV_GEM_VENDOR
- ENV['GEM_VENDOR'] = File.join @tempdir, 'vendor', 'gems'
+ ENV["GEM_VENDOR"] = File.join @tempdir, "vendor", "gems"
- assert_equal ENV['GEM_VENDOR'], Gem.vendor_dir
+ assert_equal ENV["GEM_VENDOR"], Gem.vendor_dir
refute Gem.vendor_dir.frozen?
end
@@ -1493,18 +1493,18 @@ class TestGem < Gem::TestCase
plugin_path = File.join "lib", "rubygems_plugin.rb"
Dir.chdir @tempdir do
- FileUtils.mkdir_p 'lib'
+ FileUtils.mkdir_p "lib"
File.open plugin_path, "w" do |fp|
fp.puts "class TestGem; PLUGINS_LOADED << 'plugin'; end"
end
- foo1 = util_spec 'foo', '1' do |s|
+ foo1 = util_spec "foo", "1" do |s|
s.files << plugin_path
end
install_gem foo1
- foo2 = util_spec 'foo', '2' do |s|
+ foo2 = util_spec "foo", "2" do |s|
s.files << plugin_path
end
@@ -1513,7 +1513,7 @@ class TestGem < Gem::TestCase
Gem::Specification.reset
- gem 'foo'
+ gem "foo"
Gem.load_plugins
@@ -1524,12 +1524,12 @@ class TestGem < Gem::TestCase
plugin_path = File.join "lib", "rubygems_plugin.rb"
Dir.chdir @tempdir do
- FileUtils.mkdir_p 'lib'
+ FileUtils.mkdir_p "lib"
File.open plugin_path, "w" do |fp|
fp.puts "class TestGem; PLUGINS_LOADED << 'plugin'; end"
end
- foo = util_spec 'foo', '1' do |s|
+ foo = util_spec "foo", "1" do |s|
s.files << plugin_path
end
@@ -1538,7 +1538,7 @@ class TestGem < Gem::TestCase
Gem.paths = { "GEM_PATH" => [Gem.dir, Gem.user_dir].join(File::PATH_SEPARATOR) }
- gem 'foo'
+ gem "foo"
Gem.load_plugins
@@ -1546,30 +1546,30 @@ class TestGem < Gem::TestCase
end
def test_load_env_plugins
- with_plugin('load') { Gem.load_env_plugins }
+ with_plugin("load") { Gem.load_env_plugins }
assert_equal :loaded, TEST_PLUGIN_LOAD rescue nil
util_remove_interrupt_command
# Should attempt to cause a StandardError
- with_plugin('standarderror') { Gem.load_env_plugins }
+ with_plugin("standarderror") { Gem.load_env_plugins }
assert_equal :loaded, TEST_PLUGIN_STANDARDERROR rescue nil
util_remove_interrupt_command
# Should attempt to cause an Exception
- with_plugin('exception') { Gem.load_env_plugins }
+ with_plugin("exception") { Gem.load_env_plugins }
assert_equal :loaded, TEST_PLUGIN_EXCEPTION rescue nil
end
def test_gem_path_ordering
refute_equal Gem.dir, Gem.user_dir
- write_file File.join(@tempdir, 'lib', "g.rb") {|fp| fp.puts "" }
- write_file File.join(@tempdir, 'lib', 'm.rb') {|fp| fp.puts "" }
+ write_file File.join(@tempdir, "lib", "g.rb") {|fp| fp.puts "" }
+ write_file File.join(@tempdir, "lib", "m.rb") {|fp| fp.puts "" }
- g = util_spec 'g', '1', nil, "lib/g.rb"
- m = util_spec 'm', '1', nil, "lib/m.rb"
+ g = util_spec "g", "1", nil, "lib/g.rb"
+ m = util_spec "m", "1", nil, "lib/m.rb"
install_gem g, :install_dir => Gem.dir
m0 = install_gem m, :install_dir => Gem.dir
@@ -1588,15 +1588,15 @@ class TestGem < Gem::TestCase
Gem::Specification.reset
Gem.searcher = nil
- assert_equal Gem::Dependency.new('m','1').to_specs,
- Gem::Dependency.new('m','1').to_specs.sort
+ assert_equal Gem::Dependency.new("m","1").to_specs,
+ Gem::Dependency.new("m","1").to_specs.sort
assert_equal \
[expected.gem_dir],
- Gem::Dependency.new('m','1').to_specs.map(&:gem_dir).sort,
+ Gem::Dependency.new("m","1").to_specs.map(&:gem_dir).sort,
"Wrong specs for #{_name}"
- spec = Gem::Dependency.new('m','1').to_spec
+ spec = Gem::Dependency.new("m","1").to_spec
assert_equal \
File.join(_paths.first, "gems", "m-1"),
@@ -1606,7 +1606,7 @@ class TestGem < Gem::TestCase
gem "m"
- spec = Gem::Dependency.new('m','1').to_spec
+ spec = Gem::Dependency.new("m","1").to_spec
assert spec.activated?, "dependency not activated for #{_name}"
assert_equal \
@@ -1621,11 +1621,11 @@ class TestGem < Gem::TestCase
end
def test_gem_path_ordering_short
- write_file File.join(@tempdir, 'lib', "g.rb") {|fp| fp.puts "" }
- write_file File.join(@tempdir, 'lib', 'm.rb') {|fp| fp.puts "" }
+ write_file File.join(@tempdir, "lib", "g.rb") {|fp| fp.puts "" }
+ write_file File.join(@tempdir, "lib", "m.rb") {|fp| fp.puts "" }
- g = util_spec 'g', '1', nil, "lib/g.rb"
- m = util_spec 'm', '1', nil, "lib/m.rb"
+ g = util_spec "g", "1", nil, "lib/g.rb"
+ m = util_spec "m", "1", nil, "lib/m.rb"
install_gem g, :install_dir => Gem.dir
install_gem m, :install_dir => Gem.dir
@@ -1635,7 +1635,7 @@ class TestGem < Gem::TestCase
assert_equal \
File.join(Gem.dir, "gems", "m-1"),
- Gem::Dependency.new('m','1').to_spec.gem_dir,
+ Gem::Dependency.new("m","1").to_spec.gem_dir,
"Wrong spec selected"
end
@@ -1702,7 +1702,7 @@ class TestGem < Gem::TestCase
s.bindir = "exe"
end
- write_file File.join(@tempdir, 'exe', 'foo') do |fp|
+ write_file File.join(@tempdir, "exe", "foo") do |fp|
fp.puts "puts Gem.loaded_specs.values.map(&:full_name).sort"
end
@@ -1716,7 +1716,7 @@ class TestGem < Gem::TestCase
install_gem b, :install_dir => path
install_gem c, :install_dir => path
- ENV['GEM_PATH'] = path
+ ENV["GEM_PATH"] = path
with_rubygems_gemdeps("-") do
new_PATH = [File.join(path, "bin"), ENV["PATH"]].join(File::PATH_SEPARATOR)
@@ -1751,7 +1751,7 @@ class TestGem < Gem::TestCase
s.bindir = "exe"
end
- write_file File.join(@tempdir, 'exe', 'foo') do |fp|
+ write_file File.join(@tempdir, "exe", "foo") do |fp|
fp.puts "puts Gem.loaded_specs.values.map(&:full_name).sort"
end
@@ -1765,7 +1765,7 @@ class TestGem < Gem::TestCase
install_gem b, :install_dir => path
install_gem c, :install_dir => path
- ENV['GEM_PATH'] = path
+ ENV["GEM_PATH"] = path
with_rubygems_gemdeps("-") do
Dir.mkdir "sub1"
@@ -1837,14 +1837,14 @@ class TestGem < Gem::TestCase
end
def test_use_gemdeps
- gem_deps_file = 'gem.deps.rb'.tap(&Gem::UNTAINT)
- spec = util_spec 'a', 1
+ gem_deps_file = "gem.deps.rb".tap(&Gem::UNTAINT)
+ spec = util_spec "a", 1
install_specs spec
spec = Gem::Specification.find {|s| s == spec }
refute spec.activated?
- File.open gem_deps_file, 'w' do |io|
+ File.open gem_deps_file, "w" do |io|
io.write 'gem "a"'
end
@@ -1858,11 +1858,11 @@ class TestGem < Gem::TestCase
def test_use_gemdeps_ENV
with_rubygems_gemdeps(nil) do
- spec = util_spec 'a', 1
+ spec = util_spec "a", 1
refute spec.activated?
- File.open 'gem.deps.rb', 'w' do |io|
+ File.open "gem.deps.rb", "w" do |io|
io.write 'gem "a"'
end
@@ -1874,33 +1874,33 @@ class TestGem < Gem::TestCase
def test_use_gemdeps_argument_missing
e = assert_raise ArgumentError do
- Gem.use_gemdeps 'gem.deps.rb'
+ Gem.use_gemdeps "gem.deps.rb"
end
- assert_equal 'Unable to find gem dependencies file at gem.deps.rb',
+ assert_equal "Unable to find gem dependencies file at gem.deps.rb",
e.message
end
def test_use_gemdeps_argument_missing_match_ENV
- with_rubygems_gemdeps('gem.deps.rb') do
+ with_rubygems_gemdeps("gem.deps.rb") do
e = assert_raise ArgumentError do
- Gem.use_gemdeps 'gem.deps.rb'
+ Gem.use_gemdeps "gem.deps.rb"
end
- assert_equal 'Unable to find gem dependencies file at gem.deps.rb',
+ assert_equal "Unable to find gem dependencies file at gem.deps.rb",
e.message
end
end
def test_use_gemdeps_automatic
- with_rubygems_gemdeps('-') do
- spec = util_spec 'a', 1
+ with_rubygems_gemdeps("-") do
+ spec = util_spec "a", 1
install_specs spec
spec = Gem::Specification.find {|s| s == spec }
refute spec.activated?
- File.open 'Gemfile', 'w' do |io|
+ File.open "Gemfile", "w" do |io|
io.write 'gem "a"'
end
@@ -1911,7 +1911,7 @@ class TestGem < Gem::TestCase
end
def test_use_gemdeps_automatic_missing
- with_rubygems_gemdeps('-') do
+ with_rubygems_gemdeps("-") do
Gem.use_gemdeps
assert true # count
@@ -1919,12 +1919,12 @@ class TestGem < Gem::TestCase
end
def test_use_gemdeps_disabled
- with_rubygems_gemdeps('') do
- spec = util_spec 'a', 1
+ with_rubygems_gemdeps("") do
+ spec = util_spec "a", 1
refute spec.activated?
- File.open 'gem.deps.rb', 'w' do |io|
+ File.open "gem.deps.rb", "w" do |io|
io.write 'gem "a"'
end
@@ -1935,8 +1935,8 @@ class TestGem < Gem::TestCase
end
def test_use_gemdeps_missing_gem
- with_rubygems_gemdeps('x') do
- File.open 'x', 'w' do |io|
+ with_rubygems_gemdeps("x") do
+ File.open "x", "w" do |io|
io.write 'gem "a"'
end
@@ -1957,14 +1957,14 @@ You may need to `bundle install` to install missing gems
end
def test_use_gemdeps_specific
- with_rubygems_gemdeps('x') do
- spec = util_spec 'a', 1
+ with_rubygems_gemdeps("x") do
+ spec = util_spec "a", 1
install_specs spec
spec = Gem::Specification.find {|s| s == spec }
refute spec.activated?
- File.open 'x', 'w' do |io|
+ File.open "x", "w" do |io|
io.write 'gem "a"'
end
@@ -1991,8 +1991,8 @@ You may need to `bundle install` to install missing gems
# Ensure that `Gem.source_date_epoch` is consistent even if
# $SOURCE_DATE_EPOCH has not been set.
def test_default_source_date_epoch_doesnt_change
- old_epoch = ENV['SOURCE_DATE_EPOCH']
- ENV['SOURCE_DATE_EPOCH'] = nil
+ old_epoch = ENV["SOURCE_DATE_EPOCH"]
+ ENV["SOURCE_DATE_EPOCH"] = nil
# Unfortunately, there is no real way to test this aside from waiting
# enough for `Time.now.to_i` to change -- which is a whole second.
@@ -2003,23 +2003,23 @@ You may need to `bundle install` to install missing gems
b = Gem.source_date_epoch
assert_equal a, b
ensure
- ENV['SOURCE_DATE_EPOCH'] = old_epoch
+ ENV["SOURCE_DATE_EPOCH"] = old_epoch
end
private
def ruby_install_name(name)
with_clean_path_to_ruby do
- orig_RUBY_INSTALL_NAME = RbConfig::CONFIG['ruby_install_name']
- RbConfig::CONFIG['ruby_install_name'] = name
+ orig_RUBY_INSTALL_NAME = RbConfig::CONFIG["ruby_install_name"]
+ RbConfig::CONFIG["ruby_install_name"] = name
begin
yield
ensure
if orig_RUBY_INSTALL_NAME
- RbConfig::CONFIG['ruby_install_name'] = orig_RUBY_INSTALL_NAME
+ RbConfig::CONFIG["ruby_install_name"] = orig_RUBY_INSTALL_NAME
else
- RbConfig::CONFIG.delete 'ruby_install_name'
+ RbConfig::CONFIG.delete "ruby_install_name"
end
end
end
@@ -2074,12 +2074,12 @@ You may need to `bundle install` to install missing gems
end
def util_exec_gem
- spec, _ = util_spec 'a', '4' do |s|
- s.executables = ['exec', 'abin']
+ spec, _ = util_spec "a", "4" do |s|
+ s.executables = ["exec", "abin"]
end
- @exec_path = File.join spec.full_gem_path, spec.bindir, 'exec'
- @abin_path = File.join spec.full_gem_path, spec.bindir, 'abin'
+ @exec_path = File.join spec.full_gem_path, spec.bindir, "exec"
+ @abin_path = File.join spec.full_gem_path, spec.bindir, "abin"
spec
end
@@ -2093,20 +2093,20 @@ You may need to `bundle install` to install missing gems
end
def with_path_and_rubyopt(path_value, rubyopt_value)
- path, ENV['PATH'] = ENV['PATH'], path_value
- rubyopt, ENV['RUBYOPT'] = ENV['RUBYOPT'], rubyopt_value
+ path, ENV["PATH"] = ENV["PATH"], path_value
+ rubyopt, ENV["RUBYOPT"] = ENV["RUBYOPT"], rubyopt_value
yield
ensure
- ENV['PATH'] = path
- ENV['RUBYOPT'] = rubyopt
+ ENV["PATH"] = path
+ ENV["RUBYOPT"] = rubyopt
end
def with_rubygems_gemdeps(value)
- rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], value
+ rubygems_gemdeps, ENV["RUBYGEMS_GEMDEPS"] = ENV["RUBYGEMS_GEMDEPS"], value
yield
ensure
- ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps
+ ENV["RUBYGEMS_GEMDEPS"] = rubygems_gemdeps
end
end
diff --git a/test/rubygems/test_gem_available_set.rb b/test/rubygems/test_gem_available_set.rb
index c4164d77f2..576f3f4221 100644
--- a/test/rubygems/test_gem_available_set.rb
+++ b/test/rubygems/test_gem_available_set.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/available_set'
-require 'rubygems/security'
+require_relative "helper"
+require "rubygems/available_set"
+require "rubygems/security"
class TestGemAvailableSet < Gem::TestCase
def setup
@@ -11,7 +11,7 @@ class TestGemAvailableSet < Gem::TestCase
end
def test_add_and_empty
- a1, _ = util_gem 'a', '1'
+ a1, _ = util_gem "a", "1"
set = Gem::AvailableSet.new
assert set.empty?
@@ -24,8 +24,8 @@ class TestGemAvailableSet < Gem::TestCase
end
def test_find_all
- a1, a1_gem = util_gem 'a', 1
- a1a, a1a_gem = util_gem 'a', '1.a'
+ a1, a1_gem = util_gem "a", 1
+ a1a, a1a_gem = util_gem "a", "1.a"
a1_source = Gem::Source::SpecificFile.new a1_gem
a1a_source = Gem::Source::SpecificFile.new a1a_gem
@@ -34,26 +34,26 @@ class TestGemAvailableSet < Gem::TestCase
set.add a1, a1_source
set.add a1a, a1a_source
- dep = Gem::Resolver::DependencyRequest.new dep('a'), nil
+ dep = Gem::Resolver::DependencyRequest.new dep("a"), nil
assert_equal %w[a-1], set.find_all(dep).map {|spec| spec.full_name }
- dep = Gem::Resolver::DependencyRequest.new dep('a', '>= 0.a'), nil
+ dep = Gem::Resolver::DependencyRequest.new dep("a", ">= 0.a"), nil
assert_equal %w[a-1 a-1.a],
set.find_all(dep).map {|spec| spec.full_name }.sort
end
def test_match_platform
- a1, _ = util_gem 'a', '1' do |g|
+ a1, _ = util_gem "a", "1" do |g|
g.platform = "something-weird-yep"
end
- a1c, _ = util_gem 'a', '2' do |g|
+ a1c, _ = util_gem "a", "2" do |g|
g.platform = Gem::Platform.local
end
- a2, _ = util_gem 'a', '2'
+ a2, _ = util_gem "a", "2"
set = Gem::AvailableSet.new
set.add a1, @source
@@ -66,8 +66,8 @@ class TestGemAvailableSet < Gem::TestCase
end
def test_best
- a1, _ = util_gem 'a', '1'
- a2, _ = util_gem 'a', '2'
+ a1, _ = util_gem "a", "1"
+ a2, _ = util_gem "a", "2"
set = Gem::AvailableSet.new
set.add a1, @source
@@ -79,7 +79,7 @@ class TestGemAvailableSet < Gem::TestCase
end
def test_remove_installed_bang
- a1, _ = util_spec 'a', '1'
+ a1, _ = util_spec "a", "1"
install_specs a1
a1.activate
@@ -95,8 +95,8 @@ class TestGemAvailableSet < Gem::TestCase
end
def test_sorted_normal_versions
- a1, _ = util_gem 'a', '1'
- a2, _ = util_gem 'a', '2'
+ a1, _ = util_gem "a", "1"
+ a2, _ = util_gem "a", "2"
set = Gem::AvailableSet.new
set.add a1, @source
@@ -109,11 +109,11 @@ class TestGemAvailableSet < Gem::TestCase
end
def test_sorted_respect_pre
- a1a, _ = util_gem 'a', '1.a'
- a1, _ = util_gem 'a', '1'
- a2a, _ = util_gem 'a', '2.a'
- a2, _ = util_gem 'a', '2'
- a3a, _ = util_gem 'a', '3.a'
+ a1a, _ = util_gem "a", "1.a"
+ a1, _ = util_gem "a", "1"
+ a2a, _ = util_gem "a", "2.a"
+ a2, _ = util_gem "a", "2"
+ a3a, _ = util_gem "a", "3.a"
set = Gem::AvailableSet.new
set.add a1, @source
diff --git a/test/rubygems/test_gem_bundler_version_finder.rb b/test/rubygems/test_gem_bundler_version_finder.rb
index 7494a94d6e..60e2b65047 100644
--- a/test/rubygems/test_gem_bundler_version_finder.rb
+++ b/test/rubygems/test_gem_bundler_version_finder.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require_relative 'helper'
+require_relative "helper"
class TestGemBundlerVersionFinder < Gem::TestCase
def setup
@@ -78,7 +78,7 @@ class TestGemBundlerVersionFinder < Gem::TestCase
def test_deleted_directory
pend "Cannot perform this test on windows" if win_platform?
- pend "Cannot perform this test on Solaris" if /solaris/ =~ RUBY_PLATFORM
+ pend "Cannot perform this test on Solaris" if RUBY_PLATFORM.include?("solaris")
require "tmpdir"
orig_dir = Dir.pwd
diff --git a/test/rubygems/test_gem_command.rb b/test/rubygems/test_gem_command.rb
index 65b9b040b7..99fa89364d 100644
--- a/test/rubygems/test_gem_command.rb
+++ b/test/rubygems/test_gem_command.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/command'
+require_relative "helper"
+require "rubygems/command"
class Gem::Command
public :parser
@@ -15,13 +15,13 @@ class TestGemCommand < Gem::TestCase
@common_options = Gem::Command.common_options.dup
Gem::Command.common_options.clear
Gem::Command.common_options << [
- ['-x', '--exe', 'Execute'], lambda do |*a|
+ ["-x", "--exe", "Execute"], lambda do |*a|
@xopt = true
end
]
- @cmd_name = 'doit'
- @cmd = Gem::Command.new @cmd_name, 'summary'
+ @cmd_name = "doit"
+ @cmd = Gem::Command.new @cmd_name, "summary"
end
def teardown
@@ -31,7 +31,7 @@ class TestGemCommand < Gem::TestCase
def test_self_add_specific_extra_args
added_args = %w[--all]
- @cmd.add_option('--all') {|v,o| }
+ @cmd.add_option("--all") {|v,o| }
Gem::Command.add_specific_extra_args @cmd_name, added_args
@@ -86,7 +86,7 @@ class TestGemCommand < Gem::TestCase
end
def test_defaults
- @cmd.add_option('-h', '--help [COMMAND]', 'Get help on COMMAND') do |value, options|
+ @cmd.add_option("-h", "--help [COMMAND]", "Get help on COMMAND") do |value, options|
options[:help] = value
end
@@ -119,7 +119,7 @@ class TestGemCommand < Gem::TestCase
@cmd.when_invoked { true }
ex = assert_raise Gem::OptionParser::InvalidOption do
- @cmd.invoke('-zzz')
+ @cmd.invoke("-zzz")
end
assert_match(/invalid option:/, ex.message)
@@ -151,12 +151,12 @@ class TestGemCommand < Gem::TestCase
done = false
use_ui @ui do
- @cmd.add_option('-h', '--help [COMMAND]', 'Get help on COMMAND') do |value, options|
+ @cmd.add_option("-h", "--help [COMMAND]", "Get help on COMMAND") do |value, options|
options[:help] = true
done = true
end
- @cmd.invoke('--help')
+ @cmd.invoke("--help")
assert done
end
@@ -174,7 +174,7 @@ class TestGemCommand < Gem::TestCase
end
def test_invoke_with_options
- @cmd.add_option('-h', '--help [COMMAND]', 'Get help on COMMAND') do |value, options|
+ @cmd.add_option("-h", "--help [COMMAND]", "Get help on COMMAND") do |value, options|
options[:help] = true
end
@@ -183,7 +183,7 @@ class TestGemCommand < Gem::TestCase
end
use_ui @ui do
- @cmd.invoke '-h'
+ @cmd.invoke "-h"
end
assert_match %r{Usage: gem doit}, @ui.output
@@ -191,40 +191,40 @@ class TestGemCommand < Gem::TestCase
def test_add_option
assert_nothing_raised RuntimeError do
- @cmd.add_option('--force', 'skip validation of the spec') {|v,o| }
+ @cmd.add_option("--force", "skip validation of the spec") {|v,o| }
end
end
def test_add_option_with_empty
assert_raise RuntimeError, "Do not pass an empty string in opts" do
- @cmd.add_option('', 'skip validation of the spec') {|v,o| }
+ @cmd.add_option("", "skip validation of the spec") {|v,o| }
end
end
def test_option_recognition
- @cmd.add_option('-h', '--help [COMMAND]', 'Get help on COMMAND') do |value, options|
+ @cmd.add_option("-h", "--help [COMMAND]", "Get help on COMMAND") do |value, options|
options[:help] = true
end
- @cmd.add_option('-f', '--file FILE', 'File option') do |value, options|
+ @cmd.add_option("-f", "--file FILE", "File option") do |value, options|
options[:help] = true
end
- @cmd.add_option('--silent', 'Silence RubyGems output') do |value, options|
+ @cmd.add_option("--silent", "Silence RubyGems output") do |value, options|
options[:silent] = true
end
- assert @cmd.handles?(['-x'])
- assert @cmd.handles?(['-h'])
- assert @cmd.handles?(['-h', 'command'])
- assert @cmd.handles?(['--help', 'command'])
- assert @cmd.handles?(['-f', 'filename'])
- assert @cmd.handles?(['--file=filename'])
- assert @cmd.handles?(['--silent'])
- refute @cmd.handles?(['-z'])
- refute @cmd.handles?(['-f'])
- refute @cmd.handles?(['--toothpaste'])
-
- args = ['-h', 'command']
+ assert @cmd.handles?(["-x"])
+ assert @cmd.handles?(["-h"])
+ assert @cmd.handles?(["-h", "command"])
+ assert @cmd.handles?(["--help", "command"])
+ assert @cmd.handles?(["-f", "filename"])
+ assert @cmd.handles?(["--file=filename"])
+ assert @cmd.handles?(["--silent"])
+ refute @cmd.handles?(["-z"])
+ refute @cmd.handles?(["-f"])
+ refute @cmd.handles?(["--toothpaste"])
+
+ args = ["-h", "command"]
@cmd.handles?(args)
- assert_equal ['-h', 'command'], args
+ assert_equal ["-h", "command"], args
end
def test_deprecate_option
@@ -234,13 +234,13 @@ WARNING: The \"--test\" option has been deprecated and will be removed in Rubyg
testCommand = Class.new(Gem::Command) do
def initialize
- super('test', 'Gem::Command instance for testing')
+ super("test", "Gem::Command instance for testing")
- add_option('-t', '--test', 'Test command') do |value, options|
+ add_option("-t", "--test", "Test command") do |value, options|
options[:test] = true
end
- deprecate_option('--test', version: '3.1')
+ deprecate_option("--test", version: "3.1")
end
def execute
@@ -263,13 +263,13 @@ WARNING: The \"--test\" option has been deprecated and will be removed in futur
testCommand = Class.new(Gem::Command) do
def initialize
- super('test', 'Gem::Command instance for testing')
+ super("test", "Gem::Command instance for testing")
- add_option('-t', '--test', 'Test command') do |value, options|
+ add_option("-t", "--test", "Test command") do |value, options|
options[:test] = true
end
- deprecate_option('--test')
+ deprecate_option("--test")
end
def execute
@@ -292,13 +292,13 @@ WARNING: The \"--test\" option has been deprecated and will be removed in Rubyg
testCommand = Class.new(Gem::Command) do
def initialize
- super('test', 'Gem::Command instance for testing')
+ super("test", "Gem::Command instance for testing")
- add_option('-t', '--test', 'Test command') do |value, options|
+ add_option("-t", "--test", "Test command") do |value, options|
options[:test] = true
end
- deprecate_option('--test', version: '3.1', extra_msg: 'Whether you set `--test` mode or not, this dummy app always runs in test mode.')
+ deprecate_option("--test", version: "3.1", extra_msg: "Whether you set `--test` mode or not, this dummy app always runs in test mode.")
end
def execute
@@ -321,13 +321,13 @@ WARNING: The \"--test\" option has been deprecated and will be removed in futur
testCommand = Class.new(Gem::Command) do
def initialize
- super('test', 'Gem::Command instance for testing')
+ super("test", "Gem::Command instance for testing")
- add_option('-t', '--test', 'Test command') do |value, options|
+ add_option("-t", "--test", "Test command") do |value, options|
options[:test] = true
end
- deprecate_option('--test', extra_msg: 'Whether you set `--test` mode or not, this dummy app always runs in test mode.')
+ deprecate_option("--test", extra_msg: "Whether you set `--test` mode or not, this dummy app always runs in test mode.")
end
def execute
@@ -364,11 +364,11 @@ ERROR: Could not find a valid gem 'nonexistent_with_hint' (>= 0) in any reposit
def test_show_lookup_failure_suggestions_none
spec_fetcher do |fetcher|
- fetcher.spec 'correct', 2
+ fetcher.spec "correct", 2
end
use_ui @ui do
- @cmd.show_lookup_failure 'other', Gem::Requirement.default, [], :remote
+ @cmd.show_lookup_failure "other", Gem::Requirement.default, [], :remote
end
expected = <<-EXPECTED
diff --git a/test/rubygems/test_gem_command_manager.rb b/test/rubygems/test_gem_command_manager.rb
index 00197d10f7..b8f35192ae 100644
--- a/test/rubygems/test_gem_command_manager.rb
+++ b/test/rubygems/test_gem_command_manager.rb
@@ -1,9 +1,9 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/command_manager'
+require_relative "helper"
+require "rubygems/command_manager"
class TestGemCommandManager < Gem::TestCase
- PROJECT_DIR = File.expand_path('../..', __dir__).tap(&Gem::UNTAINT)
+ PROJECT_DIR = File.expand_path("../..", __dir__).tap(&Gem::UNTAINT)
def setup
super
@@ -12,38 +12,38 @@ class TestGemCommandManager < Gem::TestCase
end
def test_find_command
- command = @command_manager.find_command 'install'
+ command = @command_manager.find_command "install"
assert_kind_of Gem::Commands::InstallCommand, command
- command = @command_manager.find_command 'ins'
+ command = @command_manager.find_command "ins"
assert_kind_of Gem::Commands::InstallCommand, command
end
def test_find_command_ambiguous
e = assert_raise Gem::CommandLineError do
- @command_manager.find_command 'u'
+ @command_manager.find_command "u"
end
- assert_equal 'Ambiguous command u matches [uninstall, unpack, update]',
+ assert_equal "Ambiguous command u matches [uninstall, unpack, update]",
e.message
end
def test_find_alias_command
- command = @command_manager.find_command 'i'
+ command = @command_manager.find_command "i"
assert_kind_of Gem::Commands::InstallCommand, command
end
def test_find_login_alias_command
- command = @command_manager.find_command 'login'
+ command = @command_manager.find_command "login"
assert_kind_of Gem::Commands::SigninCommand, command
end
def test_find_logout_alias_comamnd
- command = @command_manager.find_command 'logout'
+ command = @command_manager.find_command "logout"
assert_kind_of Gem::Commands::SignoutCommand, command
end
@@ -54,7 +54,7 @@ class TestGemCommandManager < Gem::TestCase
@command_manager.register_command :ins
- command = @command_manager.find_command 'ins'
+ command = @command_manager.find_command "ins"
assert_kind_of ins_command, command
ensure
@@ -63,18 +63,18 @@ class TestGemCommandManager < Gem::TestCase
def test_find_command_unknown
e = assert_raise Gem::UnknownCommandError do
- @command_manager.find_command 'xyz'
+ @command_manager.find_command "xyz"
end
- assert_equal 'Unknown command xyz', e.message
+ assert_equal "Unknown command xyz", e.message
end
def test_find_command_unknown_suggestions
e = assert_raise Gem::UnknownCommandError do
- @command_manager.find_command 'pish'
+ @command_manager.find_command "pish"
end
- message = 'Unknown command pish'.dup
+ message = "Unknown command pish".dup
if RUBY_VERSION >= "2.4" && defined?(DidYouMean::SPELL_CHECKERS) && defined?(DidYouMean::Correctable)
message << "\nDid you mean? \"push\""
@@ -100,7 +100,7 @@ class TestGemCommandManager < Gem::TestCase
assert_raise Gem::MockGemUi::TermError do
@command_manager.run %w[interrupt]
end
- assert_equal '', ui.output
+ assert_equal "", ui.output
assert_equal "ERROR: Interrupted\n", ui.error
end
ensure
@@ -117,7 +117,7 @@ class TestGemCommandManager < Gem::TestCase
assert_raise Gem::MockGemUi::TermError do
@command_manager.run %w[crash]
end
- assert_equal '', ui.output
+ assert_equal "", ui.output
err = ui.error.split("\n").first
assert_equal "ERROR: Loading command: crash (RuntimeError)", err
end
@@ -141,7 +141,7 @@ class TestGemCommandManager < Gem::TestCase
#capture all install options
use_ui @ui do
check_options = nil
- @command_manager['install'].when_invoked do |options|
+ @command_manager["install"].when_invoked do |options|
check_options = options
true
end
@@ -166,7 +166,7 @@ class TestGemCommandManager < Gem::TestCase
assert_equal true, check_options[:force]
assert_equal :local, check_options[:domain]
assert_equal false, check_options[:wrappers]
- assert_equal Gem::Requirement.new('3.0'), check_options[:version]
+ assert_equal Gem::Requirement.new("3.0"), check_options[:version]
assert_equal Dir.pwd, check_options[:install_dir]
assert_equal Dir.pwd, check_options[:bin_dir]
@@ -191,7 +191,7 @@ class TestGemCommandManager < Gem::TestCase
def test_process_args_uninstall
#capture all uninstall options
check_options = nil
- @command_manager['uninstall'].when_invoked do |options|
+ @command_manager["uninstall"].when_invoked do |options|
check_options = options
true
end
@@ -204,14 +204,14 @@ class TestGemCommandManager < Gem::TestCase
check_options = nil
@command_manager.process_args %w[uninstall foobar --version 3.0]
assert_equal "foobar", check_options[:args].first
- assert_equal Gem::Requirement.new('3.0'), check_options[:version]
+ assert_equal Gem::Requirement.new("3.0"), check_options[:version]
end
# HACK move to check command test
def test_process_args_check
#capture all check options
check_options = nil
- @command_manager['check'].when_invoked do |options|
+ @command_manager["check"].when_invoked do |options|
check_options = options
true
end
@@ -230,7 +230,7 @@ class TestGemCommandManager < Gem::TestCase
def test_process_args_build
#capture all build options
check_options = nil
- @command_manager['build'].when_invoked do |options|
+ @command_manager["build"].when_invoked do |options|
check_options = options
true
end
@@ -242,14 +242,14 @@ class TestGemCommandManager < Gem::TestCase
#check settings
check_options = nil
@command_manager.process_args %w[build foobar.rb]
- assert_equal 'foobar.rb', check_options[:args].first
+ assert_equal "foobar.rb", check_options[:args].first
end
# HACK move to query command test
def test_process_args_query
#capture all query options
check_options = nil
- @command_manager['query'].when_invoked do |options|
+ @command_manager["query"].when_invoked do |options|
check_options = options
true
end
@@ -290,25 +290,25 @@ class TestGemCommandManager < Gem::TestCase
def test_process_args_update
#capture all update options
check_options = nil
- @command_manager['update'].when_invoked do |options|
+ @command_manager["update"].when_invoked do |options|
check_options = options
true
end
#check defaults
@command_manager.process_args %w[update]
- assert_includes check_options[:document], 'ri'
+ assert_includes check_options[:document], "ri"
#check settings
check_options = nil
@command_manager.process_args %w[update --force --document=ri --install-dir .]
- assert_includes check_options[:document], 'ri'
+ assert_includes check_options[:document], "ri"
assert_equal true, check_options[:force]
assert_equal Dir.pwd, check_options[:install_dir]
end
def test_deprecated_command
- require 'rubygems/command'
+ require "rubygems/command"
foo_command = Class.new(Gem::Command) do
extend Gem::Deprecate
diff --git a/test/rubygems/test_gem_commands_build_command.rb b/test/rubygems/test_gem_commands_build_command.rb
index 1304beb580..1edb30f221 100644
--- a/test/rubygems/test_gem_commands_build_command.rb
+++ b/test/rubygems/test_gem_commands_build_command.rb
@@ -1,32 +1,32 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/commands/build_command'
-require 'rubygems/package'
+require_relative "helper"
+require "rubygems/commands/build_command"
+require "rubygems/package"
class TestGemCommandsBuildCommand < Gem::TestCase
- CERT_FILE = cert_path 'public3072'
- SIGNING_KEY = key_path 'private3072'
+ CERT_FILE = cert_path "public3072"
+ SIGNING_KEY = key_path "private3072"
- EXPIRED_CERT_FILE = cert_path 'expired'
- PRIVATE_KEY_FILE = key_path 'private'
+ EXPIRED_CERT_FILE = cert_path "expired"
+ PRIVATE_KEY_FILE = key_path "private"
def setup
super
- readme_file = File.join(@tempdir, 'README.md')
+ readme_file = File.join(@tempdir, "README.md")
begin
umask_orig = File.umask(2)
- File.open readme_file, 'w' do |f|
- f.write 'My awesome gem'
+ File.open readme_file, "w" do |f|
+ f.write "My awesome gem"
end
ensure
File.umask(umask_orig)
end
- @gem = util_spec 'some_gem' do |s|
- s.license = 'AGPL-3.0'
- s.files = ['README.md']
+ @gem = util_spec "some_gem" do |s|
+ s.license = "AGPL-3.0"
+ s.files = ["README.md"]
end
@cmd = Gem::Commands::BuildCommand.new
@@ -44,7 +44,7 @@ class TestGemCommandsBuildCommand < Gem::TestCase
def test_options_filename
gemspec_file = File.join(@tempdir, @gem.spec_name)
- File.open gemspec_file, 'w' do |gs|
+ File.open gemspec_file, "w" do |gs|
gs.write @gem.to_ruby
end
@@ -79,7 +79,7 @@ class TestGemCommandsBuildCommand < Gem::TestCase
def test_execute
gemspec_file = File.join(@tempdir, @gem.spec_name)
- File.open gemspec_file, 'w' do |gs|
+ File.open gemspec_file, "w" do |gs|
gs.write @gem.to_ruby
end
@@ -91,7 +91,7 @@ class TestGemCommandsBuildCommand < Gem::TestCase
def test_execute_platform
gemspec_file = File.join(@tempdir, @gem.spec_name)
- File.open gemspec_file, 'w' do |gs|
+ File.open gemspec_file, "w" do |gs|
gs.write @gem.to_ruby
end
@@ -110,15 +110,15 @@ class TestGemCommandsBuildCommand < Gem::TestCase
def test_execute_bad_name
[".", "-", "_"].each do |special_char|
- gem = util_spec 'some_gem_with_bad_name' do |s|
+ gem = util_spec "some_gem_with_bad_name" do |s|
s.name = "#{special_char}bad_gem_name"
- s.license = 'AGPL-3.0'
- s.files = ['README.md']
+ s.license = "AGPL-3.0"
+ s.files = ["README.md"]
end
gemspec_file = File.join(@tempdir, gem.spec_name)
- File.open gemspec_file, 'w' do |gs|
+ File.open gemspec_file, "w" do |gs|
gs.write gem.to_ruby
end
@@ -137,7 +137,7 @@ class TestGemCommandsBuildCommand < Gem::TestCase
def test_execute_strict_without_warnings
gemspec_file = File.join(@tempdir, @gem.spec_name)
- File.open gemspec_file, 'w' do |gs|
+ File.open gemspec_file, "w" do |gs|
gs.write @gem.to_ruby
end
@@ -165,13 +165,13 @@ class TestGemCommandsBuildCommand < Gem::TestCase
end
def test_execute_strict_with_warnings
- bad_gem = util_spec 'some_bad_gem' do |s|
- s.files = ['README.md']
+ bad_gem = util_spec "some_bad_gem" do |s|
+ s.files = ["README.md"]
end
gemspec_file = File.join(@tempdir, bad_gem.spec_name)
- File.open gemspec_file, 'w' do |gs|
+ File.open gemspec_file, "w" do |gs|
gs.write bad_gem.to_ruby
end
@@ -201,7 +201,7 @@ class TestGemCommandsBuildCommand < Gem::TestCase
gemspec_file = File.join(@tempdir, @gem.spec_name)
- File.open gemspec_file, 'w' do |gs|
+ File.open gemspec_file, "w" do |gs|
gs.write @gem.to_ruby.sub(/11-08/, "11-8")
end
@@ -218,7 +218,7 @@ class TestGemCommandsBuildCommand < Gem::TestCase
assert_equal "", out
assert_match(/invalid date format in specification/, err)
- assert_equal '', @ui.output
+ assert_equal "", @ui.output
assert_equal "ERROR: Error loading gemspec. Aborting.\n", @ui.error
end
@@ -230,22 +230,22 @@ class TestGemCommandsBuildCommand < Gem::TestCase
end
end
- assert_equal '', @ui.output
+ assert_equal "", @ui.output
assert_equal "ERROR: Couldn't find a gemspec file matching 'some_gem' in #{@tempdir}\n", @ui.error
end
def test_execute_outside_dir
- gemspec_dir = File.join @tempdir, 'build_command_gem'
+ gemspec_dir = File.join @tempdir, "build_command_gem"
gemspec_file = File.join gemspec_dir, @gem.spec_name
- readme_file = File.join gemspec_dir, 'README.md'
+ readme_file = File.join gemspec_dir, "README.md"
FileUtils.mkdir_p gemspec_dir
- File.open readme_file, 'w' do |f|
+ File.open readme_file, "w" do |f|
f.write "My awesome gem"
end
- File.open gemspec_file, 'w' do |gs|
+ File.open gemspec_file, "w" do |gs|
gs.write @gem.to_ruby
end
@@ -273,17 +273,17 @@ class TestGemCommandsBuildCommand < Gem::TestCase
end
def test_execute_outside_dir_with_glob_argument
- gemspec_dir = File.join @tempdir, 'build_command_gem'
+ gemspec_dir = File.join @tempdir, "build_command_gem"
gemspec_file = File.join gemspec_dir, @gem.spec_name
- readme_file = File.join gemspec_dir, 'README.md'
+ readme_file = File.join gemspec_dir, "README.md"
FileUtils.mkdir_p gemspec_dir
- File.open readme_file, 'w' do |f|
+ File.open readme_file, "w" do |f|
f.write "My awesome gem"
end
- File.open gemspec_file, 'w' do |gs|
+ File.open gemspec_file, "w" do |gs|
gs.write @gem.to_ruby
end
@@ -311,17 +311,17 @@ class TestGemCommandsBuildCommand < Gem::TestCase
end
def test_execute_outside_dir_no_gemspec_present
- gemspec_dir = File.join @tempdir, 'build_command_gem'
+ gemspec_dir = File.join @tempdir, "build_command_gem"
gemspec_file = File.join @tempdir, @gem.spec_name
- readme_file = File.join gemspec_dir, 'README.md'
+ readme_file = File.join gemspec_dir, "README.md"
FileUtils.mkdir_p gemspec_dir
- File.open readme_file, 'w' do |f|
+ File.open readme_file, "w" do |f|
f.write "My awesome gem"
end
- File.open gemspec_file, 'w' do |gs|
+ File.open gemspec_file, "w" do |gs|
gs.write @gem.to_ruby
end
@@ -342,14 +342,14 @@ class TestGemCommandsBuildCommand < Gem::TestCase
end
def test_execute_outside_dir_without_gem_name
- gemspec_dir = File.join(@tempdir, 'build_command_gem')
+ gemspec_dir = File.join(@tempdir, "build_command_gem")
gemspec_file = File.join(gemspec_dir, @gem.spec_name)
- readme_file = File.join gemspec_dir, 'README.md'
+ readme_file = File.join gemspec_dir, "README.md"
FileUtils.mkdir_p(gemspec_dir)
- File.open readme_file, 'w' do |f|
+ File.open readme_file, "w" do |f|
f.write "My awesome gem"
end
@@ -383,20 +383,20 @@ class TestGemCommandsBuildCommand < Gem::TestCase
end
def test_execute_outside_dir_with_external_gemspec
- gemspec_dir = File.join @tempdir, 'gemspec_dir'
+ gemspec_dir = File.join @tempdir, "gemspec_dir"
gemspec_file = File.join gemspec_dir, @gem.spec_name
- gemcode_dir = File.join @tempdir, 'build_command_gem'
- readme_file = File.join gemcode_dir, 'README.md'
+ gemcode_dir = File.join @tempdir, "build_command_gem"
+ readme_file = File.join gemcode_dir, "README.md"
FileUtils.mkdir_p gemspec_dir
FileUtils.mkdir_p gemcode_dir
- File.open readme_file, 'w' do |f|
+ File.open readme_file, "w" do |f|
f.write "My awesome gem in nested directory"
end
- File.open gemspec_file, 'w' do |gs|
+ File.open gemspec_file, "w" do |gs|
gs.write @gem.to_ruby
end
@@ -424,20 +424,20 @@ class TestGemCommandsBuildCommand < Gem::TestCase
end
def test_execute_outside_dir_with_external_relative_gemspec
- gemspec_dir = File.join @tempdir, 'gemspec_dir'
+ gemspec_dir = File.join @tempdir, "gemspec_dir"
gemspec_file = File.join gemspec_dir, @gem.spec_name
- gemcode_dir = File.join @tempdir, 'build_command_gem'
- readme_file = File.join gemcode_dir, 'README.md'
+ gemcode_dir = File.join @tempdir, "build_command_gem"
+ readme_file = File.join gemcode_dir, "README.md"
FileUtils.mkdir_p gemspec_dir
FileUtils.mkdir_p gemcode_dir
- File.open readme_file, 'w' do |f|
+ File.open readme_file, "w" do |f|
f.write "My awesome gem in nested directory"
end
- File.open gemspec_file, 'w' do |gs|
+ File.open gemspec_file, "w" do |gs|
gs.write @gem.to_ruby
end
@@ -467,7 +467,7 @@ class TestGemCommandsBuildCommand < Gem::TestCase
def test_can_find_gemspecs_without_dot_gemspec
gemspec_file = File.join(@tempdir, @gem.name)
- File.open gemspec_file + ".gemspec", 'w' do |gs|
+ File.open gemspec_file + ".gemspec", "w" do |gs|
gs.write @gem.to_ruby
end
@@ -571,7 +571,7 @@ class TestGemCommandsBuildCommand < Gem::TestCase
@gem.send :remove_instance_variable, :@rubygems_version
- File.open gemspec_file, 'w' do |gs|
+ File.open gemspec_file, "w" do |gs|
gs.write @gem.to_ruby
end
@@ -582,18 +582,18 @@ class TestGemCommandsBuildCommand < Gem::TestCase
end
def test_build_signed_gem
- pend 'openssl is missing' unless Gem::HAVE_OPENSSL && !java_platform?
+ pend "openssl is missing" unless Gem::HAVE_OPENSSL && !java_platform?
trust_dir = Gem::Security.trust_dir
- spec = util_spec 'some_gem' do |s|
+ spec = util_spec "some_gem" do |s|
s.signing_key = SIGNING_KEY
s.cert_chain = [CERT_FILE]
end
gemspec_file = File.join(@tempdir, spec.spec_name)
- File.open gemspec_file, 'w' do |gs|
+ File.open gemspec_file, "w" do |gs|
gs.write spec.to_ruby
end
@@ -609,7 +609,7 @@ class TestGemCommandsBuildCommand < Gem::TestCase
end
def test_build_signed_gem_with_cert_expiration_length_days
- pend 'openssl is missing' unless Gem::HAVE_OPENSSL && !java_platform?
+ pend "openssl is missing" unless Gem::HAVE_OPENSSL && !java_platform?
gem_path = File.join Gem.user_home, ".gem"
Dir.mkdir gem_path
@@ -622,14 +622,14 @@ class TestGemCommandsBuildCommand < Gem::TestCase
tmp_private_key_file = File.join gem_path, "gem-private_key.pem"
File.write(tmp_private_key_file, File.read(PRIVATE_KEY_FILE))
- spec = util_spec 'some_gem' do |s|
+ spec = util_spec "some_gem" do |s|
s.signing_key = tmp_private_key_file
s.cert_chain = [tmp_expired_cert_file]
end
gemspec_file = File.join(@tempdir, spec.spec_name)
- File.open gemspec_file, 'w' do |gs|
+ File.open gemspec_file, "w" do |gs|
gs.write spec.to_ruby
end
@@ -653,7 +653,7 @@ class TestGemCommandsBuildCommand < Gem::TestCase
end
def test_build_auto_resign_cert
- pend 'openssl is missing' unless Gem::HAVE_OPENSSL && !java_platform?
+ pend "openssl is missing" unless Gem::HAVE_OPENSSL && !java_platform?
gem_path = File.join Gem.user_home, ".gem"
Dir.mkdir gem_path
@@ -666,14 +666,14 @@ class TestGemCommandsBuildCommand < Gem::TestCase
tmp_private_key_file = File.join gem_path, "gem-private_key.pem"
File.write(tmp_private_key_file, File.read(PRIVATE_KEY_FILE))
- spec = util_spec 'some_gem' do |s|
+ spec = util_spec "some_gem" do |s|
s.signing_key = tmp_private_key_file
s.cert_chain = [tmp_expired_cert_file]
end
gemspec_file = File.join(@tempdir, spec.spec_name)
- File.open gemspec_file, 'w' do |gs|
+ File.open gemspec_file, "w" do |gs|
gs.write spec.to_ruby
end
diff --git a/test/rubygems/test_gem_commands_cert_command.rb b/test/rubygems/test_gem_commands_cert_command.rb
index 901bf5aed6..ffcc14ffbb 100644
--- a/test/rubygems/test_gem_commands_cert_command.rb
+++ b/test/rubygems/test_gem_commands_cert_command.rb
@@ -1,28 +1,28 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/commands/cert_command'
+require_relative "helper"
+require "rubygems/commands/cert_command"
unless Gem::HAVE_OPENSSL
- warn 'Skipping `gem cert` tests. openssl not found.'
+ warn "Skipping `gem cert` tests. openssl not found."
end
if Gem.java_platform?
- warn 'Skipping `gem cert` tests on jruby.'
+ warn "Skipping `gem cert` tests on jruby."
end
class TestGemCommandsCertCommand < Gem::TestCase
- ALTERNATE_CERT = load_cert 'alternate'
- EXPIRED_PUBLIC_CERT = load_cert 'expired'
+ ALTERNATE_CERT = load_cert "alternate"
+ EXPIRED_PUBLIC_CERT = load_cert "expired"
- ALTERNATE_KEY_FILE = key_path 'alternate'
- PRIVATE_KEY_FILE = key_path 'private'
- PRIVATE_EC_KEY_FILE = key_path 'private_ec'
- PUBLIC_KEY_FILE = key_path 'public'
+ ALTERNATE_KEY_FILE = key_path "alternate"
+ PRIVATE_KEY_FILE = key_path "private"
+ PRIVATE_EC_KEY_FILE = key_path "private_ec"
+ PUBLIC_KEY_FILE = key_path "public"
- ALTERNATE_CERT_FILE = cert_path 'alternate'
- CHILD_CERT_FILE = cert_path 'child'
- PUBLIC_CERT_FILE = cert_path 'public'
- EXPIRED_PUBLIC_CERT_FILE = cert_path 'expired'
+ ALTERNATE_CERT_FILE = cert_path "alternate"
+ CHILD_CERT_FILE = cert_path "child"
+ PUBLIC_CERT_FILE = cert_path "public"
+ EXPIRED_PUBLIC_CERT_FILE = cert_path "expired"
def setup
super
@@ -44,7 +44,7 @@ class TestGemCommandsCertCommand < Gem::TestCase
@trust_dir.trust_cert PUBLIC_CERT
@trust_dir.trust_cert ALTERNATE_CERT
- matches = @cmd.certificates_matching ''
+ matches = @cmd.certificates_matching ""
# HACK OpenSSL::X509::Certificate#== is Object#==, so do this the hard way
match = matches.next
@@ -64,7 +64,7 @@ class TestGemCommandsCertCommand < Gem::TestCase
@trust_dir.trust_cert PUBLIC_CERT
@trust_dir.trust_cert ALTERNATE_CERT
- matches = @cmd.certificates_matching 'alternate'
+ matches = @cmd.certificates_matching "alternate"
match = matches.next
assert_equal ALTERNATE_CERT.to_pem, match.first.to_pem
@@ -91,7 +91,7 @@ class TestGemCommandsCertCommand < Gem::TestCase
end
def test_execute_add_twice
- self.class.cert_path 'alternate'
+ self.class.cert_path "alternate"
@cmd.handle_options %W[
--add #{PUBLIC_CERT_FILE}
@@ -112,7 +112,7 @@ Added '/CN=alternate/DC=example'
end
def test_execute_build
- passphrase = 'Foo bar'
+ passphrase = "Foo bar"
@cmd.handle_options %W[--build nobody@example.com]
@@ -139,12 +139,12 @@ Added '/CN=alternate/DC=example'
assert_empty output
assert_empty @build_ui.error
- assert_path_exist File.join(@tempdir, 'gem-private_key.pem')
- assert_path_exist File.join(@tempdir, 'gem-public_cert.pem')
+ assert_path_exist File.join(@tempdir, "gem-private_key.pem")
+ assert_path_exist File.join(@tempdir, "gem-public_cert.pem")
end
def test_execute_build_key_algorithm_ec_key
- passphrase = 'Foo bar'
+ passphrase = "Foo bar"
@cmd.handle_options %W[--build nobody@example.com --key-algorithm ec]
@@ -171,16 +171,16 @@ Added '/CN=alternate/DC=example'
assert_empty output
assert_empty @build_ui.error
- assert_path_exist File.join(@tempdir, 'gem-private_key.pem')
+ assert_path_exist File.join(@tempdir, "gem-private_key.pem")
- cert_path = File.join(@tempdir, 'gem-public_cert.pem')
+ cert_path = File.join(@tempdir, "gem-public_cert.pem")
assert_path_exist cert_path
cert = OpenSSL::X509::Certificate.new(File.read(cert_path))
assert cert.public_key.is_a? OpenSSL::PKey::EC
end
def test_execute_build_bad_email_address
- passphrase = 'Foo bar'
+ passphrase = "Foo bar"
email = "nobody@"
@cmd.handle_options %W[--build #{email}]
@@ -188,7 +188,6 @@ Added '/CN=alternate/DC=example'
@build_ui = Gem::MockGemUi.new "#{passphrase}\n#{passphrase}"
use_ui @build_ui do
-
e = assert_raise Gem::CommandLineError do
@cmd.execute
end
@@ -196,13 +195,13 @@ Added '/CN=alternate/DC=example'
assert_equal "Invalid email address #{email}",
e.message
- assert_path_not_exist File.join(@tempdir, 'gem-private_key.pem')
- assert_path_not_exist File.join(@tempdir, 'gem-public_cert.pem')
+ assert_path_not_exist File.join(@tempdir, "gem-private_key.pem")
+ assert_path_not_exist File.join(@tempdir, "gem-public_cert.pem")
end
end
def test_execute_build_expiration_days
- passphrase = 'Foo bar'
+ passphrase = "Foo bar"
@cmd.handle_options %W[
--build nobody@example.com
@@ -232,8 +231,8 @@ Added '/CN=alternate/DC=example'
assert_empty output
assert_empty @build_ui.error
- assert_path_exist File.join(@tempdir, 'gem-private_key.pem')
- assert_path_exist File.join(@tempdir, 'gem-public_cert.pem')
+ assert_path_exist File.join(@tempdir, "gem-private_key.pem")
+ assert_path_exist File.join(@tempdir, "gem-public_cert.pem")
pem = File.read("#{@tempdir}/gem-public_cert.pem")
cert = OpenSSL::X509::Certificate.new(pem)
@@ -243,8 +242,8 @@ Added '/CN=alternate/DC=example'
end
def test_execute_build_bad_passphrase_confirmation
- passphrase = 'Foo bar'
- passphrase_confirmation = 'Fu bar'
+ passphrase = "Foo bar"
+ passphrase_confirmation = "Fu bar"
@cmd.handle_options %W[--build nobody@example.com]
@@ -266,11 +265,10 @@ Added '/CN=alternate/DC=example'
assert_equal "Passphrase and passphrase confirmation don't match",
e.message
-
end
- assert_path_not_exist File.join(@tempdir, 'gem-private_key.pem')
- assert_path_not_exist File.join(@tempdir, 'gem-public_cert.pem')
+ assert_path_not_exist File.join(@tempdir, "gem-private_key.pem")
+ assert_path_not_exist File.join(@tempdir, "gem-public_cert.pem")
end
def test_execute_build_key
@@ -291,8 +289,8 @@ Added '/CN=alternate/DC=example'
assert_empty output
assert_empty @ui.error
- assert_path_exist File.join(@tempdir, 'gem-public_cert.pem')
- assert_path_not_exist File.join(@tempdir, 'gem-private_key.pem')
+ assert_path_exist File.join(@tempdir, "gem-public_cert.pem")
+ assert_path_not_exist File.join(@tempdir, "gem-private_key.pem")
end
def test_execute_build_encrypted_key
@@ -313,7 +311,7 @@ Added '/CN=alternate/DC=example'
assert_empty output
assert_empty @ui.error
- assert_path_exist File.join(@tempdir, 'gem-public_cert.pem')
+ assert_path_exist File.join(@tempdir, "gem-public_cert.pem")
end
def test_execute_build_ec_key
@@ -334,8 +332,8 @@ Added '/CN=alternate/DC=example'
assert_empty output
assert_empty @ui.error
- assert_path_exist File.join(@tempdir, 'gem-public_cert.pem')
- assert_path_not_exist File.join(@tempdir, 'gem-private_key.pem')
+ assert_path_exist File.join(@tempdir, "gem-public_cert.pem")
+ assert_path_not_exist File.join(@tempdir, "gem-private_key.pem")
end
def test_execute_certificate
@@ -343,8 +341,8 @@ Added '/CN=alternate/DC=example'
@cmd.handle_options %W[--certificate #{PUBLIC_CERT_FILE}]
end
- assert_equal '', @ui.output
- assert_equal '', @ui.error
+ assert_equal "", @ui.output
+ assert_equal "", @ui.error
assert_equal PUBLIC_CERT.to_pem, @cmd.options[:issuer_cert].to_pem
end
@@ -383,8 +381,8 @@ Added '/CN=alternate/DC=example'
@cmd.send :handle_options, %W[--private-key #{PRIVATE_KEY_FILE}]
end
- assert_equal '', @ui.output
- assert_equal '', @ui.error
+ assert_equal "", @ui.output
+ assert_equal "", @ui.error
assert_equal PRIVATE_KEY.to_pem, @cmd.options[:key].to_pem
end
@@ -394,8 +392,8 @@ Added '/CN=alternate/DC=example'
@cmd.send :handle_options, %W[--private-key #{ENCRYPTED_PRIVATE_KEY_PATH}]
end
- assert_equal '', @ui.output
- assert_equal '', @ui.error
+ assert_equal "", @ui.output
+ assert_equal "", @ui.error
assert_equal ENCRYPTED_PRIVATE_KEY.to_pem, @cmd.options[:key].to_pem
end
@@ -414,7 +412,7 @@ Added '/CN=alternate/DC=example'
end
assert_equal "Removed '/CN=nobody/DC=example'\n", @ui.output
- assert_equal '', @ui.error
+ assert_equal "", @ui.error
assert_path_not_exist cert_path
end
@@ -441,7 +439,7 @@ Removed '/CN=nobody/DC=example'
EXPECTED
assert_equal expected, @ui.output
- assert_equal '', @ui.error
+ assert_equal "", @ui.error
assert_path_not_exist public_path
assert_path_not_exist alternate_path
@@ -469,17 +467,17 @@ Removed '/CN=alternate/DC=example'
EXPECTED
assert_equal expected, @ui.output
- assert_equal '', @ui.error
+ assert_equal "", @ui.error
assert_path_not_exist public_path
assert_path_not_exist alternate_path
end
def test_execute_sign
- path = File.join @tempdir, 'cert.pem'
+ path = File.join @tempdir, "cert.pem"
Gem::Security.write ALTERNATE_CERT, path, 0600
- assert_equal '/CN=alternate/DC=example', ALTERNATE_CERT.issuer.to_s
+ assert_equal "/CN=alternate/DC=example", ALTERNATE_CERT.issuer.to_s
@cmd.handle_options %W[
--private-key #{PRIVATE_KEY_FILE}
@@ -492,12 +490,12 @@ Removed '/CN=alternate/DC=example'
@cmd.execute
end
- assert_equal '', @ui.output
- assert_equal '', @ui.error
+ assert_equal "", @ui.output
+ assert_equal "", @ui.error
cert = OpenSSL::X509::Certificate.new File.read path
- assert_equal '/CN=nobody/DC=example', cert.issuer.to_s
+ assert_equal "/CN=nobody/DC=example", cert.issuer.to_s
mask = 0100600 & (~File.umask)
@@ -505,10 +503,10 @@ Removed '/CN=alternate/DC=example'
end
def test_execute_sign_encrypted_key
- path = File.join @tempdir, 'cert.pem'
+ path = File.join @tempdir, "cert.pem"
Gem::Security.write ALTERNATE_CERT, path, 0600
- assert_equal '/CN=alternate/DC=example', ALTERNATE_CERT.issuer.to_s
+ assert_equal "/CN=alternate/DC=example", ALTERNATE_CERT.issuer.to_s
@cmd.handle_options %W[
--private-key #{ENCRYPTED_PRIVATE_KEY_PATH}
@@ -521,12 +519,12 @@ Removed '/CN=alternate/DC=example'
@cmd.execute
end
- assert_equal '', @ui.output
- assert_equal '', @ui.error
+ assert_equal "", @ui.output
+ assert_equal "", @ui.error
cert = OpenSSL::X509::Certificate.new File.read path
- assert_equal '/CN=nobody/DC=example', cert.issuer.to_s
+ assert_equal "/CN=nobody/DC=example", cert.issuer.to_s
mask = 0100600 & (~File.umask)
@@ -534,18 +532,18 @@ Removed '/CN=alternate/DC=example'
end
def test_execute_sign_default
- FileUtils.mkdir_p File.join Gem.user_home, '.gem'
+ FileUtils.mkdir_p File.join Gem.user_home, ".gem"
- private_key_path = File.join Gem.user_home, '.gem', 'gem-private_key.pem'
+ private_key_path = File.join Gem.user_home, ".gem", "gem-private_key.pem"
Gem::Security.write PRIVATE_KEY, private_key_path
- public_cert_path = File.join Gem.user_home, '.gem', 'gem-public_cert.pem'
+ public_cert_path = File.join Gem.user_home, ".gem", "gem-public_cert.pem"
Gem::Security.write PUBLIC_CERT, public_cert_path
- path = File.join @tempdir, 'cert.pem'
+ path = File.join @tempdir, "cert.pem"
Gem::Security.write ALTERNATE_CERT, path, 0600
- assert_equal '/CN=alternate/DC=example', ALTERNATE_CERT.issuer.to_s
+ assert_equal "/CN=alternate/DC=example", ALTERNATE_CERT.issuer.to_s
@cmd.handle_options %W[--sign #{path}]
@@ -553,12 +551,12 @@ Removed '/CN=alternate/DC=example'
@cmd.execute
end
- assert_equal '', @ui.output
- assert_equal '', @ui.error
+ assert_equal "", @ui.output
+ assert_equal "", @ui.error
cert = OpenSSL::X509::Certificate.new File.read path
- assert_equal '/CN=nobody/DC=example', cert.issuer.to_s
+ assert_equal "/CN=nobody/DC=example", cert.issuer.to_s
mask = 0100600 & (~File.umask)
@@ -566,18 +564,18 @@ Removed '/CN=alternate/DC=example'
end
def test_execute_sign_default_encrypted_key
- FileUtils.mkdir_p File.join(Gem.user_home, '.gem')
+ FileUtils.mkdir_p File.join(Gem.user_home, ".gem")
- private_key_path = File.join Gem.user_home, '.gem', 'gem-private_key.pem'
+ private_key_path = File.join Gem.user_home, ".gem", "gem-private_key.pem"
Gem::Security.write ENCRYPTED_PRIVATE_KEY, private_key_path, 0600, PRIVATE_KEY_PASSPHRASE
- public_cert_path = File.join Gem.user_home, '.gem', 'gem-public_cert.pem'
+ public_cert_path = File.join Gem.user_home, ".gem", "gem-public_cert.pem"
Gem::Security.write PUBLIC_CERT, public_cert_path
- path = File.join @tempdir, 'cert.pem'
+ path = File.join @tempdir, "cert.pem"
Gem::Security.write ALTERNATE_CERT, path, 0600
- assert_equal '/CN=alternate/DC=example', ALTERNATE_CERT.issuer.to_s
+ assert_equal "/CN=alternate/DC=example", ALTERNATE_CERT.issuer.to_s
@cmd.handle_options %W[--sign #{path}]
@@ -585,12 +583,12 @@ Removed '/CN=alternate/DC=example'
@cmd.execute
end
- assert_equal '', @ui.output
- assert_equal '', @ui.error
+ assert_equal "", @ui.output
+ assert_equal "", @ui.error
cert = OpenSSL::X509::Certificate.new File.read path
- assert_equal '/CN=nobody/DC=example', cert.issuer.to_s
+ assert_equal "/CN=nobody/DC=example", cert.issuer.to_s
mask = 0100600 & (~File.umask)
@@ -598,15 +596,15 @@ Removed '/CN=alternate/DC=example'
end
def test_execute_sign_no_cert
- FileUtils.mkdir_p File.join Gem.user_home, '.gem'
+ FileUtils.mkdir_p File.join Gem.user_home, ".gem"
- private_key_path = File.join Gem.user_home, '.gem', 'gem-private_key.pem'
+ private_key_path = File.join Gem.user_home, ".gem", "gem-private_key.pem"
Gem::Security.write PRIVATE_KEY, private_key_path
- path = File.join @tempdir, 'cert.pem'
+ path = File.join @tempdir, "cert.pem"
Gem::Security.write ALTERNATE_CERT, path, 0600
- assert_equal '/CN=alternate/DC=example', ALTERNATE_CERT.issuer.to_s
+ assert_equal "/CN=alternate/DC=example", ALTERNATE_CERT.issuer.to_s
@cmd.handle_options %W[--sign #{path}]
@@ -616,7 +614,7 @@ Removed '/CN=alternate/DC=example'
end
end
- assert_equal '', @ui.output
+ assert_equal "", @ui.output
expected = <<-EXPECTED
ERROR: --certificate not specified and ~/.gem/gem-public_cert.pem does not exist
@@ -626,15 +624,15 @@ ERROR: --certificate not specified and ~/.gem/gem-public_cert.pem does not exis
end
def test_execute_sign_no_key
- FileUtils.mkdir_p File.join Gem.user_home, '.gem'
+ FileUtils.mkdir_p File.join Gem.user_home, ".gem"
- public_cert_path = File.join Gem.user_home, '.gem', 'gem-public_cert.pem'
+ public_cert_path = File.join Gem.user_home, ".gem", "gem-public_cert.pem"
Gem::Security.write PUBLIC_CERT, public_cert_path
- path = File.join @tempdir, 'cert.pem'
+ path = File.join @tempdir, "cert.pem"
Gem::Security.write ALTERNATE_CERT, path, 0600
- assert_equal '/CN=alternate/DC=example', ALTERNATE_CERT.issuer.to_s
+ assert_equal "/CN=alternate/DC=example", ALTERNATE_CERT.issuer.to_s
@cmd.handle_options %W[--sign #{path}]
@@ -644,7 +642,7 @@ ERROR: --certificate not specified and ~/.gem/gem-public_cert.pem does not exis
end
end
- assert_equal '', @ui.output
+ assert_equal "", @ui.output
expected = <<-EXPECTED
ERROR: --private-key not specified and ~/.gem/gem-private_key.pem does not exist
@@ -657,10 +655,10 @@ ERROR: --private-key not specified and ~/.gem/gem-private_key.pem does not exis
gem_path = File.join Gem.user_home, ".gem"
Dir.mkdir gem_path
- path = File.join @tempdir, 'cert.pem'
+ path = File.join @tempdir, "cert.pem"
Gem::Security.write EXPIRED_PUBLIC_CERT, path, 0600
- assert_equal '/CN=nobody/DC=example', EXPIRED_PUBLIC_CERT.issuer.to_s
+ assert_equal "/CN=nobody/DC=example", EXPIRED_PUBLIC_CERT.issuer.to_s
tmp_expired_cert_file = File.join(Dir.tmpdir, File.basename(EXPIRED_PUBLIC_CERT_FILE))
@cleanup << tmp_expired_cert_file
@@ -682,17 +680,17 @@ ERROR: --private-key not specified and ~/.gem/gem-private_key.pem does not exis
/INFO: Your certificate #{tmp_expired_cert_file} has been re-signed\nINFO: Your expired certificate will be located at: #{expected_path}\.[0-9]+/,
@ui.output
)
- assert_equal '', @ui.error
+ assert_equal "", @ui.error
end
def test_execute_re_sign_with_cert_expiration_length_days
gem_path = File.join Gem.user_home, ".gem"
Dir.mkdir gem_path
- path = File.join @tempdir, 'cert.pem'
+ path = File.join @tempdir, "cert.pem"
Gem::Security.write EXPIRED_PUBLIC_CERT, path, 0600
- assert_equal '/CN=nobody/DC=example', EXPIRED_PUBLIC_CERT.issuer.to_s
+ assert_equal "/CN=nobody/DC=example", EXPIRED_PUBLIC_CERT.issuer.to_s
tmp_expired_cert_file = File.join(Dir.tmpdir, File.basename(EXPIRED_PUBLIC_CERT_FILE))
@cleanup << tmp_expired_cert_file
@@ -714,7 +712,7 @@ ERROR: --private-key not specified and ~/.gem/gem-private_key.pem does not exis
cert_days_to_expire = (re_signed_cert.not_after - re_signed_cert.not_before).to_i / (24 * 60 * 60)
assert_equal(28, cert_days_to_expire)
- assert_equal '', @ui.error
+ assert_equal "", @ui.error
end
def test_handle_options
@@ -740,11 +738,11 @@ ERROR: --private-key not specified and ~/.gem/gem-private_key.pem does not exis
assert_equal %w[nobody@example other@example],
@cmd.options[:build].map {|name| name.to_s }
- assert_equal ['', 'example'], @cmd.options[:list]
+ assert_equal ["", "example"], @cmd.options[:list]
end
def test_handle_options_add_bad
- nonexistent = File.join @tempdir, 'nonexistent'
+ nonexistent = File.join @tempdir, "nonexistent"
e = assert_raise Gem::OptionParser::InvalidArgument do
@cmd.handle_options %W[--add #{nonexistent}]
end
@@ -752,7 +750,7 @@ ERROR: --private-key not specified and ~/.gem/gem-private_key.pem does not exis
assert_equal "invalid argument: --add #{nonexistent}: does not exist",
e.message
- bad = File.join @tempdir, 'bad'
+ bad = File.join @tempdir, "bad"
FileUtils.touch bad
e = assert_raise Gem::OptionParser::InvalidArgument do
@@ -764,7 +762,7 @@ ERROR: --private-key not specified and ~/.gem/gem-private_key.pem does not exis
end
def test_handle_options_certificate
- nonexistent = File.join @tempdir, 'nonexistent'
+ nonexistent = File.join @tempdir, "nonexistent"
e = assert_raise Gem::OptionParser::InvalidArgument do
@cmd.handle_options %W[--certificate #{nonexistent}]
end
@@ -772,7 +770,7 @@ ERROR: --private-key not specified and ~/.gem/gem-private_key.pem does not exis
assert_equal "invalid argument: --certificate #{nonexistent}: does not exist",
e.message
- bad = File.join @tempdir, 'bad'
+ bad = File.join @tempdir, "bad"
FileUtils.touch bad
e = assert_raise Gem::OptionParser::InvalidArgument do
@@ -785,7 +783,7 @@ ERROR: --private-key not specified and ~/.gem/gem-private_key.pem does not exis
end
def test_handle_options_key_bad
- nonexistent = File.join @tempdir, 'nonexistent'
+ nonexistent = File.join @tempdir, "nonexistent"
e = assert_raise Gem::OptionParser::InvalidArgument do
@cmd.handle_options %W[--private-key #{nonexistent}]
end
@@ -794,7 +792,7 @@ ERROR: --private-key not specified and ~/.gem/gem-private_key.pem does not exis
"--private-key #{nonexistent}: does not exist",
e.message
- bad = File.join @tempdir, 'bad'
+ bad = File.join @tempdir, "bad"
FileUtils.touch bad
e = assert_raise Gem::OptionParser::InvalidArgument do
@@ -850,7 +848,7 @@ ERROR: --private-key not specified and ~/.gem/gem-private_key.pem does not exis
end
def test_handle_options_sign_nonexistent
- nonexistent = File.join @tempdir, 'nonexistent'
+ nonexistent = File.join @tempdir, "nonexistent"
e = assert_raise Gem::OptionParser::InvalidArgument do
@cmd.handle_options %W[
--private-key #{ALTERNATE_KEY_FILE}
diff --git a/test/rubygems/test_gem_commands_check_command.rb b/test/rubygems/test_gem_commands_check_command.rb
index f280b060c4..9233f7b5ce 100644
--- a/test/rubygems/test_gem_commands_check_command.rb
+++ b/test/rubygems/test_gem_commands_check_command.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/commands/check_command'
+require_relative "helper"
+require "rubygems/commands/check_command"
class TestGemCommandsCheckCommand < Gem::TestCase
def setup
@@ -45,8 +45,8 @@ class TestGemCommandsCheckCommand < Gem::TestCase
end
def test_doctor
- gem 'a'
- b = gem 'b'
+ gem "a"
+ b = gem "b"
FileUtils.rm b.spec_file
diff --git a/test/rubygems/test_gem_commands_cleanup_command.rb b/test/rubygems/test_gem_commands_cleanup_command.rb
index fc98998012..51d59df58c 100644
--- a/test/rubygems/test_gem_commands_cleanup_command.rb
+++ b/test/rubygems/test_gem_commands_cleanup_command.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/commands/cleanup_command'
-require 'rubygems/installer'
+require_relative "helper"
+require "rubygems/commands/cleanup_command"
+require "rubygems/installer"
class TestGemCommandsCleanupCommand < Gem::TestCase
def setup
@@ -9,8 +9,8 @@ class TestGemCommandsCleanupCommand < Gem::TestCase
@cmd = Gem::Commands::CleanupCommand.new
- @a_1 = util_spec 'a', 1
- @a_2 = util_spec 'a', 2
+ @a_1 = util_spec "a", 1
+ @a_2 = util_spec "a", 2
install_gem @a_1
install_gem @a_2
@@ -66,12 +66,12 @@ class TestGemCommandsCleanupCommand < Gem::TestCase
end
def test_execute_all_dependencies
- @b_1 = util_spec 'b', 1 do |s|
- s.add_dependency 'a', '1'
+ @b_1 = util_spec "b", 1 do |s|
+ s.add_dependency "a", "1"
end
- @b_2 = util_spec 'b', 2 do |s|
- s.add_dependency 'a', '2'
+ @b_2 = util_spec "b", 2 do |s|
+ s.add_dependency "a", "2"
end
install_gem @b_1
@@ -86,12 +86,12 @@ class TestGemCommandsCleanupCommand < Gem::TestCase
end
def test_execute_dev_dependencies
- @b_1 = util_spec 'b', 1 do |s|
- s.add_development_dependency 'a', '1'
+ @b_1 = util_spec "b", 1 do |s|
+ s.add_development_dependency "a", "1"
end
- @c_1 = util_spec 'c', 1 do |s|
- s.add_development_dependency 'a', '2'
+ @c_1 = util_spec "c", 1 do |s|
+ s.add_development_dependency "a", "2"
end
install_gem @b_1
@@ -105,12 +105,12 @@ class TestGemCommandsCleanupCommand < Gem::TestCase
end
def test_execute_without_dev_dependencies
- @b_1 = util_spec 'b', 1 do |s|
- s.add_development_dependency 'a', '1'
+ @b_1 = util_spec "b", 1 do |s|
+ s.add_development_dependency "a", "1"
end
- @c_1 = util_spec 'c', 1 do |s|
- s.add_development_dependency 'a', '2'
+ @c_1 = util_spec "c", 1 do |s|
+ s.add_development_dependency "a", "2"
end
install_gem @b_1
@@ -124,14 +124,14 @@ class TestGemCommandsCleanupCommand < Gem::TestCase
end
def test_execute_all
- gemhome2 = File.join @tempdir, 'gemhome2'
+ gemhome2 = File.join @tempdir, "gemhome2"
Gem.ensure_gem_subdirectories gemhome2
Gem.use_paths @gemhome, gemhome2
- @b_1 = util_spec 'b', 1
- @b_2 = util_spec 'b', 2
+ @b_1 = util_spec "b", 1
+ @b_2 = util_spec "b", 2
install_gem @b_1
install_gem @b_2
@@ -140,15 +140,15 @@ class TestGemCommandsCleanupCommand < Gem::TestCase
@cmd.execute
- assert_equal @gemhome, Gem.dir, 'GEM_HOME'
- assert_equal [@gemhome, gemhome2], Gem.path.sort, 'GEM_PATH'
+ assert_equal @gemhome, Gem.dir, "GEM_HOME"
+ assert_equal [@gemhome, gemhome2], Gem.path.sort, "GEM_PATH"
assert_path_not_exist @a_1.gem_dir
assert_path_not_exist @b_1.gem_dir
end
def test_execute_all_user
- @a_1_1, = util_gem 'a', '1.1'
+ @a_1_1, = util_gem "a", "1.1"
@a_1_1 = install_gem @a_1_1 # pick up user install path
Gem::Specification.dirs = [Gem.dir, Gem.user_dir]
@@ -167,7 +167,7 @@ class TestGemCommandsCleanupCommand < Gem::TestCase
def test_execute_all_user_no_sudo
FileUtils.chmod 0555, @gemhome
- @a_1_1, = util_gem 'a', '1.1'
+ @a_1_1, = util_gem "a", "1.1"
@a_1_1 = install_gem @a_1_1, :user_install => true # pick up user install path
Gem::Specification.dirs = [Gem.dir, Gem.user_dir]
@@ -195,11 +195,11 @@ class TestGemCommandsCleanupCommand < Gem::TestCase
end
def test_execute_keeps_older_versions_with_deps
- @b_1 = util_spec 'b', 1
- @b_2 = util_spec 'b', 2
+ @b_1 = util_spec "b", 1
+ @b_2 = util_spec "b", 2
- @c = util_spec 'c', 1 do |s|
- s.add_dependency 'b', '1'
+ @c = util_spec "c", 1 do |s|
+ s.add_dependency "b", "1"
end
install_gem @b_1
@@ -216,9 +216,9 @@ class TestGemCommandsCleanupCommand < Gem::TestCase
def test_execute_ignore_default_gem_verbose
Gem.configuration.verbose = :really
- @b_1 = util_spec 'b', 1
+ @b_1 = util_spec "b", 1
@b_default = new_default_spec "b", "2"
- @b_2 = util_spec 'b', 3
+ @b_2 = util_spec "b", 3
install_gem @b_1
install_default_gems @b_default
@@ -235,12 +235,12 @@ class TestGemCommandsCleanupCommand < Gem::TestCase
end
def test_execute_remove_gem_home_only
- c_1, = util_gem 'c', '1'
- c_2, = util_gem 'c', '2'
- d_1, = util_gem 'd', '1'
- d_2, = util_gem 'd', '2'
- e_1, = util_gem 'e', '1'
- e_2, = util_gem 'e', '2'
+ c_1, = util_gem "c", "1"
+ c_2, = util_gem "c", "2"
+ d_1, = util_gem "d", "1"
+ d_2, = util_gem "d", "2"
+ e_1, = util_gem "e", "1"
+ e_2, = util_gem "e", "2"
c_1 = install_gem c_1, :user_install => true # pick up user install path
c_2 = install_gem c_2
@@ -263,11 +263,11 @@ class TestGemCommandsCleanupCommand < Gem::TestCase
end
def test_execute_user_install
- c_1, = util_gem 'c', '1.0'
- c_2, = util_gem 'c', '1.1'
+ c_1, = util_gem "c", "1.0"
+ c_2, = util_gem "c", "1.1"
- d_1, = util_gem 'd', '1.0'
- d_2, = util_gem 'd', '1.1'
+ d_1, = util_gem "d", "1.0"
+ d_2, = util_gem "d", "1.1"
c_1 = install_gem c_1, :user_install => true # pick up user install path
c_2 = install_gem c_2, :user_install => true # pick up user install path
diff --git a/test/rubygems/test_gem_commands_contents_command.rb b/test/rubygems/test_gem_commands_contents_command.rb
index cf93d81e7e..1b9da8a92e 100644
--- a/test/rubygems/test_gem_commands_contents_command.rb
+++ b/test/rubygems/test_gem_commands_contents_command.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/commands/contents_command'
+require_relative "helper"
+require "rubygems/commands/contents_command"
class TestGemCommandsContentsCommand < Gem::TestCase
def setup
@@ -20,7 +20,7 @@ class TestGemCommandsContentsCommand < Gem::TestCase
def test_execute
@cmd.options[:args] = %w[foo]
- gem 'foo'
+ gem "foo"
use_ui @ui do
@cmd.execute
@@ -34,8 +34,8 @@ class TestGemCommandsContentsCommand < Gem::TestCase
def test_execute_all
@cmd.options[:all] = true
- gem 'foo'
- gem 'bar'
+ gem "foo"
+ gem "bar"
use_ui @ui do
@cmd.execute
@@ -63,8 +63,8 @@ class TestGemCommandsContentsCommand < Gem::TestCase
def test_execute_exact_match
@cmd.options[:args] = %w[foo]
- gem 'foo'
- gem 'bar'
+ gem "foo"
+ gem "bar"
use_ui @ui do
@cmd.execute
@@ -79,7 +79,7 @@ class TestGemCommandsContentsCommand < Gem::TestCase
@cmd.options[:args] = %w[foo]
@cmd.options[:lib_only] = true
- gem 'foo'
+ gem "foo"
use_ui @ui do
@cmd.execute
@@ -106,9 +106,9 @@ class TestGemCommandsContentsCommand < Gem::TestCase
def test_execute_missing_version
@cmd.options[:args] = %w[foo]
- @cmd.options[:version] = Gem::Requirement.new '= 2'
+ @cmd.options[:version] = Gem::Requirement.new "= 2"
- gem 'foo', 1
+ gem "foo", 1
assert_raise Gem::MockGemUi::TermError do
use_ui @ui do
@@ -123,7 +123,7 @@ class TestGemCommandsContentsCommand < Gem::TestCase
def test_execute_missing_multiple
@cmd.options[:args] = %w[foo bar]
- gem 'foo'
+ gem "foo"
use_ui @ui do
@cmd.execute
@@ -138,8 +138,8 @@ class TestGemCommandsContentsCommand < Gem::TestCase
def test_execute_multiple
@cmd.options[:args] = %w[foo bar]
- gem 'foo'
- gem 'bar'
+ gem "foo"
+ gem "bar"
use_ui @ui do
@cmd.execute
@@ -155,13 +155,13 @@ class TestGemCommandsContentsCommand < Gem::TestCase
@cmd.options[:args] = %w[foo]
@cmd.options[:show_install_dir] = true
- gem 'foo'
+ gem "foo"
use_ui @ui do
@cmd.execute
end
- expected = File.join @gemhome, 'gems', 'foo-2'
+ expected = File.join @gemhome, "gems", "foo-2"
assert_equal "#{expected}\n", @ui.output
assert_equal "", @ui.error
@@ -171,14 +171,14 @@ class TestGemCommandsContentsCommand < Gem::TestCase
@cmd.options[:args] = %w[foo]
@cmd.options[:show_install_dir] = true
- gem 'foo', 1
- gem 'foo', 2
+ gem "foo", 1
+ gem "foo", 2
use_ui @ui do
@cmd.execute
end
- expected = File.join @gemhome, 'gems', 'foo-2'
+ expected = File.join @gemhome, "gems", "foo-2"
assert_equal "#{expected}\n", @ui.output
assert_equal "", @ui.error
@@ -187,16 +187,16 @@ class TestGemCommandsContentsCommand < Gem::TestCase
def test_execute_show_install_dir_version
@cmd.options[:args] = %w[foo]
@cmd.options[:show_install_dir] = true
- @cmd.options[:version] = Gem::Requirement.new '= 1'
+ @cmd.options[:version] = Gem::Requirement.new "= 1"
- gem 'foo', 1
- gem 'foo', 2
+ gem "foo", 1
+ gem "foo", 2
use_ui @ui do
@cmd.execute
end
- expected = File.join @gemhome, 'gems', 'foo-1'
+ expected = File.join @gemhome, "gems", "foo-1"
assert_equal "#{expected}\n", @ui.output
assert_equal "", @ui.error
@@ -206,7 +206,7 @@ class TestGemCommandsContentsCommand < Gem::TestCase
@cmd.options[:args] = %w[foo]
@cmd.options[:prefix] = false
- gem 'foo'
+ gem "foo"
use_ui @ui do
@cmd.execute
@@ -236,9 +236,9 @@ lib/foo.rb
end
expected = [
- [RbConfig::CONFIG['bindir'], 'default_command'],
- [RbConfig::CONFIG['rubylibdir'], 'default/gem.rb'],
- [RbConfig::CONFIG['archdir'], 'default_gem.so'],
+ [RbConfig::CONFIG["bindir"], "default_command"],
+ [RbConfig::CONFIG["rubylibdir"], "default/gem.rb"],
+ [RbConfig::CONFIG["archdir"], "default_gem.so"],
].sort.map {|a|File.join a }.join "\n"
assert_equal expected, @ui.output.chomp
@@ -264,7 +264,7 @@ lib/foo.rb
assert @cmd.options[:lib_only]
refute @cmd.options[:prefix]
assert_equal %w[foo], @cmd.options[:specdirs]
- assert_equal Gem::Requirement.new('0.0.2'), @cmd.options[:version]
+ assert_equal Gem::Requirement.new("0.0.2"), @cmd.options[:version]
assert @cmd.options[:show_install_dir]
end
end
diff --git a/test/rubygems/test_gem_commands_dependency_command.rb b/test/rubygems/test_gem_commands_dependency_command.rb
index 13c7c065b5..d9571275cb 100644
--- a/test/rubygems/test_gem_commands_dependency_command.rb
+++ b/test/rubygems/test_gem_commands_dependency_command.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/commands/dependency_command'
+require_relative "helper"
+require "rubygems/commands/dependency_command"
class TestGemCommandsDependencyCommand < Gem::TestCase
def setup
@@ -11,9 +11,9 @@ class TestGemCommandsDependencyCommand < Gem::TestCase
end
def test_execute
- quick_gem 'foo' do |gem|
- gem.add_dependency 'bar', '> 1'
- gem.add_dependency 'baz', '> 1'
+ quick_gem "foo" do |gem|
+ gem.add_dependency "bar", "> 1"
+ gem.add_dependency "baz", "> 1"
end
@cmd.options[:args] = %w[foo]
@@ -24,16 +24,16 @@ class TestGemCommandsDependencyCommand < Gem::TestCase
assert_equal "Gem foo-2\n bar (> 1)\n baz (> 1)\n\n",
@stub_ui.output
- assert_equal '', @stub_ui.error
+ assert_equal "", @stub_ui.error
end
def test_execute_no_args
- install_specs util_spec 'x', '2'
+ install_specs util_spec "x", "2"
spec_fetcher do |fetcher|
- fetcher.spec 'a', 1
- fetcher.spec 'a', '2.a'
- fetcher.spec 'dep_x', 1, 'x' => '>= 1'
+ fetcher.spec "a", 1
+ fetcher.spec "a", "2.a"
+ fetcher.spec "dep_x", 1, "x" => ">= 1"
fetcher.legacy_platform
end
@@ -58,7 +58,7 @@ Gem x-2
EOF
assert_equal expected, @stub_ui.output
- assert_equal '', @stub_ui.error
+ assert_equal "", @stub_ui.error
end
def test_execute_no_match
@@ -71,14 +71,14 @@ Gem x-2
end
assert_equal "No gems found matching foo (>= 0)\n", @stub_ui.output
- assert_equal '', @stub_ui.error
+ assert_equal "", @stub_ui.error
end
def test_execute_pipe_format
- spec = util_spec 'foo' do |gem|
- gem.add_dependency 'bar', '> 1'
+ spec = util_spec "foo" do |gem|
+ gem.add_dependency "bar", "> 1"
end
- install_specs util_spec 'bar', 2
+ install_specs util_spec "bar", 2
install_specs spec
@cmd.options[:args] = %w[foo]
@@ -89,15 +89,15 @@ Gem x-2
end
assert_equal "bar --version '> 1'\n", @stub_ui.output
- assert_equal '', @stub_ui.error
+ assert_equal "", @stub_ui.error
end
def test_execute_regexp
spec_fetcher do |fetcher|
- fetcher.spec 'a', 1
- fetcher.spec 'a', '2.a'
- fetcher.spec 'a_evil', 9
- fetcher.spec 'b', 2
+ fetcher.spec "a", 1
+ fetcher.spec "a", "2.a"
+ fetcher.spec "a_evil", 9
+ fetcher.spec "b", 2
end
@cmd.options[:args] = %w[[ab]]
@@ -118,17 +118,17 @@ Gem b-2
EOF
assert_equal expected, @stub_ui.output
- assert_equal '', @stub_ui.error
+ assert_equal "", @stub_ui.error
end
def test_execute_reverse
# FIX: this shouldn't need to write out, but fails if you switch it
- quick_gem 'foo' do |gem|
- gem.add_dependency 'bar', '> 1'
+ quick_gem "foo" do |gem|
+ gem.add_dependency "bar", "> 1"
end
- quick_gem 'baz' do |gem|
- gem.add_dependency 'foo'
+ quick_gem "baz" do |gem|
+ gem.add_dependency "foo"
end
@cmd.options[:args] = %w[foo]
@@ -147,7 +147,7 @@ Gem foo-2
EOF
assert_equal expected, @stub_ui.output
- assert_equal '', @stub_ui.error
+ assert_equal "", @stub_ui.error
end
def test_execute_reverse_remote
@@ -165,15 +165,15 @@ Gem foo-2
ERROR: Only reverse dependencies for local gems are supported.
EOF
- assert_equal '', @stub_ui.output
+ assert_equal "", @stub_ui.output
assert_equal expected, @stub_ui.error
end
def test_execute_remote
- install_specs util_spec 'bar', '2'
+ install_specs util_spec "bar", "2"
spec_fetcher do |fetcher|
- fetcher.spec 'foo', 2, 'bar' => '> 1'
+ fetcher.spec "foo", 2, "bar" => "> 1"
end
@cmd.options[:args] = %w[foo]
@@ -184,7 +184,7 @@ ERROR: Only reverse dependencies for local gems are supported.
end
assert_equal "Gem foo-2\n bar (> 1)\n\n", @stub_ui.output
- assert_equal '', @stub_ui.error
+ assert_equal "", @stub_ui.error
end
def test_execute_remote_version
@@ -192,25 +192,25 @@ ERROR: Only reverse dependencies for local gems are supported.
Gem::RemoteFetcher.fetcher = @fetcher
spec_fetcher do |fetcher|
- fetcher.spec 'a', 1
- fetcher.spec 'a', 2
+ fetcher.spec "a", 1
+ fetcher.spec "a", 2
end
@cmd.options[:args] = %w[a]
@cmd.options[:domain] = :remote
- @cmd.options[:version] = req '= 1'
+ @cmd.options[:version] = req "= 1"
use_ui @stub_ui do
@cmd.execute
end
assert_equal "Gem a-1\n\n", @stub_ui.output
- assert_equal '', @stub_ui.error
+ assert_equal "", @stub_ui.error
end
def test_execute_prerelease
spec_fetcher do |fetcher|
- fetcher.spec 'a', '2.a'
+ fetcher.spec "a", "2.a"
end
@cmd.options[:args] = %w[a]
@@ -222,6 +222,6 @@ ERROR: Only reverse dependencies for local gems are supported.
end
assert_equal "Gem a-2.a\n\n", @stub_ui.output
- assert_equal '', @stub_ui.error
+ assert_equal "", @stub_ui.error
end
end
diff --git a/test/rubygems/test_gem_commands_environment_command.rb b/test/rubygems/test_gem_commands_environment_command.rb
index 2bf80d8d85..91ed774cb6 100644
--- a/test/rubygems/test_gem_commands_environment_command.rb
+++ b/test/rubygems/test_gem_commands_environment_command.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/commands/environment_command'
+require_relative "helper"
+require "rubygems/commands/environment_command"
class TestGemCommandsEnvironmentCommand < Gem::TestCase
def setup
@@ -11,9 +11,9 @@ class TestGemCommandsEnvironmentCommand < Gem::TestCase
def test_execute
orig_sources = Gem.sources.dup
- orig_path, ENV['PATH'] = ENV['PATH'], %w[/usr/local/bin /usr/bin /bin].join(File::PATH_SEPARATOR)
+ orig_path, ENV["PATH"] = ENV["PATH"], %w[/usr/local/bin /usr/bin /bin].join(File::PATH_SEPARATOR)
Gem.sources.replace %w[http://gems.example.com]
- Gem.configuration['gemcutter_key'] = 'blah'
+ Gem.configuration["gemcutter_key"] = "blah"
@cmd.send :handle_options, %w[]
@@ -25,6 +25,8 @@ class TestGemCommandsEnvironmentCommand < Gem::TestCase
assert_match %r{RUBY VERSION: \d+\.\d+\.\d+ \(.*\) \[.*\]}, @ui.output
assert_match %r{INSTALLATION DIRECTORY: #{Regexp.escape @gemhome}},
@ui.output
+ assert_match %r{USER INSTALLATION DIRECTORY: #{Regexp.escape Gem.user_dir}},
+ @ui.output
assert_match %r{RUBYGEMS PREFIX: }, @ui.output
assert_match %r{RUBY EXECUTABLE:.*#{RbConfig::CONFIG['ruby_install_name']}},
@ui.output
@@ -49,7 +51,7 @@ class TestGemCommandsEnvironmentCommand < Gem::TestCase
ensure
Gem.sources.replace orig_sources
- ENV['PATH'] = orig_path
+ ENV["PATH"] = orig_path
end
def test_execute_gemdir
@@ -60,7 +62,29 @@ class TestGemCommandsEnvironmentCommand < Gem::TestCase
end
assert_equal "#{@gemhome}\n", @ui.output
- assert_equal '', @ui.error
+ assert_equal "", @ui.error
+ end
+
+ def test_execute_user_gemdir
+ @cmd.send :handle_options, %w[user_gemdir]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_equal "#{Gem.user_dir}\n", @ui.output
+ assert_equal "", @ui.error
+ end
+
+ def test_execute_user_gemhome
+ @cmd.send :handle_options, %w[user_gemhome]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_equal "#{Gem.user_dir}\n", @ui.output
+ assert_equal "", @ui.error
end
def test_execute_gempath
@@ -71,13 +95,13 @@ class TestGemCommandsEnvironmentCommand < Gem::TestCase
end
assert_equal "#{@gemhome}\n", @ui.output
- assert_equal '', @ui.error
+ assert_equal "", @ui.error
end
def test_execute_gempath_multiple
Gem.clear_paths
path = [@gemhome, "#{@gemhome}2"].join File::PATH_SEPARATOR
- ENV['GEM_PATH'] = path
+ ENV["GEM_PATH"] = path
@cmd.send :handle_options, %w[gempath]
@@ -86,7 +110,7 @@ class TestGemCommandsEnvironmentCommand < Gem::TestCase
end
assert_equal "#{Gem.path.join File::PATH_SEPARATOR}\n", @ui.output
- assert_equal '', @ui.error
+ assert_equal "", @ui.error
end
def test_execute_remotesources
@@ -100,7 +124,7 @@ class TestGemCommandsEnvironmentCommand < Gem::TestCase
end
assert_equal "http://gems.example.com\n", @ui.output
- assert_equal '', @ui.error
+ assert_equal "", @ui.error
ensure
Gem.sources.replace orig_sources
@@ -115,8 +139,8 @@ class TestGemCommandsEnvironmentCommand < Gem::TestCase
end
end
- assert_equal '', @ui.output
- assert_equal '', @ui.error
+ assert_equal "", @ui.output
+ assert_equal "", @ui.error
end
def test_execute_version
@@ -127,7 +151,7 @@ class TestGemCommandsEnvironmentCommand < Gem::TestCase
end
assert_equal "#{Gem::VERSION}\n", @ui.output
- assert_equal '', @ui.error
+ assert_equal "", @ui.error
end
def test_execute_platform
@@ -138,6 +162,6 @@ class TestGemCommandsEnvironmentCommand < Gem::TestCase
end
assert_equal "#{Gem.platforms.join File::PATH_SEPARATOR}\n", @ui.output
- assert_equal '', @ui.error
+ assert_equal "", @ui.error
end
end
diff --git a/test/rubygems/test_gem_commands_fetch_command.rb b/test/rubygems/test_gem_commands_fetch_command.rb
index 7d4c77afaa..f2a4464c7d 100644
--- a/test/rubygems/test_gem_commands_fetch_command.rb
+++ b/test/rubygems/test_gem_commands_fetch_command.rb
@@ -1,8 +1,8 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/package'
-require 'rubygems/security'
-require 'rubygems/commands/fetch_command'
+require_relative "helper"
+require "rubygems/package"
+require "rubygems/security"
+require "rubygems/commands/fetch_command"
class TestGemCommandsFetchCommand < Gem::TestCase
def setup
@@ -13,10 +13,10 @@ class TestGemCommandsFetchCommand < Gem::TestCase
def test_execute
specs = spec_fetcher do |fetcher|
- fetcher.gem 'a', 2
+ fetcher.gem "a", 2
end
- assert_path_not_exist File.join(@tempdir, 'cache'), 'sanity check'
+ assert_path_not_exist File.join(@tempdir, "cache"), "sanity check"
@cmd.options[:args] = %w[a]
@@ -26,24 +26,24 @@ class TestGemCommandsFetchCommand < Gem::TestCase
end
end
- a2 = specs['a-2']
+ a2 = specs["a-2"]
assert_path_exist(File.join(@tempdir, a2.file_name),
"#{a2.full_name} not fetched")
- assert_path_not_exist File.join(@tempdir, 'cache'),
- 'gem repository directories must not be created'
+ assert_path_not_exist File.join(@tempdir, "cache"),
+ "gem repository directories must not be created"
end
def test_execute_latest
specs = spec_fetcher do |fetcher|
- fetcher.gem 'a', 1
- fetcher.gem 'a', 2
+ fetcher.gem "a", 1
+ fetcher.gem "a", 2
end
- assert_path_not_exist File.join(@tempdir, 'cache'), 'sanity check'
+ assert_path_not_exist File.join(@tempdir, "cache"), "sanity check"
@cmd.options[:args] = %w[a]
- @cmd.options[:version] = req('>= 0.1')
+ @cmd.options[:version] = req(">= 0.1")
use_ui @ui do
Dir.chdir @tempdir do
@@ -51,17 +51,17 @@ class TestGemCommandsFetchCommand < Gem::TestCase
end
end
- a2 = specs['a-2']
+ a2 = specs["a-2"]
assert_path_exist(File.join(@tempdir, a2.file_name),
"#{a2.full_name} not fetched")
- assert_path_not_exist File.join(@tempdir, 'cache'),
- 'gem repository directories must not be created'
+ assert_path_not_exist File.join(@tempdir, "cache"),
+ "gem repository directories must not be created"
end
def test_execute_prerelease
specs = spec_fetcher do |fetcher|
- fetcher.gem 'a', 2
- fetcher.gem 'a', '2.a'
+ fetcher.gem "a", 2
+ fetcher.gem "a", "2.a"
end
@cmd.options[:args] = %w[a]
@@ -73,7 +73,7 @@ class TestGemCommandsFetchCommand < Gem::TestCase
end
end
- a2 = specs['a-2']
+ a2 = specs["a-2"]
assert_path_exist(File.join(@tempdir, a2.file_name),
"#{a2.full_name} not fetched")
@@ -83,7 +83,7 @@ class TestGemCommandsFetchCommand < Gem::TestCase
a2_spec, a2 = util_gem("a", "2")
a2_universal_darwin_spec, a2_universal_darwin = util_gem("a", "2") do |s|
- s.platform = 'universal-darwin'
+ s.platform = "universal-darwin"
end
Gem::RemoteFetcher.fetcher = @fetcher = Gem::FakeFetcher.new
@@ -103,7 +103,7 @@ class TestGemCommandsFetchCommand < Gem::TestCase
@fetcher.data["#{@gem_repo}gems/#{a2_universal_darwin_spec.file_name}"] = Gem.read_binary(a2_universal_darwin)
FileUtils.cp a2_universal_darwin, a2_universal_darwin_spec.cache_file
- util_set_arch 'arm64-darwin20' do
+ util_set_arch "arm64-darwin20" do
use_ui @ui do
Dir.chdir @tempdir do
@cmd.execute
@@ -117,8 +117,8 @@ class TestGemCommandsFetchCommand < Gem::TestCase
def test_execute_specific_prerelease
specs = spec_fetcher do |fetcher|
- fetcher.gem 'a', 2
- fetcher.gem 'a', '2.a'
+ fetcher.gem "a", 2
+ fetcher.gem "a", "2.a"
end
@cmd.options[:args] = %w[a]
@@ -131,7 +131,7 @@ class TestGemCommandsFetchCommand < Gem::TestCase
end
end
- a2_pre = specs['a-2.a']
+ a2_pre = specs["a-2.a"]
assert_path_exist(File.join(@tempdir, a2_pre.file_name),
"#{a2_pre.full_name} not fetched")
@@ -139,12 +139,12 @@ class TestGemCommandsFetchCommand < Gem::TestCase
def test_execute_version
specs = spec_fetcher do |fetcher|
- fetcher.gem 'a', 1
- fetcher.gem 'a', 2
+ fetcher.gem "a", 1
+ fetcher.gem "a", 2
end
@cmd.options[:args] = %w[a]
- @cmd.options[:version] = Gem::Requirement.new '1'
+ @cmd.options[:version] = Gem::Requirement.new "1"
use_ui @ui do
Dir.chdir @tempdir do
@@ -152,7 +152,7 @@ class TestGemCommandsFetchCommand < Gem::TestCase
end
end
- a1 = specs['a-1']
+ a1 = specs["a-1"]
assert_path_exist(File.join(@tempdir, a1.file_name),
"#{a1.full_name} not fetched")
@@ -160,7 +160,7 @@ class TestGemCommandsFetchCommand < Gem::TestCase
def test_execute_version_specified_by_colon
specs = spec_fetcher do |fetcher|
- fetcher.gem 'a', 1
+ fetcher.gem "a", 1
end
@cmd.options[:args] = %w[a:1]
@@ -171,7 +171,7 @@ class TestGemCommandsFetchCommand < Gem::TestCase
end
end
- a1 = specs['a-1']
+ a1 = specs["a-1"]
assert_path_exist(File.join(@tempdir, a1.file_name),
"#{a1.full_name} not fetched")
@@ -179,7 +179,7 @@ class TestGemCommandsFetchCommand < Gem::TestCase
def test_execute_two_version
@cmd.options[:args] = %w[a b]
- @cmd.options[:version] = Gem::Requirement.new '1'
+ @cmd.options[:version] = Gem::Requirement.new "1"
use_ui @ui do
assert_raise Gem::MockGemUi::TermError, @ui.error do
@@ -196,8 +196,8 @@ class TestGemCommandsFetchCommand < Gem::TestCase
def test_execute_two_version_specified_by_colon
specs = spec_fetcher do |fetcher|
- fetcher.gem 'a', 1
- fetcher.gem 'b', 1
+ fetcher.gem "a", 1
+ fetcher.gem "b", 1
end
@cmd.options[:args] = %w[a:1 b:1]
@@ -208,8 +208,8 @@ class TestGemCommandsFetchCommand < Gem::TestCase
end
end
- a1 = specs['a-1']
- b1 = specs['b-1']
+ a1 = specs["a-1"]
+ b1 = specs["b-1"]
assert_path_exist(File.join(@tempdir, a1.file_name),
"#{a1.full_name} not fetched")
@@ -219,7 +219,7 @@ class TestGemCommandsFetchCommand < Gem::TestCase
def test_execute_version_nonexistent
spec_fetcher do |fetcher|
- fetcher.spec 'foo', 1
+ fetcher.spec "foo", 1
end
@cmd.options[:args] = %w[foo:2]
@@ -238,7 +238,7 @@ ERROR: Possible alternatives: foo
def test_execute_nonexistent_hint_disabled
spec_fetcher do |fetcher|
- fetcher.spec 'foo', 1
+ fetcher.spec "foo", 1
end
@cmd.options[:args] = %w[foo:2]
diff --git a/test/rubygems/test_gem_commands_generate_index_command.rb b/test/rubygems/test_gem_commands_generate_index_command.rb
index 5b7b37a446..c0e18119ed 100644
--- a/test/rubygems/test_gem_commands_generate_index_command.rb
+++ b/test/rubygems/test_gem_commands_generate_index_command.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/indexer'
-require 'rubygems/commands/generate_index_command'
+require_relative "helper"
+require "rubygems/indexer"
+require "rubygems/commands/generate_index_command"
class TestGemCommandsGenerateIndexCommand < Gem::TestCase
def setup
@@ -35,21 +35,21 @@ class TestGemCommandsGenerateIndexCommand < Gem::TestCase
def test_handle_options_directory
return if win_platform?
- refute_equal '/nonexistent', @cmd.options[:directory]
+ refute_equal "/nonexistent", @cmd.options[:directory]
@cmd.handle_options %w[--directory /nonexistent]
- assert_equal '/nonexistent', @cmd.options[:directory]
+ assert_equal "/nonexistent", @cmd.options[:directory]
end
def test_handle_options_directory_windows
return unless win_platform?
- refute_equal '/nonexistent', @cmd.options[:directory]
+ refute_equal "/nonexistent", @cmd.options[:directory]
@cmd.handle_options %w[--directory C:/nonexistent]
- assert_equal 'C:/nonexistent', @cmd.options[:directory]
+ assert_equal "C:/nonexistent", @cmd.options[:directory]
end
def test_handle_options_update
diff --git a/test/rubygems/test_gem_commands_help_command.rb b/test/rubygems/test_gem_commands_help_command.rb
index 98e5b62be0..b84bc4f7ef 100644
--- a/test/rubygems/test_gem_commands_help_command.rb
+++ b/test/rubygems/test_gem_commands_help_command.rb
@@ -11,41 +11,41 @@ class TestGemCommandsHelpCommand < Gem::TestCase
@cmd = Gem::Commands::HelpCommand.new
- load File.expand_path('rubygems_plugin.rb', __dir__) unless Gem::Commands.const_defined? :InterruptCommand
+ load File.expand_path("rubygems_plugin.rb", __dir__) unless Gem::Commands.const_defined? :InterruptCommand
end
def test_gem_help_bad
- util_gem 'bad' do |out, err|
- assert_equal('', out)
+ util_gem "bad" do |out, err|
+ assert_equal("", out)
assert_match "Unknown command bad", err
end
end
def test_gem_help_gem_dependencies
- util_gem 'gem_dependencies' do |out, err|
- assert_match 'gem.deps.rb', out
- assert_equal '', err
+ util_gem "gem_dependencies" do |out, err|
+ assert_match "gem.deps.rb", out
+ assert_equal "", err
end
end
def test_gem_help_platforms
- util_gem 'platforms' do |out, err|
+ util_gem "platforms" do |out, err|
assert_match(/x86-freebsd/, out)
- assert_equal '', err
+ assert_equal "", err
end
end
def test_gem_help_build
- util_gem 'build' do |out, err|
+ util_gem "build" do |out, err|
assert_match(/-C PATH *Run as if gem build was started in <PATH>/, out)
- assert_equal '', err
+ assert_equal "", err
end
end
def test_gem_help_commands
mgr = Gem::CommandManager.new
- util_gem 'commands' do |out, err|
+ util_gem "commands" do |out, err|
mgr.command_names.each do |cmd|
unless mgr[cmd].deprecated?
assert_match(/\s+#{cmd}\s+\S+/, out)
@@ -63,7 +63,7 @@ class TestGemCommandsHelpCommand < Gem::TestCase
def test_gem_help_commands_omits_deprecated_commands
mgr = Gem::CommandManager.new
- util_gem 'commands' do |out, err|
+ util_gem "commands" do |out, err|
deprecated_commands = mgr.command_names.select {|cmd| mgr[cmd].deprecated? }
deprecated_commands.each do |cmd|
refute_match(/\A\s+#{cmd}\s+\S+\z/, out)
@@ -75,7 +75,7 @@ class TestGemCommandsHelpCommand < Gem::TestCase
util_gem do |out, err|
assert_match(/Usage:/, out)
assert_match(/gem install/, out)
- assert_equal '', err
+ assert_equal "", err
end
end
diff --git a/test/rubygems/test_gem_commands_info_command.rb b/test/rubygems/test_gem_commands_info_command.rb
index 462075f98c..b18b405da6 100644
--- a/test/rubygems/test_gem_commands_info_command.rb
+++ b/test/rubygems/test_gem_commands_info_command.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/commands/info_command'
+require_relative "helper"
+require "rubygems/commands/info_command"
class TestGemCommandsInfoCommand < Gem::TestCase
def setup
diff --git a/test/rubygems/test_gem_commands_install_command.rb b/test/rubygems/test_gem_commands_install_command.rb
index 6127fcc124..7a58bcd7cb 100644
--- a/test/rubygems/test_gem_commands_install_command.rb
+++ b/test/rubygems/test_gem_commands_install_command.rb
@@ -1,8 +1,8 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/commands/install_command'
-require 'rubygems/request_set'
-require 'rubygems/rdoc'
+require_relative "helper"
+require "rubygems/commands/install_command"
+require "rubygems/request_set"
+require "rubygems/rdoc"
class TestGemCommandsInstallCommand < Gem::TestCase
def setup
@@ -30,8 +30,8 @@ class TestGemCommandsInstallCommand < Gem::TestCase
def test_execute_exclude_prerelease
spec_fetcher do |fetcher|
- fetcher.gem 'a', 2
- fetcher.gem 'a', '2.pre'
+ fetcher.gem "a", 2
+ fetcher.gem "a", "2.pre"
end
@cmd.options[:args] = %w[a]
@@ -47,13 +47,13 @@ class TestGemCommandsInstallCommand < Gem::TestCase
def test_execute_explicit_version_includes_prerelease
specs = spec_fetcher do |fetcher|
- fetcher.gem 'a', 2
- fetcher.gem 'a', '2.a'
+ fetcher.gem "a", 2
+ fetcher.gem "a", "2.a"
end
- a2_pre = specs['a-2.a']
+ a2_pre = specs["a-2.a"]
- @cmd.handle_options [a2_pre.name, '--version', a2_pre.version.to_s,
+ @cmd.handle_options [a2_pre.name, "--version", a2_pre.version.to_s,
"--no-document"]
assert @cmd.options[:prerelease]
assert @cmd.options[:version].satisfied_by?(a2_pre.version)
@@ -69,12 +69,12 @@ class TestGemCommandsInstallCommand < Gem::TestCase
def test_execute_local
specs = spec_fetcher do |fetcher|
- fetcher.gem 'a', 2
+ fetcher.gem "a", 2
end
@cmd.options[:domain] = :local
- FileUtils.mv specs['a-2'].cache_file, @tempdir
+ FileUtils.mv specs["a-2"].cache_file, @tempdir
@cmd.options[:args] = %w[a]
@@ -97,14 +97,14 @@ class TestGemCommandsInstallCommand < Gem::TestCase
def test_execute_local_dependency_nonexistent
specs = spec_fetcher do |fetcher|
- fetcher.gem 'foo', 2, 'bar' => '0.5'
+ fetcher.gem "foo", 2, "bar" => "0.5"
end
@cmd.options[:domain] = :local
- FileUtils.mv specs['foo-2'].cache_file, @tempdir
+ FileUtils.mv specs["foo-2"].cache_file, @tempdir
- @cmd.options[:args] = ['foo']
+ @cmd.options[:args] = ["foo"]
use_ui @ui do
orig_dir = Dir.pwd
@@ -128,15 +128,15 @@ ERROR: Could not find a valid gem 'bar' (= 0.5) (required by 'foo' (>= 0)) in a
def test_execute_local_dependency_nonexistent_ignore_dependencies
specs = spec_fetcher do |fetcher|
- fetcher.gem 'foo', 2, 'bar' => '0.5'
+ fetcher.gem "foo", 2, "bar" => "0.5"
end
@cmd.options[:domain] = :local
@cmd.options[:ignore_dependencies] = true
- FileUtils.mv specs['foo-2'].cache_file, @tempdir
+ FileUtils.mv specs["foo-2"].cache_file, @tempdir
- @cmd.options[:args] = ['foo']
+ @cmd.options[:args] = ["foo"]
use_ui @ui do
orig_dir = Dir.pwd
@@ -155,16 +155,16 @@ ERROR: Could not find a valid gem 'bar' (= 0.5) (required by 'foo' (>= 0)) in a
def test_execute_local_transitive_prerelease
specs = spec_fetcher do |fetcher|
- fetcher.download 'a', 2, 'b' => "2.a", 'c' => '3'
- fetcher.download 'b', '2.a'
- fetcher.download 'c', '3'
+ fetcher.download "a", 2, "b" => "2.a", "c" => "3"
+ fetcher.download "b", "2.a"
+ fetcher.download "c", "3"
end
@cmd.options[:domain] = :local
- FileUtils.mv specs['a-2'].cache_file, @tempdir
- FileUtils.mv specs['b-2.a'].cache_file, @tempdir
- FileUtils.mv specs['c-3'].cache_file, @tempdir
+ FileUtils.mv specs["a-2"].cache_file, @tempdir
+ FileUtils.mv specs["b-2.a"].cache_file, @tempdir
+ FileUtils.mv specs["c-3"].cache_file, @tempdir
@cmd.options[:args] = %w[a]
@@ -187,16 +187,16 @@ ERROR: Could not find a valid gem 'bar' (= 0.5) (required by 'foo' (>= 0)) in a
end
def test_execute_no_user_install
- pend 'skipped on MS Windows (chmod has no effect)' if win_platform?
- pend 'skipped in root privilege' if Process.uid.zero?
+ pend "skipped on MS Windows (chmod has no effect)" if win_platform?
+ pend "skipped in root privilege" if Process.uid.zero?
specs = spec_fetcher do |fetcher|
- fetcher.gem 'a', 2
+ fetcher.gem "a", 2
end
@cmd.options[:user_install] = false
- FileUtils.mv specs['a-2'].cache_file, @tempdir
+ FileUtils.mv specs["a-2"].cache_file, @tempdir
@cmd.options[:args] = %w[a]
@@ -295,10 +295,10 @@ ERROR: Could not find a valid gem 'bar' (= 0.5) (required by 'foo' (>= 0)) in a
def test_execute_dependency_nonexistent
spec_fetcher do |fetcher|
- fetcher.spec 'foo', 2, 'bar' => '0.5'
+ fetcher.spec "foo", 2, "bar" => "0.5"
end
- @cmd.options[:args] = ['foo']
+ @cmd.options[:args] = ["foo"]
use_ui @ui do
e = assert_raise Gem::MockGemUi::TermError do
@@ -451,8 +451,8 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_execute_prerelease_skipped_when_no_flag_set
spec_fetcher do |fetcher|
- fetcher.gem 'a', 1
- fetcher.gem 'a', '3.a'
+ fetcher.gem "a", 1
+ fetcher.gem "a", "3.a"
end
@cmd.options[:prerelease] = false
@@ -469,8 +469,8 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_execute_prerelease_wins_over_previous_ver
spec_fetcher do |fetcher|
- fetcher.download 'a', 1
- fetcher.download 'a', '2.a'
+ fetcher.download "a", 1
+ fetcher.download "a", "2.a"
end
@cmd.options[:prerelease] = true
@@ -487,8 +487,8 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_execute_with_version_specified_by_colon
spec_fetcher do |fetcher|
- fetcher.download 'a', 1
- fetcher.download 'a', 2
+ fetcher.download "a", 1
+ fetcher.download "a", 2
end
@cmd.options[:args] = %w[a:1]
@@ -504,8 +504,8 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_execute_prerelease_skipped_when_non_pre_available
spec_fetcher do |fetcher|
- fetcher.gem 'a', '2.pre'
- fetcher.gem 'a', 2
+ fetcher.gem "a", "2.pre"
+ fetcher.gem "a", 2
end
@cmd.options[:prerelease] = true
@@ -525,15 +525,15 @@ ERROR: Possible alternatives: non_existent_with_hint
local = Gem::Platform.local
spec_fetcher do |fetcher|
- fetcher.download 'a', 2
- fetcher.download 'a', 2 do |s|
+ fetcher.download "a", 2
+ fetcher.download "a", 2 do |s|
s.required_ruby_version = "< #{RUBY_VERSION}.a"
s.platform = local
end
- fetcher.download 'a', 3 do |s|
+ fetcher.download "a", 3 do |s|
s.required_ruby_version = ">= #{next_ruby}"
end
- fetcher.download 'a', 3 do |s|
+ fetcher.download "a", 3 do |s|
s.required_ruby_version = ">= #{next_ruby}"
s.platform = local
end
@@ -553,8 +553,8 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_execute_required_ruby_version_upper_bound
local = Gem::Platform.local
spec_fetcher do |fetcher|
- fetcher.gem 'a', 2.0
- fetcher.gem 'a', 2.0 do |s|
+ fetcher.gem "a", 2.0
+ fetcher.gem "a", 2.0 do |s|
s.required_ruby_version = "< #{RUBY_VERSION}.a"
s.platform = local
end
@@ -573,8 +573,8 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_execute_required_ruby_version_specific_not_met
spec_fetcher do |fetcher|
- fetcher.gem 'a', '1.0' do |s|
- s.required_ruby_version = '= 1.4.6'
+ fetcher.gem "a", "1.0" do |s|
+ s.required_ruby_version = "= 1.4.6"
end
end
@@ -593,8 +593,8 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_execute_required_ruby_version_specific_prerelease_met
spec_fetcher do |fetcher|
- fetcher.gem 'a', '1.0' do |s|
- s.required_ruby_version = '>= 1.4.6.preview2'
+ fetcher.gem "a", "1.0" do |s|
+ s.required_ruby_version = ">= 1.4.6.preview2"
end
end
@@ -613,7 +613,7 @@ ERROR: Possible alternatives: non_existent_with_hint
next_ruby_pre = Gem.ruby_version.segments.map.with_index {|n, i| i == 1 ? n + 1 : n }.join(".") + ".a"
spec_fetcher do |fetcher|
- fetcher.gem 'a', '1.0' do |s|
+ fetcher.gem "a", "1.0" do |s|
s.required_ruby_version = "> #{next_ruby_pre}"
end
end
@@ -633,8 +633,8 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_execute_required_rubygems_version_wrong
spec_fetcher do |fetcher|
- fetcher.gem 'a', '1.0' do |s|
- s.required_rubygems_version = '< 0'
+ fetcher.gem "a", "1.0" do |s|
+ s.required_rubygems_version = "< 0"
end
end
@@ -653,7 +653,7 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_execute_rdoc
specs = spec_fetcher do |fetcher|
- fetcher.gem 'a', 2
+ fetcher.gem "a", 2
end
Gem.done_installing(&Gem::RDoc.method(:generation_hook))
@@ -661,7 +661,7 @@ ERROR: Possible alternatives: non_existent_with_hint
@cmd.options[:document] = %w[rdoc ri]
@cmd.options[:domain] = :local
- a2 = specs['a-2']
+ a2 = specs["a-2"]
FileUtils.mv a2.cache_file, @tempdir
@cmd.options[:args] = %w[a]
@@ -683,22 +683,22 @@ ERROR: Possible alternatives: non_existent_with_hint
wait_for_child_process_to_exit
- assert_path_exist File.join(a2.doc_dir, 'ri')
- assert_path_exist File.join(a2.doc_dir, 'rdoc')
+ assert_path_exist File.join(a2.doc_dir, "ri")
+ assert_path_exist File.join(a2.doc_dir, "rdoc")
end
def test_execute_rdoc_with_path
specs = spec_fetcher do |fetcher|
- fetcher.gem 'a', 2
+ fetcher.gem "a", 2
end
Gem.done_installing(&Gem::RDoc.method(:generation_hook))
@cmd.options[:document] = %w[rdoc ri]
@cmd.options[:domain] = :local
- @cmd.options[:install_dir] = 'whatever'
+ @cmd.options[:install_dir] = "whatever"
- a2 = specs['a-2']
+ a2 = specs["a-2"]
FileUtils.mv a2.cache_file, @tempdir
@cmd.options[:args] = %w[a]
@@ -720,19 +720,19 @@ ERROR: Possible alternatives: non_existent_with_hint
wait_for_child_process_to_exit
- assert_path_exist 'whatever/doc/a-2', 'documentation not installed'
+ assert_path_exist "whatever/doc/a-2", "documentation not installed"
end
def test_execute_saves_build_args
specs = spec_fetcher do |fetcher|
- fetcher.gem 'a', 2
+ fetcher.gem "a", 2
end
args = %w[--with-awesome=true --more-awesome=yes]
Gem::Command.build_args = args
- a2 = specs['a-2']
+ a2 = specs["a-2"]
FileUtils.mv a2.cache_file, @tempdir
@cmd.options[:domain] = :local
@@ -762,7 +762,7 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_execute_remote
spec_fetcher do |fetcher|
- fetcher.gem 'a', 2
+ fetcher.gem "a", 2
end
@cmd.options[:args] = %w[a]
@@ -782,7 +782,7 @@ ERROR: Possible alternatives: non_existent_with_hint
FileUtils.touch("a.gem")
spec_fetcher do |fetcher|
- fetcher.gem 'a', 2
+ fetcher.gem "a", 2
end
@cmd.options[:args] = %w[a]
@@ -800,7 +800,7 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_execute_remote_truncates_existing_gemspecs
spec_fetcher do |fetcher|
- fetcher.gem 'a', 1
+ fetcher.gem "a", 1
end
@cmd.options[:domain] = :remote
@@ -816,7 +816,7 @@ ERROR: Possible alternatives: non_existent_with_hint
assert_equal %w[a-1], @cmd.installed_specs.map {|spec| spec.full_name }
assert_match "1 gem installed", @ui.output
- a1_gemspec = File.join(@gemhome, 'specifications', "a-1.gemspec")
+ a1_gemspec = File.join(@gemhome, "specifications", "a-1.gemspec")
initial_a1_gemspec_content = File.read(a1_gemspec)
modified_a1_gemspec_content = initial_a1_gemspec_content + "\n # AAAAAAA\n"
@@ -833,14 +833,14 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_execute_remote_ignores_files
specs = spec_fetcher do |fetcher|
- fetcher.gem 'a', 1
- fetcher.gem 'a', 2
+ fetcher.gem "a", 1
+ fetcher.gem "a", 2
end
@cmd.options[:domain] = :remote
- a1 = specs['a-1']
- a2 = specs['a-2']
+ a1 = specs["a-1"]
+ a2 = specs["a-2"]
FileUtils.mv a2.cache_file, @tempdir
@@ -849,7 +849,7 @@ ERROR: Possible alternatives: non_existent_with_hint
@cmd.options[:args] = [a2.name]
- gemdir = File.join @gemhome, 'specifications'
+ gemdir = File.join @gemhome, "specifications"
a2_gemspec = File.join(gemdir, "a-2.gemspec")
a1_gemspec = File.join(gemdir, "a-1.gemspec")
@@ -878,12 +878,12 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_execute_two
specs = spec_fetcher do |fetcher|
- fetcher.gem 'a', 2
- fetcher.gem 'b', 2
+ fetcher.gem "a", 2
+ fetcher.gem "b", 2
end
- FileUtils.mv specs['a-2'].cache_file, @tempdir
- FileUtils.mv specs['b-2'].cache_file, @tempdir
+ FileUtils.mv specs["a-2"].cache_file, @tempdir
+ FileUtils.mv specs["b-2"].cache_file, @tempdir
@cmd.options[:domain] = :local
@@ -929,10 +929,10 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_execute_two_version_specified_by_colon
spec_fetcher do |fetcher|
- fetcher.gem 'a', 1
- fetcher.gem 'a', 2
- fetcher.gem 'b', 1
- fetcher.gem 'b', 2
+ fetcher.gem "a", 1
+ fetcher.gem "a", 2
+ fetcher.gem "b", 1
+ fetcher.gem "b", 2
end
@cmd.options[:args] = %w[a:1 b:1]
@@ -948,9 +948,9 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_execute_conservative
spec_fetcher do |fetcher|
- fetcher.download 'b', 2
+ fetcher.download "b", 2
- fetcher.gem 'a', 2
+ fetcher.gem "a", 2
end
@cmd.options[:conservative] = true
@@ -981,7 +981,7 @@ ERROR: Possible alternatives: non_existent_with_hint
done_installing = true
end
- spec = util_spec 'a', 2
+ spec = util_spec "a", 2
util_build_gem spec
@@ -989,21 +989,21 @@ ERROR: Possible alternatives: non_existent_with_hint
@cmd.options[:ignore_dependencies] = true
- @cmd.install_gem 'a', '>= 0'
+ @cmd.install_gem "a", ">= 0"
assert_equal %w[a-2], @cmd.installed_specs.map {|s| s.full_name }
- assert done_installing, 'documentation was not generated'
+ assert done_installing, "documentation was not generated"
end
def test_install_gem_ignore_dependencies_remote
spec_fetcher do |fetcher|
- fetcher.gem 'a', 2
+ fetcher.gem "a", 2
end
@cmd.options[:ignore_dependencies] = true
- @cmd.install_gem 'a', '>= 0'
+ @cmd.install_gem "a", ">= 0"
assert_equal %w[a-2], @cmd.installed_specs.map {|spec| spec.full_name }
end
@@ -1011,22 +1011,22 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_install_gem_ignore_dependencies_remote_platform_local
local = Gem::Platform.local
spec_fetcher do |fetcher|
- fetcher.gem 'a', 3
+ fetcher.gem "a", 3
- fetcher.gem 'a', 3 do |s|
+ fetcher.gem "a", 3 do |s|
s.platform = local
end
end
@cmd.options[:ignore_dependencies] = true
- @cmd.install_gem 'a', '>= 0'
+ @cmd.install_gem "a", ">= 0"
assert_equal %W[a-3-#{local}], @cmd.installed_specs.map {|spec| spec.full_name }
end
def test_install_gem_ignore_dependencies_specific_file
- spec = util_spec 'a', 2
+ spec = util_spec "a", 2
util_build_gem spec
@@ -1041,8 +1041,8 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_parses_requirement_from_gemname
spec_fetcher do |fetcher|
- fetcher.gem 'a', 2
- fetcher.gem 'b', 2
+ fetcher.gem "a", 2
+ fetcher.gem "b", 2
end
@cmd.options[:domain] = :local
@@ -1088,12 +1088,12 @@ ERROR: Possible alternatives: non_existent_with_hint
assert_equal 2, e.exit_code
- assert_match 'Unable to download data', @ui.error
+ assert_match "Unable to download data", @ui.error
end
def test_show_source_problems_even_on_success
spec_fetcher do |fetcher|
- fetcher.download 'a', 2
+ fetcher.download "a", 2
end
Gem.sources << "http://nonexistent.example"
@@ -1118,7 +1118,7 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_redact_credentials_from_uri_on_warning
spec_fetcher do |fetcher|
- fetcher.download 'a', 2
+ fetcher.download "a", 2
end
Gem.sources << "http://username:SECURE_TOKEN@nonexistent.example"
@@ -1143,7 +1143,7 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_execute_uses_from_a_gemdeps
spec_fetcher do |fetcher|
- fetcher.gem 'a', 2
+ fetcher.gem "a", 2
end
File.open @gemdeps, "w" do |f|
@@ -1166,7 +1166,7 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_execute_uses_from_a_gemdeps_with_no_lock
spec_fetcher do |fetcher|
- fetcher.gem 'a', 2
+ fetcher.gem "a", 2
end
File.open @gemdeps, "w" do |f|
@@ -1190,8 +1190,8 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_execute_installs_from_a_gemdeps_with_conservative
spec_fetcher do |fetcher|
- fetcher.download 'a', 2
- fetcher.gem 'a', 1
+ fetcher.download "a", 2
+ fetcher.gem "a", 1
end
File.open @gemdeps, "w" do |f|
@@ -1214,7 +1214,7 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_execute_installs_from_a_gemdeps
spec_fetcher do |fetcher|
- fetcher.download 'a', 2
+ fetcher.download "a", 2
end
File.open @gemdeps, "w" do |f|
@@ -1236,8 +1236,8 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_execute_installs_deps_a_gemdeps
spec_fetcher do |fetcher|
- fetcher.download 'q', '1.0'
- fetcher.download 'r', '2.0', 'q' => nil
+ fetcher.download "q", "1.0"
+ fetcher.download "r", "2.0", "q" => nil
end
File.open @gemdeps, "w" do |f|
@@ -1262,9 +1262,9 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_execute_uses_deps_a_gemdeps
spec_fetcher do |fetcher|
- fetcher.download 'r', '2.0', 'q' => nil
+ fetcher.download "r", "2.0", "q" => nil
- fetcher.spec 'q', '1.0'
+ fetcher.spec "q", "1.0"
end
File.open @gemdeps, "w" do |f|
@@ -1289,8 +1289,8 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_execute_installs_deps_a_gemdeps_into_a_path
spec_fetcher do |fetcher|
- fetcher.download 'q', '1.0'
- fetcher.download 'r', '2.0', 'q' => nil
+ fetcher.download "q", "1.0"
+ fetcher.download "r", "2.0", "q" => nil
end
File.open @gemdeps, "w" do |f|
@@ -1319,11 +1319,11 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_execute_with_gemdeps_path_ignores_system
specs = spec_fetcher do |fetcher|
- fetcher.download 'q', '1.0'
- fetcher.download 'r', '2.0', 'q' => nil
+ fetcher.download "q", "1.0"
+ fetcher.download "r", "2.0", "q" => nil
end
- install_specs specs['q-1.0']
+ install_specs specs["q-1.0"]
File.open @gemdeps, "w" do |f|
f << "gem 'r'"
@@ -1351,11 +1351,11 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_execute_uses_deps_a_gemdeps_with_a_path
specs = spec_fetcher do |fetcher|
- fetcher.gem 'q', '1.0'
- fetcher.gem 'r', '2.0', 'q' => nil
+ fetcher.gem "q", "1.0"
+ fetcher.gem "r", "2.0", "q" => nil
end
- i = Gem::Installer.at specs['q-1.0'].cache_file, :install_dir => "gf-path"
+ i = Gem::Installer.at specs["q-1.0"].cache_file, :install_dir => "gf-path"
i.install
assert File.file?("gf-path/specifications/q-1.0.gemspec"), "not installed"
@@ -1382,39 +1382,39 @@ ERROR: Possible alternatives: non_existent_with_hint
end
def test_handle_options_file
- FileUtils.touch 'Gemfile'
+ FileUtils.touch "Gemfile"
@cmd.handle_options %w[-g Gemfile]
- assert_equal 'Gemfile', @cmd.options[:gemdeps]
+ assert_equal "Gemfile", @cmd.options[:gemdeps]
- FileUtils.rm 'Gemfile'
+ FileUtils.rm "Gemfile"
- FileUtils.touch 'gem.deps.rb'
+ FileUtils.touch "gem.deps.rb"
@cmd.handle_options %w[--file gem.deps.rb]
- assert_equal 'gem.deps.rb', @cmd.options[:gemdeps]
+ assert_equal "gem.deps.rb", @cmd.options[:gemdeps]
- FileUtils.rm 'gem.deps.rb'
+ FileUtils.rm "gem.deps.rb"
- FileUtils.touch 'Isolate'
+ FileUtils.touch "Isolate"
@cmd.handle_options %w[-g]
- assert_equal 'Isolate', @cmd.options[:gemdeps]
+ assert_equal "Isolate", @cmd.options[:gemdeps]
- FileUtils.touch 'Gemfile'
+ FileUtils.touch "Gemfile"
@cmd.handle_options %w[-g]
- assert_equal 'Gemfile', @cmd.options[:gemdeps]
+ assert_equal "Gemfile", @cmd.options[:gemdeps]
- FileUtils.touch 'gem.deps.rb'
+ FileUtils.touch "gem.deps.rb"
@cmd.handle_options %w[-g]
- assert_equal 'gem.deps.rb', @cmd.options[:gemdeps]
+ assert_equal "gem.deps.rb", @cmd.options[:gemdeps]
end
def test_handle_options_suggest
@@ -1442,9 +1442,9 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_explain_platform_local
local = Gem::Platform.local
spec_fetcher do |fetcher|
- fetcher.spec 'a', 2
+ fetcher.spec "a", 2
- fetcher.spec 'a', 2 do |s|
+ fetcher.spec "a", 2 do |s|
s.platform = local
end
end
@@ -1468,9 +1468,9 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_explain_platform_local_ignore_dependencies
local = Gem::Platform.local
spec_fetcher do |fetcher|
- fetcher.spec 'a', 3
+ fetcher.spec "a", 3
- fetcher.spec 'a', 3 do |s|
+ fetcher.spec "a", 3 do |s|
s.platform = local
end
end
@@ -1495,9 +1495,9 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_explain_platform_ruby
local = Gem::Platform.local
spec_fetcher do |fetcher|
- fetcher.spec 'a', 2
+ fetcher.spec "a", 2
- fetcher.spec 'a', 2 do |s|
+ fetcher.spec "a", 2 do |s|
s.platform = local
end
end
@@ -1524,9 +1524,9 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_explain_platform_ruby_ignore_dependencies
local = Gem::Platform.local
spec_fetcher do |fetcher|
- fetcher.spec 'a', 3
+ fetcher.spec "a", 3
- fetcher.spec 'a', 3 do |s|
+ fetcher.spec "a", 3 do |s|
s.platform = local
end
end
diff --git a/test/rubygems/test_gem_commands_list_command.rb b/test/rubygems/test_gem_commands_list_command.rb
index d8cffce7a3..ec3f2517bf 100644
--- a/test/rubygems/test_gem_commands_list_command.rb
+++ b/test/rubygems/test_gem_commands_list_command.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/commands/list_command'
+require_relative "helper"
+require "rubygems/commands/list_command"
class TestGemCommandsListCommand < Gem::TestCase
def setup
@@ -9,7 +9,7 @@ class TestGemCommandsListCommand < Gem::TestCase
@cmd = Gem::Commands::ListCommand.new
spec_fetcher do |fetcher|
- fetcher.spec 'c', 1
+ fetcher.spec "c", 1
end
@fetcher.data["#{@gem_repo}Marshal.#{Gem.marshal_version}"] = proc do
@@ -27,6 +27,6 @@ class TestGemCommandsListCommand < Gem::TestCase
end
assert_equal "true\n", @ui.output
- assert_equal '', @ui.error
+ assert_equal "", @ui.error
end
end
diff --git a/test/rubygems/test_gem_commands_lock_command.rb b/test/rubygems/test_gem_commands_lock_command.rb
index f8afca1e29..b785cbcfdd 100644
--- a/test/rubygems/test_gem_commands_lock_command.rb
+++ b/test/rubygems/test_gem_commands_lock_command.rb
@@ -1,18 +1,18 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/commands/lock_command'
+require_relative "helper"
+require "rubygems/commands/lock_command"
class TestGemCommandsLockCommand < Gem::TestCase
def setup
super
- @a1 = quick_gem 'a', '1'
- @b1 = quick_gem 'b', '1' do |s|
- s.add_runtime_dependency 'a'
+ @a1 = quick_gem "a", "1"
+ @b1 = quick_gem "b", "1" do |s|
+ s.add_runtime_dependency "a"
end
- @d1 = quick_gem 'd', '1' do |s|
- s.add_runtime_dependency 'z'
+ @d1 = quick_gem "d", "1" do |s|
+ s.add_runtime_dependency "z"
end
@cmd = Gem::Commands::LockCommand.new
@@ -32,7 +32,7 @@ gem 'a', '= 1'
EXPECTED
assert_equal expected, @ui.output
- assert_equal '', @ui.error
+ assert_equal "", @ui.error
end
def test_execute_missing_dependency
@@ -49,7 +49,7 @@ gem 'd', '= 1'
EXPECTED
assert_equal expected, @ui.output
- assert_equal '', @ui.error
+ assert_equal "", @ui.error
end
def test_execute_strict
@@ -61,6 +61,6 @@ gem 'd', '= 1'
end
end
- assert_equal 'Could not find gem c-1, try using the full name', e.message
+ assert_equal "Could not find gem c-1, try using the full name", e.message
end
end
diff --git a/test/rubygems/test_gem_commands_mirror.rb b/test/rubygems/test_gem_commands_mirror.rb
index 470f1c30fa..423aba2656 100644
--- a/test/rubygems/test_gem_commands_mirror.rb
+++ b/test/rubygems/test_gem_commands_mirror.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/commands/mirror_command'
+require_relative "helper"
+require "rubygems/commands/mirror_command"
class TestGemCommandsMirrorCommand < Gem::TestCase
def setup
diff --git a/test/rubygems/test_gem_commands_open_command.rb b/test/rubygems/test_gem_commands_open_command.rb
index 29cff1ed97..f970ca12d6 100644
--- a/test/rubygems/test_gem_commands_open_command.rb
+++ b/test/rubygems/test_gem_commands_open_command.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/commands/open_command'
+require_relative "helper"
+require "rubygems/commands/open_command"
class TestGemCommandsOpenCommand < Gem::TestCase
def setup
@@ -23,8 +23,8 @@ class TestGemCommandsOpenCommand < Gem::TestCase
@cmd.options[:args] = %w[foo]
@cmd.options[:editor] = "#{ruby_with_rubygems_in_load_path} -eexit --"
- gem 'foo', '1.0.0'
- spec = gem 'foo', '1.0.1'
+ gem "foo", "1.0.0"
+ spec = gem "foo", "1.0.1"
assert_nothing_raised Gem::MockGemUi::TermError do
Dir.stub(:chdir, spec.full_gem_path) do
diff --git a/test/rubygems/test_gem_commands_outdated_command.rb b/test/rubygems/test_gem_commands_outdated_command.rb
index dc5c40a782..4ed111a0e7 100644
--- a/test/rubygems/test_gem_commands_outdated_command.rb
+++ b/test/rubygems/test_gem_commands_outdated_command.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/commands/outdated_command'
+require_relative "helper"
+require "rubygems/commands/outdated_command"
class TestGemCommandsOutdatedCommand < Gem::TestCase
def setup
@@ -15,10 +15,10 @@ class TestGemCommandsOutdatedCommand < Gem::TestCase
def test_execute
spec_fetcher do |fetcher|
- fetcher.download 'foo', '1.0'
- fetcher.download 'foo', '2.0'
- fetcher.gem 'foo', '0.1'
- fetcher.gem 'foo', '0.2'
+ fetcher.download "foo", "1.0"
+ fetcher.download "foo", "2.0"
+ fetcher.gem "foo", "0.1"
+ fetcher.gem "foo", "0.2"
end
use_ui @ui do
@@ -31,10 +31,10 @@ class TestGemCommandsOutdatedCommand < Gem::TestCase
def test_execute_with_up_to_date_platform_specific_gem
spec_fetcher do |fetcher|
- fetcher.download 'foo', '2.0'
+ fetcher.download "foo", "2.0"
- fetcher.gem 'foo', '1.0'
- fetcher.gem 'foo', '2.0' do |s|
+ fetcher.gem "foo", "1.0"
+ fetcher.gem "foo", "2.0" do |s|
s.platform = Gem::Platform.local
end
end
diff --git a/test/rubygems/test_gem_commands_owner_command.rb b/test/rubygems/test_gem_commands_owner_command.rb
index 5b06b628c2..ca77041000 100644
--- a/test/rubygems/test_gem_commands_owner_command.rb
+++ b/test/rubygems/test_gem_commands_owner_command.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/commands/owner_command'
+require_relative "helper"
+require "rubygems/commands/owner_command"
class TestGemCommandsOwnerCommand < Gem::TestCase
def setup
@@ -36,7 +36,7 @@ class TestGemCommandsOwnerCommand < Gem::TestCase
- id: 4
EOF
- @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners.yaml"] = [response, 200, 'OK']
+ @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners.yaml"] = [response, 200, "OK"]
use_ui @stub_ui do
@cmd.show_owners("freewill")
@@ -66,7 +66,7 @@ EOF
- id: 4
EOF
- @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners.yaml"] = [response, 200, 'OK']
+ @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners.yaml"] = [response, 200, "OK"]
assert_raise Psych::DisallowedClass do
use_ui @ui do
@@ -80,7 +80,7 @@ EOF
host = "http://rubygems.example"
ENV["RUBYGEMS_HOST"] = host
- @stub_fetcher.data["#{host}/api/v1/gems/freewill/owners.yaml"] = [response, 200, 'OK']
+ @stub_fetcher.data["#{host}/api/v1/gems/freewill/owners.yaml"] = [response, 200, "OK"]
use_ui @stub_ui do
@cmd.show_owners("freewill")
@@ -95,7 +95,7 @@ EOF
host = "http://rubygems.example"
@cmd.host = host
- @stub_fetcher.data["#{host}/api/v1/gems/freewill/owners.yaml"] = [response, 200, 'OK']
+ @stub_fetcher.data["#{host}/api/v1/gems/freewill/owners.yaml"] = [response, 200, "OK"]
use_ui @stub_ui do
@cmd.show_owners("freewill")
@@ -107,7 +107,7 @@ EOF
def test_show_owners_denied
response = "You don't have permission to push to this gem"
- @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners.yaml"] = [response, 403, 'Forbidden']
+ @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners.yaml"] = [response, 403, "Forbidden"]
assert_raise Gem::MockGemUi::TermError do
use_ui @stub_ui do
@@ -120,21 +120,21 @@ EOF
def test_show_owners_key
response = "- email: user1@example.com\n"
- @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners.yaml"] = [response, 200, 'OK']
- File.open Gem.configuration.credentials_path, 'a' do |f|
- f.write ':other: 701229f217cdf23b1344c7b4b54ca97'
+ @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners.yaml"] = [response, 200, "OK"]
+ File.open Gem.configuration.credentials_path, "a" do |f|
+ f.write ":other: 701229f217cdf23b1344c7b4b54ca97"
end
Gem.configuration.load_api_keys
@cmd.handle_options %w[-k other]
- @cmd.show_owners('freewill')
+ @cmd.show_owners("freewill")
- assert_equal '701229f217cdf23b1344c7b4b54ca97', @stub_fetcher.last_request['Authorization']
+ assert_equal "701229f217cdf23b1344c7b4b54ca97", @stub_fetcher.last_request["Authorization"]
end
def test_add_owners
response = "Owner added successfully."
- @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 200, 'OK']
+ @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 200, "OK"]
use_ui @stub_ui do
@cmd.add_owners("freewill", ["user-new1@example.com"])
@@ -149,7 +149,7 @@ EOF
def test_add_owners_denied
response = "You don't have permission to push to this gem"
- @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 403, 'Forbidden']
+ @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 403, "Forbidden"]
use_ui @stub_ui do
@cmd.add_owners("freewill", ["user-new1@example.com"])
@@ -162,8 +162,8 @@ EOF
host = "http://rubygems.example"
add_owner_response = "Owner added successfully."
show_owners_response = "- email: user1@example.com\n"
- @stub_fetcher.data["#{host}/api/v1/gems/freewill/owners"] = [add_owner_response, 200, 'OK']
- @stub_fetcher.data["#{host}/api/v1/gems/freewill/owners.yaml"] = [show_owners_response, 200, 'OK']
+ @stub_fetcher.data["#{host}/api/v1/gems/freewill/owners"] = [add_owner_response, 200, "OK"]
+ @stub_fetcher.data["#{host}/api/v1/gems/freewill/owners.yaml"] = [show_owners_response, 200, "OK"]
@cmd.handle_options %W[--host #{host} --add user-new1@example.com freewill]
@@ -178,21 +178,21 @@ EOF
def test_add_owners_key
response = "Owner added successfully."
- @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 200, 'OK']
- File.open Gem.configuration.credentials_path, 'a' do |f|
- f.write ':other: 701229f217cdf23b1344c7b4b54ca97'
+ @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 200, "OK"]
+ File.open Gem.configuration.credentials_path, "a" do |f|
+ f.write ":other: 701229f217cdf23b1344c7b4b54ca97"
end
Gem.configuration.load_api_keys
@cmd.handle_options %w[-k other]
- @cmd.add_owners('freewill', ['user-new1@example.com'])
+ @cmd.add_owners("freewill", ["user-new1@example.com"])
- assert_equal '701229f217cdf23b1344c7b4b54ca97', @stub_fetcher.last_request['Authorization']
+ assert_equal "701229f217cdf23b1344c7b4b54ca97", @stub_fetcher.last_request["Authorization"]
end
def test_remove_owners
response = "Owner removed successfully."
- @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 200, 'OK']
+ @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 200, "OK"]
use_ui @stub_ui do
@cmd.remove_owners("freewill", ["user-remove1@example.com"])
@@ -207,7 +207,7 @@ EOF
def test_remove_owners_denied
response = "You don't have permission to push to this gem"
- @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 403, 'Forbidden']
+ @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 403, "Forbidden"]
use_ui @stub_ui do
@cmd.remove_owners("freewill", ["user-remove1@example.com"])
@@ -218,21 +218,21 @@ EOF
def test_remove_owners_key
response = "Owner removed successfully."
- @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 200, 'OK']
- File.open Gem.configuration.credentials_path, 'a' do |f|
- f.write ':other: 701229f217cdf23b1344c7b4b54ca97'
+ @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 200, "OK"]
+ File.open Gem.configuration.credentials_path, "a" do |f|
+ f.write ":other: 701229f217cdf23b1344c7b4b54ca97"
end
Gem.configuration.load_api_keys
@cmd.handle_options %w[-k other]
- @cmd.remove_owners('freewill', ['user-remove1@example.com'])
+ @cmd.remove_owners("freewill", ["user-remove1@example.com"])
- assert_equal '701229f217cdf23b1344c7b4b54ca97', @stub_fetcher.last_request['Authorization']
+ assert_equal "701229f217cdf23b1344c7b4b54ca97", @stub_fetcher.last_request["Authorization"]
end
def test_remove_owners_missing
- response = 'Owner could not be found.'
- @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 404, 'Not Found']
+ response = "Owner could not be found."
+ @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 404, "Not Found"]
use_ui @stub_ui do
@cmd.remove_owners("freewill", ["missing@example"])
@@ -246,8 +246,8 @@ EOF
response_success = "Owner added successfully."
@stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [
- [response_fail, 401, 'Unauthorized'],
- [response_success, 200, 'OK'],
+ [response_fail, 401, "Unauthorized"],
+ [response_success, 200, "OK"],
]
@otp_ui = Gem::MockGemUi.new "111111\n"
@@ -255,15 +255,15 @@ EOF
@cmd.add_owners("freewill", ["user-new1@example.com"])
end
- assert_match 'You have enabled multi-factor authentication. Please enter OTP code.', @otp_ui.output
- assert_match 'Code: ', @otp_ui.output
+ assert_match "You have enabled multi-factor authentication. Please enter OTP code.", @otp_ui.output
+ assert_match "Code: ", @otp_ui.output
assert_match response_success, @otp_ui.output
- assert_equal '111111', @stub_fetcher.last_request['OTP']
+ assert_equal "111111", @stub_fetcher.last_request["OTP"]
end
def test_otp_verified_failure
response = "You have enabled multifactor authentication but your request doesn't have the correct OTP code. Please check it and retry."
- @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 401, 'Unauthorized']
+ @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 401, "Unauthorized"]
@otp_ui = Gem::MockGemUi.new "111111\n"
use_ui @otp_ui do
@@ -271,9 +271,9 @@ EOF
end
assert_match response, @otp_ui.output
- assert_match 'You have enabled multi-factor authentication. Please enter OTP code.', @otp_ui.output
- assert_match 'Code: ', @otp_ui.output
- assert_equal '111111', @stub_fetcher.last_request['OTP']
+ assert_match "You have enabled multi-factor authentication. Please enter OTP code.", @otp_ui.output
+ assert_match "Code: ", @otp_ui.output
+ assert_equal "111111", @stub_fetcher.last_request["OTP"]
end
def test_remove_owners_unathorized_api_key
@@ -281,7 +281,7 @@ EOF
response_success = "Owner removed successfully."
@stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [
- [response_forbidden, 403, 'Forbidden'],
+ [response_forbidden, 403, "Forbidden"],
[response_success, 200, "OK"],
]
@stub_fetcher.data["#{Gem.host}/api/v1/api_key"] = ["", 200, "OK"]
@@ -305,7 +305,7 @@ EOF
response_success = "Owner added successfully."
@stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [
- [response_forbidden, 403, 'Forbidden'],
+ [response_forbidden, 403, "Forbidden"],
[response_success, 200, "OK"],
]
@stub_fetcher.data["#{Gem.host}/api/v1/api_key"] = ["", 200, "OK"]
diff --git a/test/rubygems/test_gem_commands_pristine_command.rb b/test/rubygems/test_gem_commands_pristine_command.rb
index f4000f4657..5bf1d27eb9 100644
--- a/test/rubygems/test_gem_commands_pristine_command.rb
+++ b/test/rubygems/test_gem_commands_pristine_command.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/commands/pristine_command'
+require_relative "helper"
+require "rubygems/commands/pristine_command"
class TestGemCommandsPristineCommand < Gem::TestCase
def setup
@@ -11,29 +11,29 @@ class TestGemCommandsPristineCommand < Gem::TestCase
end
def test_execute
- a = util_spec 'a' do |s|
+ a = util_spec "a" do |s|
s.executables = %w[foo]
s.files = %w[bin/foo lib/a.rb]
end
- write_file File.join(@tempdir, 'lib', 'a.rb') do |fp|
+ write_file File.join(@tempdir, "lib", "a.rb") do |fp|
fp.puts "puts __FILE__"
end
- write_file File.join(@tempdir, 'bin', 'foo') do |fp|
+ write_file File.join(@tempdir, "bin", "foo") do |fp|
fp.puts "#!/usr/bin/ruby"
end
install_gem a
- foo_path = File.join @gemhome, 'gems', a.full_name, 'bin', 'foo'
- a_rb_path = File.join @gemhome, 'gems', a.full_name, 'lib', 'a.rb'
+ foo_path = File.join @gemhome, "gems", a.full_name, "bin", "foo"
+ a_rb_path = File.join @gemhome, "gems", a.full_name, "lib", "a.rb"
write_file foo_path do |io|
- io.puts 'I changed it!'
+ io.puts "I changed it!"
end
write_file a_rb_path do |io|
- io.puts 'I changed it!'
+ io.puts "I changed it!"
end
@cmd.options[:args] = %w[a]
@@ -102,18 +102,18 @@ class TestGemCommandsPristineCommand < Gem::TestCase
end
def test_execute_all
- a = util_spec 'a' do |s|
+ a = util_spec "a" do |s|
s.executables = %w[foo]
end
- write_file File.join(@tempdir, 'bin', 'foo') do |fp|
+ write_file File.join(@tempdir, "bin", "foo") do |fp|
fp.puts "#!/usr/bin/ruby"
end
install_gem a
- gem_bin = File.join @gemhome, 'gems', a.full_name, 'bin', 'foo'
- gem_stub = File.join @gemhome, 'bin', 'foo'
+ gem_bin = File.join @gemhome, "gems", a.full_name, "bin", "foo"
+ gem_stub = File.join @gemhome, "bin", "foo"
FileUtils.rm gem_bin
FileUtils.rm gem_stub
@@ -135,17 +135,17 @@ class TestGemCommandsPristineCommand < Gem::TestCase
end
def test_execute_env_shebang
- a = util_spec 'a' do |s|
+ a = util_spec "a" do |s|
s.executables = %w[foo]
s.files = %w[bin/foo]
end
- write_file File.join(@tempdir, 'bin', 'foo') do |fp|
+ write_file File.join(@tempdir, "bin", "foo") do |fp|
fp.puts "#!/usr/bin/ruby"
end
install_gem a
- gem_exec = File.join @gemhome, 'bin', 'foo'
+ gem_exec = File.join @gemhome, "bin", "foo"
FileUtils.rm gem_exec
@@ -157,7 +157,7 @@ class TestGemCommandsPristineCommand < Gem::TestCase
assert_path_exist gem_exec
- ruby_exec = sprintf Gem.default_exec_format, 'ruby'
+ ruby_exec = sprintf Gem.default_exec_format, "ruby"
bin_env = win_platform? ? "" : %w[/usr/bin/env /bin/env].find {|f| File.executable?(f) } + " "
@@ -165,11 +165,11 @@ class TestGemCommandsPristineCommand < Gem::TestCase
end
def test_execute_extensions_explicit
- a = util_spec 'a' do |s|
- s.extensions << 'ext/a/extconf.rb'
+ a = util_spec "a" do |s|
+ s.extensions << "ext/a/extconf.rb"
end
- ext_path = File.join @tempdir, 'ext', 'a', 'extconf.rb'
+ ext_path = File.join @tempdir, "ext", "a", "extconf.rb"
write_file ext_path do |io|
io.write <<-'RUBY'
File.open "Makefile", "w" do |f|
@@ -180,7 +180,7 @@ class TestGemCommandsPristineCommand < Gem::TestCase
RUBY
end
- b = util_spec 'b'
+ b = util_spec "b"
install_gem a
install_gem b
@@ -195,19 +195,19 @@ class TestGemCommandsPristineCommand < Gem::TestCase
out = @ui.output.split "\n"
- assert_equal 'Restoring gems to pristine condition...', out.shift
- assert_equal 'Building native extensions. This could take a while...',
+ assert_equal "Restoring gems to pristine condition...", out.shift
+ assert_equal "Building native extensions. This could take a while...",
out.shift
assert_equal "Restored #{a.full_name}", out.shift
assert_empty out, out.inspect
end
def test_execute_no_extension
- a = util_spec 'a' do |s|
- s.extensions << 'ext/a/extconf.rb'
+ a = util_spec "a" do |s|
+ s.extensions << "ext/a/extconf.rb"
end
- ext_path = File.join @tempdir, 'ext', 'a', 'extconf.rb'
+ ext_path = File.join @tempdir, "ext", "a", "extconf.rb"
write_file ext_path do |io|
io.write "# extconf.rb\nrequire 'mkmf'; create_makefile 'a'"
end
@@ -223,18 +223,18 @@ class TestGemCommandsPristineCommand < Gem::TestCase
out = @ui.output.split "\n"
- assert_equal 'Restoring gems to pristine condition...', out.shift
+ assert_equal "Restoring gems to pristine condition...", out.shift
assert_equal "Skipped #{a.full_name}, it needs to compile an extension",
out.shift
assert_empty out, out.inspect
end
def test_execute_with_extension_with_build_args
- a = util_spec 'a' do |s|
- s.extensions << 'ext/a/extconf.rb'
+ a = util_spec "a" do |s|
+ s.extensions << "ext/a/extconf.rb"
end
- ext_path = File.join @tempdir, 'ext', 'a', 'extconf.rb'
+ ext_path = File.join @tempdir, "ext", "a", "extconf.rb"
write_file ext_path do |io|
io.write <<-'RUBY'
File.open "Makefile", "w" do |f|
@@ -257,7 +257,7 @@ class TestGemCommandsPristineCommand < Gem::TestCase
out = @ui.output.split "\n"
- assert_equal 'Restoring gems to pristine condition...', out.shift
+ assert_equal "Restoring gems to pristine condition...", out.shift
assert_equal "Building native extensions with: '--with-awesome=true --sweet'", out.shift
assert_equal "This could take a while...", out.shift
assert_equal "Restored #{a.full_name}", out.shift
@@ -265,8 +265,8 @@ class TestGemCommandsPristineCommand < Gem::TestCase
end
def test_execute_many
- a = util_spec 'a'
- b = util_spec 'b'
+ a = util_spec "a"
+ b = util_spec "b"
install_gem a
install_gem b
@@ -286,14 +286,14 @@ class TestGemCommandsPristineCommand < Gem::TestCase
end
def test_skip
- a = util_spec 'a'
- b = util_spec 'b'
+ a = util_spec "a"
+ b = util_spec "b"
install_gem a
install_gem b
@cmd.options[:args] = %w[a b]
- @cmd.options[:skip] = 'a'
+ @cmd.options[:skip] = "a"
use_ui @ui do
@cmd.execute
@@ -308,16 +308,16 @@ class TestGemCommandsPristineCommand < Gem::TestCase
end
def test_skip_many_gems
- a = util_spec 'a'
- b = util_spec 'b'
- c = util_spec 'c'
+ a = util_spec "a"
+ b = util_spec "b"
+ c = util_spec "c"
install_gem a
install_gem b
install_gem c
@cmd.options[:args] = %w[a b c]
- @cmd.options[:skip] = ['a', 'c']
+ @cmd.options[:skip] = ["a", "c"]
use_ui @ui do
@cmd.execute
@@ -333,14 +333,14 @@ class TestGemCommandsPristineCommand < Gem::TestCase
end
def test_execute_many_multi_repo
- a = util_spec 'a'
+ a = util_spec "a"
install_gem a
Gem.clear_paths
- gemhome2 = File.join @tempdir, 'gemhome2'
+ gemhome2 = File.join @tempdir, "gemhome2"
Gem.use_paths gemhome2, [gemhome2, @gemhome]
- b = util_spec 'b'
+ b = util_spec "b"
install_gem b
@cmd.options[:args] = %w[a b]
@@ -356,21 +356,21 @@ class TestGemCommandsPristineCommand < Gem::TestCase
assert_equal "Restored #{b.full_name}", out.shift
assert_empty out, out.inspect
- assert_path_exist File.join(@gemhome, "gems", 'a-2')
- assert_path_not_exist File.join(gemhome2, "gems", 'a-2')
- assert_path_exist File.join(gemhome2, "gems", 'b-2')
- assert_path_not_exist File.join(@gemhome, "gems", 'b-2')
+ assert_path_exist File.join(@gemhome, "gems", "a-2")
+ assert_path_not_exist File.join(gemhome2, "gems", "a-2")
+ assert_path_exist File.join(gemhome2, "gems", "b-2")
+ assert_path_not_exist File.join(@gemhome, "gems", "b-2")
end
def test_execute_missing_cache_gem
specs = spec_fetcher do |fetcher|
- fetcher.gem 'a', 1
- fetcher.gem 'a', 2
- fetcher.gem 'a', 3
- fetcher.gem 'a', '3.a'
+ fetcher.gem "a", 1
+ fetcher.gem "a", 2
+ fetcher.gem "a", 3
+ fetcher.gem "a", "3.a"
end
- FileUtils.rm specs['a-2'].cache_file
+ FileUtils.rm specs["a-2"].cache_file
@cmd.options[:args] = %w[a]
@@ -396,22 +396,23 @@ class TestGemCommandsPristineCommand < Gem::TestCase
def test_execute_missing_cache_gem_when_multi_repo
specs = spec_fetcher do |fetcher|
- fetcher.gem 'a', 1
- fetcher.gem 'b', 1
+ fetcher.gem "a", 1
+ fetcher.gem "b", 1
end
- FileUtils.rm_rf File.join(@gemhome, 'gems', 'a-1')
- FileUtils.rm_rf File.join(@gemhome, 'gems', 'b-1')
+ FileUtils.rm_rf File.join(@gemhome, "gems", "a-1")
+ FileUtils.rm_rf File.join(@gemhome, "gems", "b-1")
install_gem specs["a-1"]
- FileUtils.rm File.join(@gemhome, 'cache', 'a-1.gem')
+ FileUtils.rm File.join(@gemhome, "cache", "a-1.gem")
Gem.clear_paths
- gemhome2 = File.join(@tempdir, 'gemhome2')
+ gemhome2 = File.join(@tempdir, "gemhome2")
Gem.use_paths gemhome2, [gemhome2, @gemhome]
install_gem specs["b-1"]
- FileUtils.rm File.join(gemhome2, 'cache', 'b-1.gem')
+ FileUtils.rm File.join(gemhome2, "cache", "b-1.gem")
+ Gem::Specification.reset
@cmd.options[:args] = %w[a b]
@@ -434,15 +435,15 @@ class TestGemCommandsPristineCommand < Gem::TestCase
assert_empty out, out.inspect
assert_empty @ui.error
- assert_path_exist File.join(@gemhome, "cache", 'a-1.gem')
- assert_path_not_exist File.join(gemhome2, "cache", 'a-2.gem')
- assert_path_exist File.join(@gemhome, "gems", 'a-1')
- assert_path_not_exist File.join(gemhome2, "gems", 'a-1')
+ assert_path_exist File.join(@gemhome, "cache", "a-1.gem")
+ assert_path_not_exist File.join(gemhome2, "cache", "a-2.gem")
+ assert_path_exist File.join(@gemhome, "gems", "a-1")
+ assert_path_not_exist File.join(gemhome2, "gems", "a-1")
- assert_path_exist File.join(gemhome2, "cache", 'b-1.gem')
- assert_path_not_exist File.join(@gemhome, "cache", 'b-2.gem')
- assert_path_exist File.join(gemhome2, "gems", 'b-1')
- assert_path_not_exist File.join(@gemhome, "gems", 'b-1')
+ assert_path_exist File.join(gemhome2, "cache", "b-1.gem")
+ assert_path_not_exist File.join(@gemhome, "cache", "b-2.gem")
+ assert_path_exist File.join(gemhome2, "gems", "b-1")
+ assert_path_not_exist File.join(@gemhome, "gems", "b-1")
end
def test_execute_no_gem
@@ -458,21 +459,21 @@ class TestGemCommandsPristineCommand < Gem::TestCase
end
def test_execute_only_executables
- a = util_spec 'a' do |s|
+ a = util_spec "a" do |s|
s.executables = %w[foo]
s.files = %w[bin/foo lib/a.rb]
end
- write_file File.join(@tempdir, 'lib', 'a.rb') do |fp|
+ write_file File.join(@tempdir, "lib", "a.rb") do |fp|
fp.puts "puts __FILE__"
end
- write_file File.join(@tempdir, 'bin', 'foo') do |fp|
+ write_file File.join(@tempdir, "bin", "foo") do |fp|
fp.puts "#!/usr/bin/ruby"
end
install_gem a
- gem_lib = File.join @gemhome, 'gems', a.full_name, 'lib', 'a.rb'
- gem_exec = File.join @gemhome, 'bin', 'foo'
+ gem_lib = File.join @gemhome, "gems", a.full_name, "lib", "a.rb"
+ gem_exec = File.join @gemhome, "bin", "foo"
FileUtils.rm gem_exec
FileUtils.rm gem_lib
@@ -488,25 +489,25 @@ class TestGemCommandsPristineCommand < Gem::TestCase
end
def test_execute_only_plugins
- a = util_spec 'a' do |s|
+ a = util_spec "a" do |s|
s.executables = %w[foo]
s.files = %w[bin/foo lib/a.rb lib/rubygems_plugin.rb]
end
- write_file File.join(@tempdir, 'lib', 'a.rb') do |fp|
+ write_file File.join(@tempdir, "lib", "a.rb") do |fp|
fp.puts "puts __FILE__"
end
- write_file File.join(@tempdir, 'lib', 'rubygems_plugin.rb') do |fp|
+ write_file File.join(@tempdir, "lib", "rubygems_plugin.rb") do |fp|
fp.puts "puts __FILE__"
end
- write_file File.join(@tempdir, 'bin', 'foo') do |fp|
+ write_file File.join(@tempdir, "bin", "foo") do |fp|
fp.puts "#!/usr/bin/ruby"
end
install_gem a
- gem_lib = File.join @gemhome, 'gems', a.full_name, 'lib', 'a.rb'
- gem_plugin = File.join @gemhome, 'plugins', 'a_plugin.rb'
- gem_exec = File.join @gemhome, 'bin', 'foo'
+ gem_lib = File.join @gemhome, "gems", a.full_name, "lib", "a.rb"
+ gem_plugin = File.join @gemhome, "plugins", "a_plugin.rb"
+ gem_exec = File.join @gemhome, "bin", "foo"
FileUtils.rm gem_exec
FileUtils.rm gem_plugin
@@ -524,24 +525,24 @@ class TestGemCommandsPristineCommand < Gem::TestCase
end
def test_execute_bindir
- a = util_spec 'a' do |s|
+ a = util_spec "a" do |s|
s.name = "test_gem"
s.executables = %w[foo]
s.files = %w[bin/foo]
end
- write_file File.join(@tempdir, 'bin', 'foo') do |fp|
+ write_file File.join(@tempdir, "bin", "foo") do |fp|
fp.puts "#!/usr/bin/ruby"
end
- write_file File.join(@tempdir, 'test_bin', 'foo') do |fp|
+ write_file File.join(@tempdir, "test_bin", "foo") do |fp|
fp.puts "#!/usr/bin/ruby"
end
install_gem a
- gem_exec = File.join @gemhome, 'bin', 'foo'
- gem_bindir = File.join @tempdir, 'test_bin', 'foo'
+ gem_exec = File.join @gemhome, "bin", "foo"
+ gem_bindir = File.join @tempdir, "test_bin", "foo"
FileUtils.rm gem_exec
FileUtils.rm gem_bindir
@@ -557,7 +558,7 @@ class TestGemCommandsPristineCommand < Gem::TestCase
end
def test_execute_unknown_gem_at_remote_source
- install_specs util_spec 'a'
+ install_specs util_spec "a"
@cmd.options[:args] = %w[a]
@@ -596,16 +597,16 @@ class TestGemCommandsPristineCommand < Gem::TestCase
end
def test_execute_multi_platform
- a = util_spec 'a' do |s|
- s.extensions << 'ext/a/extconf.rb'
+ a = util_spec "a" do |s|
+ s.extensions << "ext/a/extconf.rb"
end
- b = util_spec 'b' do |s|
- s.extensions << 'ext/a/extconf.rb'
+ b = util_spec "b" do |s|
+ s.extensions << "ext/a/extconf.rb"
s.platform = Gem::Platform.new("java")
end
- ext_path = File.join @tempdir, 'ext', 'a', 'extconf.rb'
+ ext_path = File.join @tempdir, "ext", "a", "extconf.rb"
write_file ext_path do |io|
io.write <<-'RUBY'
File.open "Makefile", "w" do |f|
@@ -631,8 +632,8 @@ class TestGemCommandsPristineCommand < Gem::TestCase
out = @ui.output.split "\n"
- assert_equal 'Restoring gems to pristine condition...', out.shift
- assert_equal 'Building native extensions. This could take a while...',
+ assert_equal "Restoring gems to pristine condition...", out.shift
+ assert_equal "Building native extensions. This could take a while...",
out.shift
assert_equal "Restored #{a.full_name}", out.shift
assert_empty out, out.inspect
diff --git a/test/rubygems/test_gem_commands_push_command.rb b/test/rubygems/test_gem_commands_push_command.rb
index 1bbd341eca..f38a2ae7a1 100644
--- a/test/rubygems/test_gem_commands_push_command.rb
+++ b/test/rubygems/test_gem_commands_push_command.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/commands/push_command'
+require_relative "helper"
+require "rubygems/commands/push_command"
class TestGemCommandsPushCommand < Gem::TestCase
def setup
@@ -12,7 +12,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
Gem.host = Gem::DEFAULT_HOST
Gem.configuration.disable_default_gem_server = false
- @gems_dir = File.join @tempdir, 'gems'
+ @gems_dir = File.join @tempdir, "gems"
@cache_dir = File.join @gemhome, "cache"
FileUtils.mkdir @gems_dir
@@ -21,7 +21,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
"ed244fbf2b1a52e012da8616c512fa47f9aa5250"
@spec, @path = util_gem "freewill", "1.0.0"
- @host = 'https://rubygems.example'
+ @host = "https://rubygems.example"
@api_key = Gem.configuration.rubygems_api_key
@fetcher = Gem::FakeFetcher.new
@@ -68,7 +68,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
def test_execute
@response = "Successfully registered gem: freewill (1.0.0)"
- @fetcher.data["#{Gem.host}/api/v1/gems"] = [@response, 200, 'OK']
+ @fetcher.data["#{Gem.host}/api/v1/gems"] = [@response, 200, "OK"]
@cmd.options[:args] = [@path]
@@ -81,12 +81,12 @@ class TestGemCommandsPushCommand < Gem::TestCase
end
def test_execute_host
- host = 'https://other.example'
+ host = "https://other.example"
@response = "Successfully registered gem: freewill (1.0.0)"
- @fetcher.data["#{host}/api/v1/gems"] = [@response, 200, 'OK']
+ @fetcher.data["#{host}/api/v1/gems"] = [@response, 200, "OK"]
@fetcher.data["#{Gem.host}/api/v1/gems"] =
- ['fail', 500, 'Internal Server Error']
+ ["fail", 500, "Internal Server Error"]
@cmd.options[:host] = host
@cmd.options[:args] = [@path]
@@ -101,13 +101,13 @@ class TestGemCommandsPushCommand < Gem::TestCase
def test_execute_allowed_push_host
@spec, @path = util_gem "freebird", "1.0.1" do |spec|
- spec.metadata['allowed_push_host'] = "https://privategemserver.example"
+ spec.metadata["allowed_push_host"] = "https://privategemserver.example"
end
@response = "Successfully registered gem: freewill (1.0.0)"
- @fetcher.data["#{@spec.metadata['allowed_push_host']}/api/v1/gems"] = [@response, 200, 'OK']
+ @fetcher.data["#{@spec.metadata['allowed_push_host']}/api/v1/gems"] = [@response, 200, "OK"]
@fetcher.data["#{Gem.host}/api/v1/gems"] =
- ['fail', 500, 'Internal Server Error']
+ ["fail", 500, "Internal Server Error"]
@cmd.options[:args] = [@path]
@@ -136,7 +136,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
ENV["RUBYGEMS_HOST"] = @host
Gem.configuration.disable_default_gem_server = true
@response = "Successfully registered gem: freewill (1.0.0)"
- @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, 'OK']
+ @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, "OK"]
send_battery
end
@@ -145,17 +145,17 @@ class TestGemCommandsPushCommand < Gem::TestCase
@host = "http://privategemserver.example"
@spec, @path = util_gem "freebird", "1.0.1" do |spec|
- spec.metadata['default_gem_server'] = @host
+ spec.metadata["default_gem_server"] = @host
end
@api_key = "EYKEY"
keys = {
- :rubygems_api_key => 'KEY',
+ :rubygems_api_key => "KEY",
@host => @api_key,
}
- File.open Gem.configuration.credentials_path, 'w' do |f|
+ File.open Gem.configuration.credentials_path, "w" do |f|
f.write keys.to_yaml
end
Gem.configuration.load_api_keys
@@ -163,14 +163,14 @@ class TestGemCommandsPushCommand < Gem::TestCase
FileUtils.rm Gem.configuration.credentials_path
@response = "Successfully registered gem: freebird (1.0.1)"
- @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, 'OK']
+ @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, "OK"]
send_battery
end
def test_sending_gem
@response = "Successfully registered gem: freewill (1.0.0)"
- @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, 'OK']
+ @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, "OK"]
send_battery
end
@@ -179,17 +179,17 @@ class TestGemCommandsPushCommand < Gem::TestCase
@host = "http://privategemserver.example"
@spec, @path = util_gem "freebird", "1.0.1" do |spec|
- spec.metadata['allowed_push_host'] = @host
+ spec.metadata["allowed_push_host"] = @host
end
@api_key = "PRIVKEY"
keys = {
- :rubygems_api_key => 'KEY',
+ :rubygems_api_key => "KEY",
@host => @api_key,
}
- File.open Gem.configuration.credentials_path, 'w' do |f|
+ File.open Gem.configuration.credentials_path, "w" do |f|
f.write keys.to_yaml
end
Gem.configuration.load_api_keys
@@ -197,7 +197,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
FileUtils.rm Gem.configuration.credentials_path
@response = "Successfully registered gem: freebird (1.0.1)"
- @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, 'OK']
+ @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, "OK"]
send_battery
end
@@ -205,14 +205,14 @@ class TestGemCommandsPushCommand < Gem::TestCase
@host = "http://privategemserver.example"
@spec, @path = util_gem "freebird", "1.0.1" do |spec|
- spec.metadata['allowed_push_host'] = @host
+ spec.metadata["allowed_push_host"] = @host
end
@api_key = "PRIVKEY"
ENV["GEM_HOST_API_KEY"] = "PRIVKEY"
@response = "Successfully registered gem: freebird (1.0.1)"
- @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, 'OK']
+ @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, "OK"]
send_battery
end
@@ -221,7 +221,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
@host = "http://user:password@privategemserver.example"
@spec, @path = util_gem "freebird", "1.0.1" do |spec|
- spec.metadata['allowed_push_host'] = @sanitized_host
+ spec.metadata["allowed_push_host"] = @sanitized_host
end
@api_key = "DOESNTMATTER"
@@ -230,7 +230,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
:rubygems_api_key => @api_key,
}
- File.open Gem.configuration.credentials_path, 'w' do |f|
+ File.open Gem.configuration.credentials_path, "w" do |f|
f.write keys.to_yaml
end
Gem.configuration.load_api_keys
@@ -238,13 +238,13 @@ class TestGemCommandsPushCommand < Gem::TestCase
FileUtils.rm Gem.configuration.credentials_path
@response = "Successfully registered gem: freebird (1.0.1)"
- @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, 'OK']
+ @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, "OK"]
send_battery
end
def test_sending_gem_to_disallowed_default_host
@spec, @path = util_gem "freebird", "1.0.1" do |spec|
- spec.metadata['allowed_push_host'] = "https://privategemserver.example"
+ spec.metadata["allowed_push_host"] = "https://privategemserver.example"
end
response = %(ERROR: "#{@host}" is not allowed by the gemspec, which only allows "https://privategemserver.example")
@@ -261,17 +261,17 @@ class TestGemCommandsPushCommand < Gem::TestCase
push_host = "https://privategemserver.example"
@spec, @path = util_gem "freebird", "1.0.1" do |spec|
- spec.metadata['allowed_push_host'] = push_host
+ spec.metadata["allowed_push_host"] = push_host
end
@api_key = "PRIVKEY"
keys = {
- :rubygems_api_key => 'KEY',
+ :rubygems_api_key => "KEY",
@host => @api_key,
}
- File.open Gem.configuration.credentials_path, 'w' do |f|
+ File.open Gem.configuration.credentials_path, "w" do |f|
f.write keys.to_yaml
end
Gem.configuration.load_api_keys
@@ -291,8 +291,8 @@ class TestGemCommandsPushCommand < Gem::TestCase
host = "http://privategemserver.example"
@spec, @path = util_gem "freebird", "1.0.1" do |spec|
- spec.metadata.delete('default_gem_server')
- spec.metadata['allowed_push_host'] = host
+ spec.metadata.delete("default_gem_server")
+ spec.metadata["allowed_push_host"] = host
end
api_key = "PRIVKEY"
@@ -301,7 +301,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
host => api_key,
}
- File.open Gem.configuration.credentials_path, 'w' do |f|
+ File.open Gem.configuration.credentials_path, "w" do |f|
f.write keys.to_yaml
end
Gem.configuration.load_api_keys
@@ -309,7 +309,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
FileUtils.rm Gem.configuration.credentials_path
@response = "Successfully registered gem: freebird (1.0.1)"
- @fetcher.data["#{host}/api/v1/gems"] = [@response, 200, 'OK']
+ @fetcher.data["#{host}/api/v1/gems"] = [@response, 200, "OK"]
# do not set @host
use_ui(@ui) { @cmd.send_gem(@path) }
@@ -334,7 +334,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
def test_sending_gem_denied
response = "You don't have permission to push to this gem"
- @fetcher.data["#{@host}/api/v1/gems"] = [response, 403, 'Forbidden']
+ @fetcher.data["#{@host}/api/v1/gems"] = [response, 403, "Forbidden"]
@cmd.instance_variable_set :@host, @host
assert_raise Gem::MockGemUi::TermError do
@@ -349,8 +349,8 @@ class TestGemCommandsPushCommand < Gem::TestCase
def test_sending_gem_key
@response = "Successfully registered gem: freewill (1.0.0)"
@fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, "OK"]
- File.open Gem.configuration.credentials_path, 'a' do |f|
- f.write ':other: 701229f217cdf23b1344c7b4b54ca97'
+ File.open Gem.configuration.credentials_path, "a" do |f|
+ f.write ":other: 701229f217cdf23b1344c7b4b54ca97"
end
Gem.configuration.load_api_keys
@@ -364,11 +364,11 @@ class TestGemCommandsPushCommand < Gem::TestCase
def test_otp_verified_success
response_fail = "You have enabled multifactor authentication but your request doesn't have the correct OTP code. Please check it and retry."
- response_success = 'Successfully registered gem: freewill (1.0.0)'
+ response_success = "Successfully registered gem: freewill (1.0.0)"
@fetcher.data["#{Gem.host}/api/v1/gems"] = [
- [response_fail, 401, 'Unauthorized'],
- [response_success, 200, 'OK'],
+ [response_fail, 401, "Unauthorized"],
+ [response_success, 200, "OK"],
]
@otp_ui = Gem::MockGemUi.new "111111\n"
@@ -376,15 +376,15 @@ class TestGemCommandsPushCommand < Gem::TestCase
@cmd.send_gem(@path)
end
- assert_match 'You have enabled multi-factor authentication. Please enter OTP code.', @otp_ui.output
- assert_match 'Code: ', @otp_ui.output
+ assert_match "You have enabled multi-factor authentication. Please enter OTP code.", @otp_ui.output
+ assert_match "Code: ", @otp_ui.output
assert_match response_success, @otp_ui.output
- assert_equal '111111', @fetcher.last_request['OTP']
+ assert_equal "111111", @fetcher.last_request["OTP"]
end
def test_otp_verified_failure
response = "You have enabled multifactor authentication but your request doesn't have the correct OTP code. Please check it and retry."
- @fetcher.data["#{Gem.host}/api/v1/gems"] = [response, 401, 'Unauthorized']
+ @fetcher.data["#{Gem.host}/api/v1/gems"] = [response, 401, "Unauthorized"]
@otp_ui = Gem::MockGemUi.new "111111\n"
assert_raise Gem::MockGemUi::TermError do
@@ -394,19 +394,19 @@ class TestGemCommandsPushCommand < Gem::TestCase
end
assert_match response, @otp_ui.output
- assert_match 'You have enabled multi-factor authentication. Please enter OTP code.', @otp_ui.output
- assert_match 'Code: ', @otp_ui.output
- assert_equal '111111', @fetcher.last_request['OTP']
+ assert_match "You have enabled multi-factor authentication. Please enter OTP code.", @otp_ui.output
+ assert_match "Code: ", @otp_ui.output
+ assert_equal "111111", @fetcher.last_request["OTP"]
end
def test_sending_gem_unathorized_api_key_with_mfa_enabled
response_mfa_enabled = "You have enabled multifactor authentication but your request doesn't have the correct OTP code. Please check it and retry."
response_forbidden = "The API key doesn't have access"
- response_success = 'Successfully registered gem: freewill (1.0.0)'
+ response_success = "Successfully registered gem: freewill (1.0.0)"
@fetcher.data["#{@host}/api/v1/gems"] = [
- [response_mfa_enabled, 401, 'Unauthorized'],
- [response_forbidden, 403, 'Forbidden'],
+ [response_mfa_enabled, 401, "Unauthorized"],
+ [response_forbidden, 403, "Forbidden"],
[response_success, 200, "OK"],
]
@@ -427,14 +427,14 @@ class TestGemCommandsPushCommand < Gem::TestCase
assert_match "Password:", @ui.output
assert_match "Added push_rubygem scope to the existing API key", @ui.output
assert_match response_success, @ui.output
- assert_equal '11111', @fetcher.last_request['OTP']
+ assert_equal "11111", @fetcher.last_request["OTP"]
end
def test_sending_gem_with_no_local_creds
Gem.configuration.rubygems_api_key = nil
response_mfa_enabled = "You have enabled multifactor authentication but your request doesn't have the correct OTP code. Please check it and retry."
- response_success = 'Successfully registered gem: freewill (1.0.0)'
+ response_success = "Successfully registered gem: freewill (1.0.0)"
response_profile = "mfa: disabled\n"
@fetcher.data["#{@host}/api/v1/gems"] = [
@@ -442,7 +442,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
]
@fetcher.data["#{@host}/api/v1/api_key"] = [
- [response_mfa_enabled, 401, 'Unauthorized'],
+ [response_mfa_enabled, 401, "Unauthorized"],
["", 200, "OK"],
]
@@ -466,7 +466,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
assert_match "Password:", @ui.output
assert_match "Signed in with API key:", @ui.output
assert_match response_success, @ui.output
- assert_equal '11111', @fetcher.last_request['OTP']
+ assert_equal "11111", @fetcher.last_request["OTP"]
end
private
diff --git a/test/rubygems/test_gem_commands_query_command.rb b/test/rubygems/test_gem_commands_query_command.rb
index 0cc88b1685..6882098c53 100644
--- a/test/rubygems/test_gem_commands_query_command.rb
+++ b/test/rubygems/test_gem_commands_query_command.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/commands/query_command'
+require_relative "helper"
+require "rubygems/commands/query_command"
module TestGemCommandsQueryCommandSetup
def setup
@@ -41,7 +41,7 @@ pl (1 i386-linux)
EOF
assert_equal expected, @stub_ui.output
- assert_equal '', @stub_ui.error
+ assert_equal "", @stub_ui.error
end
def test_execute_all
@@ -64,7 +64,7 @@ pl (1 i386-linux)
EOF
assert_equal expected, @stub_ui.output
- assert_equal '', @stub_ui.error
+ assert_equal "", @stub_ui.error
end
def test_execute_all_prerelease
@@ -87,15 +87,15 @@ pl (1 i386-linux)
EOF
assert_equal expected, @stub_ui.output
- assert_equal '', @stub_ui.error
+ assert_equal "", @stub_ui.error
end
def test_execute_details
spec_fetcher do |fetcher|
- fetcher.spec 'a', 2 do |s|
- s.summary = 'This is a lot of text. ' * 4
- s.authors = ['Abraham Lincoln', 'Hirohito']
- s.homepage = 'http://a.example.com/'
+ fetcher.spec "a", 2 do |s|
+ s.summary = "This is a lot of text. " * 4
+ s.authors = ["Abraham Lincoln", "Hirohito"]
+ s.homepage = "http://a.example.com/"
end
fetcher.legacy_platform
@@ -127,13 +127,13 @@ pl (1)
EOF
assert_equal expected, @stub_ui.output
- assert_equal '', @stub_ui.error
+ assert_equal "", @stub_ui.error
end
def test_execute_details_cleans_text
spec_fetcher do |fetcher|
- fetcher.spec 'a', 2 do |s|
- s.summary = 'This is a lot of text. ' * 4
+ fetcher.spec "a", 2 do |s|
+ s.summary = "This is a lot of text. " * 4
s.authors = ["Abraham Lincoln \x01", "\x02 Hirohito"]
s.homepage = "http://a.example.com/\x03"
end
@@ -167,13 +167,13 @@ pl (1)
EOF
assert_equal expected, @stub_ui.output
- assert_equal '', @stub_ui.error
+ assert_equal "", @stub_ui.error
end
def test_execute_details_truncates_summary
spec_fetcher do |fetcher|
- fetcher.spec 'a', 2 do |s|
- s.summary = 'This is a lot of text. ' * 10_000
+ fetcher.spec "a", 2 do |s|
+ s.summary = "This is a lot of text. " * 10_000
s.authors = ["Abraham Lincoln \x01", "\x02 Hirohito"]
s.homepage = "http://a.example.com/\x03"
end
@@ -207,7 +207,7 @@ pl (1)
EOF
assert_equal expected, @stub_ui.output
- assert_equal '', @stub_ui.error
+ assert_equal "", @stub_ui.error
end
def test_execute_installed
@@ -220,7 +220,7 @@ pl (1)
end
assert_equal "true\n", @stub_ui.output
- assert_equal '', @stub_ui.error
+ assert_equal "", @stub_ui.error
end
def test_execute_installed_inverse
@@ -233,7 +233,7 @@ pl (1)
end
assert_equal "false\n", @stub_ui.output
- assert_equal '', @stub_ui.error
+ assert_equal "", @stub_ui.error
assert_equal 1, e.exit_code
end
@@ -248,7 +248,7 @@ pl (1)
end
assert_equal "true\n", @stub_ui.output
- assert_equal '', @stub_ui.error
+ assert_equal "", @stub_ui.error
end
def test_execute_installed_no_name
@@ -260,7 +260,7 @@ pl (1)
end
end
- assert_equal '', @stub_ui.output
+ assert_equal "", @stub_ui.output
assert_equal "ERROR: You must specify a gem name\n", @stub_ui.error
assert_equal 4, e.exit_code
@@ -276,7 +276,7 @@ pl (1)
end
assert_equal "false\n", @stub_ui.output
- assert_equal '', @stub_ui.error
+ assert_equal "", @stub_ui.error
assert_equal 1, e.exit_code
end
@@ -291,7 +291,7 @@ pl (1)
end
assert_equal "true\n", @stub_ui.output
- assert_equal '', @stub_ui.error
+ assert_equal "", @stub_ui.error
end
def test_execute_installed_version_not_installed
@@ -304,7 +304,7 @@ pl (1)
end
assert_equal "false\n", @stub_ui.output
- assert_equal '', @stub_ui.error
+ assert_equal "", @stub_ui.error
assert_equal 1, e.exit_code
end
@@ -329,7 +329,7 @@ pl (1 i386-linux)
EOF
assert_equal expected, @stub_ui.output
- assert_equal '', @stub_ui.error
+ assert_equal "", @stub_ui.error
end
def test_execute_local_notty
@@ -351,7 +351,7 @@ pl (1 i386-linux)
EOF
assert_equal expected, @stub_ui.output
- assert_equal '', @stub_ui.error
+ assert_equal "", @stub_ui.error
end
def test_execute_local_quiet
@@ -372,7 +372,7 @@ pl (1 i386-linux)
EOF
assert_equal expected, @stub_ui.output
- assert_equal '', @stub_ui.error
+ assert_equal "", @stub_ui.error
end
def test_execute_no_versions
@@ -395,7 +395,7 @@ pl
EOF
assert_equal expected, @stub_ui.output
- assert_equal '', @stub_ui.error
+ assert_equal "", @stub_ui.error
end
def test_execute_notty
@@ -417,7 +417,7 @@ pl (1 i386-linux)
EOF
assert_equal expected, @stub_ui.output
- assert_equal '', @stub_ui.error
+ assert_equal "", @stub_ui.error
end
def test_execute_prerelease
@@ -435,7 +435,7 @@ a (3.a)
EOF
assert_equal expected, @stub_ui.output
- assert_equal '', @stub_ui.error
+ assert_equal "", @stub_ui.error
end
def test_execute_prerelease_local
@@ -502,7 +502,7 @@ pl (1 i386-linux)
EOF
assert_equal expected, @stub_ui.output
- assert_equal '', @stub_ui.error
+ assert_equal "", @stub_ui.error
end
def test_execute_remote_notty
@@ -524,7 +524,7 @@ pl (1 i386-linux)
EOF
assert_equal expected, @stub_ui.output
- assert_equal '', @stub_ui.error
+ assert_equal "", @stub_ui.error
end
def test_execute_remote_quiet
@@ -545,16 +545,16 @@ pl (1 i386-linux)
EOF
assert_equal expected, @stub_ui.output
- assert_equal '', @stub_ui.error
+ assert_equal "", @stub_ui.error
end
def test_make_entry
- a_2_name = @specs['a-2'].original_name
+ a_2_name = @specs["a-2"].original_name
@stub_fetcher.data.delete \
"#{@gem_repo}quick/Marshal.#{Gem.marshal_version}/#{a_2_name}.gemspec.rz"
- a2 = @specs['a-2']
+ a2 = @specs["a-2"]
entry_tuples = [
[Gem::NameTuple.new(a2.name, a2.version, a2.platform),
Gem.sources.first],
@@ -564,7 +564,7 @@ pl (1 i386-linux)
entry = @cmd.send :make_entry, entry_tuples, platforms
- assert_equal 'a (2)', entry
+ assert_equal "a (2)", entry
end
# Test for multiple args handling!
@@ -581,7 +581,7 @@ pl (1 i386-linux)
assert_match %r{^a }, @stub_ui.output
assert_match %r{^pl }, @stub_ui.output
- assert_equal '', @stub_ui.error
+ assert_equal "", @stub_ui.error
end
def test_show_gems
@@ -601,9 +601,9 @@ pl (1 i386-linux)
def add_gems_to_fetcher
spec_fetcher do |fetcher|
- fetcher.spec 'a', 1
- fetcher.spec 'a', 2
- fetcher.spec 'a', '3.a'
+ fetcher.spec "a", 1
+ fetcher.spec "a", 2
+ fetcher.spec "a", "3.a"
end
end
end
@@ -613,13 +613,13 @@ class TestGemCommandsQueryCommandWithoutInstalledGems < Gem::TestCase
def test_execute_platform
spec_fetcher do |fetcher|
- fetcher.spec 'a', 1
- fetcher.spec 'a', 1 do |s|
- s.platform = 'x86-linux'
+ fetcher.spec "a", 1
+ fetcher.spec "a", 1 do |s|
+ s.platform = "x86-linux"
end
- fetcher.spec 'a', 2 do |s|
- s.platform = 'universal-darwin'
+ fetcher.spec "a", 2 do |s|
+ s.platform = "universal-darwin"
end
end
@@ -637,13 +637,13 @@ a (2 universal-darwin, 1 ruby x86-linux)
EOF
assert_equal expected, @stub_ui.output
- assert_equal '', @stub_ui.error
+ assert_equal "", @stub_ui.error
end
def test_execute_show_default_gems
- spec_fetcher {|fetcher| fetcher.spec 'a', 2 }
+ spec_fetcher {|fetcher| fetcher.spec "a", 2 }
- a1 = new_default_spec 'a', 1
+ a1 = new_default_spec "a", 1
install_default_gems a1
use_ui @stub_ui do
@@ -661,8 +661,8 @@ EOF
end
def test_execute_show_default_gems_with_platform
- a1 = new_default_spec 'a', 1
- a1.platform = 'java'
+ a1 = new_default_spec "a", 1
+ a1.platform = "java"
install_default_gems a1
use_ui @stub_ui do
@@ -681,10 +681,10 @@ EOF
def test_execute_default_details
spec_fetcher do |fetcher|
- fetcher.spec 'a', 2
+ fetcher.spec "a", 2
end
- a1 = new_default_spec 'a', 1
+ a1 = new_default_spec "a", 1
install_default_gems a1
@cmd.handle_options %w[-l -d]
@@ -711,15 +711,15 @@ a (2, 1)
def test_execute_local_details
spec_fetcher do |fetcher|
- fetcher.spec 'a', 1 do |s|
- s.platform = 'x86-linux'
+ fetcher.spec "a", 1 do |s|
+ s.platform = "x86-linux"
end
- fetcher.spec 'a', 2 do |s|
- s.summary = 'This is a lot of text. ' * 4
- s.authors = ['Abraham Lincoln', 'Hirohito']
- s.homepage = 'http://a.example.com/'
- s.platform = 'universal-darwin'
+ fetcher.spec "a", 2 do |s|
+ s.summary = "This is a lot of text. " * 4
+ s.authors = ["Abraham Lincoln", "Hirohito"]
+ s.homepage = "http://a.example.com/"
+ s.platform = "universal-darwin"
end
fetcher.legacy_platform
@@ -766,9 +766,9 @@ pl (1)
def test_execute_exact_remote
spec_fetcher do |fetcher|
- fetcher.spec 'coolgem-omg', 3
- fetcher.spec 'coolgem', '4.2.1'
- fetcher.spec 'wow_coolgem', 1
+ fetcher.spec "coolgem-omg", 3
+ fetcher.spec "coolgem", "4.2.1"
+ fetcher.spec "wow_coolgem", 1
end
@cmd.handle_options %w[--remote --exact coolgem]
@@ -789,9 +789,9 @@ coolgem (4.2.1)
def test_execute_exact_local
spec_fetcher do |fetcher|
- fetcher.spec 'coolgem-omg', 3
- fetcher.spec 'coolgem', '4.2.1'
- fetcher.spec 'wow_coolgem', 1
+ fetcher.spec "coolgem-omg", 3
+ fetcher.spec "coolgem", "4.2.1"
+ fetcher.spec "wow_coolgem", 1
end
@cmd.handle_options %w[--exact coolgem]
@@ -812,13 +812,13 @@ coolgem (4.2.1)
def test_execute_exact_multiple
spec_fetcher do |fetcher|
- fetcher.spec 'coolgem-omg', 3
- fetcher.spec 'coolgem', '4.2.1'
- fetcher.spec 'wow_coolgem', 1
+ fetcher.spec "coolgem-omg", 3
+ fetcher.spec "coolgem", "4.2.1"
+ fetcher.spec "wow_coolgem", 1
- fetcher.spec 'othergem-omg', 3
- fetcher.spec 'othergem', '1.2.3'
- fetcher.spec 'wow_othergem', 1
+ fetcher.spec "othergem-omg", 3
+ fetcher.spec "othergem", "1.2.3"
+ fetcher.spec "wow_othergem", 1
end
@cmd.handle_options %w[--exact coolgem othergem]
@@ -849,9 +849,9 @@ othergem (1.2.3)
def add_gems_to_fetcher
spec_fetcher do |fetcher|
- fetcher.download 'a', 1
- fetcher.download 'a', 2
- fetcher.download 'a', '3.a'
+ fetcher.download "a", 1
+ fetcher.download "a", 2
+ fetcher.download "a", "3.a"
end
end
end
diff --git a/test/rubygems/test_gem_commands_search_command.rb b/test/rubygems/test_gem_commands_search_command.rb
index 6397dbd4d4..afa6ff8d13 100644
--- a/test/rubygems/test_gem_commands_search_command.rb
+++ b/test/rubygems/test_gem_commands_search_command.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/commands/search_command'
+require_relative "helper"
+require "rubygems/commands/search_command"
class TestGemCommandsSearchCommand < Gem::TestCase
def setup
diff --git a/test/rubygems/test_gem_commands_server_command.rb b/test/rubygems/test_gem_commands_server_command.rb
index 96c328f93f..1becde3ae2 100644
--- a/test/rubygems/test_gem_commands_server_command.rb
+++ b/test/rubygems/test_gem_commands_server_command.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/commands/server_command'
+require_relative "helper"
+require "rubygems/commands/server_command"
class TestGemCommandsServerCommand < Gem::TestCase
def setup
diff --git a/test/rubygems/test_gem_commands_setup_command.rb b/test/rubygems/test_gem_commands_setup_command.rb
index ab563b28ee..1c0963ee96 100644
--- a/test/rubygems/test_gem_commands_setup_command.rb
+++ b/test/rubygems/test_gem_commands_setup_command.rb
@@ -1,10 +1,10 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/commands/setup_command'
+require_relative "helper"
+require "rubygems/commands/setup_command"
class TestGemCommandsSetupCommand < Gem::TestCase
- bundler_gemspec = File.expand_path('../../bundler/lib/bundler/version.rb', __dir__)
+ bundler_gemspec = File.expand_path("../../bundler/lib/bundler/version.rb", __dir__)
if File.exist?(bundler_gemspec)
BUNDLER_VERS = File.read(bundler_gemspec).match(/VERSION = "(#{Gem::Version::VERSION_PATTERN})"/)[1]
else
@@ -42,11 +42,11 @@ class TestGemCommandsSetupCommand < Gem::TestCase
gemspec.bindir = "exe"
gemspec.executables = ["bundle", "bundler"]
- File.open 'bundler/bundler.gemspec', 'w' do |io|
+ File.open "bundler/bundler.gemspec", "w" do |io|
io.puts gemspec.to_ruby
end
- File.open(File.join(Gem.default_specifications_dir, "bundler-1.15.4.gemspec"), 'w') do |io|
+ File.open(File.join(Gem.default_specifications_dir, "bundler-1.15.4.gemspec"), "w") do |io|
gemspec.version = "1.15.4"
io.puts gemspec.to_ruby
end
@@ -54,16 +54,16 @@ class TestGemCommandsSetupCommand < Gem::TestCase
spec_fetcher do |fetcher|
fetcher.download "bundler", "1.15.4"
- fetcher.gem "bundler", BUNDLER_VERS
+ fetcher.gem "bundler", bundler_version
fetcher.gem "bundler-audit", "1.0.0"
end
end
def test_execute_regenerate_binstubs
- gem_bin_path = gem_install 'a'
+ gem_bin_path = gem_install "a"
write_file gem_bin_path do |io|
- io.puts 'I changed it!'
+ io.puts "I changed it!"
end
@cmd.options[:document] = []
@@ -73,9 +73,9 @@ class TestGemCommandsSetupCommand < Gem::TestCase
end
def test_execute_no_regenerate_binstubs
- gem_bin_path = gem_install 'a'
+ gem_bin_path = gem_install "a"
write_file gem_bin_path do |io|
- io.puts 'I changed it!'
+ io.puts "I changed it!"
end
@cmd.options[:document] = []
@@ -86,9 +86,9 @@ class TestGemCommandsSetupCommand < Gem::TestCase
end
def test_execute_regenerate_plugins
- gem_plugin_path = gem_install_with_plugin 'a'
+ gem_plugin_path = gem_install_with_plugin "a"
write_file gem_plugin_path do |io|
- io.puts 'I changed it!'
+ io.puts "I changed it!"
end
@cmd.options[:document] = []
@@ -98,9 +98,9 @@ class TestGemCommandsSetupCommand < Gem::TestCase
end
def test_execute_no_regenerate_plugins
- gem_plugin_path = gem_install_with_plugin 'a'
+ gem_plugin_path = gem_install_with_plugin "a"
write_file gem_plugin_path do |io|
- io.puts 'I changed it!'
+ io.puts "I changed it!"
end
@cmd.options[:document] = []
@@ -111,7 +111,7 @@ class TestGemCommandsSetupCommand < Gem::TestCase
end
def test_execute_regenerate_plugins_creates_plugins_dir_if_not_there
- gem_plugin_path = gem_install_with_plugin 'a'
+ gem_plugin_path = gem_install_with_plugin "a"
# Simulate gem installed with an older rubygems without a plugins layout
FileUtils.rm_rf Gem.plugindir
@@ -138,16 +138,16 @@ class TestGemCommandsSetupCommand < Gem::TestCase
end
def test_env_shebang_flag
- gem_bin_path = gem_install 'a'
+ gem_bin_path = gem_install "a"
write_file gem_bin_path do |io|
- io.puts 'I changed it!'
+ io.puts "I changed it!"
end
@cmd.options[:document] = []
@cmd.options[:env_shebang] = true
@cmd.execute
- ruby_exec = sprintf Gem.default_exec_format, 'ruby'
+ ruby_exec = sprintf Gem.default_exec_format, "ruby"
bin_env = win_platform? ? "" : %w[/usr/bin/env /bin/env].find {|f| File.executable?(f) } + " "
assert_match %r{\A#!\s*#{bin_env}#{ruby_exec}}, File.read(default_gem_bin_path)
@@ -159,47 +159,44 @@ class TestGemCommandsSetupCommand < Gem::TestCase
def test_destdir_flag_does_not_try_to_write_to_the_default_gem_home
FileUtils.chmod "-w", File.join(@gemhome, "plugins")
- destdir = File.join(@tempdir, 'foo')
+ destdir = File.join(@tempdir, "foo")
@cmd.options[:destdir] = destdir
@cmd.execute
- spec = Gem::Specification.load("bundler/bundler.gemspec")
-
- spec.executables.each do |e|
- assert_path_exist File.join destdir, @gemhome.gsub(/^[a-zA-Z]:/, ''), 'gems', spec.full_name, spec.bindir, e
+ bundler_spec.executables.each do |e|
+ assert_path_exist prepend_destdir(destdir, File.join(@gemhome, "gems", bundler_spec.full_name, bundler_spec.bindir, e))
end
end
def test_files_in
assert_equal %w[rubygems.rb rubygems/requirement.rb rubygems/ssl_certs/rubygems.org/foo.pem],
- @cmd.files_in('lib').sort
+ @cmd.files_in("lib").sort
end
def test_install_lib
@cmd.extend FileUtils
- Dir.mktmpdir 'lib' do |dir|
+ Dir.mktmpdir "lib" do |dir|
@cmd.install_lib dir
- assert_path_exist File.join(dir, 'rubygems.rb')
- assert_path_exist File.join(dir, 'rubygems/ssl_certs/rubygems.org/foo.pem')
+ assert_path_exist File.join(dir, "rubygems.rb")
+ assert_path_exist File.join(dir, "rubygems/ssl_certs/rubygems.org/foo.pem")
- assert_path_exist File.join(dir, 'bundler.rb')
- assert_path_exist File.join(dir, 'bundler/b.rb')
+ assert_path_exist File.join(dir, "bundler.rb")
+ assert_path_exist File.join(dir, "bundler/b.rb")
- assert_path_exist File.join(dir, 'bundler/templates/.circleci/config.yml')
- assert_path_exist File.join(dir, 'bundler/templates/.travis.yml')
+ assert_path_exist File.join(dir, "bundler/templates/.circleci/config.yml")
+ assert_path_exist File.join(dir, "bundler/templates/.travis.yml")
end
end
def test_install_default_bundler_gem
@cmd.extend FileUtils
- bin_dir = File.join(@gemhome, 'bin')
+ bin_dir = File.join(@gemhome, "bin")
@cmd.install_default_bundler_gem bin_dir
- bundler_spec = Gem::Specification.load("bundler/bundler.gemspec")
default_spec_path = File.join(Gem.default_specifications_dir, "#{bundler_spec.full_name}.gemspec")
spec = Gem::Specification.load(default_spec_path)
@@ -211,32 +208,46 @@ class TestGemCommandsSetupCommand < Gem::TestCase
assert_path_exist File.join bin_dir, e
end
- default_dir = Gem.default_specifications_dir
-
# expect to remove other versions of bundler gemspecs on default specification directory.
- assert_path_not_exist File.join(default_dir, "bundler-1.15.4.gemspec")
- assert_path_exist File.join(default_dir, "bundler-#{BUNDLER_VERS}.gemspec")
+ assert_path_not_exist previous_bundler_specification_path
+ assert_path_exist new_bundler_specification_path
# expect to not remove bundler-* gemspecs.
assert_path_exist File.join(Gem.dir, "specifications", "bundler-audit-1.0.0.gemspec")
# expect to remove normal gem that was same version. because it's promoted default gems.
- assert_path_not_exist File.join(Gem.dir, "specifications", "bundler-#{BUNDLER_VERS}.gemspec")
+ assert_path_not_exist File.join(Gem.dir, "specifications", "bundler-#{bundler_version}.gemspec")
- assert_path_exist "#{Gem.dir}/gems/bundler-#{BUNDLER_VERS}"
+ assert_path_exist "#{Gem.dir}/gems/bundler-#{bundler_version}"
assert_path_exist "#{Gem.dir}/gems/bundler-1.15.4"
assert_path_exist "#{Gem.dir}/gems/bundler-audit-1.0.0"
end
+ def test_install_default_bundler_gem_with_default_gems_not_installed_at_default_dir
+ @cmd.extend FileUtils
+
+ gemhome2 = File.join(@tempdir, "gemhome2")
+ Gem.instance_variable_set(:@default_dir, gemhome2)
+
+ FileUtils.mkdir_p gemhome2
+ bin_dir = File.join(gemhome2, "bin")
+
+ @cmd.install_default_bundler_gem bin_dir
+
+ # expect to remove other versions of bundler gemspecs on default specification directory.
+ assert_path_not_exist previous_bundler_specification_path
+ assert_path_exist new_bundler_specification_path
+ end
+
def test_install_default_bundler_gem_with_force_flag
@cmd.extend FileUtils
- bin_dir = File.join(@gemhome, 'bin')
- bundle_bin = File.join(bin_dir, 'bundle')
+ bin_dir = File.join(@gemhome, "bin")
+ bundle_bin = File.join(bin_dir, "bundle")
write_file bundle_bin do |f|
- f.puts '#!/usr/bin/ruby'
- f.puts ''
+ f.puts "#!/usr/bin/ruby"
+ f.puts ""
f.puts 'echo "hello"'
end
@@ -244,7 +255,6 @@ class TestGemCommandsSetupCommand < Gem::TestCase
@cmd.install_default_bundler_gem bin_dir
- bundler_spec = Gem::Specification.load("bundler/bundler.gemspec")
default_spec_path = File.join(Gem.default_specifications_dir, "#{bundler_spec.full_name}.gemspec")
spec = Gem::Specification.load(default_spec_path)
@@ -262,17 +272,23 @@ class TestGemCommandsSetupCommand < Gem::TestCase
FileUtils.chmod "-w", @gemhome
- destdir = File.join(@tempdir, 'foo')
- bin_dir = File.join(destdir, 'bin')
+ destdir = File.join(@tempdir, "foo")
+ bin_dir = File.join(destdir, "bin")
@cmd.options[:destdir] = destdir
@cmd.install_default_bundler_gem bin_dir
- spec = Gem::Specification.load("bundler/bundler.gemspec")
+ # leaves other versions of bundler gemspecs on default specification directory.
+ assert_path_exist previous_bundler_specification_path
+ assert_path_not_exist new_bundler_specification_path
- spec.executables.each do |e|
- assert_path_exist File.join destdir, @gemhome.gsub(/^[a-zA-Z]:/, ''), 'gems', spec.full_name, spec.bindir, e
+ # installs the updated bundler gemspec to destdir
+ assert_path_not_exist prepend_destdir(destdir, previous_bundler_specification_path)
+ assert_path_exist prepend_destdir(destdir, new_bundler_specification_path)
+
+ bundler_spec.executables.each do |e|
+ assert_path_exist prepend_destdir(destdir, File.join(@gemhome, "gems", bundler_spec.full_name, bundler_spec.bindir, e))
end
ensure
FileUtils.chmod "+w", @gemhome
@@ -281,39 +297,37 @@ class TestGemCommandsSetupCommand < Gem::TestCase
def test_install_default_bundler_gem_with_destdir_and_prefix_flags
@cmd.extend FileUtils
- destdir = File.join(@tempdir, 'foo')
- bin_dir = File.join(destdir, 'bin')
+ destdir = File.join(@tempdir, "foo")
+ bin_dir = File.join(destdir, "bin")
@cmd.options[:destdir] = destdir
@cmd.options[:prefix] = "/"
@cmd.install_default_bundler_gem bin_dir
- spec = Gem::Specification.load("bundler/bundler.gemspec")
-
- spec.executables.each do |e|
- assert_path_exist File.join destdir, 'gems', spec.full_name, spec.bindir, e
+ bundler_spec.executables.each do |e|
+ assert_path_exist File.join destdir, "gems", bundler_spec.full_name, bundler_spec.bindir, e
end
end
def test_remove_old_lib_files
lib = RbConfig::CONFIG["sitelibdir"]
- lib_rubygems = File.join lib, 'rubygems'
- lib_bundler = File.join lib, 'bundler'
- lib_rubygems_defaults = File.join lib_rubygems, 'defaults'
- lib_bundler_templates = File.join lib_bundler, 'templates'
+ lib_rubygems = File.join lib, "rubygems"
+ lib_bundler = File.join lib, "bundler"
+ lib_rubygems_defaults = File.join lib_rubygems, "defaults"
+ lib_bundler_templates = File.join lib_bundler, "templates"
- securerandom_rb = File.join lib, 'securerandom.rb'
+ securerandom_rb = File.join lib, "securerandom.rb"
- engine_defaults_rb = File.join lib_rubygems_defaults, 'jruby.rb'
- os_defaults_rb = File.join lib_rubygems_defaults, 'operating_system.rb'
+ engine_defaults_rb = File.join lib_rubygems_defaults, "jruby.rb"
+ os_defaults_rb = File.join lib_rubygems_defaults, "operating_system.rb"
- old_gauntlet_rubygems_rb = File.join lib, 'gauntlet_rubygems.rb'
+ old_gauntlet_rubygems_rb = File.join lib, "gauntlet_rubygems.rb"
- old_builder_rb = File.join lib_rubygems, 'builder.rb'
- old_format_rb = File.join lib_rubygems, 'format.rb'
- old_bundler_c_rb = File.join lib_bundler, 'c.rb'
- old_bundler_ci = File.join lib_bundler_templates, '.lecacy_ci', 'config.yml'
+ old_builder_rb = File.join lib_rubygems, "builder.rb"
+ old_format_rb = File.join lib_rubygems, "format.rb"
+ old_bundler_c_rb = File.join lib_bundler, "c.rb"
+ old_bundler_ci = File.join lib_bundler_templates, ".lecacy_ci", "config.yml"
files_that_go = [old_gauntlet_rubygems_rb, old_builder_rb, old_format_rb, old_bundler_c_rb, old_bundler_ci]
files_that_stay = [securerandom_rb, engine_defaults_rb, os_defaults_rb]
@@ -328,15 +342,15 @@ class TestGemCommandsSetupCommand < Gem::TestCase
end
def test_remove_old_man_files
- man = File.join RbConfig::CONFIG['mandir'], 'man'
+ man = File.join RbConfig::CONFIG["mandir"], "man"
- ruby_1 = File.join man, 'man1', 'ruby.1'
- bundle_b_1 = File.join man, 'man1', 'bundle-b.1'
- bundle_b_1_ronn = File.join man, 'man1', 'bundle-b.1.ronn'
- bundle_b_1_txt = File.join man, 'man1', 'bundle-b.1.txt'
- gemfile_5 = File.join man, 'man5', 'gemfile.5'
- gemfile_5_ronn = File.join man, 'man5', 'gemfile.5.ronn'
- gemfile_5_txt = File.join man, 'man5', 'gemfile.5.txt'
+ ruby_1 = File.join man, "man1", "ruby.1"
+ bundle_b_1 = File.join man, "man1", "bundle-b.1"
+ bundle_b_1_ronn = File.join man, "man1", "bundle-b.1.ronn"
+ bundle_b_1_txt = File.join man, "man1", "bundle-b.1.txt"
+ gemfile_5 = File.join man, "man5", "gemfile.5"
+ gemfile_5_ronn = File.join man, "man5", "gemfile.5.ronn"
+ gemfile_5_txt = File.join man, "man5", "gemfile.5.txt"
files_that_go = [bundle_b_1, bundle_b_1_txt, bundle_b_1_ronn, gemfile_5, gemfile_5_txt, gemfile_5_ronn]
files_that_stay = [ruby_1]
@@ -354,9 +368,9 @@ class TestGemCommandsSetupCommand < Gem::TestCase
@default_external = @ui.outs.external_encoding
@ui.outs.set_encoding Encoding::US_ASCII
- @cmd.options[:previous_version] = Gem::Version.new '2.0.2'
+ @cmd.options[:previous_version] = Gem::Version.new "2.0.2"
- File.open 'CHANGELOG.md', 'w' do |io|
+ File.open "CHANGELOG.md", "w" do |io|
io.puts <<-HISTORY_TXT
# #{Gem::VERSION} / 2013-03-26
@@ -403,7 +417,7 @@ class TestGemCommandsSetupCommand < Gem::TestCase
list.each do |file|
FileUtils.mkdir_p File.dirname(file)
- File.open file, 'w' do |io|
+ File.open file, "w" do |io|
io.puts "# #{File.basename(file)}"
end
end
@@ -414,18 +428,18 @@ class TestGemCommandsSetupCommand < Gem::TestCase
s.executables = [name]
s.files = %W[bin/#{name}]
end
- write_file File.join @tempdir, 'bin', name do |f|
- f.puts '#!/usr/bin/ruby'
+ write_file File.join @tempdir, "bin", name do |f|
+ f.puts "#!/usr/bin/ruby"
end
install_gem gem
- File.join @gemhome, 'bin', name
+ File.join @gemhome, "bin", name
end
def gem_install_with_plugin(name)
gem = util_spec name do |s|
s.files = %W[lib/rubygems_plugin.rb]
end
- write_file File.join @tempdir, 'lib', 'rubygems_plugin.rb' do |f|
+ write_file File.join @tempdir, "lib", "rubygems_plugin.rb" do |f|
f.puts "require '#{gem.plugins.first}'"
end
install_gem gem
@@ -434,14 +448,34 @@ class TestGemCommandsSetupCommand < Gem::TestCase
end
def default_gem_bin_path
- File.join RbConfig::CONFIG['bindir'], 'gem'
+ File.join RbConfig::CONFIG["bindir"], "gem"
end
def default_bundle_bin_path
- File.join RbConfig::CONFIG['bindir'], 'bundle'
+ File.join RbConfig::CONFIG["bindir"], "bundle"
end
def default_bundler_bin_path
- File.join RbConfig::CONFIG['bindir'], 'bundler'
+ File.join RbConfig::CONFIG["bindir"], "bundler"
+ end
+
+ def previous_bundler_specification_path
+ File.join(Gem.default_specifications_dir, "bundler-1.15.4.gemspec")
+ end
+
+ def new_bundler_specification_path
+ File.join(Gem.default_specifications_dir, "bundler-#{bundler_version}.gemspec")
+ end
+
+ def bundler_spec
+ Gem::Specification.load("bundler/bundler.gemspec")
+ end
+
+ def bundler_version
+ bundler_spec.version
+ end
+
+ def prepend_destdir(destdir, path)
+ File.join(destdir, path.gsub(/^[a-zA-Z]:/, ""))
end
end unless Gem.java_platform?
diff --git a/test/rubygems/test_gem_commands_signin_command.rb b/test/rubygems/test_gem_commands_signin_command.rb
index cfc0b570e3..ce745bff20 100644
--- a/test/rubygems/test_gem_commands_signin_command.rb
+++ b/test/rubygems/test_gem_commands_signin_command.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/commands/signin_command'
-require 'rubygems/installer'
+require_relative "helper"
+require "rubygems/commands/signin_command"
+require "rubygems/installer"
class TestGemCommandsSigninCommand < Gem::TestCase
def setup
@@ -34,7 +34,7 @@ class TestGemCommandsSigninCommand < Gem::TestCase
end
def test_execute_when_already_signed_in_with_same_host
- host = 'http://some-gemcutter-compatible-host.org'
+ host = "http://some-gemcutter-compatible-host.org"
util_capture(nil, host) { @cmd.execute }
old_credentials = load_yaml_file Gem.configuration.credentials_path
@@ -46,10 +46,10 @@ class TestGemCommandsSigninCommand < Gem::TestCase
end
def test_execute_when_already_signed_in_with_different_host
- api_key = 'a5fdbb6ba150cbb83aad2bb2fede64cf04045xxxx'
+ api_key = "a5fdbb6ba150cbb83aad2bb2fede64cf04045xxxx"
util_capture(nil, nil, api_key) { @cmd.execute }
- host = 'http://some-gemcutter-compatible-host.org'
+ host = "http://some-gemcutter-compatible-host.org"
util_capture(nil, host, api_key) { @cmd.execute }
credentials = load_yaml_file Gem.configuration.credentials_path
@@ -60,13 +60,13 @@ class TestGemCommandsSigninCommand < Gem::TestCase
end
def test_execute_with_host_supplied
- host = 'http://some-gemcutter-compatible-host.org'
+ host = "http://some-gemcutter-compatible-host.org"
sign_in_ui = util_capture(nil, host) { @cmd.execute }
assert_match %r{Enter your #{host} credentials.}, sign_in_ui.output
assert_match %r{Signed in.}, sign_in_ui.output
- api_key = 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903'
+ api_key = "a5fdbb6ba150cbb83aad2bb2fede64cf040453903"
credentials = load_yaml_file Gem.configuration.credentials_path
assert_equal api_key, credentials[host]
end
@@ -74,16 +74,16 @@ class TestGemCommandsSigninCommand < Gem::TestCase
def test_execute_with_valid_creds_set_for_default_host
util_capture { @cmd.execute }
- api_key = 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903'
+ api_key = "a5fdbb6ba150cbb83aad2bb2fede64cf040453903"
credentials = load_yaml_file Gem.configuration.credentials_path
assert_equal api_key, credentials[:rubygems_api_key]
end
def test_execute_with_key_name_and_scope
- email = 'you@example.com'
- password = 'secret'
- api_key = '1234'
+ email = "you@example.com"
+ password = "secret"
+ api_key = "1234"
fetcher = Gem::RemoteFetcher.fetcher
key_name_ui = Gem::MockGemUi.new "#{email}\n#{password}\ntest-key\n\ny\n\n\n\n\n\n"
@@ -106,9 +106,9 @@ class TestGemCommandsSigninCommand < Gem::TestCase
end
def test_execute_with_key_name_scope_and_mfa_level_of_ui_only
- email = 'you@example.com'
- password = 'secret'
- api_key = '1234'
+ email = "you@example.com"
+ password = "secret"
+ api_key = "1234"
fetcher = Gem::RemoteFetcher.fetcher
mfa_level = "ui_only"
@@ -133,9 +133,9 @@ class TestGemCommandsSigninCommand < Gem::TestCase
end
def test_execute_with_key_name_scope_and_mfa_level_of_gem_signin
- email = 'you@example.com'
- password = 'secret'
- api_key = '1234'
+ email = "you@example.com"
+ password = "secret"
+ api_key = "1234"
fetcher = Gem::RemoteFetcher.fetcher
mfa_level = "ui_and_gem_signin"
@@ -159,20 +159,34 @@ class TestGemCommandsSigninCommand < Gem::TestCase
assert_equal api_key, credentials[:rubygems_api_key]
end
+ def test_execute_with_warnings
+ email = "you@example.com"
+ password = "secret"
+ api_key = "1234"
+ fetcher = Gem::RemoteFetcher.fetcher
+ mfa_level = "disabled"
+ warning = "/[WARNING/] For protection of your account and gems"
+
+ key_name_ui = Gem::MockGemUi.new "#{email}\n#{password}\ntest-key\n\ny\n\n\n\n\n\ny"
+ util_capture(key_name_ui, nil, api_key, fetcher, mfa_level, warning) { @cmd.execute }
+
+ assert_match warning, key_name_ui.output
+ end
+
def test_execute_on_gemserver_without_profile_me_endpoint
- host = 'http://some-gemcutter-compatible-host.org'
+ host = "http://some-gemcutter-compatible-host.org"
- email = 'you@example.com'
- password = 'secret'
- api_key = '1234'
+ email = "you@example.com"
+ password = "secret"
+ api_key = "1234"
fetcher = Gem::RemoteFetcher.fetcher
key_name_ui = Gem::MockGemUi.new "#{email}\n#{password}\ntest-key\n\ny\n\n\n\n\n\ny"
# Set the expected response for the Web-API supplied
- ENV['RUBYGEMS_HOST'] = host
+ ENV["RUBYGEMS_HOST"] = host
data_key = "#{ENV['RUBYGEMS_HOST']}/api/v1/api_key"
- fetcher.data[data_key] = [api_key, 200, 'OK']
+ fetcher.data[data_key] = [api_key, 200, "OK"]
use_ui key_name_ui do
@cmd.execute
@@ -193,15 +207,15 @@ class TestGemCommandsSigninCommand < Gem::TestCase
# Utility method to capture IO/UI within the block passed
- def util_capture(ui_stub = nil, host = nil, api_key = nil, fetcher = Gem::FakeFetcher.new, mfa_level = "disabled")
- api_key ||= 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903'
- response = [api_key, 200, 'OK']
- profile_response = [ "mfa: #{mfa_level}\n" , 200, 'OK']
- email = 'you@example.com'
- password = 'secret'
+ def util_capture(ui_stub = nil, host = nil, api_key = nil, fetcher = Gem::FakeFetcher.new, mfa_level = "disabled", warning = nil)
+ api_key ||= "a5fdbb6ba150cbb83aad2bb2fede64cf040453903"
+ response = [api_key, 200, "OK"]
+ profile_response = [ "mfa: #{mfa_level}\nwarning: #{warning}" , 200, "OK"]
+ email = "you@example.com"
+ password = "secret"
# Set the expected response for the Web-API supplied
- ENV['RUBYGEMS_HOST'] = host || Gem::DEFAULT_HOST
+ ENV["RUBYGEMS_HOST"] = host || Gem::DEFAULT_HOST
data_key = "#{ENV['RUBYGEMS_HOST']}/api/v1/api_key"
fetcher.data[data_key] = response
profile = "#{ENV['RUBYGEMS_HOST']}/api/v1/profile/me.yaml"
diff --git a/test/rubygems/test_gem_commands_signout_command.rb b/test/rubygems/test_gem_commands_signout_command.rb
index aa6300b6ab..992b127a94 100644
--- a/test/rubygems/test_gem_commands_signout_command.rb
+++ b/test/rubygems/test_gem_commands_signout_command.rb
@@ -1,8 +1,8 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/commands/signout_command'
-require 'rubygems/installer'
+require_relative "helper"
+require "rubygems/commands/signout_command"
+require "rubygems/installer"
class TestGemCommandsSignoutCommand < Gem::TestCase
def setup
diff --git a/test/rubygems/test_gem_commands_sources_command.rb b/test/rubygems/test_gem_commands_sources_command.rb
index 7bca0f3803..b7c164c0e6 100644
--- a/test/rubygems/test_gem_commands_sources_command.rb
+++ b/test/rubygems/test_gem_commands_sources_command.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/commands/sources_command'
+require_relative "helper"
+require "rubygems/commands/sources_command"
class TestGemCommandsSourcesCommand < Gem::TestCase
def setup
@@ -20,7 +20,7 @@ class TestGemCommandsSourcesCommand < Gem::TestCase
end
def test_initialize_proxy
- assert @cmd.handles?(['--http-proxy', 'http://proxy.example.com'])
+ assert @cmd.handles?(["--http-proxy", "http://proxy.example.com"])
end
def test_execute
@@ -37,12 +37,12 @@ class TestGemCommandsSourcesCommand < Gem::TestCase
EOF
assert_equal expected, @ui.output
- assert_equal '', @ui.error
+ assert_equal "", @ui.error
end
def test_execute_add
spec_fetcher do |fetcher|
- fetcher.spec 'a', 1
+ fetcher.spec "a", 1
end
specs = Gem::Specification.map do |spec|
@@ -70,7 +70,7 @@ class TestGemCommandsSourcesCommand < Gem::TestCase
EOF
assert_equal expected, @ui.output
- assert_equal '', @ui.error
+ assert_equal "", @ui.error
end
def test_execute_add_allow_typo_squatting_source
@@ -161,7 +161,6 @@ class TestGemCommandsSourcesCommand < Gem::TestCase
ui = Gem::MockGemUi.new("n")
use_ui ui do
-
assert_raise Gem::MockGemUi::TermError do
@cmd.execute
end
@@ -182,7 +181,7 @@ class TestGemCommandsSourcesCommand < Gem::TestCase
uri = "http://beta-gems.example.com/specs.#{@marshal_version}.gz"
@fetcher.data[uri] = proc do
- raise Gem::RemoteFetcher::FetchError.new('it died', uri)
+ raise Gem::RemoteFetcher::FetchError.new("it died", uri)
end
@cmd.handle_options %w[--add http://beta-gems.example.com]
@@ -199,7 +198,57 @@ Error fetching http://beta-gems.example.com:
EOF
assert_equal expected, @ui.output
- assert_equal '', @ui.error
+ assert_equal "", @ui.error
+ end
+
+ def test_execute_add_existent_source_invalid_uri
+ spec_fetcher
+
+ uri = "https://u:p@example.com/specs.#{@marshal_version}.gz"
+
+ @cmd.handle_options %w[--add https://u:p@example.com]
+ @fetcher.data[uri] = proc do
+ raise Gem::RemoteFetcher::FetchError.new("it died", uri)
+ end
+
+ use_ui @ui do
+ assert_raise Gem::MockGemUi::TermError do
+ @cmd.execute
+ end
+ end
+
+ expected = <<-EOF
+Error fetching https://u:REDACTED@example.com:
+\tit died (https://u:REDACTED@example.com/specs.#{@marshal_version}.gz)
+ EOF
+
+ assert_equal expected, @ui.output
+ assert_equal "", @ui.error
+ end
+
+ def test_execute_add_existent_source_invalid_uri_with_error_by_chance_including_the_uri_password
+ spec_fetcher
+
+ uri = "https://u:secret@example.com/specs.#{@marshal_version}.gz"
+
+ @cmd.handle_options %w[--add https://u:secret@example.com]
+ @fetcher.data[uri] = proc do
+ raise Gem::RemoteFetcher::FetchError.new("it secretly died", uri)
+ end
+
+ use_ui @ui do
+ assert_raise Gem::MockGemUi::TermError do
+ @cmd.execute
+ end
+ end
+
+ expected = <<-EOF
+Error fetching https://u:REDACTED@example.com:
+\tit secretly died (https://u:REDACTED@example.com/specs.#{@marshal_version}.gz)
+ EOF
+
+ assert_equal expected, @ui.output
+ assert_equal "", @ui.error
end
def test_execute_add_redundant_source
@@ -218,7 +267,7 @@ source #{@gem_repo} already present in the cache
EOF
assert_equal expected, @ui.output
- assert_equal '', @ui.error
+ assert_equal "", @ui.error
end
def test_execute_add_redundant_source_trailing_slash
@@ -238,7 +287,7 @@ source #{@gem_repo} already present in the cache
EOF
assert_equal expected, @ui.output
- assert_equal '', @ui.error
+ assert_equal "", @ui.error
# Re-add pre-existing gem source (w/o slash)
repo_without_slash = "http://gems.example.com"
@@ -255,7 +304,7 @@ http://gems.example.com added to sources
EOF
assert_equal expected, @ui.output
- assert_equal '', @ui.error
+ assert_equal "", @ui.error
# Re-add original gem source (w/ slash)
@cmd.handle_options %W[--add #{repo_with_slash}]
@@ -272,14 +321,14 @@ source http://gems.example.com/ already present in the cache
EOF
assert_equal expected, @ui.output
- assert_equal '', @ui.error
+ assert_equal "", @ui.error
end
def test_execute_add_http_rubygems_org
- http_rubygems_org = 'http://rubygems.org/'
+ http_rubygems_org = "http://rubygems.org/"
spec_fetcher do |fetcher|
- fetcher.spec 'a', 1
+ fetcher.spec "a", 1
end
specs = Gem::Specification.map do |spec|
@@ -344,10 +393,10 @@ source http://gems.example.com/ already present in the cache
end
def test_execute_add_https_rubygems_org
- https_rubygems_org = 'https://rubygems.org/'
+ https_rubygems_org = "https://rubygems.org/"
spec_fetcher do |fetcher|
- fetcher.spec 'a', 1
+ fetcher.spec "a", 1
end
specs = Gem::Specification.map do |spec|
@@ -397,7 +446,7 @@ beta-gems.example.com is not a URI
EOF
assert_equal expected, @ui.output
- assert_equal '', @ui.error
+ assert_equal "", @ui.error
end
def test_execute_clear_all
@@ -412,10 +461,10 @@ beta-gems.example.com is not a URI
EOF
assert_equal expected, @ui.output
- assert_equal '', @ui.error
+ assert_equal "", @ui.error
dir = Gem.spec_cache_dir
- refute File.exist?(dir), 'cache dir removed'
+ refute File.exist?(dir), "cache dir removed"
end
def test_execute_list
@@ -432,7 +481,7 @@ beta-gems.example.com is not a URI
EOF
assert_equal expected, @ui.output
- assert_equal '', @ui.error
+ assert_equal "", @ui.error
end
def test_execute_remove
@@ -445,7 +494,7 @@ beta-gems.example.com is not a URI
expected = "#{@gem_repo} removed from sources\n"
assert_equal expected, @ui.output
- assert_equal '', @ui.error
+ assert_equal "", @ui.error
end
def test_execute_remove_no_network
@@ -464,14 +513,14 @@ beta-gems.example.com is not a URI
expected = "#{@gem_repo} removed from sources\n"
assert_equal expected, @ui.output
- assert_equal '', @ui.error
+ assert_equal "", @ui.error
end
def test_execute_update
@cmd.handle_options %w[--update]
spec_fetcher do |fetcher|
- fetcher.gem 'a', 1
+ fetcher.gem "a", 1
end
use_ui @ui do
@@ -479,6 +528,6 @@ beta-gems.example.com is not a URI
end
assert_equal "source cache successfully updated\n", @ui.output
- assert_equal '', @ui.error
+ assert_equal "", @ui.error
end
end
diff --git a/test/rubygems/test_gem_commands_specification_command.rb b/test/rubygems/test_gem_commands_specification_command.rb
index c8cb7df32e..7564baa2ca 100644
--- a/test/rubygems/test_gem_commands_specification_command.rb
+++ b/test/rubygems/test_gem_commands_specification_command.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/commands/specification_command'
+require_relative "helper"
+require "rubygems/commands/specification_command"
class TestGemCommandsSpecificationCommand < Gem::TestCase
def setup
@@ -10,7 +10,7 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase
end
def test_execute
- foo = util_spec 'foo'
+ foo = util_spec "foo"
install_specs foo
@@ -22,12 +22,12 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase
assert_match %r{Gem::Specification}, @ui.output
assert_match %r{name: foo}, @ui.output
- assert_equal '', @ui.error
+ assert_equal "", @ui.error
end
def test_execute_all
- install_specs util_spec 'foo', '0.0.1'
- install_specs util_spec 'foo', '0.0.2'
+ install_specs util_spec "foo", "0.0.1"
+ install_specs util_spec "foo", "0.0.2"
@cmd.options[:args] = %w[foo]
@cmd.options[:all] = true
@@ -40,12 +40,12 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase
assert_match %r{name: foo}, @ui.output
assert_match %r{version: 0.0.1}, @ui.output
assert_match %r{version: 0.0.2}, @ui.output
- assert_equal '', @ui.error
+ assert_equal "", @ui.error
end
def test_execute_all_conflicts_with_version
- util_spec 'foo', '0.0.1'
- util_spec 'foo', '0.0.2'
+ util_spec "foo", "0.0.1"
+ util_spec "foo", "0.0.2"
@cmd.options[:args] = %w[foo]
@cmd.options[:all] = true
@@ -57,7 +57,7 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase
end
end
- assert_equal '', @ui.output
+ assert_equal "", @ui.output
assert_equal "ERROR: Specify --all or -v, not both\n", @ui.error
end
@@ -70,7 +70,7 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase
end
end
- assert_equal '', @ui.output
+ assert_equal "", @ui.output
assert_equal "ERROR: No gem matching 'foo (>= 0)' found\n", @ui.error
end
@@ -84,13 +84,13 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase
end
end
- assert_equal '', @ui.output
+ assert_equal "", @ui.output
assert_equal "ERROR: No gem matching 'foo (= 1.3.2)' found\n", @ui.error
end
def test_execute_exact_match
- install_specs util_spec 'foo'
- install_specs util_spec 'foo_bar'
+ install_specs util_spec "foo"
+ install_specs util_spec "foo_bar"
@cmd.options[:args] = %w[foo]
@@ -100,11 +100,11 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase
assert_match %r{Gem::Specification}, @ui.output
assert_match %r{name: foo}, @ui.output
- assert_equal '', @ui.error
+ assert_equal "", @ui.error
end
def test_execute_field
- foo = util_spec 'foo', '2'
+ foo = util_spec "foo", "2"
install_specs foo
@@ -118,7 +118,7 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase
end
def test_execute_file
- foo = util_spec 'foo' do |s|
+ foo = util_spec "foo" do |s|
s.files = %w[lib/code.rb]
end
@@ -132,11 +132,11 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase
assert_match %r{Gem::Specification}, @ui.output
assert_match %r{name: foo}, @ui.output
- assert_equal '', @ui.error
+ assert_equal "", @ui.error
end
def test_execute_marshal
- foo = util_spec 'foo', '2'
+ foo = util_spec "foo", "2"
install_specs foo
@@ -148,12 +148,12 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase
end
assert_equal foo, Marshal.load(@ui.output)
- assert_equal '', @ui.error
+ assert_equal "", @ui.error
end
def test_execute_remote
spec_fetcher do |fetcher|
- fetcher.spec 'foo', 1
+ fetcher.spec "foo", 1
end
@cmd.options[:args] = %w[foo]
@@ -169,8 +169,8 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase
def test_execute_remote_with_version
spec_fetcher do |fetcher|
- fetcher.spec 'foo', "1"
- fetcher.spec 'foo', "2"
+ fetcher.spec "foo", "1"
+ fetcher.spec "foo", "2"
end
@cmd.options[:args] = %w[foo]
@@ -190,9 +190,9 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase
original_platforms = Gem.platforms.dup
spec_fetcher do |fetcher|
- fetcher.spec 'foo', "1"
- fetcher.spec 'foo', "1" do |s|
- s.platform = 'x86_64-linux'
+ fetcher.spec "foo", "1"
+ fetcher.spec "foo", "1" do |s|
+ s.platform = "x86_64-linux"
end
end
@@ -216,8 +216,8 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase
def test_execute_remote_without_prerelease
spec_fetcher do |fetcher|
- fetcher.spec 'foo', '2.0.0'
- fetcher.spec 'foo', '2.0.1.pre'
+ fetcher.spec "foo", "2.0.0"
+ fetcher.spec "foo", "2.0.1.pre"
end
@cmd.options[:args] = %w[foo]
@@ -237,8 +237,8 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase
def test_execute_remote_with_prerelease
spec_fetcher do |fetcher|
- fetcher.spec 'foo', '2.0.0'
- fetcher.spec 'foo', '2.0.1.pre'
+ fetcher.spec "foo", "2.0.0"
+ fetcher.spec "foo", "2.0.1.pre"
end
@cmd.options[:args] = %w[foo]
@@ -258,7 +258,7 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase
end
def test_execute_ruby
- foo = util_spec 'foo'
+ foo = util_spec "foo"
install_specs foo
@@ -271,6 +271,6 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase
assert_match %r{Gem::Specification.new}, @ui.output
assert_match %r{s.name = "foo"}, @ui.output
- assert_equal '', @ui.error
+ assert_equal "", @ui.error
end
end
diff --git a/test/rubygems/test_gem_commands_stale_command.rb b/test/rubygems/test_gem_commands_stale_command.rb
index 83bd3e5def..99eb23fb30 100644
--- a/test/rubygems/test_gem_commands_stale_command.rb
+++ b/test/rubygems/test_gem_commands_stale_command.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/commands/stale_command'
+require_relative "helper"
+require "rubygems/commands/stale_command"
class TestGemCommandsStaleCommand < Gem::TestCase
def setup
@@ -11,12 +11,12 @@ class TestGemCommandsStaleCommand < Gem::TestCase
def test_execute_sorts
files = %w[lib/foo_bar.rb Rakefile]
- foo_bar = util_spec 'foo_bar' do |gem|
+ foo_bar = util_spec "foo_bar" do |gem|
gem.files = files
end
install_specs foo_bar
- bar_baz = util_spec 'bar_baz' do |gem|
+ bar_baz = util_spec "bar_baz" do |gem|
gem.files = files
end
install_specs bar_baz
diff --git a/test/rubygems/test_gem_commands_uninstall_command.rb b/test/rubygems/test_gem_commands_uninstall_command.rb
index 5bd2c40d59..083b831c98 100644
--- a/test/rubygems/test_gem_commands_uninstall_command.rb
+++ b/test/rubygems/test_gem_commands_uninstall_command.rb
@@ -1,12 +1,12 @@
# frozen_string_literal: true
-require_relative 'installer_test_case'
-require 'rubygems/commands/uninstall_command'
+require_relative "installer_test_case"
+require "rubygems/commands/uninstall_command"
class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
def setup
super
@cmd = Gem::Commands::UninstallCommand.new
- @executable = File.join(@gemhome, 'bin', 'executable')
+ @executable = File.join(@gemhome, "bin", "executable")
end
def test_execute_all_named
@@ -14,20 +14,20 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
util_make_gems
- default = new_default_spec 'default', '1'
+ default = new_default_spec "default", "1"
install_default_gems default
gemhome2 = "#{@gemhome}2"
- a_4, = util_gem 'a', 4
+ a_4, = util_gem "a", 4
install_gem a_4, :install_dir => gemhome2
Gem::Specification.dirs = [@gemhome, gemhome2]
- assert_includes Gem::Specification.all_names, 'a-1'
- assert_includes Gem::Specification.all_names, 'a-4'
- assert_includes Gem::Specification.all_names, 'b-2'
- assert_includes Gem::Specification.all_names, 'default-1'
+ assert_includes Gem::Specification.all_names, "a-1"
+ assert_includes Gem::Specification.all_names, "a-4"
+ assert_includes Gem::Specification.all_names, "b-2"
+ assert_includes Gem::Specification.all_names, "default-1"
@cmd.options[:all] = true
@cmd.options[:args] = %w[a]
@@ -41,10 +41,10 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
end
def test_execute_all_named_default_single
- z_1 = new_default_spec 'z', '1'
+ z_1 = new_default_spec "z", "1"
install_default_gems z_1
- assert_includes Gem::Specification.all_names, 'z-1'
+ assert_includes Gem::Specification.all_names, "z-1"
@cmd.options[:all] = true
@cmd.options[:args] = %w[z]
@@ -57,18 +57,18 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
output = @ui.output.split "\n"
- assert_equal 'Gem z-1 cannot be uninstalled because it is a default gem', output.shift
+ assert_equal "Gem z-1 cannot be uninstalled because it is a default gem", output.shift
end
def test_execute_all_named_default_multiple
- z_1 = new_default_spec 'z', '1'
+ z_1 = new_default_spec "z", "1"
install_default_gems z_1
- z_2, = util_gem 'z', 2
+ z_2, = util_gem "z", 2
install_gem z_2
- assert_includes Gem::Specification.all_names, 'z-1'
- assert_includes Gem::Specification.all_names, 'z-2'
+ assert_includes Gem::Specification.all_names, "z-1"
+ assert_includes Gem::Specification.all_names, "z-2"
@cmd.options[:all] = true
@cmd.options[:args] = %w[z]
@@ -81,15 +81,15 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
output = @ui.output.split "\n"
- assert_equal 'Gem z-1 cannot be uninstalled because it is a default gem', output.shift
- assert_equal 'Successfully uninstalled z-2', output.shift
+ assert_equal "Gem z-1 cannot be uninstalled because it is a default gem", output.shift
+ assert_equal "Successfully uninstalled z-2", output.shift
end
def test_execute_dependency_order
initial_install
- c = quick_gem 'c' do |spec|
- spec.add_dependency 'a'
+ c = quick_gem "c" do |spec|
+ spec.add_dependency "a"
end
util_build_gem c
@@ -110,9 +110,9 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
output = ui.output.split "\n"
- assert_equal 'Successfully uninstalled c-2', output.shift
+ assert_equal "Successfully uninstalled c-2", output.shift
assert_equal "Removing executable", output.shift
- assert_equal 'Successfully uninstalled a-2', output.shift
+ assert_equal "Successfully uninstalled a-2", output.shift
end
def test_execute_removes_executable
@@ -149,12 +149,12 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
FileUtils.rm_f @executable # Wish this didn't happen in #setup
- Gem::Installer.exec_format = 'foo-%s-bar'
+ Gem::Installer.exec_format = "foo-%s-bar"
installer.format_executable = true
installer.install
- formatted_executable = File.join @gemhome, 'bin', 'foo-executable-bar'
+ formatted_executable = File.join @gemhome, "bin", "foo-executable-bar"
assert_equal true, File.exist?(formatted_executable)
@cmd.options[:executables] = true
@@ -197,19 +197,19 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
util_make_gems
- assert_equal 3, Gem::Specification.find_all_by_name('a').length
+ assert_equal 3, Gem::Specification.find_all_by_name("a").length
- @cmd.options[:version] = '1'
+ @cmd.options[:version] = "1"
@cmd.options[:force] = true
- @cmd.options[:args] = ['a']
+ @cmd.options[:args] = ["a"]
use_ui ui do
@cmd.execute
end
- assert_equal 2, Gem::Specification.find_all_by_name('a').length
+ assert_equal 2, Gem::Specification.find_all_by_name("a").length
- assert File.exist? File.join(@gemhome, 'bin', 'executable')
+ assert File.exist? File.join(@gemhome, "bin", "executable")
end
def test_execute_with_version_specified_as_colon
@@ -219,18 +219,18 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
util_make_gems
- assert_equal 3, Gem::Specification.find_all_by_name('a').length
+ assert_equal 3, Gem::Specification.find_all_by_name("a").length
@cmd.options[:force] = true
- @cmd.options[:args] = ['a:1']
+ @cmd.options[:args] = ["a:1"]
use_ui ui do
@cmd.execute
end
- assert_equal 2, Gem::Specification.find_all_by_name('a').length
+ assert_equal 2, Gem::Specification.find_all_by_name("a").length
- assert File.exist? File.join(@gemhome, 'bin', 'executable')
+ assert File.exist? File.join(@gemhome, "bin", "executable")
end
def test_uninstall_selection
@@ -238,22 +238,22 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
util_make_gems
- list = Gem::Specification.find_all_by_name 'a'
+ list = Gem::Specification.find_all_by_name "a"
- @cmd.options[:args] = ['a']
+ @cmd.options[:args] = ["a"]
use_ui ui do
@cmd.execute
end
- updated_list = Gem::Specification.find_all_by_name('a')
+ updated_list = Gem::Specification.find_all_by_name("a")
assert_equal list.length - 1, updated_list.length
- assert_match ' 1. a-1', ui.output
- assert_match ' 2. a-2', ui.output
- assert_match ' 3. a-3.a', ui.output
- assert_match ' 4. All versions', ui.output
- assert_match 'uninstalled a-1', ui.output
+ assert_match " 1. a-1", ui.output
+ assert_match " 2. a-2", ui.output
+ assert_match " 3. a-3.a", ui.output
+ assert_match " 4. All versions", ui.output
+ assert_match "uninstalled a-1", ui.output
end
def test_uninstall_selection_multiple_gems
@@ -261,31 +261,31 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
util_make_gems
- a_list = Gem::Specification.find_all_by_name('a')
- b_list = Gem::Specification.find_all_by_name('b')
+ a_list = Gem::Specification.find_all_by_name("a")
+ b_list = Gem::Specification.find_all_by_name("b")
list = a_list + b_list
- @cmd.options[:args] = ['a', 'b']
+ @cmd.options[:args] = ["a", "b"]
use_ui ui do
@cmd.execute
end
- updated_a_list = Gem::Specification.find_all_by_name('a')
- updated_b_list = Gem::Specification.find_all_by_name('b')
+ updated_a_list = Gem::Specification.find_all_by_name("a")
+ updated_b_list = Gem::Specification.find_all_by_name("b")
updated_list = updated_a_list + updated_b_list
assert_equal list.length - 2, updated_list.length
out = ui.output.split("\n")
- assert_match 'uninstalled b-2', out.shift
- assert_match '', out.shift
- assert_match 'Select gem to uninstall:', out.shift
- assert_match ' 1. a-1', out.shift
- assert_match ' 2. a-2', out.shift
- assert_match ' 3. a-3.a', out.shift
- assert_match ' 4. All versions', out.shift
- assert_match 'uninstalled a-1', out.shift
+ assert_match "uninstalled b-2", out.shift
+ assert_match "", out.shift
+ assert_match "Select gem to uninstall:", out.shift
+ assert_match " 1. a-1", out.shift
+ assert_match " 2. a-2", out.shift
+ assert_match " 3. a-3.a", out.shift
+ assert_match " 4. All versions", out.shift
+ assert_match "uninstalled a-1", out.shift
assert_empty out
end
@@ -294,22 +294,22 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
ui = Gem::MockGemUi.new "y\n"
- a_1, = util_gem 'a', 1
+ a_1, = util_gem "a", 1
install_gem a_1
- a_3a, = util_gem 'a', '3.a'
+ a_3a, = util_gem "a", "3.a"
install_gem a_3a
- assert_equal 3, Gem::Specification.find_all_by_name('a').length
+ assert_equal 3, Gem::Specification.find_all_by_name("a").length
@cmd.options[:force] = true
- @cmd.options[:args] = ['a']
+ @cmd.options[:args] = ["a"]
use_ui ui do
@cmd.execute
end
- assert_empty Gem::Specification.find_all_by_name('a')
+ assert_empty Gem::Specification.find_all_by_name("a")
assert_match "Removing executable", ui.output
refute File.exist? @executable
end
@@ -321,36 +321,36 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
util_make_gems
- assert Gem::Specification.find_all_by_name('dep_x').length > 0
- assert Gem::Specification.find_all_by_name('x').length > 0
+ assert Gem::Specification.find_all_by_name("dep_x").length > 0
+ assert Gem::Specification.find_all_by_name("x").length > 0
@cmd.options[:force] = true
- @cmd.options[:args] = ['x']
+ @cmd.options[:args] = ["x"]
use_ui ui do
@cmd.execute
end
- assert Gem::Specification.find_all_by_name('dep_x').length > 0
- assert Gem::Specification.find_all_by_name('x').length.zero?
+ assert Gem::Specification.find_all_by_name("dep_x").length > 0
+ assert Gem::Specification.find_all_by_name("x").length.zero?
end
def test_execute_all
util_make_gems
- default = new_default_spec 'default', '1'
+ default = new_default_spec "default", "1"
install_default_gems default
gemhome2 = "#{@gemhome}2"
- a_4, = util_gem 'a', 4
+ a_4, = util_gem "a", 4
install_gem a_4
Gem::Specification.dirs = [@gemhome, gemhome2]
- assert_includes Gem::Specification.all_names, 'a-1'
- assert_includes Gem::Specification.all_names, 'a-4'
- assert_includes Gem::Specification.all_names, 'default-1'
+ assert_includes Gem::Specification.all_names, "a-1"
+ assert_includes Gem::Specification.all_names, "a-4"
+ assert_includes Gem::Specification.all_names, "default-1"
@cmd.options[:all] = true
@cmd.options[:args] = []
@@ -368,14 +368,14 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
gemhome2 = "#{@gemhome}2"
- a_4, = util_gem 'a', 4
+ a_4, = util_gem "a", 4
install_gem a_4 , :install_dir => gemhome2
Gem::Specification.dirs = [@gemhome, gemhome2]
- assert_includes Gem::Specification.all_names, 'a-4'
+ assert_includes Gem::Specification.all_names, "a-4"
- @cmd.options[:args] = ['a:4']
+ @cmd.options[:args] = ["a:4"]
e = assert_raise Gem::InstallError do
use_ui ui do
@@ -397,7 +397,7 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
end
def test_handle_options_vendor
- vendordir(File.join(@tempdir, 'vendor')) do
+ vendordir(File.join(@tempdir, "vendor")) do
use_ui @ui do
@cmd.handle_options %w[--vendor]
end
@@ -440,7 +440,7 @@ WARNING: Use your OS package manager to uninstall vendor gems
@cmd.handle_options %w[--vendor]
end
- assert_equal 'invalid option: --vendor your platform is not supported',
+ assert_equal "invalid option: --vendor your platform is not supported",
e.message
refute @cmd.options[:vendor]
@@ -449,7 +449,7 @@ WARNING: Use your OS package manager to uninstall vendor gems
end
def test_execute_with_gem_not_installed
- @cmd.options[:args] = ['d']
+ @cmd.options[:args] = ["d"]
use_ui ui do
@cmd.execute
diff --git a/test/rubygems/test_gem_commands_unpack_command.rb b/test/rubygems/test_gem_commands_unpack_command.rb
index 55369f1eeb..1d9d0b6bd0 100644
--- a/test/rubygems/test_gem_commands_unpack_command.rb
+++ b/test/rubygems/test_gem_commands_unpack_command.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/commands/unpack_command'
+require_relative "helper"
+require "rubygems/commands/unpack_command"
class TestGemCommandsUnpackCommand < Gem::TestCase
def setup
@@ -17,28 +17,28 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
assert_equal(
@cmd.find_in_cache(File.basename @a1.cache_file),
@a1.cache_file,
- 'found a-1.gem in the cache'
+ "found a-1.gem in the cache"
)
end
def test_get_path
specs = spec_fetcher do |fetcher|
- fetcher.gem 'a', 1
+ fetcher.gem "a", 1
end
- dep = Gem::Dependency.new 'a', 1
+ dep = Gem::Dependency.new "a", 1
assert_equal(
@cmd.get_path(dep),
- specs['a-1'].cache_file,
- 'fetches a-1 and returns the cache path'
+ specs["a-1"].cache_file,
+ "fetches a-1 and returns the cache path"
)
- FileUtils.rm specs['a-1'].cache_file
+ FileUtils.rm specs["a-1"].cache_file
assert_equal(
@cmd.get_path(dep),
- specs['a-1'].cache_file,
- 'when removed from cache, refetches a-1'
+ specs["a-1"].cache_file,
+ "when removed from cache, refetches a-1"
)
end
@@ -53,18 +53,18 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
end
end
- assert File.exist?(File.join(@tempdir, 'a-3.a')), 'a should be unpacked'
- assert File.exist?(File.join(@tempdir, 'b-2')), 'b should be unpacked'
+ assert File.exist?(File.join(@tempdir, "a-3.a")), "a should be unpacked"
+ assert File.exist?(File.join(@tempdir, "b-2")), "b should be unpacked"
end
def test_execute_gem_path
spec_fetcher do |fetcher|
- fetcher.gem 'a', '3.a'
+ fetcher.gem "a", "3.a"
end
Gem.clear_paths
- gemhome2 = File.join @tempdir, 'gemhome2'
+ gemhome2 = File.join @tempdir, "gemhome2"
Gem.use_paths gemhome2, [gemhome2, @gemhome]
@@ -76,7 +76,7 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
end
end
- assert File.exist?(File.join(@tempdir, 'a-3.a'))
+ assert File.exist?(File.join(@tempdir, "a-3.a"))
end
def test_execute_gem_path_missing
@@ -84,7 +84,7 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
Gem.clear_paths
- gemhome2 = File.join @tempdir, 'gemhome2'
+ gemhome2 = File.join @tempdir, "gemhome2"
Gem.use_paths gemhome2, [gemhome2, @gemhome]
@@ -96,13 +96,13 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
end
end
- assert_equal '', @ui.output
+ assert_equal "", @ui.output
end
def test_execute_remote
spec_fetcher do |fetcher|
- fetcher.download 'a', 1
- fetcher.download 'a', 2
+ fetcher.download "a", 1
+ fetcher.download "a", 2
end
Gem.configuration.verbose = :really
@@ -114,7 +114,7 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
end
end
- assert File.exist?(File.join(@tempdir, 'a-2')), 'a should be unpacked'
+ assert File.exist?(File.join(@tempdir, "a-2")), "a should be unpacked"
end
def test_execute_spec
@@ -129,15 +129,15 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
end
end
- assert File.exist?(File.join(@tempdir, 'a-3.a.gemspec'))
- assert File.exist?(File.join(@tempdir, 'b-2.gemspec'))
+ assert File.exist?(File.join(@tempdir, "a-3.a.gemspec"))
+ assert File.exist?(File.join(@tempdir, "b-2.gemspec"))
end
def test_execute_spec_target
util_make_gems
@cmd.options[:args] = %w[a b]
- @cmd.options[:target] = 'specs'
+ @cmd.options[:target] = "specs"
@cmd.options[:spec] = true
use_ui @ui do
@@ -146,12 +146,12 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
end
end
- assert File.exist?(File.join(@tempdir, 'specs/a-3.a.gemspec'))
- assert File.exist?(File.join(@tempdir, 'specs/b-2.gemspec'))
+ assert File.exist?(File.join(@tempdir, "specs/a-3.a.gemspec"))
+ assert File.exist?(File.join(@tempdir, "specs/b-2.gemspec"))
end
def test_execute_sudo
- pend 'Cannot perform this test on windows (chmod)' if win_platform?
+ pend "Cannot perform this test on windows (chmod)" if win_platform?
util_make_gems
@@ -165,7 +165,7 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
end
end
- assert File.exist?(File.join(@tempdir, 'b-2')), 'b should be unpacked'
+ assert File.exist?(File.join(@tempdir, "b-2")), "b should be unpacked"
ensure
FileUtils.chmod 0755, @gemhome
end
@@ -173,7 +173,7 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
def test_execute_with_target_option
util_make_gems
- target = 'with_target'
+ target = "with_target"
@cmd.options[:args] = %w[a]
@cmd.options[:target] = target
@@ -183,12 +183,12 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
end
end
- assert File.exist?(File.join(@tempdir, target, 'a-3.a'))
+ assert File.exist?(File.join(@tempdir, target, "a-3.a"))
end
def test_execute_exact_match
- foo_spec = util_spec 'foo'
- foo_bar_spec = util_spec 'foo_bar'
+ foo_spec = util_spec "foo"
+ foo_bar_spec = util_spec "foo_bar"
use_ui @ui do
Dir.chdir @tempdir do
diff --git a/test/rubygems/test_gem_commands_update_command.rb b/test/rubygems/test_gem_commands_update_command.rb
index c765e9a8df..58bc7576da 100644
--- a/test/rubygems/test_gem_commands_update_command.rb
+++ b/test/rubygems/test_gem_commands_update_command.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/commands/update_command'
+require_relative "helper"
+require "rubygems/commands/update_command"
class TestGemCommandsUpdateCommand < Gem::TestCase
def setup
@@ -12,20 +12,20 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
@cmd.options[:document] = []
@specs = spec_fetcher do |fetcher|
- fetcher.download 'a', 1
- fetcher.download 'a', 2
- fetcher.download 'a', '3.a'
+ fetcher.download "a", 1
+ fetcher.download "a", 2
+ fetcher.download "a", "3.a"
end
- @a1_path = @specs['a-1'].cache_file
- @a2_path = @specs['a-1'].cache_file
- @a3a_path = @specs['a-3.a'].cache_file
+ @a1_path = @specs["a-1"].cache_file
+ @a2_path = @specs["a-1"].cache_file
+ @a3a_path = @specs["a-3.a"].cache_file
end
def test_execute
spec_fetcher do |fetcher|
- fetcher.download 'a', 2
- fetcher.spec 'a', 1
+ fetcher.download "a", 2
+ fetcher.spec "a", 1
end
@cmd.options[:args] = []
@@ -43,11 +43,11 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
def test_execute_multiple
spec_fetcher do |fetcher|
- fetcher.download 'a', 2
- fetcher.download 'ab', 2
+ fetcher.download "a", 2
+ fetcher.download "ab", 2
- fetcher.spec 'a', 1
- fetcher.spec 'ab', 1
+ fetcher.spec "a", 1
+ fetcher.spec "ab", 1
end
@cmd.options[:args] = %w[a]
@@ -65,7 +65,7 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
def test_execute_system
spec_fetcher do |fetcher|
- fetcher.download 'rubygems-update', 9 do |s|
+ fetcher.download "rubygems-update", 9 do |s|
s.files = %w[setup.rb]
end
end
@@ -87,7 +87,7 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
def test_execute_system_at_latest
spec_fetcher do |fetcher|
- fetcher.download 'rubygems-update', Gem::VERSION do |s|
+ fetcher.download "rubygems-update", Gem::VERSION do |s|
s.files = %w[setup.rb]
end
end
@@ -108,9 +108,9 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
def test_execute_system_when_latest_does_not_support_your_ruby
spec_fetcher do |fetcher|
- fetcher.download 'rubygems-update', 9 do |s|
+ fetcher.download "rubygems-update", 9 do |s|
s.files = %w[setup.rb]
- s.required_ruby_version = '> 9'
+ s.required_ruby_version = "> 9"
end
end
@@ -133,11 +133,11 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
def test_execute_system_multiple
spec_fetcher do |fetcher|
- fetcher.download 'rubygems-update', 8 do |s|
+ fetcher.download "rubygems-update", 8 do |s|
s.files = %w[setup.rb]
end
- fetcher.download 'rubygems-update', 9 do |s|
+ fetcher.download "rubygems-update", 9 do |s|
s.files = %w[setup.rb]
end
end
@@ -159,7 +159,7 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
def test_execute_system_update_installed
spec_fetcher do |fetcher|
- fetcher.download 'rubygems-update', 8 do |s|
+ fetcher.download "rubygems-update", 8 do |s|
s.files = %w[setup.rb]
end
end
@@ -170,7 +170,7 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
@cmd.execute
spec_fetcher do |fetcher|
- fetcher.download 'rubygems-update', 9 do |s|
+ fetcher.download "rubygems-update", 9 do |s|
s.files = %w[setup.rb]
end
end
@@ -191,13 +191,44 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
assert_empty out
end
+ def test_execute_system_update_installed_in_non_default_gem_path
+ rubygems_update_spec = quick_gem "rubygems-update", 9 do |s|
+ write_file File.join(@tempdir, "setup.rb")
+
+ s.files += %w[setup.rb]
+ end
+
+ util_setup_spec_fetcher rubygems_update_spec
+
+ rubygems_update_package = Gem::Package.build rubygems_update_spec
+
+ gemhome2 = "#{@gemhome}2"
+
+ Gem::Installer.at(rubygems_update_package, :install_dir => gemhome2).install
+
+ Gem.use_paths @gemhome, [gemhome2, @gemhome]
+
+ @cmd.options[:args] = []
+ @cmd.options[:system] = true
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ out = @ui.output.split "\n"
+ assert_equal "Installing RubyGems 9", out.shift
+ assert_equal "RubyGems system software updated", out.shift
+
+ assert_empty out
+ end
+
def test_execute_system_specific
spec_fetcher do |fetcher|
- fetcher.download 'rubygems-update', 8 do |s|
+ fetcher.download "rubygems-update", 8 do |s|
s.files = %w[setup.rb]
end
- fetcher.download 'rubygems-update', 9 do |s|
+ fetcher.download "rubygems-update", 9 do |s|
s.files = %w[setup.rb]
end
end
@@ -219,7 +250,7 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
def test_execute_system_specific_older_than_minimum_supported_rubygems
spec_fetcher do |fetcher|
- fetcher.download 'rubygems-update', "2.5.1" do |s|
+ fetcher.download "rubygems-update", "2.5.1" do |s|
s.files = %w[setup.rb]
end
end
@@ -248,7 +279,7 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
def test_execute_system_specific_older_than_3_2_removes_plugins_dir
spec_fetcher do |fetcher|
- fetcher.download 'rubygems-update', 3.1 do |s|
+ fetcher.download "rubygems-update", 3.1 do |s|
s.files = %w[setup.rb]
end
end
@@ -266,7 +297,7 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
@cmd.options[:system] = "3.1"
FileUtils.mkdir_p Gem.plugindir
- write_file File.join(Gem.plugindir, 'a_plugin.rb')
+ write_file File.join(Gem.plugindir, "a_plugin.rb")
@cmd.execute
@@ -275,7 +306,7 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
def test_execute_system_specific_newer_than_or_equal_to_3_2_leaves_plugins_dir_alone
spec_fetcher do |fetcher|
- fetcher.download 'rubygems-update', "3.2.a" do |s|
+ fetcher.download "rubygems-update", "3.2.a" do |s|
s.files = %w[setup.rb]
end
end
@@ -293,7 +324,7 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
@cmd.options[:system] = "3.2.a"
FileUtils.mkdir_p Gem.plugindir
- plugin_file = File.join(Gem.plugindir, 'a_plugin.rb')
+ plugin_file = File.join(Gem.plugindir, "a_plugin.rb")
write_file plugin_file
@cmd.execute
@@ -304,11 +335,11 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
def test_execute_system_specifically_to_latest_version
spec_fetcher do |fetcher|
- fetcher.download 'rubygems-update', 8 do |s|
+ fetcher.download "rubygems-update", 8 do |s|
s.files = %w[setup.rb]
end
- fetcher.download 'rubygems-update', 9 do |s|
+ fetcher.download "rubygems-update", 9 do |s|
s.files = %w[setup.rb]
end
end
@@ -369,12 +400,12 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
@cmd.options[:system] = true
@cmd.options[:silent] = true
- assert_equal true, @cmd.update_rubygems_arguments.include?('--silent')
+ assert_equal true, @cmd.update_rubygems_arguments.include?("--silent")
end
def test_execute_system_silent
spec_fetcher do |fetcher|
- fetcher.download 'rubygems-update', 9 do |s|
+ fetcher.download "rubygems-update", 9 do |s|
s.files = %w[setup.rb]
end
end
@@ -398,12 +429,12 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
def test_execute_dependencies
spec_fetcher do |fetcher|
- fetcher.download 'a', 2, 'b' => 2, 'c' => 2
- fetcher.download 'b', 2
- fetcher.download 'c', 2
+ fetcher.download "a", 2, "b" => 2, "c" => 2
+ fetcher.download "b", 2
+ fetcher.download "c", 2
- fetcher.spec 'a', 1, 'c' => '1.2'
- fetcher.spec 'c', '1.2'
+ fetcher.spec "a", 1, "c" => "1.2"
+ fetcher.spec "c", "1.2"
end
Gem::Specification.reset
@@ -425,8 +456,8 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
def test_execute_rdoc
spec_fetcher do |fetcher|
- fetcher.download 'a', 2
- fetcher.spec 'a', 1
+ fetcher.download "a", 2
+ fetcher.spec "a", 1
end
Gem.done_installing(&Gem::RDoc.method(:generation_hook))
@@ -441,16 +472,16 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
wait_for_child_process_to_exit
- a2 = @specs['a-2']
+ a2 = @specs["a-2"]
- assert_path_exist File.join(a2.doc_dir, 'rdoc')
+ assert_path_exist File.join(a2.doc_dir, "rdoc")
end
def test_execute_named
spec_fetcher do |fetcher|
- fetcher.download 'a', 2
+ fetcher.download "a", 2
- fetcher.spec 'a', 1
+ fetcher.spec "a", 1
end
@cmd.options[:args] = %w[a]
@@ -469,10 +500,10 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
def test_execute_named_some_up_to_date
spec_fetcher do |fetcher|
- fetcher.download 'a', 2
- fetcher.spec 'a', 1
+ fetcher.download "a", 2
+ fetcher.spec "a", 1
- fetcher.spec 'b', 2
+ fetcher.spec "b", 2
end
@cmd.options[:args] = %w[a b]
@@ -492,7 +523,7 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
def test_execute_named_up_to_date
spec_fetcher do |fetcher|
- fetcher.spec 'a', 2
+ fetcher.spec "a", 2
end
@cmd.options[:args] = %w[a]
@@ -504,15 +535,16 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
out = @ui.output.split "\n"
assert_equal "Updating installed gems", out.shift
assert_equal "Nothing to update", out.shift
+ assert_equal "Gems already up-to-date: a", out.shift
assert_empty out
end
def test_execute_named_up_to_date_prerelease
spec_fetcher do |fetcher|
- fetcher.download 'a', '3.a'
+ fetcher.download "a", "3.a"
- fetcher.gem 'a', 2
+ fetcher.gem "a", 2
end
@cmd.options[:args] = %w[a]
@@ -532,7 +564,7 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
def test_execute_up_to_date
spec_fetcher do |fetcher|
- fetcher.gem 'a', 2
+ fetcher.gem "a", 2
end
@cmd.options[:args] = []
@@ -574,63 +606,63 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
def test_fetch_remote_gems
specs = spec_fetcher do |fetcher|
- fetcher.gem 'a', 1
- fetcher.gem 'a', 2
+ fetcher.gem "a", 1
+ fetcher.gem "a", 2
end
expected = [
- [Gem::NameTuple.new('a', v(2), Gem::Platform::RUBY),
+ [Gem::NameTuple.new("a", v(2), Gem::Platform::RUBY),
Gem::Source.new(@gem_repo)],
]
- assert_equal expected, @cmd.fetch_remote_gems(specs['a-1'])
+ assert_equal expected, @cmd.fetch_remote_gems(specs["a-1"])
end
def test_fetch_remote_gems_error
Gem.sources.replace %w[http://nonexistent.example]
assert_raise Gem::RemoteFetcher::FetchError do
- @cmd.fetch_remote_gems @specs['a-1']
+ @cmd.fetch_remote_gems @specs["a-1"]
end
end
def test_fetch_remote_gems_mismatch
- platform = Gem::Platform.new 'x86-freebsd9'
+ platform = Gem::Platform.new "x86-freebsd9"
specs = spec_fetcher do |fetcher|
- fetcher.spec 'a', 1
- fetcher.spec 'a', 2
+ fetcher.spec "a", 1
+ fetcher.spec "a", 2
- fetcher.spec 'a', 2 do |s|
+ fetcher.spec "a", 2 do |s|
s.platform = platform
end
end
expected = [
- [Gem::NameTuple.new('a', v(2), Gem::Platform::RUBY),
+ [Gem::NameTuple.new("a", v(2), Gem::Platform::RUBY),
Gem::Source.new(@gem_repo)],
]
- assert_equal expected, @cmd.fetch_remote_gems(specs['a-1'])
+ assert_equal expected, @cmd.fetch_remote_gems(specs["a-1"])
end
def test_fetch_remote_gems_prerelease
specs = spec_fetcher do |fetcher|
- fetcher.gem 'a', 1
- fetcher.gem 'a', 2
- fetcher.gem 'a', '3.a'
+ fetcher.gem "a", 1
+ fetcher.gem "a", 2
+ fetcher.gem "a", "3.a"
end
@cmd.options[:prerelease] = true
expected = [
- [Gem::NameTuple.new('a', v(2), Gem::Platform::RUBY),
+ [Gem::NameTuple.new("a", v(2), Gem::Platform::RUBY),
Gem::Source.new(@gem_repo)],
- [Gem::NameTuple.new('a', v('3.a'), Gem::Platform::RUBY),
+ [Gem::NameTuple.new("a", v("3.a"), Gem::Platform::RUBY),
Gem::Source.new(@gem_repo)],
]
- assert_equal expected, @cmd.fetch_remote_gems(specs['a-1'])
+ assert_equal expected, @cmd.fetch_remote_gems(specs["a-1"])
end
def test_handle_options_system
@@ -667,11 +699,11 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
def test_update_gem_prerelease
spec_fetcher do |fetcher|
- fetcher.spec 'a', '1.a'
- fetcher.gem 'a', '1.b'
+ fetcher.spec "a", "1.a"
+ fetcher.gem "a", "1.b"
end
- @cmd.update_gem 'a', Gem::Requirement.new('= 1.b')
+ @cmd.update_gem "a", Gem::Requirement.new("= 1.b")
refute_empty @cmd.updated
@@ -680,15 +712,15 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
def test_update_gem_unresolved_dependency
spec_fetcher do |fetcher|
- fetcher.spec 'a', 1
- fetcher.gem 'a', 2 do |s|
- s.add_dependency 'b', '>= 2'
+ fetcher.spec "a", 1
+ fetcher.gem "a", 2 do |s|
+ s.add_dependency "b", ">= 2"
end
- fetcher.spec 'b', 1
+ fetcher.spec "b", 1
end
- @cmd.update_gem 'a'
+ @cmd.update_gem "a"
assert_empty @cmd.updated
end
@@ -698,18 +730,18 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
arguments = @cmd.update_rubygems_arguments
- assert_equal '--prefix', arguments.shift
+ assert_equal "--prefix", arguments.shift
assert_equal Gem.prefix, arguments.shift
- assert_equal '--no-document', arguments.shift
- assert_equal '--previous-version', arguments.shift
+ assert_equal "--no-document", arguments.shift
+ assert_equal "--previous-version", arguments.shift
assert_equal Gem::VERSION, arguments.shift
assert_empty arguments
end
def test_explain
spec_fetcher do |fetcher|
- fetcher.download 'a', 2
- fetcher.spec 'a', 1
+ fetcher.download "a", 2
+ fetcher.spec "a", 1
end
@cmd.options[:explain] = true
@@ -729,13 +761,13 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
def test_explain_platform_local
local = Gem::Platform.local
spec_fetcher do |fetcher|
- fetcher.download 'a', 2
+ fetcher.download "a", 2
- fetcher.download 'a', 2 do |s|
+ fetcher.download "a", 2 do |s|
s.platform = local
end
- fetcher.spec 'a', 1
+ fetcher.spec "a", 1
end
@cmd.options[:explain] = true
@@ -755,13 +787,13 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
def test_explain_platform_ruby
local = Gem::Platform.local
spec_fetcher do |fetcher|
- fetcher.download 'a', 2
+ fetcher.download "a", 2
- fetcher.download 'a', 2 do |s|
+ fetcher.download "a", 2 do |s|
s.platform = local
end
- fetcher.spec 'a', 1
+ fetcher.spec "a", 1
end
# equivalent to --platform=ruby
@@ -780,4 +812,24 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
assert_equal " a-2", out.shift
assert_empty out
end
+
+ def test_execute_named_not_installed_and_no_update
+ spec_fetcher do |fetcher|
+ fetcher.spec "a", 2
+ end
+
+ @cmd.options[:args] = %w[a b]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ out = @ui.output.split "\n"
+ assert_equal "Updating installed gems", out.shift
+ assert_equal "Nothing to update", out.shift
+ assert_equal "Gems already up-to-date: a", out.shift
+ assert_equal "Gems not currently installed: b", out.shift
+
+ assert_empty out
+ end
end
diff --git a/test/rubygems/test_gem_commands_which_command.rb b/test/rubygems/test_gem_commands_which_command.rb
index a398dc5708..46e95bf619 100644
--- a/test/rubygems/test_gem_commands_which_command.rb
+++ b/test/rubygems/test_gem_commands_which_command.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/commands/which_command'
+require_relative "helper"
+require "rubygems/commands/which_command"
class TestGemCommandsWhichCommand < Gem::TestCase
def setup
@@ -19,7 +19,7 @@ class TestGemCommandsWhichCommand < Gem::TestCase
end
assert_equal "#{@foo_bar.full_gem_path}/lib/foo_bar.rb\n", @ui.output
- assert_equal '', @ui.error
+ assert_equal "", @ui.error
end
def test_execute_directory
@@ -31,7 +31,7 @@ class TestGemCommandsWhichCommand < Gem::TestCase
end
end
- assert_equal '', @ui.output
+ assert_equal "", @ui.output
assert_match %r{Can.t find Ruby library file or shared library directory\n},
@ui.error
end
@@ -63,14 +63,14 @@ class TestGemCommandsWhichCommand < Gem::TestCase
end
end
- assert_equal '', @ui.output
+ assert_equal "", @ui.output
assert_match %r{Can.t find Ruby library file or shared library missinglib\n},
@ui.error
end
def util_foo_bar
files = %w[lib/foo_bar.rb lib/directory/baz.rb Rakefile]
- @foo_bar = util_spec 'foo_bar' do |gem|
+ @foo_bar = util_spec "foo_bar" do |gem|
gem.files = files
end
install_specs @foo_bar
diff --git a/test/rubygems/test_gem_commands_yank_command.rb b/test/rubygems/test_gem_commands_yank_command.rb
index b798eb3689..878b52416e 100644
--- a/test/rubygems/test_gem_commands_yank_command.rb
+++ b/test/rubygems/test_gem_commands_yank_command.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/commands/yank_command'
+require_relative "helper"
+require "rubygems/commands/yank_command"
class TestGemCommandsYankCommand < Gem::TestCase
def setup
@@ -9,12 +9,12 @@ class TestGemCommandsYankCommand < Gem::TestCase
credential_setup
@cmd = Gem::Commands::YankCommand.new
- @cmd.options[:host] = 'http://example'
+ @cmd.options[:host] = "http://example"
@fetcher = Gem::RemoteFetcher.fetcher
- Gem.configuration.rubygems_api_key = 'key'
- Gem.configuration.api_keys[:KEY] = 'other'
+ Gem.configuration.rubygems_api_key = "key"
+ Gem.configuration.api_keys[:KEY] = "other"
end
def teardown
@@ -30,7 +30,7 @@ class TestGemCommandsYankCommand < Gem::TestCase
assert_equal :KEY, @cmd.options[:key]
assert_equal "HOST", @cmd.options[:host]
assert_nil @cmd.options[:platform]
- assert_equal req('= 1.0'), @cmd.options[:version]
+ assert_equal req("= 1.0"), @cmd.options[:version]
end
def test_handle_options_missing_argument
@@ -42,12 +42,12 @@ class TestGemCommandsYankCommand < Gem::TestCase
end
def test_execute
- yank_uri = 'http://example/api/v1/gems/yank'
- @fetcher.data[yank_uri] = ['Successfully yanked', 200, 'OK']
+ yank_uri = "http://example/api/v1/gems/yank"
+ @fetcher.data[yank_uri] = ["Successfully yanked", 200, "OK"]
@cmd.options[:args] = %w[a]
@cmd.options[:added_platform] = true
- @cmd.options[:version] = req('= 1.0')
+ @cmd.options[:version] = req("= 1.0")
use_ui @ui do
@cmd.execute
@@ -57,82 +57,82 @@ class TestGemCommandsYankCommand < Gem::TestCase
assert_match %r{Successfully yanked}, @ui.output
platform = Gem.platforms[1]
- body = @fetcher.last_request.body.split('&').sort
+ body = @fetcher.last_request.body.split("&").sort
assert_equal %W[gem_name=a platform=#{platform} version=1.0], body
- assert_equal 'key', @fetcher.last_request['Authorization']
+ assert_equal "key", @fetcher.last_request["Authorization"]
assert_equal [yank_uri], @fetcher.paths
end
def test_execute_with_otp_success
- response_fail = 'You have enabled multifactor authentication but your request doesn\'t have the correct OTP code. Please check it and retry.'
- yank_uri = 'http://example/api/v1/gems/yank'
+ response_fail = "You have enabled multifactor authentication but your request doesn't have the correct OTP code. Please check it and retry."
+ yank_uri = "http://example/api/v1/gems/yank"
@fetcher.data[yank_uri] = [
- [response_fail, 401, 'Unauthorized'],
- ['Successfully yanked', 200, 'OK'],
+ [response_fail, 401, "Unauthorized"],
+ ["Successfully yanked", 200, "OK"],
]
@cmd.options[:args] = %w[a]
@cmd.options[:added_platform] = true
- @cmd.options[:version] = req('= 1.0')
+ @cmd.options[:version] = req("= 1.0")
@otp_ui = Gem::MockGemUi.new "111111\n"
use_ui @otp_ui do
@cmd.execute
end
- assert_match 'You have enabled multi-factor authentication. Please enter OTP code.', @otp_ui.output
- assert_match 'Code: ', @otp_ui.output
+ assert_match "You have enabled multi-factor authentication. Please enter OTP code.", @otp_ui.output
+ assert_match "Code: ", @otp_ui.output
assert_match %r{Yanking gem from http://example}, @otp_ui.output
assert_match %r{Successfully yanked}, @otp_ui.output
- assert_equal '111111', @fetcher.last_request['OTP']
+ assert_equal "111111", @fetcher.last_request["OTP"]
end
def test_execute_with_otp_failure
- response = 'You have enabled multifactor authentication but your request doesn\'t have the correct OTP code. Please check it and retry.'
- yank_uri = 'http://example/api/v1/gems/yank'
- @fetcher.data[yank_uri] = [response, 401, 'Unauthorized']
+ response = "You have enabled multifactor authentication but your request doesn't have the correct OTP code. Please check it and retry."
+ yank_uri = "http://example/api/v1/gems/yank"
+ @fetcher.data[yank_uri] = [response, 401, "Unauthorized"]
@cmd.options[:args] = %w[a]
@cmd.options[:added_platform] = true
- @cmd.options[:version] = req('= 1.0')
+ @cmd.options[:version] = req("= 1.0")
@otp_ui = Gem::MockGemUi.new "111111\n"
use_ui @otp_ui do
@cmd.execute
end
- assert_match 'You have enabled multi-factor authentication. Please enter OTP code.', @otp_ui.output
+ assert_match "You have enabled multi-factor authentication. Please enter OTP code.", @otp_ui.output
assert_match response, @otp_ui.output
- assert_match 'Code: ', @otp_ui.output
- assert_equal '111111', @fetcher.last_request['OTP']
+ assert_match "Code: ", @otp_ui.output
+ assert_equal "111111", @fetcher.last_request["OTP"]
end
def test_execute_key
- yank_uri = 'http://example/api/v1/gems/yank'
- @fetcher.data[yank_uri] = ['Successfully yanked', 200, 'OK']
+ yank_uri = "http://example/api/v1/gems/yank"
+ @fetcher.data[yank_uri] = ["Successfully yanked", 200, "OK"]
@cmd.options[:args] = %w[a]
- @cmd.options[:version] = req('= 1.0')
+ @cmd.options[:version] = req("= 1.0")
@cmd.options[:key] = :KEY
use_ui @ui do
@cmd.execute
end
- body = @fetcher.last_request.body.split('&').sort
+ body = @fetcher.last_request.body.split("&").sort
assert_equal %w[gem_name=a version=1.0], body
- assert_equal 'other', @fetcher.last_request['Authorization']
+ assert_equal "other", @fetcher.last_request["Authorization"]
end
def test_execute_host
- host = 'https://other.example'
+ host = "https://other.example"
yank_uri = "#{host}/api/v1/gems/yank"
- @fetcher.data[yank_uri] = ['Successfully yanked', 200, 'OK']
+ @fetcher.data[yank_uri] = ["Successfully yanked", 200, "OK"]
@cmd.options[:args] = %w[a]
- @cmd.options[:version] = req('= 1.0')
+ @cmd.options[:version] = req("= 1.0")
@cmd.options[:host] = host
use_ui @ui do
@@ -142,26 +142,26 @@ class TestGemCommandsYankCommand < Gem::TestCase
assert_match %r{Yanking gem from https://other.example}, @ui.output
assert_match %r{Successfully yanked}, @ui.output
- body = @fetcher.last_request.body.split('&').sort
+ body = @fetcher.last_request.body.split("&").sort
assert_equal %w[gem_name=a version=1.0], body
- assert_equal 'key', @fetcher.last_request['Authorization']
+ assert_equal "key", @fetcher.last_request["Authorization"]
assert_equal [yank_uri], @fetcher.paths
end
def test_yank_gem_unathorized_api_key
response_forbidden = "The API key doesn't have access"
- response_success = 'Successfully yanked'
- host = 'http://example'
+ response_success = "Successfully yanked"
+ host = "http://example"
@fetcher.data["#{host}/api/v1/gems/yank"] = [
- [response_forbidden, 403, 'Forbidden'],
+ [response_forbidden, 403, "Forbidden"],
[response_success, 200, "OK"],
]
@fetcher.data["#{host}/api/v1/api_key"] = ["", 200, "OK"]
@cmd.options[:args] = %w[a]
@cmd.options[:added_platform] = true
- @cmd.options[:version] = req('= 1.0')
+ @cmd.options[:version] = req("= 1.0")
@cmd.instance_variable_set :@host, host
@cmd.instance_variable_set :@scope, :yank_rubygem
diff --git a/test/rubygems/test_gem_config_file.rb b/test/rubygems/test_gem_config_file.rb
index 3e09079df8..e23773a133 100644
--- a/test/rubygems/test_gem_config_file.rb
+++ b/test/rubygems/test_gem_config_file.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/config_file'
+require_relative "helper"
+require "rubygems/config_file"
class TestGemConfigFile < Gem::TestCase
def setup
@@ -8,15 +8,15 @@ class TestGemConfigFile < Gem::TestCase
credential_setup
- @temp_conf = File.join @tempdir, '.gemrc'
+ @temp_conf = File.join @tempdir, ".gemrc"
@cfg_args = %W[--config-file #{@temp_conf}]
Gem::ConfigFile::OPERATING_SYSTEM_DEFAULTS.clear
Gem::ConfigFile::PLATFORM_DEFAULTS.clear
- @env_gemrc = ENV['GEMRC']
- ENV['GEMRC'] = ''
+ @env_gemrc = ENV["GEMRC"]
+ ENV["GEMRC"] = ""
util_config_file
end
@@ -25,7 +25,7 @@ class TestGemConfigFile < Gem::TestCase
Gem::ConfigFile::OPERATING_SYSTEM_DEFAULTS.clear
Gem::ConfigFile::PLATFORM_DEFAULTS.clear
- ENV['GEMRC'] = @env_gemrc
+ ENV["GEMRC"] = @env_gemrc
credential_teardown
@@ -35,7 +35,7 @@ class TestGemConfigFile < Gem::TestCase
def test_initialize
assert_equal @temp_conf, @cfg.config_file_name
- assert_equal false, @cfg.backtrace
+ assert_equal true, @cfg.backtrace
assert_equal true, @cfg.update_sources
assert_equal Gem::ConfigFile::DEFAULT_BULK_THRESHOLD, @cfg.bulk_threshold
assert_equal true, @cfg.verbose
@@ -43,7 +43,7 @@ class TestGemConfigFile < Gem::TestCase
assert_equal 365, @cfg.cert_expiration_length_days
assert_equal false, @cfg.ipv4_fallback_enabled
- File.open @temp_conf, 'w' do |fp|
+ File.open @temp_conf, "w" do |fp|
fp.puts ":backtrace: true"
fp.puts ":update_sources: false"
fp.puts ":bulk_threshold: 10"
@@ -66,17 +66,17 @@ class TestGemConfigFile < Gem::TestCase
assert_equal false, @cfg.verbose
assert_equal false, @cfg.update_sources
assert_equal %w[http://more-gems.example.com], @cfg.sources
- assert_equal '--wrappers', @cfg[:install]
- assert_equal(['/usr/ruby/1.8/lib/ruby/gems/1.8', '/var/ruby/1.8/gem_home'],
+ assert_equal "--wrappers", @cfg[:install]
+ assert_equal(["/usr/ruby/1.8/lib/ruby/gems/1.8", "/var/ruby/1.8/gem_home"],
@cfg.path)
assert_equal 0, @cfg.ssl_verify_mode
- assert_equal '/etc/ssl/certs', @cfg.ssl_ca_cert
+ assert_equal "/etc/ssl/certs", @cfg.ssl_ca_cert
assert_equal 28, @cfg.cert_expiration_length_days
assert_equal true, @cfg.ipv4_fallback_enabled
end
def test_initialize_ipv4_fallback_enabled_env
- ENV['IPV4_FALLBACK_ENABLED'] = 'true'
+ ENV["IPV4_FALLBACK_ENABLED"] = "true"
util_config_file %W[--config-file #{@temp_conf}]
assert_equal true, @cfg.ipv4_fallback_enabled
@@ -102,37 +102,37 @@ class TestGemConfigFile < Gem::TestCase
def test_initialize_operating_system_override
Gem::ConfigFile::OPERATING_SYSTEM_DEFAULTS[:bulk_threshold] = 1
- Gem::ConfigFile::OPERATING_SYSTEM_DEFAULTS['install'] = '--no-env-shebang'
+ Gem::ConfigFile::OPERATING_SYSTEM_DEFAULTS["install"] = "--no-env-shebang"
Gem::ConfigFile::PLATFORM_DEFAULTS[:bulk_threshold] = 2
util_config_file
assert_equal 2, @cfg.bulk_threshold
- assert_equal '--no-env-shebang', @cfg[:install]
+ assert_equal "--no-env-shebang", @cfg[:install]
end
def test_initialize_platform_override
Gem::ConfigFile::PLATFORM_DEFAULTS[:bulk_threshold] = 2
- Gem::ConfigFile::PLATFORM_DEFAULTS['install'] = '--no-env-shebang'
+ Gem::ConfigFile::PLATFORM_DEFAULTS["install"] = "--no-env-shebang"
- File.open Gem::ConfigFile::SYSTEM_WIDE_CONFIG_FILE, 'w' do |fp|
+ File.open Gem::ConfigFile::SYSTEM_WIDE_CONFIG_FILE, "w" do |fp|
fp.puts ":bulk_threshold: 3"
end
util_config_file
assert_equal 3, @cfg.bulk_threshold
- assert_equal '--no-env-shebang', @cfg[:install]
+ assert_equal "--no-env-shebang", @cfg[:install]
end
def test_initialize_system_wide_override
- File.open Gem::ConfigFile::SYSTEM_WIDE_CONFIG_FILE, 'w' do |fp|
+ File.open Gem::ConfigFile::SYSTEM_WIDE_CONFIG_FILE, "w" do |fp|
fp.puts ":backtrace: false"
fp.puts ":bulk_threshold: 2048"
end
- File.open @temp_conf, 'w' do |fp|
+ File.open @temp_conf, "w" do |fp|
fp.puts ":backtrace: true"
end
@@ -143,28 +143,28 @@ class TestGemConfigFile < Gem::TestCase
end
def test_initialize_environment_variable_override
- File.open Gem::ConfigFile::SYSTEM_WIDE_CONFIG_FILE, 'w' do |fp|
- fp.puts ':backtrace: false'
- fp.puts ':verbose: false'
- fp.puts ':bulk_threshold: 2048'
+ File.open Gem::ConfigFile::SYSTEM_WIDE_CONFIG_FILE, "w" do |fp|
+ fp.puts ":backtrace: false"
+ fp.puts ":verbose: false"
+ fp.puts ":bulk_threshold: 2048"
end
- conf1 = File.join @tempdir, 'gemrc1'
- File.open conf1, 'w' do |fp|
- fp.puts ':backtrace: true'
+ conf1 = File.join @tempdir, "gemrc1"
+ File.open conf1, "w" do |fp|
+ fp.puts ":backtrace: true"
end
- conf2 = File.join @tempdir, 'gemrc2'
- File.open conf2, 'w' do |fp|
- fp.puts ':verbose: true'
+ conf2 = File.join @tempdir, "gemrc2"
+ File.open conf2, "w" do |fp|
+ fp.puts ":verbose: true"
end
- conf3 = File.join @tempdir, 'gemrc3'
- File.open conf3, 'w' do |fp|
- fp.puts ':verbose: :loud'
+ conf3 = File.join @tempdir, "gemrc3"
+ File.open conf3, "w" do |fp|
+ fp.puts ":verbose: :loud"
end
ps = File::PATH_SEPARATOR
- ENV['GEMRC'] = conf1 + ps + conf2 + ps + conf3
+ ENV["GEMRC"] = conf1 + ps + conf2 + ps + conf3
util_config_file
@@ -174,7 +174,7 @@ class TestGemConfigFile < Gem::TestCase
end
def test_set_config_file_name_from_environment_variable
- ENV['GEMRC'] = "/tmp/.gemrc"
+ ENV["GEMRC"] = "/tmp/.gemrc"
cfg = Gem::ConfigFile.new([])
assert_equal cfg.config_file_name, "/tmp/.gemrc"
end
@@ -182,22 +182,22 @@ class TestGemConfigFile < Gem::TestCase
def test_api_keys
assert_nil @cfg.instance_variable_get :@api_keys
- temp_cred = File.join Gem.user_home, '.gem', 'credentials'
+ temp_cred = File.join Gem.user_home, ".gem", "credentials"
FileUtils.mkdir_p File.dirname(temp_cred)
- File.open temp_cred, 'w', 0600 do |fp|
- fp.puts ':rubygems_api_key: 701229f217cdf23b1344c7b4b54ca97'
+ File.open temp_cred, "w", 0600 do |fp|
+ fp.puts ":rubygems_api_key: 701229f217cdf23b1344c7b4b54ca97"
end
util_config_file
- assert_equal({ :rubygems => '701229f217cdf23b1344c7b4b54ca97' },
+ assert_equal({ :rubygems => "701229f217cdf23b1344c7b4b54ca97" },
@cfg.api_keys)
end
def test_check_credentials_permissions
- pend 'chmod not supported' if win_platform?
+ pend "chmod not supported" if win_platform?
- @cfg.rubygems_api_key = 'x'
+ @cfg.rubygems_api_key = "x"
File.chmod 0644, @cfg.credentials_path
@@ -239,6 +239,12 @@ if you believe they were disclosed to a third party.
end
def test_handle_arguments_backtrace
+ File.open @temp_conf, "w" do |fp|
+ fp.puts ":backtrace: false"
+ end
+
+ util_config_file %W[--config-file=#{@temp_conf}]
+
assert_equal false, @cfg.backtrace
args = %w[--backtrace]
@@ -257,7 +263,7 @@ if you believe they were disclosed to a third party.
@cfg.handle_arguments args
end
- assert_match 'NOTE', err
+ assert_match "NOTE", err
assert_equal true, $DEBUG
ensure
@@ -265,7 +271,7 @@ if you believe they were disclosed to a third party.
end
def test_handle_arguments_override
- File.open @temp_conf, 'w' do |fp|
+ File.open @temp_conf, "w" do |fp|
fp.puts ":backtrace: false"
end
@@ -275,6 +281,12 @@ if you believe they were disclosed to a third party.
end
def test_handle_arguments_traceback
+ File.open @temp_conf, "w" do |fp|
+ fp.puts ":backtrace: false"
+ end
+
+ util_config_file %W[--config-file=#{@temp_conf}]
+
assert_equal false, @cfg.backtrace
args = %w[--traceback]
@@ -287,8 +299,8 @@ if you believe they were disclosed to a third party.
def test_handle_arguments_norc
assert_equal @temp_conf, @cfg.config_file_name
- File.open @temp_conf, 'w' do |fp|
- fp.puts ":backtrace: true"
+ File.open @temp_conf, "w" do |fp|
+ fp.puts ":backtrace: false"
fp.puts ":update_sources: false"
fp.puts ":bulk_threshold: 10"
fp.puts ":verbose: false"
@@ -300,7 +312,7 @@ if you believe they were disclosed to a third party.
util_config_file args
- assert_equal false, @cfg.backtrace
+ assert_equal true, @cfg.backtrace
assert_equal true, @cfg.update_sources
assert_equal Gem::ConfigFile::DEFAULT_BULK_THRESHOLD, @cfg.bulk_threshold
assert_equal true, @cfg.verbose
@@ -308,23 +320,23 @@ if you believe they were disclosed to a third party.
end
def test_load_api_keys
- temp_cred = File.join Gem.user_home, '.gem', 'credentials'
+ temp_cred = File.join Gem.user_home, ".gem", "credentials"
FileUtils.mkdir_p File.dirname(temp_cred)
- File.open temp_cred, 'w', 0600 do |fp|
+ File.open temp_cred, "w", 0600 do |fp|
fp.puts ":rubygems_api_key: 701229f217cdf23b1344c7b4b54ca97"
fp.puts ":other: a5fdbb6ba150cbb83aad2bb2fede64c"
end
util_config_file
- assert_equal({ :rubygems => '701229f217cdf23b1344c7b4b54ca97',
- :other => 'a5fdbb6ba150cbb83aad2bb2fede64c' }, @cfg.api_keys)
+ assert_equal({ :rubygems => "701229f217cdf23b1344c7b4b54ca97",
+ :other => "a5fdbb6ba150cbb83aad2bb2fede64c" }, @cfg.api_keys)
end
def test_load_api_keys_bad_permission
- pend 'chmod not supported' if win_platform?
+ pend "chmod not supported" if win_platform?
- @cfg.rubygems_api_key = 'x'
+ @cfg.rubygems_api_key = "x"
File.chmod 0644, @cfg.credentials_path
@@ -346,12 +358,12 @@ if you believe they were disclosed to a third party.
end
def test_rubygems_api_key_equals
- @cfg.rubygems_api_key = 'x'
+ @cfg.rubygems_api_key = "x"
- assert_equal 'x', @cfg.rubygems_api_key
+ assert_equal "x", @cfg.rubygems_api_key
expected = {
- :rubygems_api_key => 'x',
+ :rubygems_api_key => "x",
}
assert_equal expected, load_yaml_file(@cfg.credentials_path)
@@ -364,18 +376,18 @@ if you believe they were disclosed to a third party.
end
def test_rubygems_api_key_equals_bad_permission
- pend 'chmod not supported' if win_platform?
+ pend "chmod not supported" if win_platform?
- @cfg.rubygems_api_key = 'x'
+ @cfg.rubygems_api_key = "x"
File.chmod 0644, @cfg.credentials_path
assert_raise Gem::MockGemUi::TermError do
- @cfg.rubygems_api_key = 'y'
+ @cfg.rubygems_api_key = "y"
end
expected = {
- :rubygems_api_key => 'x',
+ :rubygems_api_key => "x",
}
assert_equal expected, load_yaml_file(@cfg.credentials_path)
@@ -386,32 +398,32 @@ if you believe they were disclosed to a third party.
end
def test_write
- @cfg.backtrace = true
+ @cfg.backtrace = false
@cfg.update_sources = false
@cfg.bulk_threshold = 10
@cfg.verbose = false
Gem.sources.replace %w[http://more-gems.example.com]
- @cfg[:install] = '--wrappers'
+ @cfg[:install] = "--wrappers"
@cfg.write
util_config_file
# These should not be written out to the config file.
- assert_equal false, @cfg.backtrace, 'backtrace'
+ assert_equal true, @cfg.backtrace, "backtrace"
assert_equal Gem::ConfigFile::DEFAULT_BULK_THRESHOLD, @cfg.bulk_threshold,
- 'bulk_threshold'
- assert_equal true, @cfg.update_sources, 'update_sources'
- assert_equal true, @cfg.verbose, 'verbose'
+ "bulk_threshold"
+ assert_equal true, @cfg.update_sources, "update_sources"
+ assert_equal true, @cfg.verbose, "verbose"
- assert_equal '--wrappers', @cfg[:install], 'install'
+ assert_equal "--wrappers", @cfg[:install], "install"
# this should be written out to the config file.
assert_equal %w[http://more-gems.example.com], Gem.sources
end
def test_write_from_hash
- File.open @temp_conf, 'w' do |fp|
+ File.open @temp_conf, "w" do |fp|
fp.puts ":backtrace: true"
fp.puts ":bulk_threshold: 10"
fp.puts ":update_sources: false"
@@ -431,29 +443,29 @@ if you believe they were disclosed to a third party.
@cfg.bulk_threshold = 20
@cfg.verbose = :junk
Gem.sources.replace %w[http://even-more-gems.example.com]
- @cfg[:install] = '--wrappers --no-rdoc'
+ @cfg[:install] = "--wrappers --no-rdoc"
@cfg.write
util_config_file
# These should not be written out to the config file
- assert_equal true, @cfg.backtrace, 'backtrace'
- assert_equal 10, @cfg.bulk_threshold, 'bulk_threshold'
- assert_equal false, @cfg.update_sources, 'update_sources'
- assert_equal false, @cfg.verbose, 'verbose'
+ assert_equal true, @cfg.backtrace, "backtrace"
+ assert_equal 10, @cfg.bulk_threshold, "bulk_threshold"
+ assert_equal false, @cfg.update_sources, "update_sources"
+ assert_equal false, @cfg.verbose, "verbose"
assert_equal 2, @cfg.ssl_verify_mode
- assert_equal '/nonexistent/ca_cert.pem', @cfg.ssl_ca_cert
- assert_equal '/nonexistent/client_cert.pem', @cfg.ssl_client_cert
+ assert_equal "/nonexistent/ca_cert.pem", @cfg.ssl_ca_cert
+ assert_equal "/nonexistent/client_cert.pem", @cfg.ssl_client_cert
- assert_equal '--wrappers --no-rdoc', @cfg[:install], 'install'
+ assert_equal "--wrappers --no-rdoc", @cfg[:install], "install"
assert_equal %w[http://even-more-gems.example.com], Gem.sources
end
def test_ignore_invalid_config_file
- File.open @temp_conf, 'w' do |fp|
+ File.open @temp_conf, "w" do |fp|
fp.puts "invalid: yaml:"
end
@@ -467,7 +479,7 @@ if you believe they were disclosed to a third party.
end
def test_load_ssl_verify_mode_from_config
- File.open @temp_conf, 'w' do |fp|
+ File.open @temp_conf, "w" do |fp|
fp.puts ":ssl_verify_mode: 1"
end
util_config_file
@@ -475,19 +487,19 @@ if you believe they were disclosed to a third party.
end
def test_load_ssl_ca_cert_from_config
- File.open @temp_conf, 'w' do |fp|
+ File.open @temp_conf, "w" do |fp|
fp.puts ":ssl_ca_cert: /home/me/certs"
end
util_config_file
- assert_equal('/home/me/certs', @cfg.ssl_ca_cert)
+ assert_equal("/home/me/certs", @cfg.ssl_ca_cert)
end
def test_load_ssl_client_cert_from_config
- File.open @temp_conf, 'w' do |fp|
+ File.open @temp_conf, "w" do |fp|
fp.puts ":ssl_client_cert: /home/me/mine.pem"
end
util_config_file
- assert_equal('/home/me/mine.pem', @cfg.ssl_client_cert)
+ assert_equal("/home/me/mine.pem", @cfg.ssl_client_cert)
end
def util_config_file(args = @cfg_args)
@@ -495,7 +507,7 @@ if you believe they were disclosed to a third party.
end
def test_disable_default_gem_server
- File.open @temp_conf, 'w' do |fp|
+ File.open @temp_conf, "w" do |fp|
fp.puts ":disable_default_gem_server: true"
end
util_config_file
diff --git a/test/rubygems/test_gem_dependency.rb b/test/rubygems/test_gem_dependency.rb
index 5551966da2..c585e87087 100644
--- a/test/rubygems/test_gem_dependency.rb
+++ b/test/rubygems/test_gem_dependency.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/dependency'
+require_relative "helper"
+require "rubygems/dependency"
class TestGemDependency < Gem::TestCase
def setup
@@ -18,7 +18,7 @@ class TestGemDependency < Gem::TestCase
def test_initialize_type_bad
e = assert_raise ArgumentError do
- Gem::Dependency.new 'monkey' => '1.0'
+ Gem::Dependency.new "monkey" => "1.0"
end
assert_equal 'dependency name must be a String, was {"monkey"=>"1.0"}',
@@ -36,11 +36,11 @@ class TestGemDependency < Gem::TestCase
end
def test_initialize_prerelease
- d = dep 'd', '1.a'
+ d = dep "d", "1.a"
assert d.prerelease?
- d = dep 'd', '= 1.a'
+ d = dep "d", "= 1.a"
assert d.prerelease?
end
@@ -105,8 +105,8 @@ class TestGemDependency < Gem::TestCase
def test_equals_tilde_object
o = Object.new
- def o.name ; 'a' end
- def o.version ; '0' end
+ def o.name ; "a" end
+ def o.version ; "0" end
assert_match dep("a"), o
end
@@ -133,142 +133,142 @@ class TestGemDependency < Gem::TestCase
end
def test_match_eh_name_tuple
- a_dep = dep 'a'
+ a_dep = dep "a"
- a_tup = Gem::NameTuple.new 'a', 1
- b_tup = Gem::NameTuple.new 'b', 2
- c_tup = Gem::NameTuple.new 'c', '2.a'
+ a_tup = Gem::NameTuple.new "a", 1
+ b_tup = Gem::NameTuple.new "b", 2
+ c_tup = Gem::NameTuple.new "c", "2.a"
assert a_dep.match? a_tup
refute a_dep.match? b_tup
- b_dep = dep 'b', '>= 3'
+ b_dep = dep "b", ">= 3"
refute b_dep.match? b_tup
- c_dep = dep 'c', '>= 1'
+ c_dep = dep "c", ">= 1"
refute c_dep.match? c_tup
- c_dep = dep 'c'
+ c_dep = dep "c"
refute c_dep.match? c_tup
- c_dep = dep 'c', '2.a'
+ c_dep = dep "c", "2.a"
assert c_dep.match? c_tup
end
def test_match_eh_allow_prerelease
- a_dep = dep 'a'
+ a_dep = dep "a"
- a_tup = Gem::NameTuple.new 'a', 1
- b_tup = Gem::NameTuple.new 'b', 2
- c_tup = Gem::NameTuple.new 'c', '2.a'
+ a_tup = Gem::NameTuple.new "a", 1
+ b_tup = Gem::NameTuple.new "b", 2
+ c_tup = Gem::NameTuple.new "c", "2.a"
assert a_dep.match? a_tup, nil, true
refute a_dep.match? b_tup, nil, true
- b_dep = dep 'b', '>= 3'
+ b_dep = dep "b", ">= 3"
refute b_dep.match? b_tup, nil, true
- c_dep = dep 'c', '>= 1'
+ c_dep = dep "c", ">= 1"
assert c_dep.match? c_tup, nil, true
- c_dep = dep 'c'
+ c_dep = dep "c"
assert c_dep.match? c_tup, nil, true
- c_dep = dep 'c', '2.a'
+ c_dep = dep "c", "2.a"
assert c_dep.match? c_tup, nil, true
end
def test_match_eh_specification
- a_dep = dep 'a'
+ a_dep = dep "a"
- a_spec = util_spec 'a', 1
- b_spec = util_spec 'b', 2
- c_spec = util_spec 'c', '2.a'
+ a_spec = util_spec "a", 1
+ b_spec = util_spec "b", 2
+ c_spec = util_spec "c", "2.a"
assert a_dep.match? a_spec
refute a_dep.match? b_spec
- b_dep = dep 'b', '>= 3'
+ b_dep = dep "b", ">= 3"
refute b_dep.match? b_spec
- c_dep = dep 'c', '>= 1'
+ c_dep = dep "c", ">= 1"
refute c_dep.match? c_spec
- c_dep = dep 'c'
+ c_dep = dep "c"
refute c_dep.match? c_spec
- c_dep = dep 'c', '2.a'
+ c_dep = dep "c", "2.a"
assert c_dep.match? c_spec
end
def test_matches_spec_eh
- spec = util_spec 'b', 2
+ spec = util_spec "b", 2
- refute dep('a') .matches_spec?(spec), 'name mismatch'
- assert dep('b') .matches_spec?(spec), 'name match'
- refute dep('b', '= 1') .matches_spec?(spec), 'requirement mismatch'
- assert dep('b', '~> 2').matches_spec?(spec), 'requirement match'
+ refute dep("a") .matches_spec?(spec), "name mismatch"
+ assert dep("b") .matches_spec?(spec), "name match"
+ refute dep("b", "= 1") .matches_spec?(spec), "requirement mismatch"
+ assert dep("b", "~> 2").matches_spec?(spec), "requirement match"
end
def test_matches_spec_eh_prerelease
- spec = util_spec 'b', '2.1.a'
+ spec = util_spec "b", "2.1.a"
- refute dep('a') .matches_spec?(spec), 'name mismatch'
- assert dep('b') .matches_spec?(spec), 'name match'
- refute dep('b', '= 1') .matches_spec?(spec), 'requirement mismatch'
- assert dep('b', '~> 2') .matches_spec?(spec), 'requirement match'
- assert dep('b', '~> 2.a').matches_spec?(spec), 'prerelease requirement'
+ refute dep("a") .matches_spec?(spec), "name mismatch"
+ assert dep("b") .matches_spec?(spec), "name match"
+ refute dep("b", "= 1") .matches_spec?(spec), "requirement mismatch"
+ assert dep("b", "~> 2") .matches_spec?(spec), "requirement match"
+ assert dep("b", "~> 2.a").matches_spec?(spec), "prerelease requirement"
end
def test_merge
- a1 = dep 'a', '~> 1.0'
- a2 = dep 'a', '= 1.0'
+ a1 = dep "a", "~> 1.0"
+ a2 = dep "a", "= 1.0"
a3 = a1.merge a2
- assert_equal dep('a', '~> 1.0', '= 1.0'), a3
+ assert_equal dep("a", "~> 1.0", "= 1.0"), a3
end
def test_merge_default
- a1 = dep 'a'
- a2 = dep 'a', '1'
+ a1 = dep "a"
+ a2 = dep "a", "1"
a3 = a1.merge a2
- assert_equal dep('a', '1'), a3
+ assert_equal dep("a", "1"), a3
end
def test_merge_name_mismatch
- a = dep 'a'
- b = dep 'b'
+ a = dep "a"
+ b = dep "b"
e = assert_raise ArgumentError do
a.merge b
end
- assert_equal 'a (>= 0) and b (>= 0) have different names',
+ assert_equal "a (>= 0) and b (>= 0) have different names",
e.message
end
def test_merge_other_default
- a1 = dep 'a', '1'
- a2 = dep 'a'
+ a1 = dep "a", "1"
+ a2 = dep "a"
a3 = a1.merge a2
- assert_equal dep('a', '1'), a3
+ assert_equal dep("a", "1"), a3
end
def test_prerelease_eh
@@ -294,44 +294,44 @@ class TestGemDependency < Gem::TestCase
end
def test_specific
- refute dep('a', '> 1').specific?
+ refute dep("a", "> 1").specific?
- assert dep('a', '= 1').specific?
+ assert dep("a", "= 1").specific?
end
def test_to_spec
- a_1 = util_spec 'a', '1'
- a_2 = util_spec 'a', '2'
+ a_1 = util_spec "a", "1"
+ a_2 = util_spec "a", "2"
- a_dep = dep 'a', '>= 0'
+ a_dep = dep "a", ">= 0"
install_specs a_1, a_2
assert_equal a_2, a_dep.to_spec
end
def test_to_spec_prerelease
- a_1 = util_spec 'a', '1'
- a_1_1_a = util_spec 'a', '1.1.a'
+ a_1 = util_spec "a", "1"
+ a_1_1_a = util_spec "a", "1.1.a"
- a_dep = dep 'a', '>= 0'
+ a_dep = dep "a", ">= 0"
install_specs a_1, a_1_1_a
assert_equal a_1, a_dep.to_spec
- a_pre_dep = dep 'a', '>= 0'
+ a_pre_dep = dep "a", ">= 0"
a_pre_dep.prerelease = true
assert_equal a_1_1_a, a_pre_dep.to_spec
end
def test_to_specs_suggests_other_versions
- a = util_spec 'a', '1.0'
+ a = util_spec "a", "1.0"
install_specs a
- a_file = File.join a.gem_dir, 'lib', 'a_file.rb'
+ a_file = File.join a.gem_dir, "lib", "a_file.rb"
write_file a_file do |io|
- io.puts '# a_file.rb'
+ io.puts "# a_file.rb"
end
dep = Gem::Dependency.new "a", "= 2.0"
@@ -344,14 +344,14 @@ class TestGemDependency < Gem::TestCase
end
def test_to_specs_respects_bundler_version
- b = util_spec 'bundler', '2.0.0.pre.1'
- b_1 = util_spec 'bundler', '1'
+ b = util_spec "bundler", "2.0.0.pre.1"
+ b_1 = util_spec "bundler", "1"
install_specs b, b_1
- b_file = File.join b.gem_dir, 'lib', 'bundler', 'setup.rb'
+ b_file = File.join b.gem_dir, "lib", "bundler", "setup.rb"
write_file b_file do |io|
- io.puts '# setup.rb'
+ io.puts "# setup.rb"
end
dep = Gem::Dependency.new "bundler", ">= 0.a"
@@ -368,13 +368,13 @@ class TestGemDependency < Gem::TestCase
end
def test_to_specs_indicates_total_gem_set_size
- a = util_spec 'a', '1.0'
+ a = util_spec "a", "1.0"
install_specs a
- a_file = File.join a.gem_dir, 'lib', 'a_file.rb'
+ a_file = File.join a.gem_dir, "lib", "a_file.rb"
write_file a_file do |io|
- io.puts '# a_file.rb'
+ io.puts "# a_file.rb"
end
dep = Gem::Dependency.new "b", "= 2.0"
diff --git a/test/rubygems/test_gem_dependency_installer.rb b/test/rubygems/test_gem_dependency_installer.rb
index f2404d61c7..2b0b874b2d 100644
--- a/test/rubygems/test_gem_dependency_installer.rb
+++ b/test/rubygems/test_gem_dependency_installer.rb
@@ -1,15 +1,15 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/dependency_installer'
-require 'rubygems/security'
+require_relative "helper"
+require "rubygems/dependency_installer"
+require "rubygems/security"
class TestGemDependencyInstaller < Gem::TestCase
def setup
super
common_installer_setup
- @gems_dir = File.join @tempdir, 'gems'
- @cache_dir = File.join @gemhome, 'cache'
+ @gems_dir = File.join @tempdir, "gems"
+ @cache_dir = File.join @gemhome, "cache"
FileUtils.mkdir @gems_dir
@@ -25,23 +25,23 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def util_setup_gems
- @a1, @a1_gem = util_gem 'a', '1' do |s|
- s.executables << 'a_bin'
+ @a1, @a1_gem = util_gem "a", "1" do |s|
+ s.executables << "a_bin"
end
- @a1_pre, @a1_pre_gem = util_gem 'a', '1.a'
+ @a1_pre, @a1_pre_gem = util_gem "a", "1.a"
- @b1, @b1_gem = util_gem 'b', '1' do |s|
- s.add_dependency 'a'
- s.add_development_dependency 'aa'
+ @b1, @b1_gem = util_gem "b", "1" do |s|
+ s.add_dependency "a"
+ s.add_development_dependency "aa"
end
- @c1, @c1_gem = util_gem 'c', '1' do |s|
- s.add_development_dependency 'b'
+ @c1, @c1_gem = util_gem "c", "1" do |s|
+ s.add_development_dependency "b"
end
- @d1, @d1_gem = util_gem 'd', '1' do |s|
- s.add_development_dependency 'c'
+ @d1, @d1_gem = util_gem "d", "1" do |s|
+ s.add_development_dependency "c"
end
util_setup_spec_fetcher(@a1, @a1_pre, @b1, @d1)
@@ -55,7 +55,7 @@ class TestGemDependencyInstaller < Gem::TestCase
Dir.chdir @tempdir do
inst = Gem::DependencyInstaller.new
- inst.install 'a'
+ inst.install "a"
end
assert_equal %w[a-1], Gem::Specification.map(&:full_name)
@@ -65,13 +65,13 @@ class TestGemDependencyInstaller < Gem::TestCase
def test_install_prerelease
util_setup_gems
- p1a, gem = util_gem 'a', '10.a'
+ p1a, gem = util_gem "a", "10.a"
util_setup_spec_fetcher(p1a, @a1, @a1_pre)
p1a_data = Gem.read_binary(gem)
- @fetcher.data['http://gems.example.com/gems/a-10.a.gem'] = p1a_data
+ @fetcher.data["http://gems.example.com/gems/a-10.a.gem"] = p1a_data
dep = Gem::Dependency.new "a"
inst = Gem::DependencyInstaller.new :prerelease => true
@@ -83,18 +83,18 @@ class TestGemDependencyInstaller < Gem::TestCase
def test_install_prerelease_bug_990
spec_fetcher do |fetcher|
- fetcher.gem 'a', '1.b' do |s|
- s.add_dependency 'b', '~> 1.a'
+ fetcher.gem "a", "1.b" do |s|
+ s.add_dependency "b", "~> 1.a"
end
- fetcher.gem 'b', '1.b' do |s|
- s.add_dependency 'c', '>= 1'
+ fetcher.gem "b", "1.b" do |s|
+ s.add_dependency "c", ">= 1"
end
- fetcher.gem 'c', '1.1.b'
+ fetcher.gem "c", "1.1.b"
end
- dep = Gem::Dependency.new 'a'
+ dep = Gem::Dependency.new "a"
inst = Gem::DependencyInstaller.new :prerelease => true
inst.install dep
@@ -103,13 +103,13 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_install_when_only_prerelease
- p1a, gem = util_gem 'p', '1.a'
+ p1a, gem = util_gem "p", "1.a"
util_setup_spec_fetcher(p1a)
p1a_data = Gem.read_binary(gem)
- @fetcher.data['http://gems.example.com/gems/p-1.a.gem'] = p1a_data
+ @fetcher.data["http://gems.example.com/gems/p-1.a.gem"] = p1a_data
dep = Gem::Dependency.new "p"
inst = Gem::DependencyInstaller.new
@@ -128,7 +128,7 @@ class TestGemDependencyInstaller < Gem::TestCase
p1a_data = Gem.read_binary(@a1_gem)
- @fetcher.data['http://gems.example.com/gems/a-1.gem'] = p1a_data
+ @fetcher.data["http://gems.example.com/gems/a-1.gem"] = p1a_data
dep = Gem::Dependency.new "a"
inst = Gem::DependencyInstaller.new :prerelease => true
@@ -141,8 +141,8 @@ class TestGemDependencyInstaller < Gem::TestCase
def test_install_all_dependencies
util_setup_gems
- _, e1_gem = util_gem 'e', '1' do |s|
- s.add_dependency 'b'
+ _, e1_gem = util_gem "e", "1" do |s|
+ s.add_dependency "b"
end
FileUtils.mv @a1_gem, @tempdir
@@ -153,15 +153,15 @@ class TestGemDependencyInstaller < Gem::TestCase
Dir.chdir @tempdir do
inst = Gem::DependencyInstaller.new :ignore_dependencies => true
- inst.install 'b'
+ inst.install "b"
end
assert_equal %w[b-1], inst.installed_gems.map {|s| s.full_name },
- 'sanity check'
+ "sanity check"
Dir.chdir @tempdir do
inst = Gem::DependencyInstaller.new
- inst.install 'e'
+ inst.install "e"
end
assert_equal %w[a-1 e-1], inst.installed_gems.map {|s| s.full_name }
@@ -178,7 +178,7 @@ class TestGemDependencyInstaller < Gem::TestCase
Dir.chdir dir do
inst = Gem::DependencyInstaller.new :cache_dir => @tempdir
- inst.install 'b'
+ inst.install "b"
end
assert_equal %w[a-1 b-1], inst.installed_gems.map {|s| s.full_name }
@@ -190,9 +190,9 @@ class TestGemDependencyInstaller < Gem::TestCase
def test_install_dependencies_satisfied
util_setup_gems
- a2, a2_gem = util_gem 'a', '2'
+ a2, a2_gem = util_gem "a", "2"
- FileUtils.rm_rf File.join(@gemhome, 'gems')
+ FileUtils.rm_rf File.join(@gemhome, "gems")
Gem::Specification.reset
@@ -203,17 +203,17 @@ class TestGemDependencyInstaller < Gem::TestCase
Dir.chdir @tempdir do
inst = Gem::DependencyInstaller.new
- inst.install 'a', req("= 2")
+ inst.install "a", req("= 2")
end
assert_equal %w[a-2], inst.installed_gems.map {|s| s.full_name },
- 'sanity check'
+ "sanity check"
FileUtils.rm File.join(@tempdir, a2.file_name)
Dir.chdir @tempdir do
inst = Gem::DependencyInstaller.new
- inst.install 'b'
+ inst.install "b"
end
assert_equal %w[a-2 b-1], Gem::Specification.map(&:full_name)
@@ -226,12 +226,12 @@ class TestGemDependencyInstaller < Gem::TestCase
def test_install_doesnt_upgrade_installed_dependencies
util_setup_gems
- a2, a2_gem = util_gem 'a', '2'
- a3, a3_gem = util_gem 'a', '3'
+ a2, a2_gem = util_gem "a", "2"
+ a3, a3_gem = util_gem "a", "3"
util_setup_spec_fetcher @a1, a3, @b1
- FileUtils.rm_rf File.join(@gemhome, 'gems')
+ FileUtils.rm_rf File.join(@gemhome, "gems")
Gem::Specification.reset
@@ -241,7 +241,7 @@ class TestGemDependencyInstaller < Gem::TestCase
FileUtils.mv a3_gem, @tempdir
Dir.chdir @tempdir do
- Gem::DependencyInstaller.new.install 'a', req("= 2")
+ Gem::DependencyInstaller.new.install "a", req("= 2")
end
FileUtils.rm File.join(@tempdir, a2.file_name)
@@ -250,7 +250,7 @@ class TestGemDependencyInstaller < Gem::TestCase
Dir.chdir @tempdir do
inst = Gem::DependencyInstaller.new
- inst.install 'b'
+ inst.install "b"
end
assert_equal %w[a-2 b-1], Gem::Specification.map(&:full_name)
@@ -274,18 +274,18 @@ class TestGemDependencyInstaller < Gem::TestCase
Dir.chdir @tempdir do
inst = Gem::DependencyInstaller.new(:build_docs_in_background => false)
- inst.install 'b'
+ inst.install "b"
end
assert_equal %w[a-1 b-1], inst.installed_gems.map {|s| s.full_name }
- assert done_installing_ran, 'post installs hook was not run'
+ assert done_installing_ran, "post installs hook was not run"
end
def test_install_dependency_development
util_setup_gems
- @aa1, @aa1_gem = util_gem 'aa', '1'
+ @aa1, @aa1_gem = util_gem "aa", "1"
FileUtils.mv @a1_gem, @tempdir
FileUtils.mv @aa1_gem, @tempdir
@@ -294,7 +294,7 @@ class TestGemDependencyInstaller < Gem::TestCase
Dir.chdir @tempdir do
inst = Gem::DependencyInstaller.new(:development => true)
- inst.install 'b'
+ inst.install "b"
end
assert_equal %w[a-1 aa-1 b-1], inst.installed_gems.map {|s| s.full_name }
@@ -303,7 +303,7 @@ class TestGemDependencyInstaller < Gem::TestCase
def test_install_dependency_development_deep
util_setup_gems
- @aa1, @aa1_gem = util_gem 'aa', '1'
+ @aa1, @aa1_gem = util_gem "aa", "1"
FileUtils.mv @a1_gem, @tempdir
FileUtils.mv @aa1_gem, @tempdir
@@ -314,7 +314,7 @@ class TestGemDependencyInstaller < Gem::TestCase
Dir.chdir @tempdir do
inst = Gem::DependencyInstaller.new(:development => true)
- inst.install 'd'
+ inst.install "d"
end
assert_equal %w[a-1 aa-1 b-1 c-1 d-1], inst.installed_gems.map {|s| s.full_name }
@@ -323,7 +323,7 @@ class TestGemDependencyInstaller < Gem::TestCase
def test_install_dependency_development_shallow
util_setup_gems
- @aa1, @aa1_gem = util_gem 'aa', '1'
+ @aa1, @aa1_gem = util_gem "aa", "1"
FileUtils.mv @a1_gem, @tempdir
FileUtils.mv @aa1_gem, @tempdir
@@ -334,7 +334,7 @@ class TestGemDependencyInstaller < Gem::TestCase
Dir.chdir @tempdir do
inst = Gem::DependencyInstaller.new(:development => true, :dev_shallow => true)
- inst.install 'd'
+ inst.install "d"
end
assert_equal %w[c-1 d-1], inst.installed_gems.map {|s| s.full_name }
@@ -350,29 +350,29 @@ class TestGemDependencyInstaller < Gem::TestCase
Dir.chdir @tempdir do
inst = Gem::DependencyInstaller.new
- inst.install 'b'
+ inst.install "b"
end
assert_equal %w[b-1], inst.installed_gems.map {|s| s.full_name }
end
def test_install_dependency_existing_extension
- extconf_rb = File.join @gemhome, 'gems', 'e-1', 'extconf.rb'
+ extconf_rb = File.join @gemhome, "gems", "e-1", "extconf.rb"
FileUtils.mkdir_p File.dirname extconf_rb
- File.open extconf_rb, 'w' do |io|
+ File.open extconf_rb, "w" do |io|
io.write <<-EXTCONF_RB
require 'mkmf'
create_makefile 'e'
EXTCONF_RB
end
- e1 = util_spec 'e', '1', nil, 'extconf.rb' do |s|
- s.extensions << 'extconf.rb'
+ e1 = util_spec "e", "1", nil, "extconf.rb" do |s|
+ s.extensions << "extconf.rb"
end
e1_gem = e1.cache_file
- _, f1_gem = util_gem 'f', '1', 'e' => nil
+ _, f1_gem = util_gem "f", "1", "e" => nil
Gem::Installer.at(e1_gem).install
FileUtils.rm_r e1.extension_dir
@@ -385,7 +385,7 @@ class TestGemDependencyInstaller < Gem::TestCase
Dir.chdir @tempdir
begin
inst = Gem::DependencyInstaller.new
- inst.install 'f'
+ inst.install "f"
ensure
Dir.chdir pwd
end
@@ -396,9 +396,9 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_install_dependency_old
- _, e1_gem = util_gem 'e', '1'
- _, f1_gem = util_gem 'f', '1', 'e' => nil
- _, f2_gem = util_gem 'f', '2'
+ _, e1_gem = util_gem "e", "1"
+ _, f1_gem = util_gem "f", "1", "e" => nil
+ _, f2_gem = util_gem "f", "2"
FileUtils.mv e1_gem, @tempdir
FileUtils.mv f1_gem, @tempdir
@@ -407,7 +407,7 @@ class TestGemDependencyInstaller < Gem::TestCase
Dir.chdir @tempdir do
inst = Gem::DependencyInstaller.new
- inst.install 'f'
+ inst.install "f"
end
assert_equal %w[f-2], inst.installed_gems.map {|s| s.full_name }
@@ -421,7 +421,7 @@ class TestGemDependencyInstaller < Gem::TestCase
Dir.chdir @tempdir do
inst = Gem::DependencyInstaller.new :domain => :local
- inst.install 'a-1.gem'
+ inst.install "a-1.gem"
end
assert_equal %w[a-1], inst.installed_gems.map {|s| s.full_name }
@@ -435,7 +435,7 @@ class TestGemDependencyInstaller < Gem::TestCase
Dir.chdir @tempdir do
inst = Gem::DependencyInstaller.new :domain => :local
- inst.install 'a-1.a.gem'
+ inst.install "a-1.a.gem"
end
assert_equal %w[a-1.a], inst.installed_gems.map {|s| s.full_name }
@@ -451,7 +451,7 @@ class TestGemDependencyInstaller < Gem::TestCase
Dir.chdir @tempdir do
inst = Gem::DependencyInstaller.new :domain => :local
- inst.install 'b-1.gem'
+ inst.install "b-1.gem"
end
assert_equal %w[a-1 b-1], inst.installed_gems.map {|s| s.full_name }
@@ -466,10 +466,10 @@ class TestGemDependencyInstaller < Gem::TestCase
inst = nil
Dir.chdir @tempdir do
- Gem::Installer.at('a-1.gem').install
+ Gem::Installer.at("a-1.gem").install
inst = Gem::DependencyInstaller.new :domain => :local
- inst.install 'b-1.gem'
+ inst.install "b-1.gem"
end
assert_equal %w[b-1], inst.installed_gems.map {|s| s.full_name }
@@ -482,7 +482,7 @@ class TestGemDependencyInstaller < Gem::TestCase
Dir.chdir @tempdir do
inst = Gem::DependencyInstaller.new :domain => :local
- inst.install 'gems/a-1.gem'
+ inst.install "gems/a-1.gem"
end
assert_equal %w[a-1], inst.installed_gems.map {|s| s.full_name }
@@ -491,12 +491,12 @@ class TestGemDependencyInstaller < Gem::TestCase
def test_install_minimal_deps
util_setup_gems
- _, e1_gem = util_gem 'e', '1' do |s|
- s.add_dependency 'b'
+ _, e1_gem = util_gem "e", "1" do |s|
+ s.add_dependency "b"
end
- _, b2_gem = util_gem 'b', '2' do |s|
- s.add_dependency 'a'
+ _, b2_gem = util_gem "b", "2" do |s|
+ s.add_dependency "a"
end
FileUtils.mv @a1_gem, @tempdir
@@ -508,15 +508,15 @@ class TestGemDependencyInstaller < Gem::TestCase
Dir.chdir @tempdir do
inst = Gem::DependencyInstaller.new :ignore_dependencies => true
- inst.install 'b', req('= 1')
+ inst.install "b", req("= 1")
end
assert_equal %w[b-1], inst.installed_gems.map {|s| s.full_name },
- 'sanity check'
+ "sanity check"
Dir.chdir @tempdir do
inst = Gem::DependencyInstaller.new :minimal_deps => true
- inst.install 'e'
+ inst.install "e"
end
assert_equal %w[a-1 e-1], inst.installed_gems.map {|s| s.full_name }
@@ -525,12 +525,12 @@ class TestGemDependencyInstaller < Gem::TestCase
def test_install_no_minimal_deps
util_setup_gems
- _, e1_gem = util_gem 'e', '1' do |s|
- s.add_dependency 'b'
+ _, e1_gem = util_gem "e", "1" do |s|
+ s.add_dependency "b"
end
- _, b2_gem = util_gem 'b', '2' do |s|
- s.add_dependency 'a'
+ _, b2_gem = util_gem "b", "2" do |s|
+ s.add_dependency "a"
end
FileUtils.mv @a1_gem, @tempdir
@@ -542,15 +542,15 @@ class TestGemDependencyInstaller < Gem::TestCase
Dir.chdir @tempdir do
inst = Gem::DependencyInstaller.new :ignore_dependencies => true
- inst.install 'b', req('= 1')
+ inst.install "b", req("= 1")
end
assert_equal %w[b-1], inst.installed_gems.map {|s| s.full_name },
- 'sanity check'
+ "sanity check"
Dir.chdir @tempdir do
inst = Gem::DependencyInstaller.new :minimal_deps => false
- inst.install 'e'
+ inst.install "e"
end
assert_equal %w[a-1 b-2 e-1], inst.installed_gems.map {|s| s.full_name }
@@ -581,13 +581,13 @@ class TestGemDependencyInstaller < Gem::TestCase
Dir.chdir @tempdir do
inst = Gem::DependencyInstaller.new :env_shebang => true, :wrappers => true, :format_executable => false
- inst.install 'a'
+ inst.install "a"
end
env = "/\\S+/env" unless Gem.win_platform?
assert_match %r{\A#!#{env} #{RbConfig::CONFIG['ruby_install_name']}\n},
- File.read(File.join(@gemhome, 'bin', 'a_bin'))
+ File.read(File.join(@gemhome, "bin", "a_bin"))
end
def test_install_force
@@ -595,12 +595,12 @@ class TestGemDependencyInstaller < Gem::TestCase
FileUtils.mv @b1_gem, @tempdir
si = util_setup_spec_fetcher @b1
- @fetcher.data['http://gems.example.com/gems/yaml'] = si.to_yaml
+ @fetcher.data["http://gems.example.com/gems/yaml"] = si.to_yaml
inst = nil
Dir.chdir @tempdir do
inst = Gem::DependencyInstaller.new :force => true
- inst.install 'b'
+ inst.install "b"
end
assert_equal %w[b-1], inst.installed_gems.map {|s| s.full_name }
@@ -616,7 +616,7 @@ class TestGemDependencyInstaller < Gem::TestCase
Dir.chdir @tempdir do
inst = Gem::DependencyInstaller.new(
:build_args => build_args)
- inst.install 'a'
+ inst.install "a"
end
assert_equal build_args.join("\n"), File.read(inst.installed_gems.first.build_info_file).strip
@@ -630,7 +630,7 @@ class TestGemDependencyInstaller < Gem::TestCase
Dir.chdir @tempdir do
inst = Gem::DependencyInstaller.new :ignore_dependencies => true
- inst.install 'b'
+ inst.install "b"
end
assert_equal %w[b-1], inst.installed_gems.map {|s| s.full_name }
@@ -645,37 +645,37 @@ class TestGemDependencyInstaller < Gem::TestCase
inst = Gem::Installer.at @a1.file_name
inst.install
- gemhome2 = File.join @tempdir, 'gemhome2'
+ gemhome2 = File.join @tempdir, "gemhome2"
Dir.mkdir gemhome2
inst = nil
Dir.chdir @tempdir do
inst = Gem::DependencyInstaller.new :install_dir => gemhome2
- inst.install 'b'
+ inst.install "b"
end
assert_equal %w[a-1 b-1], inst.installed_gems.map {|s| s.full_name }
- assert File.exist?(File.join(gemhome2, 'specifications', @a1.spec_name))
- assert File.exist?(File.join(gemhome2, 'cache', @a1.file_name))
+ assert File.exist?(File.join(gemhome2, "specifications", @a1.spec_name))
+ assert File.exist?(File.join(gemhome2, "cache", @a1.file_name))
end
def test_install_domain_both
util_setup_gems
a1_data = nil
- File.open @a1_gem, 'rb' do |fp|
+ File.open @a1_gem, "rb" do |fp|
a1_data = fp.read
end
- @fetcher.data['http://gems.example.com/gems/a-1.gem'] = a1_data
+ @fetcher.data["http://gems.example.com/gems/a-1.gem"] = a1_data
FileUtils.mv @b1_gem, @tempdir
inst = nil
Dir.chdir @tempdir do
inst = Gem::DependencyInstaller.new :domain => :both
- inst.install 'b'
+ inst.install "b"
end
assert_equal %w[a-1 b-1], inst.installed_gems.map {|s| s.full_name }
@@ -699,7 +699,7 @@ class TestGemDependencyInstaller < Gem::TestCase
Dir.chdir @tempdir do
inst = Gem::DependencyInstaller.new :domain => :both
- inst.install 'b'
+ inst.install "b"
end
assert_equal %w[a-1 b-1], inst.installed_gems.map {|s| s.full_name }
@@ -714,7 +714,7 @@ class TestGemDependencyInstaller < Gem::TestCase
Dir.chdir @tempdir do
e = assert_raise Gem::UnsatisfiableDependencyError do
inst = Gem::DependencyInstaller.new :domain => :local
- inst.install 'b'
+ inst.install "b"
end
expected = "Unable to resolve dependency: 'b (>= 0)' requires 'a (>= 0)'"
@@ -728,14 +728,14 @@ class TestGemDependencyInstaller < Gem::TestCase
util_setup_gems
a1_data = nil
- File.open @a1_gem, 'rb' do |fp|
+ File.open @a1_gem, "rb" do |fp|
a1_data = fp.read
end
- @fetcher.data['http://gems.example.com/gems/a-1.gem'] = a1_data
+ @fetcher.data["http://gems.example.com/gems/a-1.gem"] = a1_data
inst = Gem::DependencyInstaller.new :domain => :remote
- inst.install 'a'
+ inst.install "a"
assert_equal %w[a-1], inst.installed_gems.map {|s| s.full_name }
end
@@ -751,19 +751,19 @@ class TestGemDependencyInstaller < Gem::TestCase
Dir.chdir @tempdir do
inst = Gem::DependencyInstaller.new :install_dir => gemhome2
- inst.install 'a'
+ inst.install "a"
end
assert_equal %w[a-1], inst.installed_gems.map {|s| s.full_name },
- 'sanity check'
+ "sanity check"
- ENV['GEM_HOME'] = @gemhome
- ENV['GEM_PATH'] = [@gemhome, gemhome2].join File::PATH_SEPARATOR
+ ENV["GEM_HOME"] = @gemhome
+ ENV["GEM_PATH"] = [@gemhome, gemhome2].join File::PATH_SEPARATOR
Gem.clear_paths
Dir.chdir @tempdir do
inst = Gem::DependencyInstaller.new
- inst.install 'b'
+ inst.install "b"
end
assert_equal %w[b-1], inst.installed_gems.map {|s| s.full_name }
@@ -778,7 +778,7 @@ class TestGemDependencyInstaller < Gem::TestCase
Dir.chdir @tempdir do
inst = Gem::DependencyInstaller.new :force => true
- inst.install 'a'
+ inst.install "a"
end
assert_equal %w[a-1], Gem::Specification.map(&:full_name)
@@ -789,16 +789,16 @@ class TestGemDependencyInstaller < Gem::TestCase
util_setup_gems
a1_data = nil
- File.open @a1_gem, 'rb' do |fp|
+ File.open @a1_gem, "rb" do |fp|
a1_data = fp.read
end
- @fetcher.data['http://gems.example.com/gems/a-1.gem'] = a1_data
+ @fetcher.data["http://gems.example.com/gems/a-1.gem"] = a1_data
inst = Gem::DependencyInstaller.new
Dir.chdir @tempdir do
- inst.install 'a'
+ inst.install "a"
end
assert_equal %w[a-1], inst.installed_gems.map {|s| s.full_name }
@@ -808,11 +808,11 @@ class TestGemDependencyInstaller < Gem::TestCase
util_setup_gems
a1_data = nil
- File.open @a1_gem, 'rb' do |fp|
+ File.open @a1_gem, "rb" do |fp|
a1_data = fp.read
end
- @fetcher.data['http://gems.example.com/gems/a-1.gem'] = a1_data
+ @fetcher.data["http://gems.example.com/gems/a-1.gem"] = a1_data
inst = Gem::DependencyInstaller.new
@@ -827,22 +827,22 @@ class TestGemDependencyInstaller < Gem::TestCase
def test_install_remote_platform_newer
util_setup_gems
- a2_o, a2_o_gem = util_gem 'a', '2' do |s|
+ a2_o, a2_o_gem = util_gem "a", "2" do |s|
s.platform = Gem::Platform.new %w[cpu other_platform 1]
end
si = util_setup_spec_fetcher @a1, a2_o
- @fetcher.data['http://gems.example.com/gems/yaml'] = si.to_yaml
+ @fetcher.data["http://gems.example.com/gems/yaml"] = si.to_yaml
a1_data = nil
a2_o_data = nil
- File.open @a1_gem, 'rb' do |fp|
+ File.open @a1_gem, "rb" do |fp|
a1_data = fp.read
end
- File.open a2_o_gem, 'rb' do |fp|
+ File.open a2_o_gem, "rb" do |fp|
a2_o_data = fp.read
end
@@ -852,13 +852,13 @@ class TestGemDependencyInstaller < Gem::TestCase
a2_o_data
inst = Gem::DependencyInstaller.new :domain => :remote
- inst.install 'a'
+ inst.install "a"
assert_equal %w[a-1], inst.installed_gems.map {|s| s.full_name }
end
def test_install_platform_is_ignored_when_a_file_is_specified
- _, a_gem = util_gem 'a', '1' do |s|
+ _, a_gem = util_gem "a", "1" do |s|
s.platform = Gem::Platform.new %w[cpu other_platform 1]
end
@@ -868,26 +868,26 @@ class TestGemDependencyInstaller < Gem::TestCase
assert_equal %w[a-1-cpu-other_platform-1], inst.installed_gems.map {|s| s.full_name }
end
- require 'rubygems/openssl'
+ require "rubygems/openssl"
if Gem::HAVE_OPENSSL
def test_install_security_policy
util_setup_gems
- data = File.open(@a1_gem, 'rb') {|f| f.read }
- @fetcher.data['http://gems.example.com/gems/a-1.gem'] = data
+ data = File.open(@a1_gem, "rb") {|f| f.read }
+ @fetcher.data["http://gems.example.com/gems/a-1.gem"] = data
- data = File.open(@b1_gem, 'rb') {|f| f.read }
- @fetcher.data['http://gems.example.com/gems/b-1.gem'] = data
+ data = File.open(@b1_gem, "rb") {|f| f.read }
+ @fetcher.data["http://gems.example.com/gems/b-1.gem"] = data
policy = Gem::Security::HighSecurity
inst = Gem::DependencyInstaller.new :security_policy => policy
e = assert_raise Gem::Security::Exception do
- inst.install 'b'
+ inst.install "b"
end
- assert_equal 'unsigned gems are not allowed by the High Security policy',
+ assert_equal "unsigned gems are not allowed by the High Security policy",
e.message
assert_equal %w[], inst.installed_gems.map {|s| s.full_name }
@@ -899,28 +899,28 @@ class TestGemDependencyInstaller < Gem::TestCase
def test_install_no_wrappers
util_setup_gems
- @fetcher.data['http://gems.example.com/gems/a-1.gem'] = read_binary(@a1_gem)
+ @fetcher.data["http://gems.example.com/gems/a-1.gem"] = read_binary(@a1_gem)
inst = Gem::DependencyInstaller.new :wrappers => false, :format_executable => false
- inst.install 'a'
+ inst.install "a"
refute_match(%r{This file was generated by RubyGems.},
- File.read(File.join(@gemhome, 'bin', 'a_bin')))
+ File.read(File.join(@gemhome, "bin", "a_bin")))
end
end
def test_install_version
util_setup_d
- data = File.open(@d2_gem, 'rb') {|f| f.read }
- @fetcher.data['http://gems.example.com/gems/d-2.gem'] = data
+ data = File.open(@d2_gem, "rb") {|f| f.read }
+ @fetcher.data["http://gems.example.com/gems/d-2.gem"] = data
- data = File.open(@d1_gem, 'rb') {|f| f.read }
- @fetcher.data['http://gems.example.com/gems/d-1.gem'] = data
+ data = File.open(@d1_gem, "rb") {|f| f.read }
+ @fetcher.data["http://gems.example.com/gems/d-1.gem"] = data
inst = Gem::DependencyInstaller.new
- inst.install 'd', '= 1'
+ inst.install "d", "= 1"
assert_equal %w[d-1], inst.installed_gems.map {|s| s.full_name }
end
@@ -928,26 +928,26 @@ class TestGemDependencyInstaller < Gem::TestCase
def test_install_version_default
util_setup_d
- data = File.open(@d2_gem, 'rb') {|f| f.read }
- @fetcher.data['http://gems.example.com/gems/d-2.gem'] = data
+ data = File.open(@d2_gem, "rb") {|f| f.read }
+ @fetcher.data["http://gems.example.com/gems/d-2.gem"] = data
- data = File.open(@d1_gem, 'rb') {|f| f.read }
- @fetcher.data['http://gems.example.com/gems/d-1.gem'] = data
+ data = File.open(@d1_gem, "rb") {|f| f.read }
+ @fetcher.data["http://gems.example.com/gems/d-1.gem"] = data
inst = Gem::DependencyInstaller.new
- inst.install 'd'
+ inst.install "d"
assert_equal %w[d-2], inst.installed_gems.map {|s| s.full_name }
end
def test_install_legacy_spec_with_nil_required_ruby_version
- path = File.expand_path 'data/null-required-ruby-version.gemspec.rz', __dir__
+ path = File.expand_path "data/null-required-ruby-version.gemspec.rz", __dir__
spec = Marshal.load Gem.read_binary(path)
def spec.validate(*args); end
util_build_gem spec
- cache_file = File.join @tempdir, 'gems', "#{spec.original_name}.gem"
+ cache_file = File.join @tempdir, "gems", "#{spec.original_name}.gem"
FileUtils.mkdir_p File.dirname cache_file
FileUtils.mv spec.cache_file, cache_file
@@ -955,9 +955,9 @@ class TestGemDependencyInstaller < Gem::TestCase
data = Gem.read_binary(cache_file)
- @fetcher.data['http://gems.example.com/gems/activesupport-1.0.0.gem'] = data
+ @fetcher.data["http://gems.example.com/gems/activesupport-1.0.0.gem"] = data
- dep = Gem::Dependency.new 'activesupport'
+ dep = Gem::Dependency.new "activesupport"
inst = Gem::DependencyInstaller.new
inst.install dep
@@ -966,13 +966,13 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_install_legacy_spec_with_nil_required_rubygems_version
- path = File.expand_path 'data/null-required-rubygems-version.gemspec.rz', __dir__
+ path = File.expand_path "data/null-required-rubygems-version.gemspec.rz", __dir__
spec = Marshal.load Gem.read_binary(path)
def spec.validate(*args); end
util_build_gem spec
- cache_file = File.join @tempdir, 'gems', "#{spec.original_name}.gem"
+ cache_file = File.join @tempdir, "gems", "#{spec.original_name}.gem"
FileUtils.mkdir_p File.dirname cache_file
FileUtils.mv spec.cache_file, cache_file
@@ -980,9 +980,9 @@ class TestGemDependencyInstaller < Gem::TestCase
data = Gem.read_binary(cache_file)
- @fetcher.data['http://gems.example.com/gems/activesupport-1.0.0.gem'] = data
+ @fetcher.data["http://gems.example.com/gems/activesupport-1.0.0.gem"] = data
- dep = Gem::Dependency.new 'activesupport'
+ dep = Gem::Dependency.new "activesupport"
inst = Gem::DependencyInstaller.new
inst.install dep
@@ -994,7 +994,7 @@ class TestGemDependencyInstaller < Gem::TestCase
util_setup_gems
inst = Gem::DependencyInstaller.new
- dep = Gem::Dependency.new 'b', '>= 0'
+ dep = Gem::Dependency.new "b", ">= 0"
Gem::Specification.reset
@@ -1015,7 +1015,7 @@ class TestGemDependencyInstaller < Gem::TestCase
FileUtils.mv @a1_gem, @tempdir
inst = Gem::DependencyInstaller.new
- dep = Gem::Dependency.new 'a', '>= 0'
+ dep = Gem::Dependency.new "a", ">= 0"
set = nil
Dir.chdir @tempdir do
@@ -1030,12 +1030,12 @@ class TestGemDependencyInstaller < Gem::TestCase
remote, local = gems
- assert_equal 'a-1', local.spec.full_name, 'local spec'
+ assert_equal "a-1", local.spec.full_name, "local spec"
assert_equal File.join(@tempdir, @a1.file_name),
- local.source.download(local.spec), 'local path'
+ local.source.download(local.spec), "local path"
- assert_equal 'a-1', remote.spec.full_name, 'remote spec'
- assert_equal Gem::Source.new(@gem_repo), remote.source, 'remote path'
+ assert_equal "a-1", remote.spec.full