handle Unicode filenames on Windows + test

by adding an argument "encoding: 'UTF-8'" to Dir.entries.
Also add minimal test.
This commit is contained in:
Johan Holmberg 2016-11-07 14:53:21 +01:00
parent bb2e7bf4a7
commit 42342d0c96
3 changed files with 39 additions and 1 deletions

View File

@ -27,8 +27,16 @@ require "find"
module Cmdtest
class FsSnapshot
def _dir_entries(dir, &block)
if Cmdtest::Util.windows?
Dir.entries(dir, encoding: 'UTF-8', &block)
else
Dir.entries(dir, &block)
end
end
def recursive_find(ignore, prefix, dir, &block)
for entry in Dir.entries(dir)
for entry in _dir_entries(dir)
next if entry == "."
next if entry == ".."
path = File.join(dir, entry)

25
t/CMDTEST_unicode.rb Normal file
View File

@ -0,0 +1,25 @@
require "selftest_utils"
class CMDTEST_unicode < Cmdtest::Testcase
include SelftestUtils
def test_unicode
create_CMDTEST_foo [
"cmd 'create_unicode_file.rb' do",
" created_files 'tmp-ΑΒΓ-αβγ-א-Њ-åäöÅÄÖ.txt'",
"end",
]
cmd_cmdtest do
stdout_equal [
"### create_unicode_file.rb",
]
end
end
end

5
t/bin/create_unicode_file.rb Executable file
View File

@ -0,0 +1,5 @@
#!/usr/bin/env ruby
File.open('tmp-ΑΒΓ-αβγ-א-Њ-åäöÅÄÖ.txt', 'w', encoding: 'UTF-8') do |f|
f.puts 'this is tmp-ΑΒΓ-αβγ-א-Њ-åäöÅÄÖ.txt'
end