Skip to content
Snippets Groups Projects
Commit ccb613df authored by Baptiste Fontaine's avatar Baptiste Fontaine
Browse files

which: tests added


Closes Homebrew/homebrew#42954.

Signed-off-by: default avatarBaptiste Fontaine <batifon@yahoo.fr>
parent c631fc30
No related branches found
No related tags found
No related merge requests found
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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment