aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test/test_utils.rb
diff options
context:
space:
mode:
authorBaptiste Fontaine2016-01-08 18:27:03 +0100
committerBaptiste Fontaine2016-01-09 10:37:29 +0100
commitdaf659cbaec9eb1704361a61c7387f6936f78f8b (patch)
tree29ec236cb5b200f3b21cd9a63e9b8deb764145e1 /Library/Homebrew/test/test_utils.rb
parentbeb80c605fdbf1f8b958ba1268173dc415b47850 (diff)
downloadbrew-daf659cbaec9eb1704361a61c7387f6936f78f8b.tar.bz2
more utils tests
Closes Homebrew/homebrew#47856. Signed-off-by: Baptiste Fontaine <batifon@yahoo.fr>
Diffstat (limited to 'Library/Homebrew/test/test_utils.rb')
-rw-r--r--Library/Homebrew/test/test_utils.rb102
1 files changed, 101 insertions, 1 deletions
diff --git a/Library/Homebrew/test/test_utils.rb b/Library/Homebrew/test/test_utils.rb
index bff6c6dd2..128b26dea 100644
--- a/Library/Homebrew/test/test_utils.rb
+++ b/Library/Homebrew/test/test_utils.rb
@@ -1,17 +1,89 @@
require "testing_env"
+require "utils"
require "tempfile"
+class TtyTests < Homebrew::TestCase
+ def test_strip_ansi
+ assert_equal "hello",
+ Tty.strip_ansi("\033\[36;7mhello\033\[0m")
+ end
+
+ def test_truncate
+ Tty.stubs(:width).returns 10
+ assert_equal "foobar", Tty.truncate("foobar something very long")
+ assert_equal "trunca", Tty.truncate("truncate")
+ end
+
+ def test_no_tty_formatting
+ $stdout.stubs(:tty?).returns false
+ assert_nil Tty.blue
+ assert_nil Tty.white
+ assert_nil Tty.red
+ assert_nil Tty.green
+ assert_nil Tty.gray
+ assert_nil Tty.yellow
+ assert_nil Tty.reset
+ assert_nil Tty.em
+ assert_nil Tty.highlight
+ end
+end
+
class UtilTests < Homebrew::TestCase
def setup
@dir = Pathname.new(mktmpdir)
+ @env = ENV.to_hash
end
def teardown
@dir.rmtree
+ ENV.replace @env
+ end
+
+ def test_ofail
+ shutup { ofail "foo" }
+ assert Homebrew.failed
+ ensure
+ Homebrew.failed = false
+ end
+
+ def test_odie
+ expects(:exit).returns 1
+ shutup { odie "foo" }
+ end
+
+ def test_pretty_installed
+ $stdout.stubs(:tty?).returns false
+ assert_equal "foo", pretty_installed("foo")
+ end
+
+ def test_pretty_uninstalled
+ $stdout.stubs(:tty?).returns false
+ assert_equal "foo", pretty_uninstalled("foo")
+ end
+
+ def test_interactive_shell
+ mktmpdir do |path|
+ shell = "#{path}/myshell"
+ File.open(shell, "w") do |file|
+ file.write "#!/bin/sh\necho called > #{path}/called\n"
+ end
+ FileUtils.chmod 0755, shell
+ ENV["SHELL"] = shell
+ assert_nothing_raised { interactive_shell }
+ assert File.exist? "#{path}/called"
+ end
+ end
+
+ def test_run_as_not_developer
+ ENV["HOMEBREW_DEVELOPER"] = "foo"
+ run_as_not_developer do
+ assert_nil ENV["HOMEBREW_DEVELOPER"]
+ end
+ assert_equal "foo", ENV["HOMEBREW_DEVELOPER"]
end
def test_put_columns_empty
- # Issue #217 put columns with new results fails.
+ # Issue #217 put columns with no results fails.
assert_silent { puts_columns [] }
end
@@ -56,6 +128,34 @@ class UtilTests < Homebrew::TestCase
which_all("foo", "#{@dir}/bar/baz:#{@dir}/baz:#{@dir}:~baduserpath")
end
+ def test_which_editor
+ ENV["HOMEBREW_EDITOR"] = "vemate"
+ assert_equal "vemate", which_editor
+ end
+
+ def test_gzip
+ mktmpdir do |path|
+ somefile = "#{path}/somefile"
+ FileUtils.touch somefile
+ assert_equal "#{somefile}.gz",
+ gzip(somefile)[0].to_s
+ assert File.exist?("#{somefile}.gz")
+ end
+ end
+
+ def test_shell_profile
+ ENV["SHELL"] = "/bin/sh"
+ assert_equal "~/.bash_profile", shell_profile
+ ENV["SHELL"] = "/bin/bash"
+ assert_equal "~/.bash_profile", shell_profile
+ ENV["SHELL"] = "/bin/another_shell"
+ assert_equal "~/.bash_profile", shell_profile
+ ENV["SHELL"] = "/bin/zsh"
+ assert_equal "~/.zshrc", shell_profile
+ ENV["SHELL"] = "/bin/ksh"
+ assert_equal "~/.kshrc", shell_profile
+ end
+
def test_popen_read
out = Utils.popen_read("/bin/sh", "-c", "echo success").chomp
assert_equal "success", out