Skip to content

Commit

Permalink
[rubygems/rubygems] Escape regexp metachacters or use assert_include
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu authored and matzbot committed Jun 19, 2023
1 parent af66b9b commit 10e4a9a
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 17 deletions.
4 changes: 2 additions & 2 deletions test/rubygems/test_gem.rb
Expand Up @@ -1254,8 +1254,8 @@ def test_self_try_activate_missing_dep
Gem.try_activate "a_file"
end

assert_match(/Could not find 'b' /, e.message)
assert_match(/at: #{a.spec_file}/, e.message)
assert_include(e.message, "Could not find 'b' ")
assert_include(e.message, "at: #{a.spec_file}")
end

def test_self_try_activate_missing_prerelease
Expand Down
8 changes: 4 additions & 4 deletions test/rubygems/test_gem_command_manager.rb
Expand Up @@ -150,7 +150,7 @@ def test_process_args_with_c_flag_without_path
end
end

assert_match(/install isn't a directory./i, @ui.error)
assert_match(/install isn't a directory\./i, @ui.error)
end

def test_process_args_with_c_flag_path_not_found
Expand All @@ -164,7 +164,7 @@ def test_process_args_with_c_flag_path_not_found
end
end

assert_match(/#{custom_start_point} isn't a directory./i, @ui.error)
assert_match(/#{Regexp.quote(custom_start_point)} isn't a directory\./i, @ui.error)
end

def test_process_args_bad_arg
Expand Down Expand Up @@ -368,7 +368,7 @@ def execute
end

assert_equal "pew pew!\n", @ui.output
assert_match(/WARNING: foo command is deprecated. It will be removed in Rubygems [0-9]+/, @ui.error)
assert_match(/WARNING: foo command is deprecated\. It will be removed in Rubygems [0-9]+/, @ui.error)
ensure
Gem::Commands.send(:remove_const, :FooCommand)
end
Expand All @@ -393,7 +393,7 @@ def execute
end

assert_equal "pew pew!\n", @ui.output
assert_match(/WARNING: foo command is deprecated. It will be removed in Rubygems 9.9.9/, @ui.error)
assert_match(/WARNING: foo command is deprecated\. It will be removed in Rubygems 9\.9\.9/, @ui.error)
ensure
Gem::Commands.send(:remove_const, :FooCommand)
end
Expand Down
3 changes: 2 additions & 1 deletion test/rubygems/test_gem_commands_cert_command.rb
Expand Up @@ -677,8 +677,9 @@ def test_execute_re_sign

expected_path = File.join(gem_path, "#{File.basename(tmp_expired_cert_file)}.expired")

assert_include(@ui.output, "INFO: Your certificate #{tmp_expired_cert_file} has been re-signed\n")
assert_match(
/INFO: Your certificate #{tmp_expired_cert_file} has been re-signed\nINFO: Your expired certificate will be located at: #{expected_path}\.[0-9]+/,
/INFO: Your expired certificate will be located at: #{Regexp.quote(expected_path)}\.[0-9]+/,
@ui.output
)
assert_equal "", @ui.error
Expand Down
12 changes: 6 additions & 6 deletions test/rubygems/test_gem_commands_info_command.rb
Expand Up @@ -33,12 +33,12 @@ def test_execute
@cmd.execute
end

assert_match %r{#{@gem.name} \(#{@gem.version}\)\n}, @ui.output
assert_match(/Authors: #{@gem.authors.join(', ')}\n/, @ui.output)
assert_match(/Homepage: #{@gem.homepage}\n/, @ui.output)
assert_match(/License: #{@gem.license}\n/, @ui.output)
assert_match(/Installed at: #{@gem.base_dir}\n/, @ui.output)
assert_match(/#{@gem.summary}\n/, @ui.output)
assert_include(@ui.output, "#{@gem.name} (#{@gem.version})\n")
assert_include(@ui.output, "Authors: #{@gem.authors.join(", ")}\n")
assert_include(@ui.output, "Homepage: #{@gem.homepage}\n")
assert_include(@ui.output, "License: #{@gem.license}\n")
assert_include(@ui.output, "Installed at: #{@gem.base_dir}\n")
assert_include(@ui.output, "#{@gem.summary}\n")
assert_match "", @ui.error
end

Expand Down
4 changes: 2 additions & 2 deletions test/rubygems/test_gem_ext_ext_conf_builder.rb
Expand Up @@ -34,7 +34,7 @@ def test_class_build
assert_same result, output

assert_match(/^current directory:/, output[0])
assert_match(/^#{Gem.ruby}.* extconf.rb/, output[1])
assert_match(/^#{Regexp.quote(Gem.ruby)}.* extconf.rb/, output[1])
assert_equal "creating Makefile\n", output[2]
assert_match(/^current directory:/, output[3])
assert_contains_make_command "clean", output[4]
Expand Down Expand Up @@ -114,7 +114,7 @@ def test_class_build_extconf_fail

assert_equal "extconf failed, exit code 1", error.message

assert_match(/^#{Gem.ruby}.* extconf.rb/, output[1])
assert_match(/^#{Regexp.quote(Gem.ruby)}.* extconf.rb/, output[1])
assert_match(File.join(@dest_path, "mkmf.log"), output[4])
assert_includes(output, "To see why this extension failed to compile, please check the mkmf.log which can be found here:\n")

Expand Down
4 changes: 2 additions & 2 deletions test/rubygems/test_gem_installer.rb
Expand Up @@ -738,9 +738,9 @@ def test_generate_bin_uses_default_shebang
installer.generate_bin

default_shebang = Gem.ruby
shebang_line = File.open("#{@gemhome}/bin/executable") {|f| f.readlines.first }
shebang_line = File.open("#{@gemhome}/bin/executable", &:gets)
assert_match(/\A#!/, shebang_line)
assert_match(/#{default_shebang}/, shebang_line)
assert_include(shebang_line, default_shebang)
end
end

Expand Down

0 comments on commit 10e4a9a

Please sign in to comment.