From 3e4fe279b04393d480432371ff73bbb893bfe7d8 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Tue, 25 Apr 2017 19:04:00 +0200 Subject: Use `to_path_s` for `determine_pkg_config_libdir`. --- Library/Homebrew/extend/ENV.rb | 6 ++++++ Library/Homebrew/extend/ENV/std.rb | 2 +- Library/Homebrew/extend/ENV/super.rb | 6 ------ 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'Library/Homebrew') diff --git a/Library/Homebrew/extend/ENV.rb b/Library/Homebrew/extend/ENV.rb index 283e90b69..811737f10 100644 --- a/Library/Homebrew/extend/ENV.rb +++ b/Library/Homebrew/extend/ENV.rb @@ -3,6 +3,12 @@ require "extend/ENV/shared" require "extend/ENV/std" require "extend/ENV/super" +class Array + def to_path_s + map(&:to_s).uniq.select { |s| File.directory?(s) }.join(File::PATH_SEPARATOR).chuzzle + end +end + def superenv? ARGV.env != "std" && Superenv.bin end diff --git a/Library/Homebrew/extend/ENV/std.rb b/Library/Homebrew/extend/ENV/std.rb index aafc0a451..d64f2185a 100644 --- a/Library/Homebrew/extend/ENV/std.rb +++ b/Library/Homebrew/extend/ENV/std.rb @@ -62,7 +62,7 @@ module Stdenv paths << "#{HOMEBREW_PREFIX}/share/pkgconfig" paths += homebrew_extra_pkg_config_paths paths << "/usr/lib/pkgconfig" - paths.select { |d| File.directory? d }.join(File::PATH_SEPARATOR) + paths.to_path_s end # Removes the MAKEFLAGS environment variable, causing make to use a single job. diff --git a/Library/Homebrew/extend/ENV/super.rb b/Library/Homebrew/extend/ENV/super.rb index 4d6d96ad3..166973e09 100644 --- a/Library/Homebrew/extend/ENV/super.rb +++ b/Library/Homebrew/extend/ENV/super.rb @@ -330,10 +330,4 @@ module Superenv end end -class Array - def to_path_s - map(&:to_s).uniq.select { |s| File.directory? s }.join(File::PATH_SEPARATOR).chuzzle - end -end - require "extend/os/extend/ENV/super" -- cgit v1.2.3 From e221d0481a8f6bc324c507ece8e698b5f41c2d07 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Tue, 25 Apr 2017 23:42:53 +0200 Subject: Use `to_path_s` in `install_gem_setup_path!`. --- Library/Homebrew/utils.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Library/Homebrew') diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index edc540c45..972732ffe 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -190,10 +190,10 @@ module Homebrew Gem::Specification.reset # Add Gem binary directory and (if missing) Ruby binary directory to PATH. - path = ENV["PATH"].split(File::PATH_SEPARATOR) - path.unshift(RUBY_BIN) if which("ruby") != RUBY_PATH - path.unshift(Gem.bindir) - ENV["PATH"] = path.join(File::PATH_SEPARATOR) + paths = ENV["PATH"].split(File::PATH_SEPARATOR) + paths.unshift(RUBY_BIN) if which("ruby") != RUBY_PATH + paths.unshift(Gem.bindir) + ENV["PATH"] = paths.to_path_s if Gem::Specification.find_all_by_name(name, version).empty? ohai "Installing or updating '#{name}' gem" -- cgit v1.2.3 From a16746906d463ce9e4dc129bc5a76b81585ee1dd Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Thu, 27 Apr 2017 08:48:29 +0200 Subject: Add `PATH` class. --- Library/Homebrew/PATH.rb | 61 ++++++++++++++++++++++++++++++++++++++ Library/Homebrew/global.rb | 1 + Library/Homebrew/test/PATH_spec.rb | 52 ++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 Library/Homebrew/PATH.rb create mode 100644 Library/Homebrew/test/PATH_spec.rb (limited to 'Library/Homebrew') diff --git a/Library/Homebrew/PATH.rb b/Library/Homebrew/PATH.rb new file mode 100644 index 000000000..d6b549a1e --- /dev/null +++ b/Library/Homebrew/PATH.rb @@ -0,0 +1,61 @@ +class PATH + def initialize(*paths) + @paths = parse(*paths) + end + + def prepend(*paths) + @paths.unshift(*parse(*paths)) + self + end + + def append(*paths) + @paths.concat(parse(*paths)) + self + end + + def to_ary + @paths + end + alias to_a to_ary + + def to_str + @paths.join(File::PATH_SEPARATOR) + end + alias to_s to_str + + def eql?(other) + if other.respond_to?(:to_ary) + return true if to_ary == other.to_ary + end + + if other.respond_to?(:to_str) + return true if to_str == other.to_str + end + + false + end + alias == eql? + + def empty? + @paths.empty? + end + + def inspect + "" + end + + def validate + self.class.new(@paths.select(&File.method(:directory?))) + end + + private + + def parse(*paths) + paths + .flatten + .flat_map { |p| p.respond_to?(:to_str) ? p.to_str.split(File::PATH_SEPARATOR): p } + .compact + .map { |p| p.respond_to?(:to_path) ? p.to_path : p.to_str } + .uniq + end +end diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb index 108ca0cb7..b0bf647a1 100644 --- a/Library/Homebrew/global.rb +++ b/Library/Homebrew/global.rb @@ -3,6 +3,7 @@ require "extend/fileutils" require "extend/pathname" require "extend/git_repository" require "extend/ARGV" +require "PATH" require "extend/string" require "os" require "utils" diff --git a/Library/Homebrew/test/PATH_spec.rb b/Library/Homebrew/test/PATH_spec.rb new file mode 100644 index 000000000..d1b1f074d --- /dev/null +++ b/Library/Homebrew/test/PATH_spec.rb @@ -0,0 +1,52 @@ +require "PATH" + +describe PATH do + describe "#initialize" do + it "can take multiple arguments" do + expect(described_class.new("/path1", "/path2")).to eq("/path1:/path2") + end + + it "can parse a mix of arrays and arguments" do + expect(described_class.new(["/path1", "/path2"], "/path3")).to eq("/path1:/path2:/path3") + end + + it "splits an existing PATH" do + expect(described_class.new("/path1:/path2")).to eq(["/path1", "/path2"]) + end + end + + describe "#to_ary" do + it "returns a PATH array" do + expect(described_class.new("/path1", "/path2").to_ary).to eq(["/path1", "/path2"]) + end + end + + describe "#to_str" do + it "returns a PATH string" do + expect(described_class.new("/path1", "/path2").to_str).to eq("/path1:/path2") + end + end + + describe "#prepend" do + it "prepends a path to a PATH" do + expect(described_class.new("/path1").prepend("/path2").to_str).to eq("/path2:/path1") + end + end + + describe "#append" do + it "prepends a path to a PATH" do + expect(described_class.new("/path1").append("/path2").to_str).to eq("/path1:/path2") + end + end + + describe "#validate" do + it "returns a new PATH without non-existent paths" do + allow(File).to receive(:directory?).with("/path1").and_return(true) + allow(File).to receive(:directory?).with("/path2").and_return(false) + + path = described_class.new("/path1", "/path2") + expect(path.validate.to_ary).to eq(["/path1"]) + expect(path.to_ary).to eq(["/path1", "/path2"]) + end + end +end -- cgit v1.2.3 From 314483f75c8893eb68073f5863e7784797d6ea2a Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Thu, 27 Apr 2017 09:56:16 +0200 Subject: Remove `Array#to_path_s`. --- Library/Homebrew/extend/ENV.rb | 6 --- Library/Homebrew/extend/ENV/std.rb | 12 +++--- Library/Homebrew/extend/ENV/super.rb | 78 ++++++++++++++++++------------------ Library/Homebrew/utils.rb | 8 ++-- 4 files changed, 50 insertions(+), 54 deletions(-) (limited to 'Library/Homebrew') diff --git a/Library/Homebrew/extend/ENV.rb b/Library/Homebrew/extend/ENV.rb index 811737f10..283e90b69 100644 --- a/Library/Homebrew/extend/ENV.rb +++ b/Library/Homebrew/extend/ENV.rb @@ -3,12 +3,6 @@ require "extend/ENV/shared" require "extend/ENV/std" require "extend/ENV/super" -class Array - def to_path_s - map(&:to_s).uniq.select { |s| File.directory?(s) }.join(File::PATH_SEPARATOR).chuzzle - end -end - def superenv? ARGV.env != "std" && Superenv.bin end diff --git a/Library/Homebrew/extend/ENV/std.rb b/Library/Homebrew/extend/ENV/std.rb index d64f2185a..cf828cf20 100644 --- a/Library/Homebrew/extend/ENV/std.rb +++ b/Library/Homebrew/extend/ENV/std.rb @@ -57,12 +57,12 @@ module Stdenv end def determine_pkg_config_libdir - paths = [] - paths << "#{HOMEBREW_PREFIX}/lib/pkgconfig" - paths << "#{HOMEBREW_PREFIX}/share/pkgconfig" - paths += homebrew_extra_pkg_config_paths - paths << "/usr/lib/pkgconfig" - paths.to_path_s + PATH.new( + HOMEBREW_PREFIX/"lib/pkgconfig", + HOMEBREW_PREFIX/"share/pkgconfig", + homebrew_extra_pkg_config_paths, + "/usr/lib/pkgconfig", + ).validate end # Removes the MAKEFLAGS environment variable, causing make to use a single job. diff --git a/Library/Homebrew/extend/ENV/super.rb b/Library/Homebrew/extend/ENV/super.rb index 166973e09..90215da28 100644 --- a/Library/Homebrew/extend/ENV/super.rb +++ b/Library/Homebrew/extend/ENV/super.rb @@ -101,29 +101,28 @@ module Superenv end def determine_path - paths = [Superenv.bin] + path = PATH.new(Superenv.bin) # Formula dependencies can override standard tools. - paths += deps.map { |d| d.opt_bin.to_s } - - paths += homebrew_extra_paths - paths += %w[/usr/bin /bin /usr/sbin /sbin] + path.append(deps.map { |d| d.opt_bin.to_s }) + path.append(homebrew_extra_paths) + path.append("/usr/bin", "/bin", "/usr/sbin", "/sbin") # Homebrew's apple-gcc42 will be outside the PATH in superenv, # so xcrun may not be able to find it begin case homebrew_cc when "gcc-4.2" - paths << Formulary.factory("apple-gcc42").opt_bin + path.append(Formulary.factory("apple-gcc42").opt_bin) when GNU_GCC_REGEXP - paths << gcc_version_formula($&).opt_bin + path.append(gcc_version_formula($&).opt_bin) end rescue FormulaUnavailableError # Don't fail and don't add these formulae to the path if they don't exist. nil end - paths.to_path_s + path.validate end def homebrew_extra_pkg_config_paths @@ -131,15 +130,17 @@ module Superenv end def determine_pkg_config_path - paths = deps.map { |d| "#{d.opt_lib}/pkgconfig" } - paths += deps.map { |d| "#{d.opt_share}/pkgconfig" } - paths.to_path_s + PATH.new( + deps.map { |d| d.opt_lib/"pkgconfig" }, + deps.map { |d| d.opt_share/"pkgconfig" }, + ).validate end def determine_pkg_config_libdir - paths = %w[/usr/lib/pkgconfig] - paths += homebrew_extra_pkg_config_paths - paths.to_path_s + PATH.new( + "/usr/lib/pkgconfig", + homebrew_extra_pkg_config_paths, + ).validate end def homebrew_extra_aclocal_paths @@ -147,10 +148,11 @@ module Superenv end def determine_aclocal_path - paths = keg_only_deps.map { |d| "#{d.opt_share}/aclocal" } - paths << "#{HOMEBREW_PREFIX}/share/aclocal" - paths += homebrew_extra_aclocal_paths - paths.to_path_s + PATH.new( + keg_only_deps.map { |d| d.opt_share/"aclocal" }, + HOMEBREW_PREFIX/"share/aclocal", + homebrew_extra_aclocal_paths, + ).validate end def homebrew_extra_isystem_paths @@ -158,13 +160,14 @@ module Superenv end def determine_isystem_paths - paths = ["#{HOMEBREW_PREFIX}/include"] - paths += homebrew_extra_isystem_paths - paths.to_path_s + PATH.new( + HOMEBREW_PREFIX/"include", + homebrew_extra_isystem_paths, + ).validate end def determine_include_paths - keg_only_deps.map { |d| d.opt_include.to_s }.to_path_s + PATH.new(keg_only_deps.map(&:opt_include)).validate end def homebrew_extra_library_paths @@ -172,10 +175,11 @@ module Superenv end def determine_library_paths - paths = keg_only_deps.map { |d| d.opt_lib.to_s } - paths << "#{HOMEBREW_PREFIX}/lib" - paths += homebrew_extra_library_paths - paths.to_path_s + PATH.new( + keg_only_deps.map(&:opt_lib), + HOMEBREW_PREFIX/"lib", + homebrew_extra_library_paths, + ).validate end def determine_dependencies @@ -183,9 +187,10 @@ module Superenv end def determine_cmake_prefix_path - paths = keg_only_deps.map { |d| d.opt_prefix.to_s } - paths << HOMEBREW_PREFIX.to_s - paths.to_path_s + PATH.new( + keg_only_deps.map(&:opt_prefix), + HOMEBREW_PREFIX.to_s, + ).validate end def homebrew_extra_cmake_include_paths @@ -193,9 +198,7 @@ module Superenv end def determine_cmake_include_path - paths = [] - paths += homebrew_extra_cmake_include_paths - paths.to_path_s + PATH.new(homebrew_extra_cmake_include_paths).validate end def homebrew_extra_cmake_library_paths @@ -203,9 +206,7 @@ module Superenv end def determine_cmake_library_path - paths = [] - paths += homebrew_extra_cmake_library_paths - paths.to_path_s + PATH.new(homebrew_extra_cmake_library_paths).validate end def homebrew_extra_cmake_frameworks_paths @@ -213,9 +214,10 @@ module Superenv end def determine_cmake_frameworks_path - paths = deps.map { |d| d.opt_frameworks.to_s } - paths += homebrew_extra_cmake_frameworks_paths - paths.to_path_s + PATH.new( + deps.map(&:opt_frameworks), + homebrew_extra_cmake_frameworks_paths, + ).validate end def determine_make_jobs diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 972732ffe..2ac195cdb 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -190,10 +190,10 @@ module Homebrew Gem::Specification.reset # Add Gem binary directory and (if missing) Ruby binary directory to PATH. - paths = ENV["PATH"].split(File::PATH_SEPARATOR) - paths.unshift(RUBY_BIN) if which("ruby") != RUBY_PATH - paths.unshift(Gem.bindir) - ENV["PATH"] = paths.to_path_s + path = PATH.new(ENV["PATH"]) + path.prepend(RUBY_BIN) if which("ruby") != RUBY_PATH + path.prepend(Gem.bindir) + ENV["PATH"] = path.validate if Gem::Specification.find_all_by_name(name, version).empty? ohai "Installing or updating '#{name}' gem" -- cgit v1.2.3 From f8ad9d7efd5f3f489ed3c1671f16eb2a2eaef822 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Thu, 27 Apr 2017 10:44:44 +0200 Subject: Use `PATH` where possible. --- Library/Homebrew/brew.rb | 12 +++++++----- Library/Homebrew/cmd/sh.rb | 2 +- Library/Homebrew/diagnostic.rb | 2 +- Library/Homebrew/extend/ENV/shared.rb | 11 ++++++----- Library/Homebrew/extend/ENV/super.rb | 2 +- Library/Homebrew/global.rb | 2 +- Library/Homebrew/requirement.rb | 6 +++--- Library/Homebrew/utils.rb | 6 +++--- 8 files changed, 23 insertions(+), 20 deletions(-) (limited to 'Library/Homebrew') diff --git a/Library/Homebrew/brew.rb b/Library/Homebrew/brew.rb index 62cfd79c3..f2e723114 100644 --- a/Library/Homebrew/brew.rb +++ b/Library/Homebrew/brew.rb @@ -12,9 +12,9 @@ require "pathname" HOMEBREW_LIBRARY_PATH = Pathname.new(__FILE__).realpath.parent $:.unshift(HOMEBREW_LIBRARY_PATH.to_s) require "global" +require "tap" if ARGV == %w[--version] || ARGV == %w[-v] - require "tap" puts "Homebrew #{HOMEBREW_VERSION}" puts "Homebrew/homebrew-core #{CoreTap.instance.version_string}" exit 0 @@ -47,13 +47,15 @@ begin end end + path = PATH.new(ENV["PATH"]) + # Add contributed commands to PATH before checking. - Dir["#{HOMEBREW_LIBRARY}/Taps/*/*/cmd"].each do |tap_cmd_dir| - ENV["PATH"] += "#{File::PATH_SEPARATOR}#{tap_cmd_dir}" - end + path.append(Pathname.glob(Tap::TAP_DIRECTORY/"*/*/cmd")) # Add SCM wrappers. - ENV["PATH"] += "#{File::PATH_SEPARATOR}#{HOMEBREW_SHIMS_PATH}/scm" + path.append(HOMEBREW_SHIMS_PATH/"scm") + + ENV["PATH"] = path if cmd internal_cmd = require? HOMEBREW_LIBRARY_PATH.join("cmd", cmd) diff --git a/Library/Homebrew/cmd/sh.rb b/Library/Homebrew/cmd/sh.rb index 249753355..1e86784cb 100644 --- a/Library/Homebrew/cmd/sh.rb +++ b/Library/Homebrew/cmd/sh.rb @@ -23,7 +23,7 @@ module Homebrew ENV.setup_build_environment if superenv? # superenv stopped adding brew's bin but generally users will want it - ENV["PATH"] = ENV["PATH"].split(File::PATH_SEPARATOR).insert(1, "#{HOMEBREW_PREFIX}/bin").join(File::PATH_SEPARATOR) + ENV["PATH"] = PATH.new(PATH.new(ENV["PATH"]).to_a.insert(1, HOMEBREW_PREFIX/"bin")) end ENV["PS1"] = 'brew \[\033[1;32m\]\w\[\033[0m\]$ ' ENV["VERBOSE"] = "1" diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index 8cca1ba91..7657af193 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -100,7 +100,7 @@ module Homebrew # See https://github.com/Homebrew/legacy-homebrew/pull/9986 def check_path_for_trailing_slashes - all_paths = ENV["PATH"].split(File::PATH_SEPARATOR) + all_paths = PATH.new(ENV["PATH"]).to_a bad_paths = all_paths.select { |p| p[-1..-1] == "/" } return if bad_paths.empty? diff --git a/Library/Homebrew/extend/ENV/shared.rb b/Library/Homebrew/extend/ENV/shared.rb index 2cdc2f83a..6fa9b7778 100644 --- a/Library/Homebrew/extend/ENV/shared.rb +++ b/Library/Homebrew/extend/ENV/shared.rb @@ -1,6 +1,7 @@ require "formula" require "compilers" require "development_tools" +require "PATH" # Homebrew extends Ruby's `ENV` to make our code more readable. # Implemented in {SharedEnvExtension} and either {Superenv} or @@ -80,7 +81,7 @@ module SharedEnvExtension end def append_path(key, path) - append key, path, File::PATH_SEPARATOR if File.directory? path + self[key] = PATH.new(self[key]).append(path) end # Prepends a directory to `PATH`. @@ -92,7 +93,7 @@ module SharedEnvExtension # (e.g.
ENV.prepend_path "PATH", which("emacs").dirname
) def prepend_path(key, path) return if %w[/usr/bin /bin /usr/sbin /sbin].include? path.to_s - prepend key, path, File::PATH_SEPARATOR if File.directory? path + self[key] = PATH.new(self[key]).prepend(path) end def prepend_create_path(key, path) @@ -196,7 +197,7 @@ module SharedEnvExtension # @private def userpaths! - paths = self["PATH"].split(File::PATH_SEPARATOR) + paths = PATH.new(self["PATH"]).to_a # put Superenv.bin and opt path at the first new_paths = paths.select { |p| p.start_with?("#{HOMEBREW_REPOSITORY}/Library/ENV", "#{HOMEBREW_PREFIX}/opt") } # XXX hot fix to prefer brewed stuff (e.g. python) over /usr/bin. @@ -211,7 +212,7 @@ module SharedEnvExtension nil end end - %w[/usr/X11/bin /opt/X11/bin] - self["PATH"] = new_paths.uniq.join(File::PATH_SEPARATOR) + self["PATH"] = PATH.new(new_paths.uniq) end def fortran @@ -244,7 +245,7 @@ module SharedEnvExtension else if (gfortran = which("gfortran", (HOMEBREW_PREFIX/"bin").to_s)) ohai "Using Homebrew-provided fortran compiler." - elsif (gfortran = which("gfortran", ORIGINAL_PATHS.join(File::PATH_SEPARATOR))) + elsif (gfortran = which("gfortran", PATH.new(ORIGINAL_PATHS))) ohai "Using a fortran compiler found at #{gfortran}." end if gfortran diff --git a/Library/Homebrew/extend/ENV/super.rb b/Library/Homebrew/extend/ENV/super.rb index 90215da28..ac60e13cd 100644 --- a/Library/Homebrew/extend/ENV/super.rb +++ b/Library/Homebrew/extend/ENV/super.rb @@ -104,7 +104,7 @@ module Superenv path = PATH.new(Superenv.bin) # Formula dependencies can override standard tools. - path.append(deps.map { |d| d.opt_bin.to_s }) + path.append(deps.map(&:opt_bin)) path.append(homebrew_extra_paths) path.append("/usr/bin", "/bin", "/usr/sbin", "/sbin") diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb index b0bf647a1..c73d66c58 100644 --- a/Library/Homebrew/global.rb +++ b/Library/Homebrew/global.rb @@ -56,7 +56,7 @@ HOMEBREW_PULL_OR_COMMIT_URL_REGEX = %r[https://github\.com/([\w-]+)/([\w-]+)?/(? require "compat" unless ARGV.include?("--no-compat") || ENV["HOMEBREW_NO_COMPAT"] ENV["HOMEBREW_PATH"] ||= ENV["PATH"] -ORIGINAL_PATHS = ENV["HOMEBREW_PATH"].split(File::PATH_SEPARATOR).map do |p| +ORIGINAL_PATHS = PATH.new(ENV["HOMEBREW_PATH"]).to_a.map do |p| begin Pathname.new(p).expand_path rescue diff --git a/Library/Homebrew/requirement.rb b/Library/Homebrew/requirement.rb index a4bdabdd1..6146382a3 100644 --- a/Library/Homebrew/requirement.rb +++ b/Library/Homebrew/requirement.rb @@ -96,7 +96,7 @@ class Requirement # PATH. parent = satisfied_result_parent return unless parent - return if ENV["PATH"].split(File::PATH_SEPARATOR).include?(parent.to_s) + return if PATH.new(ENV["PATH"]).to_a.include?(parent.to_s) ENV.append_path("PATH", parent) end @@ -151,11 +151,11 @@ class Requirement end def which(cmd) - super(cmd, ORIGINAL_PATHS.join(File::PATH_SEPARATOR)) + super(cmd, PATH.new(ORIGINAL_PATHS)) end def which_all(cmd) - super(cmd, ORIGINAL_PATHS.join(File::PATH_SEPARATOR)) + super(cmd, PATH.new(ORIGINAL_PATHS)) end class << self diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 2ac195cdb..98a6ce6da 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -293,7 +293,7 @@ def quiet_system(cmd, *args) end def which(cmd, path = ENV["PATH"]) - path.split(File::PATH_SEPARATOR).each do |p| + PATH.new(path).to_a.each do |p| begin pcmd = File.expand_path(cmd, p) rescue ArgumentError @@ -307,7 +307,7 @@ def which(cmd, path = ENV["PATH"]) end def which_all(cmd, path = ENV["PATH"]) - path.to_s.split(File::PATH_SEPARATOR).map do |p| + PATH.new(path).to_a.map do |p| begin pcmd = File.expand_path(cmd, p) rescue ArgumentError @@ -416,7 +416,7 @@ def nostdout end def paths(env_path = ENV["PATH"]) - @paths ||= env_path.split(File::PATH_SEPARATOR).collect do |p| + @paths ||= PATH.new(env_path).to_a.collect do |p| begin File.expand_path(p).chomp("/") rescue ArgumentError -- cgit v1.2.3 From cb1ac3f9987dd27ddd6401c6ce0b5f02c4068e7e Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 28 Apr 2017 11:12:02 +0200 Subject: Don’t implement `PATH#eql?`. --- Library/Homebrew/PATH.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'Library/Homebrew') diff --git a/Library/Homebrew/PATH.rb b/Library/Homebrew/PATH.rb index d6b549a1e..0d4b9139d 100644 --- a/Library/Homebrew/PATH.rb +++ b/Library/Homebrew/PATH.rb @@ -23,7 +23,7 @@ class PATH end alias to_s to_str - def eql?(other) + def ==(other) if other.respond_to?(:to_ary) return true if to_ary == other.to_ary end @@ -34,7 +34,6 @@ class PATH false end - alias == eql? def empty? @paths.empty? -- cgit v1.2.3 From d552ff316df39048cddfeb1f554a4dd56eb0f57d Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 28 Apr 2017 11:13:47 +0200 Subject: Make `PATH#validate` return `nil` if empty. --- Library/Homebrew/PATH.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Library/Homebrew') diff --git a/Library/Homebrew/PATH.rb b/Library/Homebrew/PATH.rb index 0d4b9139d..38be51065 100644 --- a/Library/Homebrew/PATH.rb +++ b/Library/Homebrew/PATH.rb @@ -44,7 +44,8 @@ class PATH end def validate - self.class.new(@paths.select(&File.method(:directory?))) + validated_path = self.class.new(@paths.select(&File.method(:directory?))) + validated_path unless validated_path.empty? end private -- cgit v1.2.3 From 0bb9b4918e5068ab58799da11e758dbbe6592953 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 28 Apr 2017 11:14:43 +0200 Subject: Remove `PATH#inspect`. --- Library/Homebrew/PATH.rb | 4 ---- 1 file changed, 4 deletions(-) (limited to 'Library/Homebrew') diff --git a/Library/Homebrew/PATH.rb b/Library/Homebrew/PATH.rb index 38be51065..9ee621285 100644 --- a/Library/Homebrew/PATH.rb +++ b/Library/Homebrew/PATH.rb @@ -39,10 +39,6 @@ class PATH @paths.empty? end - def inspect - "" - end - def validate validated_path = self.class.new(@paths.select(&File.method(:directory?))) validated_path unless validated_path.empty? -- cgit v1.2.3 From e70f2ec33233422b70db047338aa85d9e2088042 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 28 Apr 2017 11:22:23 +0200 Subject: Make sure duplicates are remove from `PATH`. --- Library/Homebrew/PATH.rb | 4 ++-- Library/Homebrew/test/PATH_spec.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'Library/Homebrew') diff --git a/Library/Homebrew/PATH.rb b/Library/Homebrew/PATH.rb index 9ee621285..6c5cd9e41 100644 --- a/Library/Homebrew/PATH.rb +++ b/Library/Homebrew/PATH.rb @@ -4,12 +4,12 @@ class PATH end def prepend(*paths) - @paths.unshift(*parse(*paths)) + @paths = parse(*paths, *@paths) self end def append(*paths) - @paths.concat(parse(*paths)) + @paths = parse(*@paths, *paths) self end diff --git a/Library/Homebrew/test/PATH_spec.rb b/Library/Homebrew/test/PATH_spec.rb index d1b1f074d..7e42670f2 100644 --- a/Library/Homebrew/test/PATH_spec.rb +++ b/Library/Homebrew/test/PATH_spec.rb @@ -13,6 +13,10 @@ describe PATH do it "splits an existing PATH" do expect(described_class.new("/path1:/path2")).to eq(["/path1", "/path2"]) end + + it "removes duplicates" do + expect(described_class.new("/path1", "/path1")).to eq("/path1") + end end describe "#to_ary" do @@ -31,12 +35,20 @@ describe PATH do it "prepends a path to a PATH" do expect(described_class.new("/path1").prepend("/path2").to_str).to eq("/path2:/path1") end + + it "removes duplicates" do + expect(described_class.new("/path1").prepend("/path1").to_str).to eq("/path1") + end end describe "#append" do it "prepends a path to a PATH" do expect(described_class.new("/path1").append("/path2").to_str).to eq("/path1:/path2") end + + it "removes duplicates" do + expect(described_class.new("/path1").append("/path1").to_str).to eq("/path1") + end end describe "#validate" do -- cgit v1.2.3 From 22f624b373d77ede5c15db6f62672bdd81e6c9da Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 28 Apr 2017 12:39:00 +0200 Subject: Make `PATH` enumerable. --- Library/Homebrew/PATH.rb | 10 ++++++++++ Library/Homebrew/cmd/sh.rb | 2 +- Library/Homebrew/diagnostic.rb | 3 +-- Library/Homebrew/global.rb | 2 +- Library/Homebrew/requirement.rb | 2 +- Library/Homebrew/test/PATH_spec.rb | 35 +++++++++++++++++++++++++++++++++++ Library/Homebrew/utils.rb | 6 +++--- 7 files changed, 52 insertions(+), 8 deletions(-) (limited to 'Library/Homebrew') diff --git a/Library/Homebrew/PATH.rb b/Library/Homebrew/PATH.rb index 6c5cd9e41..0bee1a5f2 100644 --- a/Library/Homebrew/PATH.rb +++ b/Library/Homebrew/PATH.rb @@ -1,4 +1,9 @@ class PATH + include Enumerable + extend Forwardable + + def_delegator :@paths, :each + def initialize(*paths) @paths = parse(*paths) end @@ -13,6 +18,11 @@ class PATH self end + def insert(index, *paths) + @paths = parse(*@paths.insert(index, *paths)) + self + end + def to_ary @paths end diff --git a/Library/Homebrew/cmd/sh.rb b/Library/Homebrew/cmd/sh.rb index 1e86784cb..69f329cb3 100644 --- a/Library/Homebrew/cmd/sh.rb +++ b/Library/Homebrew/cmd/sh.rb @@ -23,7 +23,7 @@ module Homebrew ENV.setup_build_environment if superenv? # superenv stopped adding brew's bin but generally users will want it - ENV["PATH"] = PATH.new(PATH.new(ENV["PATH"]).to_a.insert(1, HOMEBREW_PREFIX/"bin")) + ENV["PATH"] = PATH.new(ENV["PATH"]).insert(1, HOMEBREW_PREFIX/"bin") end ENV["PS1"] = 'brew \[\033[1;32m\]\w\[\033[0m\]$ ' ENV["VERBOSE"] = "1" diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index 7657af193..1022e5d1d 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -100,8 +100,7 @@ module Homebrew # See https://github.com/Homebrew/legacy-homebrew/pull/9986 def check_path_for_trailing_slashes - all_paths = PATH.new(ENV["PATH"]).to_a - bad_paths = all_paths.select { |p| p[-1..-1] == "/" } + bad_paths = PATH.new(ENV["PATH"]).select { |p| p[-1..-1] == "/" } return if bad_paths.empty? inject_file_list bad_paths, <<-EOS.undent diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb index c73d66c58..877253072 100644 --- a/Library/Homebrew/global.rb +++ b/Library/Homebrew/global.rb @@ -56,7 +56,7 @@ HOMEBREW_PULL_OR_COMMIT_URL_REGEX = %r[https://github\.com/([\w-]+)/([\w-]+)?/(? require "compat" unless ARGV.include?("--no-compat") || ENV["HOMEBREW_NO_COMPAT"] ENV["HOMEBREW_PATH"] ||= ENV["PATH"] -ORIGINAL_PATHS = PATH.new(ENV["HOMEBREW_PATH"]).to_a.map do |p| +ORIGINAL_PATHS = PATH.new(ENV["HOMEBREW_PATH"]).map do |p| begin Pathname.new(p).expand_path rescue diff --git a/Library/Homebrew/requirement.rb b/Library/Homebrew/requirement.rb index 6146382a3..6c20e7917 100644 --- a/Library/Homebrew/requirement.rb +++ b/Library/Homebrew/requirement.rb @@ -96,7 +96,7 @@ class Requirement # PATH. parent = satisfied_result_parent return unless parent - return if PATH.new(ENV["PATH"]).to_a.include?(parent.to_s) + return if PATH.new(ENV["PATH"]).include?(parent.to_s) ENV.append_path("PATH", parent) end diff --git a/Library/Homebrew/test/PATH_spec.rb b/Library/Homebrew/test/PATH_spec.rb index 7e42670f2..07caae617 100644 --- a/Library/Homebrew/test/PATH_spec.rb +++ b/Library/Homebrew/test/PATH_spec.rb @@ -51,6 +51,41 @@ describe PATH do end end + describe "#insert" do + it "inserts a path at a given index" do + expect(described_class.new("/path1").insert(0, "/path2").to_str).to eq("/path2:/path1") + end + + it "can insert multiple paths" do + expect(described_class.new("/path1").insert(0, "/path2", "/path3")).to eq("/path2:/path3:/path1") + end + end + + describe "#include?" do + it "returns true if a path is included" do + path = described_class.new("/path1", "/path2") + expect(path).to include("/path1") + expect(path).to include("/path2") + end + + it "returns false if a path is not included" do + expect(described_class.new("/path1")).not_to include("/path2") + end + + it "returns false if the given string contains a separator" do + expect(described_class.new("/path1", "/path2")).not_to include("/path1:") + end + end + + describe "#each" do + it "loops through each path" do + enum = described_class.new("/path1", "/path2").each + + expect(enum.next).to eq("/path1") + expect(enum.next).to eq("/path2") + end + end + describe "#validate" do it "returns a new PATH without non-existent paths" do allow(File).to receive(:directory?).with("/path1").and_return(true) diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 98a6ce6da..257d24784 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -293,7 +293,7 @@ def quiet_system(cmd, *args) end def which(cmd, path = ENV["PATH"]) - PATH.new(path).to_a.each do |p| + PATH.new(path).each do |p| begin pcmd = File.expand_path(cmd, p) rescue ArgumentError @@ -307,7 +307,7 @@ def which(cmd, path = ENV["PATH"]) end def which_all(cmd, path = ENV["PATH"]) - PATH.new(path).to_a.map do |p| + PATH.new(path).map do |p| begin pcmd = File.expand_path(cmd, p) rescue ArgumentError @@ -416,7 +416,7 @@ def nostdout end def paths(env_path = ENV["PATH"]) - @paths ||= PATH.new(env_path).to_a.collect do |p| + @paths ||= PATH.new(env_path).collect do |p| begin File.expand_path(p).chomp("/") rescue ArgumentError -- cgit v1.2.3 From 4d5d6a65e35f9a57139710c3dc547bfa51810630 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 28 Apr 2017 12:42:17 +0200 Subject: Rename `PATH#validate` to `PATH#existing`. --- Library/Homebrew/PATH.rb | 14 +++++++++++--- Library/Homebrew/extend/ENV/std.rb | 2 +- Library/Homebrew/extend/ENV/super.rb | 22 +++++++++++----------- Library/Homebrew/test/PATH_spec.rb | 4 ++-- Library/Homebrew/utils.rb | 2 +- 5 files changed, 26 insertions(+), 18 deletions(-) (limited to 'Library/Homebrew') diff --git a/Library/Homebrew/PATH.rb b/Library/Homebrew/PATH.rb index 0bee1a5f2..eaa963ea5 100644 --- a/Library/Homebrew/PATH.rb +++ b/Library/Homebrew/PATH.rb @@ -23,6 +23,14 @@ class PATH self end + def select(&block) + self.class.new(@paths.select(&block)) + end + + def reject(&block) + self.class.new(@paths.reject(&block)) + end + def to_ary @paths end @@ -49,9 +57,9 @@ class PATH @paths.empty? end - def validate - validated_path = self.class.new(@paths.select(&File.method(:directory?))) - validated_path unless validated_path.empty? + def existing + existing_path = select(&File.method(:directory?)) + existing_path unless existing_path.empty? end private diff --git a/Library/Homebrew/extend/ENV/std.rb b/Library/Homebrew/extend/ENV/std.rb index cf828cf20..c4cc0985f 100644 --- a/Library/Homebrew/extend/ENV/std.rb +++ b/Library/Homebrew/extend/ENV/std.rb @@ -62,7 +62,7 @@ module Stdenv HOMEBREW_PREFIX/"share/pkgconfig", homebrew_extra_pkg_config_paths, "/usr/lib/pkgconfig", - ).validate + ).existing end # Removes the MAKEFLAGS environment variable, causing make to use a single job. diff --git a/Library/Homebrew/extend/ENV/super.rb b/Library/Homebrew/extend/ENV/super.rb index ac60e13cd..ef41161af 100644 --- a/Library/Homebrew/extend/ENV/super.rb +++ b/Library/Homebrew/extend/ENV/super.rb @@ -122,7 +122,7 @@ module Superenv nil end - path.validate + path.existing end def homebrew_extra_pkg_config_paths @@ -133,14 +133,14 @@ module Superenv PATH.new( deps.map { |d| d.opt_lib/"pkgconfig" }, deps.map { |d| d.opt_share/"pkgconfig" }, - ).validate + ).existing end def determine_pkg_config_libdir PATH.new( "/usr/lib/pkgconfig", homebrew_extra_pkg_config_paths, - ).validate + ).existing end def homebrew_extra_aclocal_paths @@ -152,7 +152,7 @@ module Superenv keg_only_deps.map { |d| d.opt_share/"aclocal" }, HOMEBREW_PREFIX/"share/aclocal", homebrew_extra_aclocal_paths, - ).validate + ).existing end def homebrew_extra_isystem_paths @@ -163,11 +163,11 @@ module Superenv PATH.new( HOMEBREW_PREFIX/"include", homebrew_extra_isystem_paths, - ).validate + ).existing end def determine_include_paths - PATH.new(keg_only_deps.map(&:opt_include)).validate + PATH.new(keg_only_deps.map(&:opt_include)).existing end def homebrew_extra_library_paths @@ -179,7 +179,7 @@ module Superenv keg_only_deps.map(&:opt_lib), HOMEBREW_PREFIX/"lib", homebrew_extra_library_paths, - ).validate + ).existing end def determine_dependencies @@ -190,7 +190,7 @@ module Superenv PATH.new( keg_only_deps.map(&:opt_prefix), HOMEBREW_PREFIX.to_s, - ).validate + ).existing end def homebrew_extra_cmake_include_paths @@ -198,7 +198,7 @@ module Superenv end def determine_cmake_include_path - PATH.new(homebrew_extra_cmake_include_paths).validate + PATH.new(homebrew_extra_cmake_include_paths).existing end def homebrew_extra_cmake_library_paths @@ -206,7 +206,7 @@ module Superenv end def determine_cmake_library_path - PATH.new(homebrew_extra_cmake_library_paths).validate + PATH.new(homebrew_extra_cmake_library_paths).existing end def homebrew_extra_cmake_frameworks_paths @@ -217,7 +217,7 @@ module Superenv PATH.new( deps.map(&:opt_frameworks), homebrew_extra_cmake_frameworks_paths, - ).validate + ).existing end def determine_make_jobs diff --git a/Library/Homebrew/test/PATH_spec.rb b/Library/Homebrew/test/PATH_spec.rb index 07caae617..409819a17 100644 --- a/Library/Homebrew/test/PATH_spec.rb +++ b/Library/Homebrew/test/PATH_spec.rb @@ -86,13 +86,13 @@ describe PATH do end end - describe "#validate" do + describe "#existing" do it "returns a new PATH without non-existent paths" do allow(File).to receive(:directory?).with("/path1").and_return(true) allow(File).to receive(:directory?).with("/path2").and_return(false) path = described_class.new("/path1", "/path2") - expect(path.validate.to_ary).to eq(["/path1"]) + expect(path.existing.to_ary).to eq(["/path1"]) expect(path.to_ary).to eq(["/path1", "/path2"]) end end diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 257d24784..83b8ba342 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -193,7 +193,7 @@ module Homebrew path = PATH.new(ENV["PATH"]) path.prepend(RUBY_BIN) if which("ruby") != RUBY_PATH path.prepend(Gem.bindir) - ENV["PATH"] = path.validate + ENV["PATH"] = path.existing if Gem::Specification.find_all_by_name(name, version).empty? ohai "Installing or updating '#{name}' gem" -- cgit v1.2.3 From 24f48ae7d9be865186728de9f6b324e32546ad36 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 28 Apr 2017 15:07:46 +0200 Subject: Use `PATH#select`. --- Library/Homebrew/diagnostic.rb | 2 +- Library/Homebrew/extend/ENV/shared.rb | 33 +++++++++++++++++---------------- 2 files changed, 18 insertions(+), 17 deletions(-) (limited to 'Library/Homebrew') diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index 1022e5d1d..1544e6765 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -100,7 +100,7 @@ module Homebrew # See https://github.com/Homebrew/legacy-homebrew/pull/9986 def check_path_for_trailing_slashes - bad_paths = PATH.new(ENV["PATH"]).select { |p| p[-1..-1] == "/" } + bad_paths = PATH.new(ENV["PATH"]).select { |p| p.end_with?("/") } return if bad_paths.empty? inject_file_list bad_paths, <<-EOS.undent diff --git a/Library/Homebrew/extend/ENV/shared.rb b/Library/Homebrew/extend/ENV/shared.rb index 6fa9b7778..b51ade48b 100644 --- a/Library/Homebrew/extend/ENV/shared.rb +++ b/Library/Homebrew/extend/ENV/shared.rb @@ -197,22 +197,23 @@ module SharedEnvExtension # @private def userpaths! - paths = PATH.new(self["PATH"]).to_a - # put Superenv.bin and opt path at the first - new_paths = paths.select { |p| p.start_with?("#{HOMEBREW_REPOSITORY}/Library/ENV", "#{HOMEBREW_PREFIX}/opt") } - # XXX hot fix to prefer brewed stuff (e.g. python) over /usr/bin. - new_paths << "#{HOMEBREW_PREFIX}/bin" - # reset of self["PATH"] - new_paths += paths - # user paths - new_paths += ORIGINAL_PATHS.map do |p| - begin - p.realpath.to_s - rescue - nil - end - end - %w[/usr/X11/bin /opt/X11/bin] - self["PATH"] = PATH.new(new_paths.uniq) + path = PATH.new(self["PATH"]).select do |p| + # put Superenv.bin and opt path at the first + p.start_with?("#{HOMEBREW_REPOSITORY}/Library/ENV", "#{HOMEBREW_PREFIX}/opt") + end + path.append(HOMEBREW_PREFIX/"bin") # XXX hot fix to prefer brewed stuff (e.g. python) over /usr/bin. + path.append(self["PATH"]) # reset of self["PATH"] + path.append( + # user paths + ORIGINAL_PATHS.map do |p| + begin + p.realpath.to_s + rescue + nil + end + end - %w[/usr/X11/bin /opt/X11/bin], + ) + self["PATH"] = path end def fortran -- cgit v1.2.3 From 005f165dcb3cce388ef6215ed0ed2be775f1f336 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 28 Apr 2017 20:46:52 +0200 Subject: Simplify `PATH#parse`. --- Library/Homebrew/PATH.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'Library/Homebrew') diff --git a/Library/Homebrew/PATH.rb b/Library/Homebrew/PATH.rb index eaa963ea5..f1c0ebb5d 100644 --- a/Library/Homebrew/PATH.rb +++ b/Library/Homebrew/PATH.rb @@ -65,11 +65,9 @@ class PATH private def parse(*paths) - paths - .flatten - .flat_map { |p| p.respond_to?(:to_str) ? p.to_str.split(File::PATH_SEPARATOR): p } - .compact - .map { |p| p.respond_to?(:to_path) ? p.to_path : p.to_str } - .uniq + paths.flatten + .compact + .flat_map { |p| Pathname.new(p).to_path.split(File::PATH_SEPARATOR) } + .uniq end end -- cgit v1.2.3 From 1c7238e59ba49e8c86c9830fa43d4007d24f6e83 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 30 Apr 2017 21:18:06 +0200 Subject: Add tests for `PATH#select` and `PATH#reject`. --- Library/Homebrew/test/PATH_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'Library/Homebrew') diff --git a/Library/Homebrew/test/PATH_spec.rb b/Library/Homebrew/test/PATH_spec.rb index 409819a17..b20a3d3ac 100644 --- a/Library/Homebrew/test/PATH_spec.rb +++ b/Library/Homebrew/test/PATH_spec.rb @@ -86,6 +86,18 @@ describe PATH do end end + describe "#select" do + it "returns an object of the same class instead of an Array" do + expect(described_class.new.select { true }).to be_a(described_class) + end + end + + describe "#reject" do + it "returns an object of the same class instead of an Array" do + expect(described_class.new.reject { true }).to be_a(described_class) + end + end + describe "#existing" do it "returns a new PATH without non-existent paths" do allow(File).to receive(:directory?).with("/path1").and_return(true) -- cgit v1.2.3 From 1be5eeec26000b881c2ec8ff53333266eedd9fff Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 30 Apr 2017 21:23:12 +0200 Subject: Add test and comment for `PATH#existing`. --- Library/Homebrew/PATH.rb | 1 + Library/Homebrew/test/PATH_spec.rb | 4 ++++ 2 files changed, 5 insertions(+) (limited to 'Library/Homebrew') diff --git a/Library/Homebrew/PATH.rb b/Library/Homebrew/PATH.rb index f1c0ebb5d..de7167eb4 100644 --- a/Library/Homebrew/PATH.rb +++ b/Library/Homebrew/PATH.rb @@ -59,6 +59,7 @@ class PATH def existing existing_path = select(&File.method(:directory?)) + # return nil instead of empty PATH, to unset environment variables existing_path unless existing_path.empty? end diff --git a/Library/Homebrew/test/PATH_spec.rb b/Library/Homebrew/test/PATH_spec.rb index b20a3d3ac..68233c23c 100644 --- a/Library/Homebrew/test/PATH_spec.rb +++ b/Library/Homebrew/test/PATH_spec.rb @@ -107,5 +107,9 @@ describe PATH do expect(path.existing.to_ary).to eq(["/path1"]) expect(path.to_ary).to eq(["/path1", "/path2"]) end + + it "returns nil instead of an empty #{described_class}" do + expect(described_class.new.existing).to be nil + end end end -- cgit v1.2.3