2015-08-03 13:09:07 +01:00
|
|
|
require "testing_env"
|
2015-08-14 23:23:52 +02:00
|
|
|
require "tempfile"
|
2010-03-08 22:10:12 -08:00
|
|
|
|
2014-06-18 20:32:51 -05:00
|
|
|
class UtilTests < Homebrew::TestCase
|
2015-08-14 23:23:52 +02:00
|
|
|
def setup
|
|
|
|
@dir = Pathname.new(mktmpdir)
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
@dir.rmtree
|
|
|
|
end
|
|
|
|
|
2010-03-08 22:10:12 -08:00
|
|
|
def test_put_columns_empty
|
2014-04-15 15:38:31 -05:00
|
|
|
# Issue #217 put columns with new results fails.
|
2014-06-12 22:05:45 -05:00
|
|
|
assert_silent { puts_columns [] }
|
2010-03-08 22:10:12 -08:00
|
|
|
end
|
2014-07-05 13:50:54 -05:00
|
|
|
|
2015-08-14 23:23:52 +02:00
|
|
|
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
|
|
|
|
|
2014-07-05 13:50:54 -05:00
|
|
|
def test_popen_read
|
2014-12-16 15:27:36 -05:00
|
|
|
out = Utils.popen_read("/bin/sh", "-c", "echo success").chomp
|
2014-07-05 13:50:54 -05:00
|
|
|
assert_equal "success", out
|
|
|
|
assert_predicate $?, :success?
|
|
|
|
end
|
2015-12-14 15:01:31 +01:00
|
|
|
|
|
|
|
def test_plural
|
|
|
|
assert_equal "", plural(1)
|
|
|
|
assert_equal "s", plural(0)
|
|
|
|
assert_equal "s", plural(42)
|
|
|
|
assert_equal "", plural(42, "")
|
|
|
|
end
|
2010-03-08 22:10:12 -08:00
|
|
|
end
|