aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew
diff options
context:
space:
mode:
authorBaptiste Fontaine2015-08-14 23:23:52 +0200
committerBaptiste Fontaine2015-08-16 17:03:05 +0200
commitccb613df69980c31bdae9acc5a3cd64a644f1fa2 (patch)
tree614f6250ff171bc4de9ae5738dcf7fbbd4d830da /Library/Homebrew
parentc631fc30131bc429d0da60053c5169376a507aae (diff)
downloadbrew-ccb613df69980c31bdae9acc5a3cd64a644f1fa2.tar.bz2
which: tests added
Closes Homebrew/homebrew#42954. Signed-off-by: Baptiste Fontaine <batifon@yahoo.fr>
Diffstat (limited to 'Library/Homebrew')
-rw-r--r--Library/Homebrew/test/test_utils.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/Library/Homebrew/test/test_utils.rb b/Library/Homebrew/test/test_utils.rb
index 07bb65c90..9dc283084 100644
--- a/Library/Homebrew/test/test_utils.rb
+++ b/Library/Homebrew/test/test_utils.rb
@@ -1,11 +1,48 @@
require "testing_env"
+require "tempfile"
class UtilTests < Homebrew::TestCase
+
+ def setup
+ @dir = Pathname.new(mktmpdir)
+ end
+
+ def teardown
+ @dir.rmtree
+ end
+
def test_put_columns_empty
# Issue #217 put columns with new results fails.
assert_silent { puts_columns [] }
end
+ def test_which
+ cmd = @dir/"foo"
+ FileUtils.touch cmd
+ cmd.chmod 0744
+ assert_equal Pathname.new(cmd),
+ which(File.basename(cmd), File.dirname(cmd))
+ end
+
+ def test_which_skip_non_executables
+ cmd = @dir/"foo"
+ FileUtils.touch cmd
+ assert_nil which(File.basename(cmd), File.dirname(cmd))
+ end
+
+ def test_which_skip_malformed_path
+ # 'which' should not fail if a path is malformed
+ # see https://github.com/Homebrew/homebrew/issues/32789 for an example
+ cmd = @dir/"foo"
+ FileUtils.touch cmd
+ cmd.chmod 0744
+
+ # ~~ will fail because ~foo resolves to foo's home and there is no '~' user
+ # here
+ assert_equal Pathname.new(cmd),
+ which(File.basename(cmd), "~~#{File::PATH_SEPARATOR}#{File.dirname(cmd)}")
+ end
+
def test_popen_read
out = Utils.popen_read("/bin/sh", "-c", "echo success").chomp
assert_equal "success", out