Use slash-delimited regular expressions.

This commit is contained in:
Markus Reiter 2016-10-14 20:03:34 +02:00
parent 40b7e36746
commit 1a0f8b8a02
56 changed files with 124 additions and 124 deletions

View File

@ -4,7 +4,7 @@ module Hbc
module Artifact
class AbstractFlightBlock < Base
def self.artifact_dsl_key
super.to_s.sub(%r{_block$}, "").to_sym
super.to_s.sub(/_block$/, "").to_sym
end
def self.uninstall_artifact_dsl_key

View File

@ -2,15 +2,15 @@ module Hbc
module Artifact
class Base
def self.artifact_name
@artifact_name ||= name.sub(%r{^.*:}, "").gsub(%r{(.)([A-Z])}, '\1_\2').downcase
@artifact_name ||= name.sub(/^.*:/, "").gsub(/(.)([A-Z])/, '\1_\2').downcase
end
def self.artifact_english_name
@artifact_english_name ||= name.sub(%r{^.*:}, "").gsub(%r{(.)([A-Z])}, '\1 \2')
@artifact_english_name ||= name.sub(/^.*:/, "").gsub(/(.)([A-Z])/, '\1 \2')
end
def self.artifact_english_article
@artifact_english_article ||= artifact_english_name =~ %r{^[aeiou]}i ? "an" : "a"
@artifact_english_article ||= artifact_english_name =~ /^[aeiou]/i ? "an" : "a"
end
def self.artifact_dsl_key

View File

