Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow lowercase environment variables in UTF-8 check #338

Merged
merged 2 commits into from Oct 3, 2013
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Next

Add test for current enable_utf8 behavior

  • Loading branch information...
ddfreyne committed Oct 2, 2013
commit c922faf150d14619677895332c29f6712672fe7d
@@ -102,4 +102,38 @@ def test_load_custom_commands_broken
end
end

def test_enable_utf8_only_on_tty
new_env_diff = {
'LC_ALL' => 'en_US.ISO-8859-1',
'LC_CTYPE' => 'en_US.ISO-8859-1',
'LANG' => 'en_US.ISO-8859-1',
}
with_env_vars(new_env_diff) do
io = StringIO.new
def io.tty? ; true ; end
refute Nanoc::CLI.enable_utf8?(io)

io = StringIO.new
def io.tty? ; false ; end
assert Nanoc::CLI.enable_utf8?(io)
end
end

def test_enable_utf8
io = StringIO.new
def io.tty? ; true ; end

new_env_diff = {
'LC_ALL' => 'en_US.ISO-8859-1',
'LC_CTYPE' => 'en_US.ISO-8859-1',
'LANG' => 'en_US.ISO-8859-1',
}
with_env_vars(new_env_diff) do
refute Nanoc::CLI.enable_utf8?(io)
with_env_vars({ 'LC_ALL' => 'en_US.UTF-8' }) { assert Nanoc::CLI.enable_utf8?(io) }
with_env_vars({ 'LC_CTYPE' => 'en_US.UTF-8' }) { assert Nanoc::CLI.enable_utf8?(io) }
with_env_vars({ 'LANG' => 'en_US.UTF-8' }) { assert Nanoc::CLI.enable_utf8?(io) }
end
end

end
@@ -181,7 +181,7 @@ def assert_examples_correct(object)
lines.each_slice(2) do |pair|
actual_out = eval(pair.first, b)
expected_out = eval(pair.last.match(/# ?=>(.*)/)[1], b)

assert_equal expected_out, actual_out,
"Incorrect example:\n#{pair.first}"
end
@@ -205,6 +205,14 @@ def assert_raises_frozen_error
assert_match(/(^can't modify frozen |^unable to modify frozen object$)/, error.message)
end

def with_env_vars(hash, &block)
orig_env_hash = ENV.to_hash
hash.each_pair { |k,v| ENV[k] = v }
yield
ensure
orig_env_hash.each_pair { |k,v| ENV[k] = v }
end

end

class Nanoc::TestCase < MiniTest::Unit::TestCase
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.