diff options
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/test/test_utils.rb | 10 | ||||
| -rw-r--r-- | Library/Homebrew/utils.rb | 3 |
2 files changed, 9 insertions, 4 deletions
diff --git a/Library/Homebrew/test/test_utils.rb b/Library/Homebrew/test/test_utils.rb index 08e95e190..b0caa6a2d 100644 --- a/Library/Homebrew/test/test_utils.rb +++ b/Library/Homebrew/test/test_utils.rb @@ -9,9 +9,13 @@ class TtyTests < Homebrew::TestCase end def test_truncate - Tty.stubs(:width).returns 10 - assert_equal "foobar", Tty.truncate("foobar something very long") - assert_equal "trunca", Tty.truncate("truncate") + Tty.stubs(:width).returns 15 + assert_equal "foobar some", Tty.truncate("foobar something very long") + assert_equal "truncate", Tty.truncate("truncate") + + # When the terminal is unsupported, we report 0 width + Tty.stubs(:width).returns 0 + assert_equal "foobar something very long", Tty.truncate("foobar something very long") end def test_no_tty_formatting diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index c2b0dd231..84bfb59b0 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -65,7 +65,8 @@ class Tty end def truncate(str) - str.to_s[0, width - 4] + w = width + w > 10 ? str.to_s[0, w - 4] : str end private |