@ -15,7 +15,7 @@ module Hbc
attr_reader :source, :target
def printable_target
target.to_s.sub(%r{^#{ENV['HOME']}(#{File::SEPARATOR}|$)}, "~/")
target.to_s.sub(/^#{ENV['HOME']}(#{File::SEPARATOR}|$)/, "~/")
end
ALT_NAME_ATTRIBUTE = "com.apple.metadata:kMDItemAlternateNames".freeze
@ -28,7 +28,7 @@ module Hbc
odebug "Adding #{ALT_NAME_ATTRIBUTE} metadata"
altnames = @command.run("/usr/bin/xattr",
args: ["-p", ALT_NAME_ATTRIBUTE, file.to_s],
print_stderr: false).stdout.sub(%r{\A\((.*)\)\Z}, '\1')
print_stderr: false).stdout.sub(/\A\((.*)\)\Z/, '\1')
odebug "Existing metadata is: '#{altnames}'"
altnames.concat(", ") unless altnames.empty?
altnames.concat(%Q{"#{altname}"})

View File

@ -103,7 +103,7 @@ module Hbc
ohai "Removing launchctl service #{service}"
[false, true].each do |with_sudo|
plist_status = @command.run("/bin/launchctl", args: ["list", service], sudo: with_sudo, print_stderr: false).stdout
if plist_status =~ %r{^\{}
if plist_status =~ /^\{/
@command.run!("/bin/launchctl", args: ["remove", service], sudo: with_sudo)
sleep 1
end
@ -164,8 +164,8 @@ module Hbc
pid_string = @command.run!("/usr/bin/osascript",
args: ["-e", %Q{tell application "System Events" to get the unix id of every process whose bundle identifier is "#{bundle_id}"}],
sudo: true).stdout.chomp
return [] unless pid_string =~ %r{\A\d+(?:\s*,\s*\d+)*\Z} # sanity check
pid_string.split(%r{\s*,\s*}).map(&:strip).map(&:to_i)
return [] unless pid_string =~ /\A\d+(?:\s*,\s*\d+)*\Z/ # sanity check
pid_string.split(/\s*,\s*/).map(&:strip).map(&:to_i)
end
def uninstall_login_item(directives)

View File

@ -84,7 +84,7 @@ module Hbc
def check_sha256_actually_256(sha256: cask.sha256, stanza: "sha256")
odebug "Verifying #{stanza} string is a legal SHA-256 digest"
return unless sha256.is_a?(String)
return if sha256.length == 64 && sha256[%r{^[0-9a-f]+$}i]
return if sha256.length == 64 && sha256[/^[0-9a-f]+$/i]
add_error "#{stanza} string must be of 64 hexadecimal characters"
end
@ -162,7 +162,7 @@ module Hbc
end
def bad_sourceforge_url?
bad_url_format?(%r{sourceforge},
bad_url_format?(/sourceforge/,
[
%r{\Ahttps://sourceforge\.net/projects/[^/]+/files/latest/download\Z},
%r{\Ahttps://downloads\.sourceforge\.net/(?!(project|sourceforge)\/)},
@ -174,7 +174,7 @@ module Hbc
end
def bad_osdn_url?
bad_url_format?(%r{osd}, [%r{\Ahttps?://([^/]+.)?dl\.osdn\.jp/}])
bad_url_format?(/osd/, [%r{\Ahttps?://([^/]+.)?dl\.osdn\.jp/}])
end
def check_generic_artifacts

View File

@ -17,7 +17,7 @@ module Hbc
file = symlink.readlink
new_name = file.basename
.sub(%r{\-((?:(\d|#{DSL::Version::DIVIDER_REGEX})*\-\2*)*[^\-]+)$}x,
.sub(/\-((?:(\d|#{DSL::Version::DIVIDER_REGEX})*\-\2*)*[^\-]+)$/x,
'--\1')
renamed_file = Hbc.cache.join(new_name)

View File

@ -8,7 +8,7 @@ module Hbc
dsl = DSL::Caveats.new(cask)
retval = dsl.instance_eval(&@block)
return if retval.nil?
puts retval.to_s.sub(%r{[\r\n \t]*\Z}, "\n\n")
puts retval.to_s.sub(/[\r\n \t]*\Z/, "\n\n")
end
end
end

View File

@ -129,7 +129,7 @@ module Hbc
exec "brewcask-#{command}", *ARGV[1..-1]
elsif Pathname.new(command.to_s).executable? &&
command.to_s.include?("/") &&
!command.to_s.match(%r{\.rb$})
!command.to_s.match(/\.rb$/)
# arbitrary external executable with literal path, useful
# for development and troubleshooting
exec command, *ARGV[1..-1]
@ -163,7 +163,7 @@ module Hbc
cask_taps = {}
cask_list.each do |c|
user, repo, token = c.split "/"
repo.sub!(%r{^homebrew-}i, "")
repo.sub!(/^homebrew-/i, "")
cask_taps[token] ||= []
cask_taps[token].push "#{user}/#{repo}"
end

View File

@ -2,7 +2,7 @@ module Hbc
class CLI
class Base
def self.command_name
@command_name ||= name.sub(%r{^.*:}, "").gsub(%r{(.)([A-Z])}, '\1_\2').downcase
@command_name ||= name.sub(/^.*:/, "").gsub(/(.)([A-Z])/, '\1_\2').downcase
end
def self.visible

View File

@ -5,7 +5,7 @@ module Hbc
cask_tokens = cask_tokens_from(args)
raise CaskUnspecifiedError if cask_tokens.empty?
# only respects the first argument
cask_token = cask_tokens.first.sub(%r{\.rb$}i, "")
cask_token = cask_tokens.first.sub(/\.rb$/i, "")
cask_path = Hbc.path(cask_token)
raise CaskUnavailableError, cask_token.to_s unless cask_path.exist?
puts File.open(cask_path, &:read)

View File

@ -4,7 +4,7 @@ module Hbc
def self.run(*args)
cask_tokens = cask_tokens_from(args)
raise CaskUnspecifiedError if cask_tokens.empty?
cask_token = cask_tokens.first.sub(%r{\.rb$}i, "")
cask_token = cask_tokens.first.sub(/\.rb$/i, "")
cask_path = Hbc.path(cask_token)
odebug "Creating Cask #{cask_token}"

View File

@ -53,7 +53,7 @@ module Hbc
args: %w[config --get remote.origin.url],
print_stderr: false).stdout.strip
end
if homebrew_origin !~ %r{\S}
if homebrew_origin !~ /\S/
homebrew_origin = "#{none_string} #{error_string}"
elsif homebrew_origin !~ %r{(mxcl|Homebrew)/(home)?brew(\.git)?\Z}
homebrew_origin.concat " #{error_string "warning: nonstandard origin"}"
@ -92,7 +92,7 @@ module Hbc
print_stderr: false)
.stdout
.strip
if @homebrew_constants[name] !~ %r{\S}
if @homebrew_constants[name] !~ /\S/
@homebrew_constants[name] = "#{none_string} #{error_string}"
end
path = Pathname.new(@homebrew_constants[name])
@ -104,7 +104,7 @@ module Hbc
end
def self.locale_variables
ENV.keys.grep(%r{^(?:LC_\S+|LANG|LANGUAGE)\Z}).collect { |v| %Q{#{v}="#{ENV[v]}"} }.sort.join("\n")
ENV.keys.grep(/^(?:LC_\S+|LANG|LANGUAGE)\Z/).collect { |v| %Q{#{v}="#{ENV[v]}"} }.sort.join("\n")
end
def self.privileged_uid
@ -118,7 +118,7 @@ module Hbc
end
def self.legacy_tap_pattern
%r{phinze}
/phinze/
end
def self.notfound_string

View File

@ -5,7 +5,7 @@ module Hbc
cask_tokens = cask_tokens_from(args)
raise CaskUnspecifiedError if cask_tokens.empty?
# only respects the first argument
cask_token = cask_tokens.first.sub(%r{\.rb$}i, "")
cask_token = cask_tokens.first.sub(/\.rb$/i, "")
cask_path = Hbc.path(cask_token)
odebug "Opening editor for Cask #{cask_token}"
unless cask_path.exist?

View File

@ -10,7 +10,7 @@ module Hbc
def run(*args)
commit_range = commit_range(args)
cleanup = args.any? { |a| a =~ %r{^-+c(leanup)?$}i }
cleanup = args.any? { |a| a =~ /^-+c(leanup)?$/i }
new(commit_range, cleanup: cleanup).run
end
@ -109,7 +109,7 @@ module Hbc
def relevant_stanza_modified?(cask_file)
out = git("diff", commit_range, "--", cask_file)
out =~ %r{^\+\s*(#{RELEVANT_STANZAS.join('|')})}
out =~ /^\+\s*(#{RELEVANT_STANZAS.join('|')})/
end
def git(*args)

View File

@ -2,7 +2,7 @@ module Hbc
class CLI
class InternalUseBase < Base
def self.command_name
super.sub(%r{^internal_}i, "_")
super.sub(/^internal_/i, "_")
end
def self.visible

View File

@ -21,12 +21,12 @@ module Hbc
all_tokens = CLI.nice_listing(Hbc.all_tokens)
if search_regexp
search_term = arguments.first
partial_matches = all_tokens.grep(%r{#{search_regexp}}i)
partial_matches = all_tokens.grep(/#{search_regexp}/i)
else
simplified_tokens = all_tokens.map { |t| t.sub(%r{^.*\/}, "").gsub(%r{[^a-z0-9]+}i, "") }
simplified_search_term = search_term.sub(%r{\.rb$}i, "").gsub(%r{[^a-z0-9]+}i, "")
exact_match = simplified_tokens.grep(%r{^#{simplified_search_term}$}i) { |t| all_tokens[simplified_tokens.index(t)] }.first
partial_matches = simplified_tokens.grep(%r{#{simplified_search_term}}i) { |t| all_tokens[simplified_tokens.index(t)] }
simplified_tokens = all_tokens.map { |t| t.sub(%r{^.*\/}, "").gsub(/[^a-z0-9]+/i, "") }
simplified_search_term = search_term.sub(/\.rb$/i, "").gsub(/[^a-z0-9]+/i, "")
exact_match = simplified_tokens.grep(/^#{simplified_search_term}$/i) { |t| all_tokens[simplified_tokens.index(t)] }.first
partial_matches = simplified_tokens.grep(/#{simplified_search_term}/i) { |t| all_tokens[simplified_tokens.index(t)] }
partial_matches.delete(exact_match)
end
[exact_match, partial_matches, search_term]

View File

@ -67,7 +67,7 @@ module Hbc
end
def fix?
args.any? { |arg| arg =~ %r{--(fix|(auto-?)?correct)} }
args.any? { |arg| arg =~ /--(fix|(auto-?)?correct)/ }
end
end
end

View File

@ -6,7 +6,7 @@ module Hbc
class Container
class Bzip2 < Base
def self.me?(criteria)
criteria.magic_number(%r{^BZh}n)
criteria.magic_number(/^BZh/n)
end
def extract

View File

@ -8,7 +8,7 @@ module Hbc
def self.me?(criteria)
cabextract = which("cabextract")
criteria.magic_number(%r{^MSCF}n) &&
criteria.magic_number(/^MSCF/n) &&
!cabextract.nil? &&
criteria.command.run(cabextract, args: ["-t", "--", criteria.path.to_s]).stderr.empty?
end

View File

@ -9,7 +9,7 @@ module Hbc
end
def extension(regex)
path.extname.sub(%r{^\.}, "") =~ Regexp.new(regex.source, regex.options | Regexp::IGNORECASE)
path.extname.sub(/^\./, "") =~ Regexp.new(regex.source, regex.options | Regexp::IGNORECASE)
end
def magic_number(regex)

View File

@ -6,7 +6,7 @@ module Hbc
class Container
class Gzip < Base
def self.me?(criteria)
criteria.magic_number(%r{^\037\213}n)
criteria.magic_number(/^\037\213/n)
end
def extract

View File

@ -6,7 +6,7 @@ module Hbc
class Container
class Lzma < Base
def self.me?(criteria)
criteria.magic_number(%r{^\]\000\000\200\000}n)
criteria.magic_number(/^\]\000\000\200\000/n)
end
def extract

View File

@ -4,7 +4,7 @@ module Hbc
class Container
class Otf < Naked
def self.me?(criteria)
criteria.magic_number(%r{^OTTO}n)
criteria.magic_number(/^OTTO/n)
end
end
end

View File

@ -4,9 +4,9 @@ module Hbc
class Container
class Pkg < Naked
def self.me?(criteria)
criteria.extension(%r{m?pkg$}) &&
criteria.extension(/m?pkg$/) &&
(criteria.path.directory? ||
criteria.magic_number(%r{^xar!}n))
criteria.magic_number(/^xar!/n))
end
end
end

View File

@ -4,7 +4,7 @@ module Hbc
class Container
class Rar < GenericUnar
def self.me?(criteria)
criteria.magic_number(%r{^Rar!}n) &&
criteria.magic_number(/^Rar!/n) &&
super
end
end

View File

@ -5,7 +5,7 @@ module Hbc
class SevenZip < GenericUnar
def self.me?(criteria)
# TODO: cover self-extracting archives
criteria.magic_number(%r{^7z}n) &&
criteria.magic_number(/^7z/n) &&
super
end
end

View File

@ -4,7 +4,7 @@ module Hbc
class Container
class Sit < GenericUnar
def self.me?(criteria)
criteria.magic_number(%r{^StuffIt}n) &&
criteria.magic_number(/^StuffIt/n) &&
super
end
end

View File

@ -6,7 +6,7 @@ module Hbc
class Container
class Tar < Base
def self.me?(criteria)
criteria.magic_number(%r{^.{257}ustar}n) ||
criteria.magic_number(/^.{257}ustar/n) ||
# or compressed tar (bzip2/gzip/lzma/xz)
IO.popen(["/usr/bin/tar", "-t", "-f", criteria.path.to_s], err: "/dev/null") { |io| !io.read(1).nil? }
end

View File

@ -5,9 +5,9 @@ module Hbc
class Ttf < Naked
def self.me?(criteria)
# TrueType Font
criteria.magic_number(%r{^\000\001\000\000\000}n) ||
criteria.magic_number(/^\000\001\000\000\000/n) ||
# Truetype Font Collection
criteria.magic_number(%r{^ttcf}n)
criteria.magic_number(/^ttcf/n)
end
end
end

View File

@ -6,7 +6,7 @@ module Hbc
class Container
class Xar < Base
def self.me?(criteria)
criteria.magic_number(%r{^xar!}n)
criteria.magic_number(/^xar!/n)
end
def extract

View File

@ -4,8 +4,8 @@ module Hbc
class Container
class Xip < Base
def self.me?(criteria)
criteria.magic_number(%r{^xar!}n) &&
IO.popen(["/usr/bin/xar", "-t", "-f", criteria.path.to_s], err: "/dev/null") { |io| io.read =~ %r{\AContent\nMetadata\n\Z} }
criteria.magic_number(/^xar!/n) &&
IO.popen(["/usr/bin/xar", "-t", "-f", criteria.path.to_s], err: "/dev/null") { |io| io.read =~ /\AContent\nMetadata\n\Z/ }
end
def extract

View File

@ -6,7 +6,7 @@ module Hbc
class Container
class Xz < Base
def self.me?(criteria)
criteria.magic_number(%r{^\xFD7zXZ\x00}n)
criteria.magic_number(/^\xFD7zXZ\x00/n)
end
def extract

View File

@ -4,7 +4,7 @@ module Hbc
class Container
class Zip < Base
def self.me?(criteria)
criteria.magic_number(%r{^PK(\003\004|\005\006)}n)
criteria.magic_number(/^PK(\003\004|\005\006)/n)
end
def extract

View File

@ -74,7 +74,7 @@ module Hbc
end
def temporary_path
@temporary_path ||= tarball_path.sub(%r{$}, ".incomplete")
@temporary_path ||= tarball_path.sub(/$/, ".incomplete")
end
def cached_location
@ -216,7 +216,7 @@ module Hbc
end
def repo_url
`svn info '#{@clone}' 2>/dev/null`.strip[%r{^URL: (.+)$}, 1]
`svn info '#{@clone}' 2>/dev/null`.strip[/^URL: (.+)$/, 1]
end
# super does not provide checks for already-existing downloads
@ -224,7 +224,7 @@ module Hbc
if tarball_path.exist?
puts "Already downloaded: #{tarball_path}"
else
@url = @url.sub(%r{^svn\+}, "") if @url =~ %r{^svn\+http://}
@url = @url.sub(/^svn\+/, "") if @url =~ %r{^svn\+http://}
ohai "Checking out #{@url}"
clear_cache unless @url.chomp("/") == repo_url || quiet_system("svn", "switch", @url, @clone)
@ -291,12 +291,12 @@ module Hbc
def shell_quote(str)
# Oh god escaping shell args.
# See http://notetoself.vrensk.com/2008/08/escaping-single-quotes-in-ruby-harder-than-expected/
str.gsub(%r{\\|'}) { |c| "\\#{c}" }
str.gsub(/\\|'/) { |c| "\\#{c}" }
end
def fetch_externals
`svn propget svn:externals '#{shell_quote(@url)}'`.chomp.each_line do |line|
name, url = line.split(%r{\s+})
name, url = line.split(/\s+/)
yield name, url
end
end

View File

@ -252,7 +252,7 @@ module Hbc
if block_given?
@caveats << Hbc::Caveats.new(block)
elsif string.any?
@caveats << string.map { |s| s.to_s.sub(%r{[\r\n \t]*\Z}, "\n\n") }
@caveats << string.map { |s| s.to_s.sub(/[\r\n \t]*\Z/, "\n\n") }
end
@caveats
end

View File

@ -16,7 +16,7 @@ module Hbc
def method_missing(method, *)
if method
underscored_class = self.class.name.gsub(%r{([[:lower:]])([[:upper:]][[:lower:]])}, '\1_\2').downcase
underscored_class = self.class.name.gsub(/([[:lower:]])([[:upper:]][[:lower:]])/, '\1_\2').downcase
section = underscored_class.downcase.split("::").last
Utils.method_missing_message(method, @cask.to_s, section)
nil

View File

@ -62,7 +62,7 @@ module Hbc
begin
if arg.is_a?(Symbol)
Gem::Version.new(@macos_symbols.fetch(arg))
elsif arg =~ %r{^\s*:?([a-z]\S+)\s*$}i
elsif arg =~ /^\s*:?([a-z]\S+)\s*$/i
Gem::Version.new(@macos_symbols.fetch(Regexp.last_match[1].downcase.to_sym))
elsif @inverted_macos_symbols.key?(arg)
Gem::Version.new(arg)
@ -86,7 +86,7 @@ module Hbc
def macos=(*arg)
@macos ||= []
macos = if arg.count == 1 && arg.first =~ %r{^\s*(<|>|[=<>]=)\s*(\S+)\s*$}
macos = if arg.count == 1 && arg.first =~ /^\s*(<|>|[=<>]=)\s*(\S+)\s*$/
raise "'depends_on macos' comparison expressions cannot be combined" unless @macos.empty?
operator = Regexp.last_match[1].to_sym
release = self.class.coerce_os_release(Regexp.last_match[2])
@ -103,7 +103,7 @@ module Hbc
def arch=(*arg)
@arch ||= []
arches = Array(*arg).map { |elt|
elt = elt.to_s.downcase.sub(%r{^:}, "").tr("-", "_").to_sym
elt = elt.to_s.downcase.sub(/^:/, "").tr("-", "_").to_sym
ARCH_SYNONYMS.key?(elt) ? ARCH_SYNONYMS[elt] : elt
}
invalid_arches = arches - VALID_ARCHES.keys

View File

@ -28,7 +28,7 @@ module Hbc
def valid_id?(id)
legal_lengths = Set.new [8, 16, 40]
is_valid = id.is_a?(String) && legal_lengths.include?(id.length) && id[%r{^[0-9a-f]+$}i]
is_valid = id.is_a?(String) && legal_lengths.include?(id.length) && id[/^[0-9a-f]+$/i]
raise "invalid ':key_id' value: '#{id.inspect}'" unless is_valid
is_valid

View File

@ -8,9 +8,9 @@ module Hbc
"/" => :slashes,
}.freeze
DIVIDER_REGEX = %r{(#{DIVIDERS.keys.map { |v| Regexp.quote(v) }.join('|')})}
DIVIDER_REGEX = /(#{DIVIDERS.keys.map { |v| Regexp.quote(v) }.join('|')})/
MAJOR_MINOR_PATCH_REGEX = %r{^(\d+)(?:\.(\d+)(?:\.(\d+))?)?}
MAJOR_MINOR_PATCH_REGEX = /^(\d+)(?:\.(\d+)(?:\.(\d+))?)?/
class << self
private

View File

@ -5,7 +5,7 @@ module Hbc
TIMEOUT = 10
def self.head(url)
if url.to_s =~ %r{googlecode}
if url.to_s =~ /googlecode/
googlecode_fake_head(url)
else
SystemCommand.run("/usr/bin/curl",
@ -18,7 +18,7 @@ module Hbc
def self.googlecode_fake_head(url)
command = "curl --max-time #{TIMEOUT} --verbose --location '#{url}' | head -n 20 > /dev/null"
stderr = Open3.capture3(command)[1]
stderr.split("\n").grep(%r{^< }).map { |line| line.sub(%r{^< }, "") }.join("\n")
stderr.split("\n").grep(/^< /).map { |line| line.sub(/^< /, "") }.join("\n")
end
end
end

View File

@ -136,7 +136,7 @@ module Hbc
return query_path if query_path.absolute?
return query_path if query_path.exist? && query_path.extname == ".rb"
query_without_extension = query.sub(%r{\.rb$}i, "")
query_without_extension = query.sub(/\.rb$/i, "")
token_with_tap = if query =~ %r{\A[^/]+/[^/]+/[^/]+\Z}
query_without_extension

View File

@ -3,20 +3,20 @@ module Hbc
REPO_PREFIX = "homebrew-".freeze
# per https://github.com/Homebrew/homebrew/blob/4c7bc9ec3bca729c898ee347b6135ba692ee0274/Library/Homebrew/cmd/tap.rb#L121
USER_REGEX = %r{[a-z0-9_\-]+}
USER_REGEX = /[a-z0-9_\-]+/
# per https://github.com/Homebrew/homebrew/blob/4c7bc9ec3bca729c898ee347b6135ba692ee0274/Library/Homebrew/cmd/tap.rb#L121
REPO_REGEX = %r{(?:#{REPO_PREFIX})?\w+}
REPO_REGEX = /(?:#{REPO_PREFIX})?\w+/
# per https://github.com/caskroom/homebrew-cask/blob/master/CONTRIBUTING.md#generating-a-token-for-the-cask
TOKEN_REGEX = %r{[a-z0-9\-]+}
TOKEN_REGEX = /[a-z0-9\-]+/
TAP_REGEX = %r{#{USER_REGEX}[/\-]#{REPO_REGEX}}
QUALIFIED_TOKEN_REGEX = %r{#{TAP_REGEX}/#{TOKEN_REGEX}}
def self.parse(arg)
return nil unless arg.is_a?(String) && arg.downcase =~ %r{^#{QUALIFIED_TOKEN_REGEX}$}
return nil unless arg.is_a?(String) && arg.downcase =~ /^#{QUALIFIED_TOKEN_REGEX}$/
path_elements = arg.downcase.split("/")
if path_elements.count == 2
# eg phinze-cask/google-chrome.
@ -31,7 +31,7 @@ module Hbc
# per https://github.com/Homebrew/brew/blob/master/docs/brew-tap.md
user, repo, token = path_elements
end
repo.sub!(%r{^#{REPO_PREFIX}}, "")
repo.sub!(/^#{REPO_PREFIX}/, "")
odebug "[user, repo, token] might be [#{user}, #{repo}, #{token}]"
[user, repo, token]
end

View File

@ -22,7 +22,7 @@ module Hbc
def self.for_query(query)
odebug "Translating '#{query}' into a valid Cask source"
raise CaskUnavailableError, query if query.to_s =~ %r{^\s*$}
raise CaskUnavailableError, query if query.to_s =~ /^\s*$/
source = sources.find { |s|
odebug "Testing source class #{s}"
s.me?(query)

View File

@ -7,7 +7,7 @@ module Hbc
# derived classes must define method self.me?
def self.path_for_query(query)
Pathname.new(query).sub(%r{(\.rb)?$}, ".rb")
Pathname.new(query).sub(/(\.rb)?$/, ".rb")
end
attr_reader :path

View File

@ -144,7 +144,7 @@ module Hbc
end
def self._warn_plist_garbage(command, garbage)
return true unless garbage =~ %r{\S}
return true unless garbage =~ /\S/
external = File.basename(command.first)
lines = garbage.strip.split("\n")
opoo "Non-XML stdout from #{external}:"
@ -152,8 +152,8 @@ module Hbc
end
def self._parse_plist(command, output)
raise CaskError, "Empty plist input" unless output =~ %r{\S}
output.sub!(%r{\A(.*?)(<\?\s*xml)}m, '\2')
raise CaskError, "Empty plist input" unless output =~ /\S/
output.sub!(/\A(.*?)(<\?\s*xml)/m, '\2')
_warn_plist_garbage(command, Regexp.last_match[1]) if Hbc.debug
output.sub!(%r{(<\s*/\s*plist\s*>)(.*?)\Z}m, '\1')
_warn_plist_garbage(command, Regexp.last_match[2])

View File

@ -52,7 +52,7 @@ module Hbc
case cask.url.scheme
when "http", "https" then
@response_status = response_lines.grep(%r{^HTTP}).last
@response_status = response_lines.grep(/^HTTP/).last
if @response_status.respond_to?(:strip)
@response_status.strip!
unless response_lines.index(@response_status).nil?

View File

@ -12,7 +12,7 @@ class Object
def utf8_inspect
return inspect unless defined?(Encoding)
return map(&:utf8_inspect) if respond_to?(:map)
inspect.force_encoding("UTF-8").sub(%r{\A"(.*)"\Z}, '\1')
inspect.force_encoding("UTF-8").sub(/\A"(.*)"\Z/, '\1')
end
end

View File

@ -20,7 +20,7 @@ describe Hbc::Audit do
audit.add_error "bad"
end
it { is_expected.to match(%r{failed}) }
it { is_expected.to match(/failed/) }
end
context "when there are warnings" do
@ -28,7 +28,7 @@ describe Hbc::Audit do
audit.add_warning "eh"
end
it { is_expected.to match(%r{warning}) }
it { is_expected.to match(/warning/) }
end
context "when there are errors and warnings" do
@ -37,11 +37,11 @@ describe Hbc::Audit do
audit.add_warning "eh"
end
it { is_expected.to match(%r{failed}) }
it { is_expected.to match(/failed/) }
end
context "when there are no errors or warnings" do
it { is_expected.to match(%r{passed}) }
it { is_expected.to match(/passed/) }
end
end
@ -53,7 +53,7 @@ describe Hbc::Audit do
%w[version sha256 url name homepage].each do |stanza|
context "when missing #{stanza}" do
let(:cask_token) { "missing-#{stanza}" }
it { is_expected.to fail_with(%r{#{stanza} stanza is required}) }
it { is_expected.to fail_with(/#{stanza} stanza is required/) }
end
end
end
@ -85,36 +85,36 @@ describe Hbc::Audit do
context "when sha256 is sha256 for empty string" do
let(:cask_token) { "sha256-for-empty-string" }
it { is_expected.to fail_with(%r{cannot use the sha256 for an empty string}) }
it { is_expected.to fail_with(/cannot use the sha256 for an empty string/) }
end
end
describe "appcast checks" do
context "when appcast has no sha256" do
let(:cask_token) { "appcast-missing-checkpoint" }
it { is_expected.to fail_with(%r{checkpoint sha256 is required for appcast}) }
it { is_expected.to fail_with(/checkpoint sha256 is required for appcast/) }
end
context "when appcast checkpoint is not a string of 64 hexadecimal characters" do
let(:cask_token) { "appcast-invalid-checkpoint" }
it { is_expected.to fail_with(%r{string must be of 64 hexadecimal characters}) }
it { is_expected.to fail_with(/string must be of 64 hexadecimal characters/) }
end
context "when appcast checkpoint is sha256 for empty string" do
let(:cask_token) { "appcast-checkpoint-sha256-for-empty-string" }
it { is_expected.to fail_with(%r{cannot use the sha256 for an empty string}) }
it { is_expected.to fail_with(/cannot use the sha256 for an empty string/) }
end
context "when appcast checkpoint is valid sha256" do
let(:cask_token) { "appcast-valid-checkpoint" }
it { should_not fail_with(%r{appcast :checkpoint}) }
it { should_not fail_with(/appcast :checkpoint/) }
end
context "when verifying appcast HTTP code" do
let(:cask_token) { "appcast-valid-checkpoint" }
let(:download) { instance_double(Hbc::Download) }
let(:wrong_code_msg) { %r{unexpected HTTP response code} }
let(:curl_error_msg) { %r{error retrieving appcast} }
let(:wrong_code_msg) { /unexpected HTTP response code/ }
let(:curl_error_msg) { /error retrieving appcast/ }
let(:fake_curl_result) { instance_double(Hbc::SystemCommand::Result) }
before do
@ -155,8 +155,8 @@ describe Hbc::Audit do
context "when verifying appcast checkpoint" do
let(:cask_token) { "appcast-valid-checkpoint" }
let(:download) { instance_double(Hbc::Download) }
let(:mismatch_msg) { %r{appcast checkpoint mismatch} }
let(:curl_error_msg) { %r{error retrieving appcast} }
let(:mismatch_msg) { /appcast checkpoint mismatch/ }
let(:curl_error_msg) { /error retrieving appcast/ }
let(:fake_curl_result) { instance_double(Hbc::SystemCommand::Result) }
let(:expected_checkpoint) { "d5b2dfbef7ea28c25f7a77cd7fa14d013d82b626db1d82e00e25822464ba19e2" }
@ -203,7 +203,7 @@ describe Hbc::Audit do
end
describe "preferred download URL formats" do
let(:warning_msg) { %r{URL format incorrect} }
let(:warning_msg) { /URL format incorrect/ }
context "with incorrect SourceForge URL format" do
let(:cask_token) { "sourceforge-incorrect-url-format" }
@ -234,17 +234,17 @@ describe Hbc::Audit do
describe "generic artifact checks" do
context "with no target" do
let(:cask_token) { "generic-artifact-no-target" }
it { is_expected.to fail_with(%r{target required for generic artifact}) }
it { is_expected.to fail_with(/target required for generic artifact/) }
end
context "with relative target" do
let(:cask_token) { "generic-artifact-relative-target" }
it { is_expected.to fail_with(%r{target must be absolute path for generic artifact}) }
it { is_expected.to fail_with(/target must be absolute path for generic artifact/) }
end
context "with absolute target" do
let(:cask_token) { "generic-artifact-absolute-target" }
it { should_not fail_with(%r{target required for generic artifact}) }
it { should_not fail_with(/target required for generic artifact/) }
end
end
@ -260,7 +260,7 @@ describe Hbc::Audit do
context "when doing the audit" do
it "evaluates the block" do
expect(subject).to fail_with(%r{Boom})
expect(subject).to fail_with(/Boom/)
end
end
end
@ -276,12 +276,12 @@ describe Hbc::Audit do
context "when cask token conflicts with a core formula" do
let(:formula_names) { %w[with-binary other-formula] }
it { is_expected.to warn_with(%r{possible duplicate}) }
it { is_expected.to warn_with(/possible duplicate/) }
end
context "when cask token does not conflict with a core formula" do
let(:formula_names) { %w[other-formula] }
it { should_not warn_with(%r{possible duplicate}) }
it { should_not warn_with(/possible duplicate/) }
end
end
@ -298,7 +298,7 @@ describe Hbc::Audit do
expect(verify).to receive(:all)
end
it { should_not fail_with(%r{#{error_msg}}) }
it { should_not fail_with(/#{error_msg}/) }
end
context "when download fails" do
@ -306,7 +306,7 @@ describe Hbc::Audit do
expect(download).to receive(:perform).and_raise(StandardError.new(error_msg))
end
it { is_expected.to fail_with(%r{#{error_msg}}) }
it { is_expected.to fail_with(/#{error_msg}/) }
end
context "when verification fails" do
@ -315,7 +315,7 @@ describe Hbc::Audit do
expect(verify).to receive(:all).and_raise(StandardError.new(error_msg))
end
it { is_expected.to fail_with(%r{#{error_msg}}) }
it { is_expected.to fail_with(/#{error_msg}/) }
end
end
@ -325,7 +325,7 @@ describe Hbc::Audit do
expect(cask).to receive(:version).and_raise(StandardError.new)
end
it { is_expected.to fail_with(%r{exception while auditing}) }
it { is_expected.to fail_with(/exception while auditing/) }
end
end
end

View File

@ -4,7 +4,7 @@ describe Hbc::CLI::Doctor do
it "displays some nice info about the environment" do
expect {
Hbc::CLI::Doctor.run
}.to output(%r{\A==> macOS Release:}).to_stdout
}.to output(/\A==> macOS Release:/).to_stdout
end
it "raises an exception when arguments are given" do

View File

@ -84,7 +84,7 @@ describe Hbc::SystemCommand do
(1..6).each do |i|
expect {
described_class.run(command, options)
}.to output(%r{==> #{ i }}).to_stdout
}.to output(/==> #{ i }/).to_stdout
end
end

View File

@ -243,7 +243,7 @@ describe Hbc::Artifact::App do
describe "app is missing" do
it "returns a warning and the supposed path to the app" do
contents.size.must_equal 1
contents[0].must_match(%r{.*Missing App.*: #{target_path}})
contents[0].must_match(/.*Missing App.*: #{target_path}/)
end
end
end

View File

@ -29,7 +29,7 @@ describe Hbc::CLI::Install do
lambda {
Hbc::CLI::Install.run("local-transmission", "")
}.must_output nil, %r{Warning: A Cask for local-transmission is already installed.}
}.must_output nil, /Warning: A Cask for local-transmission is already installed./
end
it "allows double install with --force" do
@ -39,7 +39,7 @@ describe Hbc::CLI::Install do
lambda {
Hbc::CLI::Install.run("local-transmission", "--force")
}.must_output %r{==> Success! local-transmission was successfully installed!}
}.must_output(/==> Success! local-transmission was successfully installed!/)
end
it "skips dependencies with --skip-cask-deps" do
@ -64,7 +64,7 @@ describe Hbc::CLI::Install do
begin
Hbc::CLI::Install.run("googlechrome")
rescue Hbc::CaskError; end
}.must_output nil, %r{No available Cask for googlechrome\. Did you mean:\ngoogle-chrome}
}.must_output nil, /No available Cask for googlechrome\. Did you mean:\ngoogle-chrome/
end
it "returns multiple suggestions for a Cask fragment" do
@ -72,7 +72,7 @@ describe Hbc::CLI::Install do
begin
Hbc::CLI::Install.run("google")
rescue Hbc::CaskError; end
}.must_output nil, %r{No available Cask for google\. Did you mean one of:\ngoogle}
}.must_output nil, /No available Cask for google\. Did you mean one of:\ngoogle/
end
describe "when no Cask is specified" do

View File

@ -19,25 +19,25 @@ describe Hbc::CLI::Search do
it "lists all available Casks with no search term" do
out = capture_io { Hbc::CLI::Search.run }[0]
out.must_match(%r{google-chrome})
out.must_match(/google-chrome/)
out.length.must_be :>, 1000
end
it "ignores hyphens in search terms" do
out = capture_io { Hbc::CLI::Search.run("goo-gle-chrome") }[0]
out.must_match(%r{google-chrome})
out.must_match(/google-chrome/)
out.length.must_be :<, 100
end
it "ignores hyphens in Cask tokens" do
out = capture_io { Hbc::CLI::Search.run("googlechrome") }[0]
out.must_match(%r{google-chrome})
out.must_match(/google-chrome/)
out.length.must_be :<, 100
end
it "accepts multiple arguments" do
out = capture_io { Hbc::CLI::Search.run("google chrome") }[0]
out.must_match(%r{google-chrome})
out.must_match(/google-chrome/)
out.length.must_be :<, 100
end
@ -49,11 +49,11 @@ describe Hbc::CLI::Search do
it "Returns both exact and partial matches" do
out = capture_io { Hbc::CLI::Search.run("mnemosyne") }[0]
out.must_match(%r{^==> Exact match\nmnemosyne\n==> Partial matches\nsubclassed-mnemosyne})
out.must_match(/^==> Exact match\nmnemosyne\n==> Partial matches\nsubclassed-mnemosyne/)
end
it "does not search the Tap name" do
out = capture_io { Hbc::CLI::Search.run("caskroom") }[0]
out.must_match(%r{^No Cask found for "caskroom"\.\n})
out.must_match(/^No Cask found for "caskroom"\.\n/)
end
end

View File

@ -93,7 +93,7 @@ describe Hbc::CLI::Uninstall do
Hbc::CLI::Uninstall.run("versioned-cask")
end
out.must_match(%r{#{token} #{first_installed_version} is still installed.})
out.must_match(/#{token} #{first_installed_version} is still installed./)
err.must_be :empty?
end
end

View File

@ -250,7 +250,7 @@ describe Hbc::DSL do
describe "appcast stanza" do
it "allows appcasts to be specified" do
cask = Hbc.load("with-appcast")
cask.appcast.to_s.must_match %r{^http}
cask.appcast.to_s.must_match(/^http/)
end
it "prevents defining multiple appcasts" do
@ -270,12 +270,12 @@ describe Hbc::DSL do
describe "gpg stanza" do
it "allows gpg stanza to be specified" do
cask = Hbc.load("with-gpg")
cask.gpg.to_s.must_match %r{\S}
cask.gpg.to_s.must_match(/\S/)
end
it "allows gpg stanza to be specified with :key_url" do
cask = Hbc.load("with-gpg-key-url")
cask.gpg.to_s.must_match %r{\S}
cask.gpg.to_s.must_match(/\S/)
end
it "prevents specifying gpg stanza multiple times" do

View File

@ -239,7 +239,7 @@ describe Hbc::Installer do
with_caveats = Hbc.load("with-caveats")
lambda {
Hbc::Installer.new(with_caveats).install
}.must_output %r{Here are some things you might want to know}
}.must_output(/Here are some things you might want to know/)
with_caveats.must_be :installed?
end
@ -247,7 +247,7 @@ describe Hbc::Installer do
with_installer_manual = Hbc.load("with-installer-manual")
lambda {
Hbc::Installer.new(with_installer_manual).install
}.must_output %r{To complete the installation of Cask with-installer-manual, you must also\nrun the installer at\n\n '#{with_installer_manual.staged_path.join('Caffeine.app')}'}
}.must_output(/To complete the installation of Cask with-installer-manual, you must also\nrun the installer at\n\n '#{with_installer_manual.staged_path.join('Caffeine.app')}'/)
with_installer_manual.must_be :installed?
end