2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
2009-11-15 11:24:45 -05:00
|
|
|
require 'test/unit'
|
|
|
|
require 'tmpdir'
|
2017-08-15 17:33:43 -04:00
|
|
|
require '-test-/file'
|
2009-11-15 11:24:45 -05:00
|
|
|
|
|
|
|
class TestDir_M17N < Test::Unit::TestCase
|
|
|
|
def with_tmpdir
|
|
|
|
Dir.mktmpdir {|dir|
|
|
|
|
Dir.chdir(dir) {
|
|
|
|
yield dir
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2014-05-28 00:20:35 -04:00
|
|
|
def assert_raw_file_name(code, encoding)
|
2012-07-23 19:32:29 -04:00
|
|
|
with_tmpdir { |dir|
|
2013-05-20 14:10:34 -04:00
|
|
|
assert_separately(["-E#{encoding}"], <<-EOS, :chdir=>dir)
|
2012-07-23 19:32:29 -04:00
|
|
|
filename = #{code}.chr('UTF-8').force_encoding("#{encoding}")
|
|
|
|
File.open(filename, "w") {}
|
|
|
|
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
|
Make rb_scan_args handle keywords more similar to Ruby methods (#2460)
Cfuncs that use rb_scan_args with the : entry suffer similar keyword
argument separation issues that Ruby methods suffer if the cfuncs
accept optional or variable arguments.
This makes the following changes to : handling.
* Treats as **kw, prompting keyword argument separation warnings
if called with a positional hash.
* Do not look for an option hash if empty keywords are provided.
For backwards compatibility, treat an empty keyword splat as a empty
mandatory positional hash argument, but emit a a warning, as this
behavior will be removed in Ruby 3. The argument number check
needs to be moved lower so it can correctly handle an empty
positional argument being added.
* If the last argument is nil and it is necessary to treat it as an option
hash in order to make sure all arguments are processed, continue to
treat the last argument as the option hash. Emit a warning in this case,
as this behavior will be removed in Ruby 3.
* If splitting the keyword hash into two hashes, issue a warning, as we
will not be splitting hashes in Ruby 3.
* If the keyword argument is required to fill a mandatory positional
argument, continue to do so, but emit a warning as this behavior will
be going away in Ruby 3.
* If keyword arguments are provided and the last argument is not a hash,
that indicates something wrong. This can happen if a cfunc is calling
rb_scan_args multiple times, and providing arguments that were not
passed to it from Ruby. Callers need to switch to the new
rb_scan_args_kw function, which allows passing of whether keywords
were provided.
This commit fixes all warnings caused by the changes above.
It switches some function calls to *_kw versions with appropriate
kw_splat flags. If delegating arguments, RB_PASS_CALLED_KEYWORDS
is used. If creating new arguments, RB_PASS_KEYWORDS is used if
the last argument is a hash to be treated as keywords.
In open_key_args in io.c, use rb_scan_args_kw.
In this case, the arguments provided come from another C
function, not Ruby. The last argument may or may not be a hash,
so we can't set keyword argument mode. However, if it is a
hash, we don't want to warn when treating it as keywords.
In Ruby files, make sure to appropriately use keyword splats
or literal keywords when calling Cfuncs that now issue keyword
argument separation warnings through rb_scan_args. Also, make
sure not to pass nil in place of an option hash.
Work around Kernel#warn warnings due to problems in the Rubygems
override of the method. There is an open pull request to fix
these issues in Rubygems, but part of the Rubygems tests for
their override fail on ruby-head due to rb_scan_args not
recognizing empty keyword splats, which this commit fixes.
Implementation wise, adding rb_scan_args_kw is kind of a pain,
because rb_scan_args takes a variable number of arguments.
In order to not duplicate all the code, the function internals need
to be split into two functions taking a va_list, and to avoid passing
in a ton of arguments, a single struct argument is used to handle
the variables previously local to the function.
2019-09-25 14:18:49 -04:00
|
|
|
ents = Dir.entries(".", **(opts||{}))
|
2013-05-20 14:10:34 -04:00
|
|
|
assert_include(ents, filename)
|
|
|
|
EOS
|
2012-07-23 19:32:29 -04:00
|
|
|
|
2016-06-19 03:55:25 -04:00
|
|
|
return if /cygwin/ =~ RUBY_PLATFORM
|
2013-05-20 14:10:34 -04:00
|
|
|
assert_separately(%w[-EASCII-8BIT], <<-EOS, :chdir=>dir)
|
2012-07-23 19:32:29 -04:00
|
|
|
filename = #{code}.chr('UTF-8').force_encoding("ASCII-8BIT")
|
|
|
|
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
|
Make rb_scan_args handle keywords more similar to Ruby methods (#2460)
Cfuncs that use rb_scan_args with the : entry suffer similar keyword
argument separation issues that Ruby methods suffer if the cfuncs
accept optional or variable arguments.
This makes the following changes to : handling.
* Treats as **kw, prompting keyword argument separation warnings
if called with a positional hash.
* Do not look for an option hash if empty keywords are provided.
For backwards compatibility, treat an empty keyword splat as a empty
mandatory positional hash argument, but emit a a warning, as this
behavior will be removed in Ruby 3. The argument number check
needs to be moved lower so it can correctly handle an empty
positional argument being added.
* If the last argument is nil and it is necessary to treat it as an option
hash in order to make sure all arguments are processed, continue to
treat the last argument as the option hash. Emit a warning in this case,
as this behavior will be removed in Ruby 3.
* If splitting the keyword hash into two hashes, issue a warning, as we
will not be splitting hashes in Ruby 3.
* If the keyword argument is required to fill a mandatory positional
argument, continue to do so, but emit a warning as this behavior will
be going away in Ruby 3.
* If keyword arguments are provided and the last argument is not a hash,
that indicates something wrong. This can happen if a cfunc is calling
rb_scan_args multiple times, and providing arguments that were not
passed to it from Ruby. Callers need to switch to the new
rb_scan_args_kw function, which allows passing of whether keywords
were provided.
This commit fixes all warnings caused by the changes above.
It switches some function calls to *_kw versions with appropriate
kw_splat flags. If delegating arguments, RB_PASS_CALLED_KEYWORDS
is used. If creating new arguments, RB_PASS_KEYWORDS is used if
the last argument is a hash to be treated as keywords.
In open_key_args in io.c, use rb_scan_args_kw.
In this case, the arguments provided come from another C
function, not Ruby. The last argument may or may not be a hash,
so we can't set keyword argument mode. However, if it is a
hash, we don't want to warn when treating it as keywords.
In Ruby files, make sure to appropriately use keyword splats
or literal keywords when calling Cfuncs that now issue keyword
argument separation warnings through rb_scan_args. Also, make
sure not to pass nil in place of an option hash.
Work around Kernel#warn warnings due to problems in the Rubygems
override of the method. There is an open pull request to fix
these issues in Rubygems, but part of the Rubygems tests for
their override fail on ruby-head due to rb_scan_args not
recognizing empty keyword splats, which this commit fixes.
Implementation wise, adding rb_scan_args_kw is kind of a pain,
because rb_scan_args takes a variable number of arguments.
In order to not duplicate all the code, the function internals need
to be split into two functions taking a va_list, and to avoid passing
in a ton of arguments, a single struct argument is used to handle
the variables previously local to the function.
2019-09-25 14:18:49 -04:00
|
|
|
ents = Dir.entries(".", **(opts||{}))
|
2012-07-23 19:32:29 -04:00
|
|
|
expected_filename = #{code}.chr('UTF-8').encode(Encoding.find("filesystem")) rescue expected_filename = "?"
|
|
|
|
expected_filename = expected_filename.force_encoding("ASCII-8BIT")
|
2013-05-20 14:10:34 -04:00
|
|
|
if /mswin|mingw/ =~ RUBY_PLATFORM
|
|
|
|
case
|
|
|
|
when ents.include?(filename)
|
|
|
|
when ents.include?(expected_filename)
|
|
|
|
filename = expected_filename
|
|
|
|
else
|
Make rb_scan_args handle keywords more similar to Ruby methods (#2460)
Cfuncs that use rb_scan_args with the : entry suffer similar keyword
argument separation issues that Ruby methods suffer if the cfuncs
accept optional or variable arguments.
This makes the following changes to : handling.
* Treats as **kw, prompting keyword argument separation warnings
if called with a positional hash.
* Do not look for an option hash if empty keywords are provided.
For backwards compatibility, treat an empty keyword splat as a empty
mandatory positional hash argument, but emit a a warning, as this
behavior will be removed in Ruby 3. The argument number check
needs to be moved lower so it can correctly handle an empty
positional argument being added.
* If the last argument is nil and it is necessary to treat it as an option
hash in order to make sure all arguments are processed, continue to
treat the last argument as the option hash. Emit a warning in this case,
as this behavior will be removed in Ruby 3.
* If splitting the keyword hash into two hashes, issue a warning, as we
will not be splitting hashes in Ruby 3.
* If the keyword argument is required to fill a mandatory positional
argument, continue to do so, but emit a warning as this behavior will
be going away in Ruby 3.
* If keyword arguments are provided and the last argument is not a hash,
that indicates something wrong. This can happen if a cfunc is calling
rb_scan_args multiple times, and providing arguments that were not
passed to it from Ruby. Callers need to switch to the new
rb_scan_args_kw function, which allows passing of whether keywords
were provided.
This commit fixes all warnings caused by the changes above.
It switches some function calls to *_kw versions with appropriate
kw_splat flags. If delegating arguments, RB_PASS_CALLED_KEYWORDS
is used. If creating new arguments, RB_PASS_KEYWORDS is used if
the last argument is a hash to be treated as keywords.
In open_key_args in io.c, use rb_scan_args_kw.
In this case, the arguments provided come from another C
function, not Ruby. The last argument may or may not be a hash,
so we can't set keyword argument mode. However, if it is a
hash, we don't want to warn when treating it as keywords.
In Ruby files, make sure to appropriately use keyword splats
or literal keywords when calling Cfuncs that now issue keyword
argument separation warnings through rb_scan_args. Also, make
sure not to pass nil in place of an option hash.
Work around Kernel#warn warnings due to problems in the Rubygems
override of the method. There is an open pull request to fix
these issues in Rubygems, but part of the Rubygems tests for
their override fail on ruby-head due to rb_scan_args not
recognizing empty keyword splats, which this commit fixes.
Implementation wise, adding rb_scan_args_kw is kind of a pain,
because rb_scan_args takes a variable number of arguments.
In order to not duplicate all the code, the function internals need
to be split into two functions taking a va_list, and to avoid passing
in a ton of arguments, a single struct argument is used to handle
the variables previously local to the function.
2019-09-25 14:18:49 -04:00
|
|
|
ents = Dir.entries(".", :encoding => Encoding.find("filesystem"))
|
2013-05-20 14:10:34 -04:00
|
|
|
filename = expected_filename
|
|
|
|
end
|
2012-07-23 19:32:29 -04:00
|
|
|
end
|
2013-05-20 14:10:34 -04:00
|
|
|
assert_include(ents, filename)
|
|
|
|
EOS
|
2012-07-23 19:32:29 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2009-11-16 08:45:59 -05:00
|
|
|
## UTF-8 default_external, no default_internal
|
|
|
|
|
|
|
|
def test_filename_extutf8
|
|
|
|
with_tmpdir {|d|
|
2013-05-20 14:10:34 -04:00
|
|
|
assert_separately(%w[-EUTF-8], <<-'EOS', :chdir=>d)
|
2009-11-16 08:45:59 -05:00
|
|
|
filename = "\u3042"
|
|
|
|
File.open(filename, "w") {}
|
2010-05-16 22:07:00 -04:00
|
|
|
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
|
Make rb_scan_args handle keywords more similar to Ruby methods (#2460)
Cfuncs that use rb_scan_args with the : entry suffer similar keyword
argument separation issues that Ruby methods suffer if the cfuncs
accept optional or variable arguments.
This makes the following changes to : handling.
* Treats as **kw, prompting keyword argument separation warnings
if called with a positional hash.
* Do not look for an option hash if empty keywords are provided.
For backwards compatibility, treat an empty keyword splat as a empty
mandatory positional hash argument, but emit a a warning, as this
behavior will be removed in Ruby 3. The argument number check
needs to be moved lower so it can correctly handle an empty
positional argument being added.
* If the last argument is nil and it is necessary to treat it as an option
hash in order to make sure all arguments are processed, continue to
treat the last argument as the option hash. Emit a warning in this case,
as this behavior will be removed in Ruby 3.
* If splitting the keyword hash into two hashes, issue a warning, as we
will not be splitting hashes in Ruby 3.
* If the keyword argument is required to fill a mandatory positional
argument, continue to do so, but emit a warning as this behavior will
be going away in Ruby 3.
* If keyword arguments are provided and the last argument is not a hash,
that indicates something wrong. This can happen if a cfunc is calling
rb_scan_args multiple times, and providing arguments that were not
passed to it from Ruby. Callers need to switch to the new
rb_scan_args_kw function, which allows passing of whether keywords
were provided.
This commit fixes all warnings caused by the changes above.
It switches some function calls to *_kw versions with appropriate
kw_splat flags. If delegating arguments, RB_PASS_CALLED_KEYWORDS
is used. If creating new arguments, RB_PASS_KEYWORDS is used if
the last argument is a hash to be treated as keywords.
In open_key_args in io.c, use rb_scan_args_kw.
In this case, the arguments provided come from another C
function, not Ruby. The last argument may or may not be a hash,
so we can't set keyword argument mode. However, if it is a
hash, we don't want to warn when treating it as keywords.
In Ruby files, make sure to appropriately use keyword splats
or literal keywords when calling Cfuncs that now issue keyword
argument separation warnings through rb_scan_args. Also, make
sure not to pass nil in place of an option hash.
Work around Kernel#warn warnings due to problems in the Rubygems
override of the method. There is an open pull request to fix
these issues in Rubygems, but part of the Rubygems tests for
their override fail on ruby-head due to rb_scan_args not
recognizing empty keyword splats, which this commit fixes.
Implementation wise, adding rb_scan_args_kw is kind of a pain,
because rb_scan_args takes a variable number of arguments.
In order to not duplicate all the code, the function internals need
to be split into two functions taking a va_list, and to avoid passing
in a ton of arguments, a single struct argument is used to handle
the variables previously local to the function.
2019-09-25 14:18:49 -04:00
|
|
|
ents = Dir.entries(".", **(opts||{}))
|
2013-05-20 14:10:34 -04:00
|
|
|
assert_include(ents, filename)
|
2009-11-16 08:45:59 -05:00
|
|
|
EOS
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_filename_extutf8_invalid
|
2016-06-19 03:55:25 -04:00
|
|
|
return if /cygwin/ =~ RUBY_PLATFORM
|
2017-08-15 17:33:43 -04:00
|
|
|
# High Sierra's APFS cannot use invalid filenames
|
|
|
|
return if Bug::File::Fs.fsname(Dir.tmpdir) == "apfs"
|
2009-11-16 08:45:59 -05:00
|
|
|
with_tmpdir {|d|
|
2013-05-20 14:10:34 -04:00
|
|
|
assert_separately(%w[-EASCII-8BIT], <<-'EOS', :chdir=>d)
|
2009-11-16 08:45:59 -05:00
|
|
|
filename = "\xff".force_encoding("ASCII-8BIT") # invalid byte sequence as UTF-8
|
|
|
|
File.open(filename, "w") {}
|
2010-05-16 22:07:00 -04:00
|
|
|
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
|
Make rb_scan_args handle keywords more similar to Ruby methods (#2460)
Cfuncs that use rb_scan_args with the : entry suffer similar keyword
argument separation issues that Ruby methods suffer if the cfuncs
accept optional or variable arguments.
This makes the following changes to : handling.
* Treats as **kw, prompting keyword argument separation warnings
if called with a positional hash.
* Do not look for an option hash if empty keywords are provided.
For backwards compatibility, treat an empty keyword splat as a empty
mandatory positional hash argument, but emit a a warning, as this
behavior will be removed in Ruby 3. The argument number check
needs to be moved lower so it can correctly handle an empty
positional argument being added.
* If the last argument is nil and it is necessary to treat it as an option
hash in order to make sure all arguments are processed, continue to
treat the last argument as the option hash. Emit a warning in this case,
as this behavior will be removed in Ruby 3.
* If splitting the keyword hash into two hashes, issue a warning, as we
will not be splitting hashes in Ruby 3.
* If the keyword argument is required to fill a mandatory positional
argument, continue to do so, but emit a warning as this behavior will
be going away in Ruby 3.
* If keyword arguments are provided and the last argument is not a hash,
that indicates something wrong. This can happen if a cfunc is calling
rb_scan_args multiple times, and providing arguments that were not
passed to it from Ruby. Callers need to switch to the new
rb_scan_args_kw function, which allows passing of whether keywords
were provided.
This commit fixes all warnings caused by the changes above.
It switches some function calls to *_kw versions with appropriate
kw_splat flags. If delegating arguments, RB_PASS_CALLED_KEYWORDS
is used. If creating new arguments, RB_PASS_KEYWORDS is used if
the last argument is a hash to be treated as keywords.
In open_key_args in io.c, use rb_scan_args_kw.
In this case, the arguments provided come from another C
function, not Ruby. The last argument may or may not be a hash,
so we can't set keyword argument mode. However, if it is a
hash, we don't want to warn when treating it as keywords.
In Ruby files, make sure to appropriately use keyword splats
or literal keywords when calling Cfuncs that now issue keyword
argument separation warnings through rb_scan_args. Also, make
sure not to pass nil in place of an option hash.
Work around Kernel#warn warnings due to problems in the Rubygems
override of the method. There is an open pull request to fix
these issues in Rubygems, but part of the Rubygems tests for
their override fail on ruby-head due to rb_scan_args not
recognizing empty keyword splats, which this commit fixes.
Implementation wise, adding rb_scan_args_kw is kind of a pain,
because rb_scan_args takes a variable number of arguments.
In order to not duplicate all the code, the function internals need
to be split into two functions taking a va_list, and to avoid passing
in a ton of arguments, a single struct argument is used to handle
the variables previously local to the function.
2019-09-25 14:18:49 -04:00
|
|
|
ents = Dir.entries(".", **(opts||{}))
|
2013-05-20 14:10:34 -04:00
|
|
|
filename = "%FF" if /darwin/ =~ RUBY_PLATFORM && ents.include?("%FF")
|
|
|
|
assert_include(ents, filename)
|
2009-11-16 08:45:59 -05:00
|
|
|
EOS
|
2013-05-20 14:10:34 -04:00
|
|
|
assert_separately(%w[-EUTF-8], <<-'EOS', :chdir=>d)
|
2009-11-16 08:45:59 -05:00
|
|
|
filename = "\xff".force_encoding("UTF-8") # invalid byte sequence as UTF-8
|
|
|
|
File.open(filename, "w") {}
|
2010-05-16 22:07:00 -04:00
|
|
|
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
|
Make rb_scan_args handle keywords more similar to Ruby methods (#2460)
Cfuncs that use rb_scan_args with the : entry suffer similar keyword
argument separation issues that Ruby methods suffer if the cfuncs
accept optional or variable arguments.
This makes the following changes to : handling.
* Treats as **kw, prompting keyword argument separation warnings
if called with a positional hash.
* Do not look for an option hash if empty keywords are provided.
For backwards compatibility, treat an empty keyword splat as a empty
mandatory positional hash argument, but emit a a warning, as this
behavior will be removed in Ruby 3. The argument number check
needs to be moved lower so it can correctly handle an empty
positional argument being added.
* If the last argument is nil and it is necessary to treat it as an option
hash in order to make sure all arguments are processed, continue to
treat the last argument as the option hash. Emit a warning in this case,
as this behavior will be removed in Ruby 3.
* If splitting the keyword hash into two hashes, issue a warning, as we
will not be splitting hashes in Ruby 3.
* If the keyword argument is required to fill a mandatory positional
argument, continue to do so, but emit a warning as this behavior will
be going away in Ruby 3.
* If keyword arguments are provided and the last argument is not a hash,
that indicates something wrong. This can happen if a cfunc is calling
rb_scan_args multiple times, and providing arguments that were not
passed to it from Ruby. Callers need to switch to the new
rb_scan_args_kw function, which allows passing of whether keywords
were provided.
This commit fixes all warnings caused by the changes above.
It switches some function calls to *_kw versions with appropriate
kw_splat flags. If delegating arguments, RB_PASS_CALLED_KEYWORDS
is used. If creating new arguments, RB_PASS_KEYWORDS is used if
the last argument is a hash to be treated as keywords.
In open_key_args in io.c, use rb_scan_args_kw.
In this case, the arguments provided come from another C
function, not Ruby. The last argument may or may not be a hash,
so we can't set keyword argument mode. However, if it is a
hash, we don't want to warn when treating it as keywords.
In Ruby files, make sure to appropriately use keyword splats
or literal keywords when calling Cfuncs that now issue keyword
argument separation warnings through rb_scan_args. Also, make
sure not to pass nil in place of an option hash.
Work around Kernel#warn warnings due to problems in the Rubygems
override of the method. There is an open pull request to fix
these issues in Rubygems, but part of the Rubygems tests for
their override fail on ruby-head due to rb_scan_args not
recognizing empty keyword splats, which this commit fixes.
Implementation wise, adding rb_scan_args_kw is kind of a pain,
because rb_scan_args takes a variable number of arguments.
In order to not duplicate all the code, the function internals need
to be split into two functions taking a va_list, and to avoid passing
in a ton of arguments, a single struct argument is used to handle
the variables previously local to the function.
2019-09-25 14:18:49 -04:00
|
|
|
ents = Dir.entries(".", **(opts||{}))
|
2013-05-20 14:10:34 -04:00
|
|
|
filename = "%FF" if /darwin/ =~ RUBY_PLATFORM && ents.include?("%FF")
|
|
|
|
assert_include(ents, filename)
|
2009-11-16 08:45:59 -05:00
|
|
|
EOS
|
|
|
|
}
|
2011-03-24 22:50:17 -04:00
|
|
|
end unless /mswin|mingw/ =~ RUBY_PLATFORM
|
2009-11-16 08:45:59 -05:00
|
|
|
|
2009-11-18 08:02:28 -05:00
|
|
|
def test_filename_as_bytes_extutf8
|
|
|
|
with_tmpdir {|d|
|
2013-05-20 14:10:34 -04:00
|
|
|
assert_separately(%w[-EUTF-8], <<-'EOS', :chdir=>d)
|
2009-11-18 08:02:28 -05:00
|
|
|
filename = "\xc2\xa1".force_encoding("utf-8")
|
|
|
|
File.open(filename, "w") {}
|
2010-05-16 22:07:00 -04:00
|
|
|
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
|
Make rb_scan_args handle keywords more similar to Ruby methods (#2460)
Cfuncs that use rb_scan_args with the : entry suffer similar keyword
argument separation issues that Ruby methods suffer if the cfuncs
accept optional or variable arguments.
This makes the following changes to : handling.
* Treats as **kw, prompting keyword argument separation warnings
if called with a positional hash.
* Do not look for an option hash if empty keywords are provided.
For backwards compatibility, treat an empty keyword splat as a empty
mandatory positional hash argument, but emit a a warning, as this
behavior will be removed in Ruby 3. The argument number check
needs to be moved lower so it can correctly handle an empty
positional argument being added.
* If the last argument is nil and it is necessary to treat it as an option
hash in order to make sure all arguments are processed, continue to
treat the last argument as the option hash. Emit a warning in this case,
as this behavior will be removed in Ruby 3.
* If splitting the keyword hash into two hashes, issue a warning, as we
will not be splitting hashes in Ruby 3.
* If the keyword argument is required to fill a mandatory positional
argument, continue to do so, but emit a warning as this behavior will
be going away in Ruby 3.
* If keyword arguments are provided and the last argument is not a hash,
that indicates something wrong. This can happen if a cfunc is calling
rb_scan_args multiple times, and providing arguments that were not
passed to it from Ruby. Callers need to switch to the new
rb_scan_args_kw function, which allows passing of whether keywords
were provided.
This commit fixes all warnings caused by the changes above.
It switches some function calls to *_kw versions with appropriate
kw_splat flags. If delegating arguments, RB_PASS_CALLED_KEYWORDS
is used. If creating new arguments, RB_PASS_KEYWORDS is used if
the last argument is a hash to be treated as keywords.
In open_key_args in io.c, use rb_scan_args_kw.
In this case, the arguments provided come from another C
function, not Ruby. The last argument may or may not be a hash,
so we can't set keyword argument mode. However, if it is a
hash, we don't want to warn when treating it as keywords.
In Ruby files, make sure to appropriately use keyword splats
or literal keywords when calling Cfuncs that now issue keyword
argument separation warnings through rb_scan_args. Also, make
sure not to pass nil in place of an option hash.
Work around Kernel#warn warnings due to problems in the Rubygems
override of the method. There is an open pull request to fix
these issues in Rubygems, but part of the Rubygems tests for
their override fail on ruby-head due to rb_scan_args not
recognizing empty keyword splats, which this commit fixes.
Implementation wise, adding rb_scan_args_kw is kind of a pain,
because rb_scan_args takes a variable number of arguments.
In order to not duplicate all the code, the function internals need
to be split into two functions taking a va_list, and to avoid passing
in a ton of arguments, a single struct argument is used to handle
the variables previously local to the function.
2019-09-25 14:18:49 -04:00
|
|
|
ents = Dir.entries(".", **(opts||{}))
|
2013-05-20 14:10:34 -04:00
|
|
|
assert_include(ents, filename)
|
2009-11-18 08:02:28 -05:00
|
|
|
EOS
|
2013-05-20 14:10:34 -04:00
|
|
|
assert_separately(%w[-EUTF-8], <<-'EOS', :chdir=>d)
|
2013-08-13 20:10:58 -04:00
|
|
|
if /mswin|mingw|darwin/ =~ RUBY_PLATFORM
|
2010-05-16 22:07:00 -04:00
|
|
|
filename = "\x8f\xa2\xc2".force_encoding("euc-jp")
|
|
|
|
else
|
|
|
|
filename = "\xc2\xa1".force_encoding("euc-jp")
|
|
|
|
end
|
2013-05-20 14:10:34 -04:00
|
|
|
assert_nothing_raised(Errno::ENOENT) do
|
2009-11-18 08:02:28 -05:00
|
|
|
open(filename) {}
|
|
|
|
end
|
|
|
|
EOS
|
2011-03-24 22:50:17 -04:00
|
|
|
# no meaning test on windows
|
2013-08-13 20:10:58 -04:00
|
|
|
unless /mswin|mingw|darwin/ =~ RUBY_PLATFORM
|
2013-05-20 14:10:34 -04:00
|
|
|
assert_separately(%W[-EUTF-8], <<-'EOS', :chdir=>d)
|
2011-03-24 22:50:17 -04:00
|
|
|
filename1 = "\xc2\xa1".force_encoding("utf-8")
|
|
|
|
filename2 = "\xc2\xa1".force_encoding("euc-jp")
|
|
|
|
filename3 = filename1.encode("euc-jp")
|
|
|
|
filename4 = filename2.encode("utf-8")
|
2013-05-20 14:10:34 -04:00
|
|
|
assert_file.stat(filename1)
|
|
|
|
assert_file.stat(filename2)
|
|
|
|
assert_file.not_exist?(filename3)
|
|
|
|
assert_file.not_exist?(filename4)
|
2011-03-24 22:50:17 -04:00
|
|
|
EOS
|
|
|
|
end
|
2009-11-18 08:02:28 -05:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2009-11-16 08:45:59 -05:00
|
|
|
## UTF-8 default_external, EUC-JP default_internal
|
|
|
|
|
|
|
|
def test_filename_extutf8_inteucjp_representable
|
|
|
|
with_tmpdir {|d|
|
2013-05-20 14:10:34 -04:00
|
|
|
assert_separately(%w[-EUTF-8], <<-'EOS', :chdir=>d)
|
2009-11-16 08:45:59 -05:00
|
|
|
filename = "\u3042"
|
|
|
|
File.open(filename, "w") {}
|
2010-05-16 22:07:00 -04:00
|
|
|
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
|
Make rb_scan_args handle keywords more similar to Ruby methods (#2460)
Cfuncs that use rb_scan_args with the : entry suffer similar keyword
argument separation issues that Ruby methods suffer if the cfuncs
accept optional or variable arguments.
This makes the following changes to : handling.
* Treats as **kw, prompting keyword argument separation warnings
if called with a positional hash.
* Do not look for an option hash if empty keywords are provided.
For backwards compatibility, treat an empty keyword splat as a empty
mandatory positional hash argument, but emit a a warning, as this
behavior will be removed in Ruby 3. The argument number check
needs to be moved lower so it can correctly handle an empty
positional argument being added.
* If the last argument is nil and it is necessary to treat it as an option
hash in order to make sure all arguments are processed, continue to
treat the last argument as the option hash. Emit a warning in this case,
as this behavior will be removed in Ruby 3.
* If splitting the keyword hash into two hashes, issue a warning, as we
will not be splitting hashes in Ruby 3.
* If the keyword argument is required to fill a mandatory positional
argument, continue to do so, but emit a warning as this behavior will
be going away in Ruby 3.
* If keyword arguments are provided and the last argument is not a hash,
that indicates something wrong. This can happen if a cfunc is calling
rb_scan_args multiple times, and providing arguments that were not
passed to it from Ruby. Callers need to switch to the new
rb_scan_args_kw function, which allows passing of whether keywords
were provided.
This commit fixes all warnings caused by the changes above.
It switches some function calls to *_kw versions with appropriate
kw_splat flags. If delegating arguments, RB_PASS_CALLED_KEYWORDS
is used. If creating new arguments, RB_PASS_KEYWORDS is used if
the last argument is a hash to be treated as keywords.
In open_key_args in io.c, use rb_scan_args_kw.
In this case, the arguments provided come from another C
function, not Ruby. The last argument may or may not be a hash,
so we can't set keyword argument mode. However, if it is a
hash, we don't want to warn when treating it as keywords.
In Ruby files, make sure to appropriately use keyword splats
or literal keywords when calling Cfuncs that now issue keyword
argument separation warnings through rb_scan_args. Also, make
sure not to pass nil in place of an option hash.
Work around Kernel#warn warnings due to problems in the Rubygems
override of the method. There is an open pull request to fix
these issues in Rubygems, but part of the Rubygems tests for
their override fail on ruby-head due to rb_scan_args not
recognizing empty keyword splats, which this commit fixes.
Implementation wise, adding rb_scan_args_kw is kind of a pain,
because rb_scan_args takes a variable number of arguments.
In order to not duplicate all the code, the function internals need
to be split into two functions taking a va_list, and to avoid passing
in a ton of arguments, a single struct argument is used to handle
the variables previously local to the function.
2019-09-25 14:18:49 -04:00
|
|
|
ents = Dir.entries(".", **(opts||{}))
|
2013-05-20 14:10:34 -04:00
|
|
|
assert_include(ents, filename)
|
2009-11-16 08:45:59 -05:00
|
|
|
EOS
|
2013-05-20 14:10:34 -04:00
|
|
|
assert_separately(%w[-EUTF-8:EUC-JP], <<-'EOS', :chdir=>d)
|
2009-11-16 08:45:59 -05:00
|
|
|
filename = "\xA4\xA2".force_encoding("euc-jp")
|
2010-05-16 22:07:00 -04:00
|
|
|
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
|
Make rb_scan_args handle keywords more similar to Ruby methods (#2460)
Cfuncs that use rb_scan_args with the : entry suffer similar keyword
argument separation issues that Ruby methods suffer if the cfuncs
accept optional or variable arguments.
This makes the following changes to : handling.
* Treats as **kw, prompting keyword argument separation warnings
if called with a positional hash.
* Do not look for an option hash if empty keywords are provided.
For backwards compatibility, treat an empty keyword splat as a empty
mandatory positional hash argument, but emit a a warning, as this
behavior will be removed in Ruby 3. The argument number check
needs to be moved lower so it can correctly handle an empty
positional argument being added.
* If the last argument is nil and it is necessary to treat it as an option
hash in order to make sure all arguments are processed, continue to
treat the last argument as the option hash. Emit a warning in this case,
as this behavior will be removed in Ruby 3.
* If splitting the keyword hash into two hashes, issue a warning, as we
will not be splitting hashes in Ruby 3.
* If the keyword argument is required to fill a mandatory positional
argument, continue to do so, but emit a warning as this behavior will
be going away in Ruby 3.
* If keyword arguments are provided and the last argument is not a hash,
that indicates something wrong. This can happen if a cfunc is calling
rb_scan_args multiple times, and providing arguments that were not
passed to it from Ruby. Callers need to switch to the new
rb_scan_args_kw function, which allows passing of whether keywords
were provided.
This commit fixes all warnings caused by the changes above.
It switches some function calls to *_kw versions with appropriate
kw_splat flags. If delegating arguments, RB_PASS_CALLED_KEYWORDS
is used. If creating new arguments, RB_PASS_KEYWORDS is used if
the last argument is a hash to be treated as keywords.
In open_key_args in io.c, use rb_scan_args_kw.
In this case, the arguments provided come from another C
function, not Ruby. The last argument may or may not be a hash,
so we can't set keyword argument mode. However, if it is a
hash, we don't want to warn when treating it as keywords.
In Ruby files, make sure to appropriately use keyword splats
or literal keywords when calling Cfuncs that now issue keyword
argument separation warnings through rb_scan_args. Also, make
sure not to pass nil in place of an option hash.
Work around Kernel#warn warnings due to problems in the Rubygems
override of the method. There is an open pull request to fix
these issues in Rubygems, but part of the Rubygems tests for
their override fail on ruby-head due to rb_scan_args not
recognizing empty keyword splats, which this commit fixes.
Implementation wise, adding rb_scan_args_kw is kind of a pain,
because rb_scan_args takes a variable number of arguments.
In order to not duplicate all the code, the function internals need
to be split into two functions taking a va_list, and to avoid passing
in a ton of arguments, a single struct argument is used to handle
the variables previously local to the function.
2019-09-25 14:18:49 -04:00
|
|
|
ents = Dir.entries(".", **(opts||{}))
|
2013-05-20 14:10:34 -04:00
|
|
|
assert_include(ents, filename)
|
2009-11-16 08:45:59 -05:00
|
|
|
EOS
|
2013-05-20 14:10:34 -04:00
|
|
|
assert_separately(%w[-EUTF-8:EUC-JP], <<-'EOS', :chdir=>d)
|
2009-11-16 08:45:59 -05:00
|
|
|
filename = "\xA4\xA2".force_encoding("euc-jp")
|
2013-05-20 14:10:34 -04:00
|
|
|
assert_nothing_raised(Errno::ENOENT) do
|
2009-11-16 08:45:59 -05:00
|
|
|
open(filename) {}
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_filename_extutf8_inteucjp_unrepresentable
|
|
|
|
with_tmpdir {|d|
|
2013-05-20 14:10:34 -04:00
|
|
|
assert_separately(%w[-EUTF-8], <<-'EOS', :chdir=>d)
|
2009-11-16 08:45:59 -05:00
|
|
|
filename1 = "\u2661" # WHITE HEART SUIT which is not representable in EUC-JP
|
|
|
|
filename2 = "\u3042" # HIRAGANA LETTER A which is representable in EUC-JP
|
|
|
|
File.open(filename1, "w") {}
|
|
|
|
File.open(filename2, "w") {}
|
2010-05-16 22:07:00 -04:00
|
|
|
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
|
Make rb_scan_args handle keywords more similar to Ruby methods (#2460)
Cfuncs that use rb_scan_args with the : entry suffer similar keyword
argument separation issues that Ruby methods suffer if the cfuncs
accept optional or variable arguments.
This makes the following changes to : handling.
* Treats as **kw, prompting keyword argument separation warnings
if called with a positional hash.
* Do not look for an option hash if empty keywords are provided.
For backwards compatibility, treat an empty keyword splat as a empty
mandatory positional hash argument, but emit a a warning, as this
behavior will be removed in Ruby 3. The argument number check
needs to be moved lower so it can correctly handle an empty
positional argument being added.
* If the last argument is nil and it is necessary to treat it as an option
hash in order to make sure all arguments are processed, continue to
treat the last argument as the option hash. Emit a warning in this case,
as this behavior will be removed in Ruby 3.
* If splitting the keyword hash into two hashes, issue a warning, as we
will not be splitting hashes in Ruby 3.
* If the keyword argument is required to fill a mandatory positional
argument, continue to do so, but emit a warning as this behavior will
be going away in Ruby 3.
* If keyword arguments are provided and the last argument is not a hash,
that indicates something wrong. This can happen if a cfunc is calling
rb_scan_args multiple times, and providing arguments that were not
passed to it from Ruby. Callers need to switch to the new
rb_scan_args_kw function, which allows passing of whether keywords
were provided.
This commit fixes all warnings caused by the changes above.
It switches some function calls to *_kw versions with appropriate
kw_splat flags. If delegating arguments, RB_PASS_CALLED_KEYWORDS
is used. If creating new arguments, RB_PASS_KEYWORDS is used if
the last argument is a hash to be treated as keywords.
In open_key_args in io.c, use rb_scan_args_kw.
In this case, the arguments provided come from another C
function, not Ruby. The last argument may or may not be a hash,
so we can't set keyword argument mode. However, if it is a
hash, we don't want to warn when treating it as keywords.
In Ruby files, make sure to appropriately use keyword splats
or literal keywords when calling Cfuncs that now issue keyword
argument separation warnings through rb_scan_args. Also, make
sure not to pass nil in place of an option hash.
Work around Kernel#warn warnings due to problems in the Rubygems
override of the method. There is an open pull request to fix
these issues in Rubygems, but part of the Rubygems tests for
their override fail on ruby-head due to rb_scan_args not
recognizing empty keyword splats, which this commit fixes.
Implementation wise, adding rb_scan_args_kw is kind of a pain,
because rb_scan_args takes a variable number of arguments.
In order to not duplicate all the code, the function internals need
to be split into two functions taking a va_list, and to avoid passing
in a ton of arguments, a single struct argument is used to handle
the variables previously local to the function.
2019-09-25 14:18:49 -04:00
|
|
|
ents = Dir.entries(".", **(opts||{}))
|
2013-05-20 14:10:34 -04:00
|
|
|
assert_include(ents, filename1)
|
|
|
|
assert_include(ents, filename2)
|
2009-11-16 08:45:59 -05:00
|
|
|
EOS
|
2013-05-20 14:10:34 -04:00
|
|
|
assert_separately(%w[-EUTF-8:EUC-JP], <<-'EOS', :chdir=>d)
|
2009-11-16 08:45:59 -05:00
|
|
|
filename1 = "\u2661" # WHITE HEART SUIT which is not representable in EUC-JP
|
|
|
|
filename2 = "\xA4\xA2".force_encoding("euc-jp") # HIRAGANA LETTER A in EUC-JP
|
2010-05-16 22:07:00 -04:00
|
|
|
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
|
Make rb_scan_args handle keywords more similar to Ruby methods (#2460)
Cfuncs that use rb_scan_args with the : entry suffer similar keyword
argument separation issues that Ruby methods suffer if the cfuncs
accept optional or variable arguments.
This makes the following changes to : handling.
* Treats as **kw, prompting keyword argument separation warnings
if called with a positional hash.
* Do not look for an option hash if empty keywords are provided.
For backwards compatibility, treat an empty keyword splat as a empty
mandatory positional hash argument, but emit a a warning, as this
behavior will be removed in Ruby 3. The argument number check
needs to be moved lower so it can correctly handle an empty
positional argument being added.
* If the last argument is nil and it is necessary to treat it as an option
hash in order to make sure all arguments are processed, continue to
treat the last argument as the option hash. Emit a warning in this case,
as this behavior will be removed in Ruby 3.
* If splitting the keyword hash into two hashes, issue a warning, as we
will not be splitting hashes in Ruby 3.
* If the keyword argument is required to fill a mandatory positional
argument, continue to do so, but emit a warning as this behavior will
be going away in Ruby 3.
* If keyword arguments are provided and the last argument is not a hash,
that indicates something wrong. This can happen if a cfunc is calling
rb_scan_args multiple times, and providing arguments that were not
passed to it from Ruby. Callers need to switch to the new
rb_scan_args_kw function, which allows passing of whether keywords
were provided.
This commit fixes all warnings caused by the changes above.
It switches some function calls to *_kw versions with appropriate
kw_splat flags. If delegating arguments, RB_PASS_CALLED_KEYWORDS
is used. If creating new arguments, RB_PASS_KEYWORDS is used if
the last argument is a hash to be treated as keywords.
In open_key_args in io.c, use rb_scan_args_kw.
In this case, the arguments provided come from another C
function, not Ruby. The last argument may or may not be a hash,
so we can't set keyword argument mode. However, if it is a
hash, we don't want to warn when treating it as keywords.
In Ruby files, make sure to appropriately use keyword splats
or literal keywords when calling Cfuncs that now issue keyword
argument separation warnings through rb_scan_args. Also, make
sure not to pass nil in place of an option hash.
Work around Kernel#warn warnings due to problems in the Rubygems
override of the method. There is an open pull request to fix
these issues in Rubygems, but part of the Rubygems tests for
their override fail on ruby-head due to rb_scan_args not
recognizing empty keyword splats, which this commit fixes.
Implementation wise, adding rb_scan_args_kw is kind of a pain,
because rb_scan_args takes a variable number of arguments.
In order to not duplicate all the code, the function internals need
to be split into two functions taking a va_list, and to avoid passing
in a ton of arguments, a single struct argument is used to handle
the variables previously local to the function.
2019-09-25 14:18:49 -04:00
|
|
|
ents = Dir.entries(".", **(opts||{}))
|
2013-05-20 14:10:34 -04:00
|
|
|
assert_include(ents, filename1)
|
|
|
|
assert_include(ents, filename2)
|
2009-11-16 08:45:59 -05:00
|
|
|
EOS
|
2013-05-20 14:10:34 -04:00
|
|
|
assert_separately(%w[-EUTF-8:EUC-JP], <<-'EOS', :chdir=>d)
|
2009-11-16 08:45:59 -05:00
|
|
|
filename1 = "\u2661" # WHITE HEART SUIT which is not representable in EUC-JP
|
|
|
|
filename2 = "\u3042" # HIRAGANA LETTER A which is representable in EUC-JP
|
|
|
|
filename3 = "\xA4\xA2".force_encoding("euc-jp") # HIRAGANA LETTER A in EUC-JP
|
2013-05-20 14:10:34 -04:00
|
|
|
assert_file.stat(filename1)
|
|
|
|
assert_file.stat(filename2)
|
|
|
|
assert_file.stat(filename3)
|
2009-11-16 08:45:59 -05:00
|
|
|
EOS
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
## others
|
|
|
|
|
2009-11-15 11:24:45 -05:00
|
|
|
def test_filename_bytes_euc_jp
|
2016-06-19 03:55:25 -04:00
|
|
|
return if /cygwin/ =~ RUBY_PLATFORM
|
2009-11-15 11:24:45 -05:00
|
|
|
with_tmpdir {|d|
|
2013-05-20 14:10:34 -04:00
|
|
|
assert_separately(%w[-EEUC-JP], <<-'EOS', :chdir=>d)
|
2009-11-15 11:24:45 -05:00
|
|
|
filename = "\xA4\xA2".force_encoding("euc-jp")
|
|
|
|
File.open(filename, "w") {}
|
2010-05-16 22:07:00 -04:00
|
|
|
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
|
Make rb_scan_args handle keywords more similar to Ruby methods (#2460)
Cfuncs that use rb_scan_args with the : entry suffer similar keyword
argument separation issues that Ruby methods suffer if the cfuncs
accept optional or variable arguments.
This makes the following changes to : handling.
* Treats as **kw, prompting keyword argument separation warnings
if called with a positional hash.
* Do not look for an option hash if empty keywords are provided.
For backwards compatibility, treat an empty keyword splat as a empty
mandatory positional hash argument, but emit a a warning, as this
behavior will be removed in Ruby 3. The argument number check
needs to be moved lower so it can correctly handle an empty
positional argument being added.
* If the last argument is nil and it is necessary to treat it as an option
hash in order to make sure all arguments are processed, continue to
treat the last argument as the option hash. Emit a warning in this case,
as this behavior will be removed in Ruby 3.
* If splitting the keyword hash into two hashes, issue a warning, as we
will not be splitting hashes in Ruby 3.
* If the keyword argument is required to fill a mandatory positional
argument, continue to do so, but emit a warning as this behavior will
be going away in Ruby 3.
* If keyword arguments are provided and the last argument is not a hash,
that indicates something wrong. This can happen if a cfunc is calling
rb_scan_args multiple times, and providing arguments that were not
passed to it from Ruby. Callers need to switch to the new
rb_scan_args_kw function, which allows passing of whether keywords
were provided.
This commit fixes all warnings caused by the changes above.
It switches some function calls to *_kw versions with appropriate
kw_splat flags. If delegating arguments, RB_PASS_CALLED_KEYWORDS
is used. If creating new arguments, RB_PASS_KEYWORDS is used if
the last argument is a hash to be treated as keywords.
In open_key_args in io.c, use rb_scan_args_kw.
In this case, the arguments provided come from another C
function, not Ruby. The last argument may or may not be a hash,
so we can't set keyword argument mode. However, if it is a
hash, we don't want to warn when treating it as keywords.
In Ruby files, make sure to appropriately use keyword splats
or literal keywords when calling Cfuncs that now issue keyword
argument separation warnings through rb_scan_args. Also, make
sure not to pass nil in place of an option hash.
Work around Kernel#warn warnings due to problems in the Rubygems
override of the method. There is an open pull request to fix
these issues in Rubygems, but part of the Rubygems tests for
their override fail on ruby-head due to rb_scan_args not
recognizing empty keyword splats, which this commit fixes.
Implementation wise, adding rb_scan_args_kw is kind of a pain,
because rb_scan_args takes a variable number of arguments.
In order to not duplicate all the code, the function internals need
to be split into two functions taking a va_list, and to avoid passing
in a ton of arguments, a single struct argument is used to handle
the variables previously local to the function.
2019-09-25 14:18:49 -04:00
|
|
|
ents = Dir.entries(".", **(opts||{}))
|
2009-11-15 11:24:45 -05:00
|
|
|
ents.each {|e| e.force_encoding("ASCII-8BIT") }
|
2013-08-13 20:10:58 -04:00
|
|
|
if /darwin/ =~ RUBY_PLATFORM
|
|
|
|
filename = filename.encode("utf-8")
|
2013-05-20 14:10:34 -04:00
|
|
|
end
|
|
|
|
assert_include(ents, filename.force_encoding("ASCII-8BIT"))
|
2009-11-15 11:24:45 -05:00
|
|
|
EOS
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_filename_euc_jp
|
2016-06-19 03:55:25 -04:00
|
|
|
return if /cygwin/ =~ RUBY_PLATFORM
|
2009-11-15 11:24:45 -05:00
|
|
|
with_tmpdir {|d|
|
2013-05-20 14:10:34 -04:00
|
|
|
assert_separately(%w[-EEUC-JP], <<-'EOS', :chdir=>d)
|
2009-11-15 11:24:45 -05:00
|
|
|
filename = "\xA4\xA2".force_encoding("euc-jp")
|
|
|
|
File.open(filename, "w") {}
|
2010-05-16 22:07:00 -04:00
|
|
|
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
|
Make rb_scan_args handle keywords more similar to Ruby methods (#2460)
Cfuncs that use rb_scan_args with the : entry suffer similar keyword
argument separation issues that Ruby methods suffer if the cfuncs
accept optional or variable arguments.
This makes the following changes to : handling.
* Treats as **kw, prompting keyword argument separation warnings
if called with a positional hash.
* Do not look for an option hash if empty keywords are provided.
For backwards compatibility, treat an empty keyword splat as a empty
mandatory positional hash argument, but emit a a warning, as this
behavior will be removed in Ruby 3. The argument number check
needs to be moved lower so it can correctly handle an empty
positional argument being added.
* If the last argument is nil and it is necessary to treat it as an option
hash in order to make sure all arguments are processed, continue to
treat the last argument as the option hash. Emit a warning in this case,
as this behavior will be removed in Ruby 3.
* If splitting the keyword hash into two hashes, issue a warning, as we
will not be splitting hashes in Ruby 3.
* If the keyword argument is required to fill a mandatory positional
argument, continue to do so, but emit a warning as this behavior will
be going away in Ruby 3.
* If keyword arguments are provided and the last argument is not a hash,
that indicates something wrong. This can happen if a cfunc is calling
rb_scan_args multiple times, and providing arguments that were not
passed to it from Ruby. Callers need to switch to the new
rb_scan_args_kw function, which allows passing of whether keywords
were provided.
This commit fixes all warnings caused by the changes above.
It switches some function calls to *_kw versions with appropriate
kw_splat flags. If delegating arguments, RB_PASS_CALLED_KEYWORDS
is used. If creating new arguments, RB_PASS_KEYWORDS is used if
the last argument is a hash to be treated as keywords.
In open_key_args in io.c, use rb_scan_args_kw.
In this case, the arguments provided come from another C
function, not Ruby. The last argument may or may not be a hash,
so we can't set keyword argument mode. However, if it is a
hash, we don't want to warn when treating it as keywords.
In Ruby files, make sure to appropriately use keyword splats
or literal keywords when calling Cfuncs that now issue keyword
argument separation warnings through rb_scan_args. Also, make
sure not to pass nil in place of an option hash.
Work around Kernel#warn warnings due to problems in the Rubygems
override of the method. There is an open pull request to fix
these issues in Rubygems, but part of the Rubygems tests for
their override fail on ruby-head due to rb_scan_args not
recognizing empty keyword splats, which this commit fixes.
Implementation wise, adding rb_scan_args_kw is kind of a pain,
because rb_scan_args takes a variable number of arguments.
In order to not duplicate all the code, the function internals need
to be split into two functions taking a va_list, and to avoid passing
in a ton of arguments, a single struct argument is used to handle
the variables previously local to the function.
2019-09-25 14:18:49 -04:00
|
|
|
ents = Dir.entries(".", **(opts||{}))
|
2013-08-13 20:10:58 -04:00
|
|
|
if /darwin/ =~ RUBY_PLATFORM
|
|
|
|
filename = filename.encode("utf-8").force_encoding("euc-jp")
|
2013-05-20 14:10:34 -04:00
|
|
|
end
|
|
|
|
assert_include(ents, filename)
|
2009-11-15 11:24:45 -05:00
|
|
|
EOS
|
2013-05-20 14:10:34 -04:00
|
|
|
assert_separately(%w[-EASCII-8BIT], <<-'EOS', :chdir=>d)
|
2012-07-23 19:32:29 -04:00
|
|
|
filename = "\xA4\xA2".force_encoding('ASCII-8BIT')
|
2012-07-24 05:57:59 -04:00
|
|
|
win_expected_filename = filename.encode(Encoding.find("filesystem"), "euc-jp") rescue "?"
|
2010-05-16 22:07:00 -04:00
|
|
|
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
|
Make rb_scan_args handle keywords more similar to Ruby methods (#2460)
Cfuncs that use rb_scan_args with the : entry suffer similar keyword
argument separation issues that Ruby methods suffer if the cfuncs
accept optional or variable arguments.
This makes the following changes to : handling.
* Treats as **kw, prompting keyword argument separation warnings
if called with a positional hash.
* Do not look for an option hash if empty keywords are provided.
For backwards compatibility, treat an empty keyword splat as a empty
mandatory positional hash argument, but emit a a warning, as this
behavior will be removed in Ruby 3. The argument number check
needs to be moved lower so it can correctly handle an empty
positional argument being added.
* If the last argument is nil and it is necessary to treat it as an option
hash in order to make sure all arguments are processed, continue to
treat the last argument as the option hash. Emit a warning in this case,
as this behavior will be removed in Ruby 3.
* If splitting the keyword hash into two hashes, issue a warning, as we
will not be splitting hashes in Ruby 3.
* If the keyword argument is required to fill a mandatory positional
argument, continue to do so, but emit a warning as this behavior will
be going away in Ruby 3.
* If keyword arguments are provided and the last argument is not a hash,
that indicates something wrong. This can happen if a cfunc is calling
rb_scan_args multiple times, and providing arguments that were not
passed to it from Ruby. Callers need to switch to the new
rb_scan_args_kw function, which allows passing of whether keywords
were provided.
This commit fixes all warnings caused by the changes above.
It switches some function calls to *_kw versions with appropriate
kw_splat flags. If delegating arguments, RB_PASS_CALLED_KEYWORDS
is used. If creating new arguments, RB_PASS_KEYWORDS is used if
the last argument is a hash to be treated as keywords.
In open_key_args in io.c, use rb_scan_args_kw.
In this case, the arguments provided come from another C
function, not Ruby. The last argument may or may not be a hash,
so we can't set keyword argument mode. However, if it is a
hash, we don't want to warn when treating it as keywords.
In Ruby files, make sure to appropriately use keyword splats
or literal keywords when calling Cfuncs that now issue keyword
argument separation warnings through rb_scan_args. Also, make
sure not to pass nil in place of an option hash.
Work around Kernel#warn warnings due to problems in the Rubygems
override of the method. There is an open pull request to fix
these issues in Rubygems, but part of the Rubygems tests for
their override fail on ruby-head due to rb_scan_args not
recognizing empty keyword splats, which this commit fixes.
Implementation wise, adding rb_scan_args_kw is kind of a pain,
because rb_scan_args takes a variable number of arguments.
In order to not duplicate all the code, the function internals need
to be split into two functions taking a va_list, and to avoid passing
in a ton of arguments, a single struct argument is used to handle
the variables previously local to the function.
2019-09-25 14:18:49 -04:00
|
|
|
ents = Dir.entries(".", **(opts||{}))
|
2013-05-20 14:10:34 -04:00
|
|
|
unless ents.include?(filename)
|
|
|
|
case RUBY_PLATFORM
|
|
|
|
when /darwin/
|
2013-08-13 20:10:58 -04:00
|
|
|
filename = filename.encode("utf-8", "euc-jp").b
|
2013-05-20 14:10:34 -04:00
|
|
|
when /mswin|mingw/
|
2015-12-14 01:40:55 -05:00
|
|
|
if ents.include?(win_expected_filename.b)
|
Make rb_scan_args handle keywords more similar to Ruby methods (#2460)
Cfuncs that use rb_scan_args with the : entry suffer similar keyword
argument separation issues that Ruby methods suffer if the cfuncs
accept optional or variable arguments.
This makes the following changes to : handling.
* Treats as **kw, prompting keyword argument separation warnings
if called with a positional hash.
* Do not look for an option hash if empty keywords are provided.
For backwards compatibility, treat an empty keyword splat as a empty
mandatory positional hash argument, but emit a a warning, as this
behavior will be removed in Ruby 3. The argument number check
needs to be moved lower so it can correctly handle an empty
positional argument being added.
* If the last argument is nil and it is necessary to treat it as an option
hash in order to make sure all arguments are processed, continue to
treat the last argument as the option hash. Emit a warning in this case,
as this behavior will be removed in Ruby 3.
* If splitting the keyword hash into two hashes, issue a warning, as we
will not be splitting hashes in Ruby 3.
* If the keyword argument is required to fill a mandatory positional
argument, continue to do so, but emit a warning as this behavior will
be going away in Ruby 3.
* If keyword arguments are provided and the last argument is not a hash,
that indicates something wrong. This can happen if a cfunc is calling
rb_scan_args multiple times, and providing arguments that were not
passed to it from Ruby. Callers need to switch to the new
rb_scan_args_kw function, which allows passing of whether keywords
were provided.
This commit fixes all warnings caused by the changes above.
It switches some function calls to *_kw versions with appropriate
kw_splat flags. If delegating arguments, RB_PASS_CALLED_KEYWORDS
is used. If creating new arguments, RB_PASS_KEYWORDS is used if
the last argument is a hash to be treated as keywords.
In open_key_args in io.c, use rb_scan_args_kw.
In this case, the arguments provided come from another C
function, not Ruby. The last argument may or may not be a hash,
so we can't set keyword argument mode. However, if it is a
hash, we don't want to warn when treating it as keywords.
In Ruby files, make sure to appropriately use keyword splats
or literal keywords when calling Cfuncs that now issue keyword
argument separation warnings through rb_scan_args. Also, make
sure not to pass nil in place of an option hash.
Work around Kernel#warn warnings due to problems in the Rubygems
override of the method. There is an open pull request to fix
these issues in Rubygems, but part of the Rubygems tests for
their override fail on ruby-head due to rb_scan_args not
recognizing empty keyword splats, which this commit fixes.
Implementation wise, adding rb_scan_args_kw is kind of a pain,
because rb_scan_args takes a variable number of arguments.
In order to not duplicate all the code, the function internals need
to be split into two functions taking a va_list, and to avoid passing
in a ton of arguments, a single struct argument is used to handle
the variables previously local to the function.
2019-09-25 14:18:49 -04:00
|
|
|
ents = Dir.entries(".", :encoding => Encoding.find("filesystem"))
|
2013-05-20 14:10:34 -04:00
|
|
|
filename = win_expected_filename
|
|
|
|
end
|
|
|
|
end
|
2012-07-23 19:32:29 -04:00
|
|
|
end
|
2013-05-20 14:10:34 -04:00
|
|
|
assert_include(ents, filename)
|
2009-11-15 12:14:43 -05:00
|
|
|
EOS
|
2009-11-15 11:24:45 -05:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2012-07-23 19:32:29 -04:00
|
|
|
def test_filename_utf8_raw_jp_name
|
2014-05-28 00:20:35 -04:00
|
|
|
assert_raw_file_name(0x3042, "UTF-8")
|
2012-07-23 19:32:29 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_filename_utf8_raw_windows_1251_name
|
2014-05-28 00:20:35 -04:00
|
|
|
assert_raw_file_name(0x0424, "UTF-8")
|
2012-07-23 19:32:29 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_filename_utf8_raw_windows_1252_name
|
2014-05-28 00:20:35 -04:00
|
|
|
assert_raw_file_name(0x00c6, "UTF-8")
|
2009-11-15 12:11:54 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_filename_ext_euc_jp_and_int_utf_8
|
2016-06-19 03:55:25 -04:00
|
|
|
return if /cygwin/ =~ RUBY_PLATFORM
|
2009-11-15 12:11:54 -05:00
|
|
|
with_tmpdir {|d|
|
2013-05-20 14:10:34 -04:00
|
|
|
assert_separately(%w[-EEUC-JP], <<-'EOS', :chdir=>d)
|
2009-11-15 12:11:54 -05:00
|
|
|
filename = "\xA4\xA2".force_encoding("euc-jp")
|
|
|
|
File.open(filename, "w") {}
|
2010-05-16 22:07:00 -04:00
|
|
|
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
|
Make rb_scan_args handle keywords more similar to Ruby methods (#2460)
Cfuncs that use rb_scan_args with the : entry suffer similar keyword
argument separation issues that Ruby methods suffer if the cfuncs
accept optional or variable arguments.
This makes the following changes to : handling.
* Treats as **kw, prompting keyword argument separation warnings
if called with a positional hash.
* Do not look for an option hash if empty keywords are provided.
For backwards compatibility, treat an empty keyword splat as a empty
mandatory positional hash argument, but emit a a warning, as this
behavior will be removed in Ruby 3. The argument number check
needs to be moved lower so it can correctly handle an empty
positional argument being added.
* If the last argument is nil and it is necessary to treat it as an option
hash in order to make sure all arguments are processed, continue to
treat the last argument as the option hash. Emit a warning in this case,
as this behavior will be removed in Ruby 3.
* If splitting the keyword hash into two hashes, issue a warning, as we
will not be splitting hashes in Ruby 3.
* If the keyword argument is required to fill a mandatory positional
argument, continue to do so, but emit a warning as this behavior will
be going away in Ruby 3.
* If keyword arguments are provided and the last argument is not a hash,
that indicates something wrong. This can happen if a cfunc is calling
rb_scan_args multiple times, and providing arguments that were not
passed to it from Ruby. Callers need to switch to the new
rb_scan_args_kw function, which allows passing of whether keywords
were provided.
This commit fixes all warnings caused by the changes above.
It switches some function calls to *_kw versions with appropriate
kw_splat flags. If delegating arguments, RB_PASS_CALLED_KEYWORDS
is used. If creating new arguments, RB_PASS_KEYWORDS is used if
the last argument is a hash to be treated as keywords.
In open_key_args in io.c, use rb_scan_args_kw.
In this case, the arguments provided come from another C
function, not Ruby. The last argument may or may not be a hash,
so we can't set keyword argument mode. However, if it is a
hash, we don't want to warn when treating it as keywords.
In Ruby files, make sure to appropriately use keyword splats
or literal keywords when calling Cfuncs that now issue keyword
argument separation warnings through rb_scan_args. Also, make
sure not to pass nil in place of an option hash.
Work around Kernel#warn warnings due to problems in the Rubygems
override of the method. There is an open pull request to fix
these issues in Rubygems, but part of the Rubygems tests for
their override fail on ruby-head due to rb_scan_args not
recognizing empty keyword splats, which this commit fixes.
Implementation wise, adding rb_scan_args_kw is kind of a pain,
because rb_scan_args takes a variable number of arguments.
In order to not duplicate all the code, the function internals need
to be split into two functions taking a va_list, and to avoid passing
in a ton of arguments, a single struct argument is used to handle
the variables previously local to the function.
2019-09-25 14:18:49 -04:00
|
|
|
ents = Dir.entries(".", **(opts||{}))
|
2013-08-13 20:10:58 -04:00
|
|
|
if /darwin/ =~ RUBY_PLATFORM
|
|
|
|
filename = filename.encode("utf-8", "euc-jp").force_encoding("euc-jp")
|
2013-05-20 14:10:34 -04:00
|
|
|
end
|
|
|
|
assert_include(ents, filename)
|
2009-11-15 12:11:54 -05:00
|
|
|
EOS
|
2013-05-20 14:10:34 -04:00
|
|
|
assert_separately(%w[-EEUC-JP:UTF-8], <<-'EOS', :chdir=>d)
|
2009-11-15 12:58:14 -05:00
|
|
|
filename = "\u3042"
|
2010-05-16 22:07:00 -04:00
|
|
|
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
|
Make rb_scan_args handle keywords more similar to Ruby methods (#2460)
Cfuncs that use rb_scan_args with the : entry suffer similar keyword
argument separation issues that Ruby methods suffer if the cfuncs
accept optional or variable arguments.
This makes the following changes to : handling.
* Treats as **kw, prompting keyword argument separation warnings
if called with a positional hash.
* Do not look for an option hash if empty keywords are provided.
For backwards compatibility, treat an empty keyword splat as a empty
mandatory positional hash argument, but emit a a warning, as this
behavior will be removed in Ruby 3. The argument number check
needs to be moved lower so it can correctly handle an empty
positional argument being added.
* If the last argument is nil and it is necessary to treat it as an option
hash in order to make sure all arguments are processed, continue to
treat the last argument as the option hash. Emit a warning in this case,
as this behavior will be removed in Ruby 3.
* If splitting the keyword hash into two hashes, issue a warning, as we
will not be splitting hashes in Ruby 3.
* If the keyword argument is required to fill a mandatory positional
argument, continue to do so, but emit a warning as this behavior will
be going away in Ruby 3.
* If keyword arguments are provided and the last argument is not a hash,
that indicates something wrong. This can happen if a cfunc is calling
rb_scan_args multiple times, and providing arguments that were not
passed to it from Ruby. Callers need to switch to the new
rb_scan_args_kw function, which allows passing of whether keywords
were provided.
This commit fixes all warnings caused by the changes above.
It switches some function calls to *_kw versions with appropriate
kw_splat flags. If delegating arguments, RB_PASS_CALLED_KEYWORDS
is used. If creating new arguments, RB_PASS_KEYWORDS is used if
the last argument is a hash to be treated as keywords.
In open_key_args in io.c, use rb_scan_args_kw.
In this case, the arguments provided come from another C
function, not Ruby. The last argument may or may not be a hash,
so we can't set keyword argument mode. However, if it is a
hash, we don't want to warn when treating it as keywords.
In Ruby files, make sure to appropriately use keyword splats
or literal keywords when calling Cfuncs that now issue keyword
argument separation warnings through rb_scan_args. Also, make
sure not to pass nil in place of an option hash.
Work around Kernel#warn warnings due to problems in the Rubygems
override of the method. There is an open pull request to fix
these issues in Rubygems, but part of the Rubygems tests for
their override fail on ruby-head due to rb_scan_args not
recognizing empty keyword splats, which this commit fixes.
Implementation wise, adding rb_scan_args_kw is kind of a pain,
because rb_scan_args takes a variable number of arguments.
In order to not duplicate all the code, the function internals need
to be split into two functions taking a va_list, and to avoid passing
in a ton of arguments, a single struct argument is used to handle
the variables previously local to the function.
2019-09-25 14:18:49 -04:00
|
|
|
ents = Dir.entries(".", **(opts||{}))
|
2013-08-13 20:10:58 -04:00
|
|
|
if /darwin/ =~ RUBY_PLATFORM
|
|
|
|
filename = filename.force_encoding("euc-jp")
|
2013-05-20 14:10:34 -04:00
|
|
|
end
|
|
|
|
assert_include(ents, filename)
|
2009-11-15 12:58:14 -05:00
|
|
|
EOS
|
|
|
|
}
|
|
|
|
end
|
2012-02-24 17:53:42 -05:00
|
|
|
|
|
|
|
def test_error_nonascii
|
|
|
|
bug6071 = '[ruby-dev:45279]'
|
|
|
|
paths = ["\u{3042}".encode("sjis"), "\u{ff}".encode("iso-8859-1")]
|
|
|
|
encs = with_tmpdir {
|
|
|
|
paths.map {|path|
|
|
|
|
Dir.open(path) rescue $!.message.encoding
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert_equal(paths.map(&:encoding), encs, bug6071)
|
|
|
|
end
|
2009-11-15 11:24:45 -05:00
|
|
|
|
2012-02-24 17:53:51 -05:00
|
|
|
def test_inspect_nonascii
|
|
|
|
bug6072 = '[ruby-dev:45280]'
|
|
|
|
paths = ["\u{3042}".encode("sjis"), "\u{ff}".encode("iso-8859-1")]
|
|
|
|
encs = with_tmpdir {
|
|
|
|
paths.map {|path|
|
|
|
|
Dir.mkdir(path)
|
|
|
|
Dir.open(path) {|d| d.inspect.encoding}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert_equal(paths.map(&:encoding), encs, bug6072)
|
|
|
|
end
|
2012-09-04 23:03:24 -04:00
|
|
|
|
|
|
|
def test_glob_incompatible
|
|
|
|
d = "\u{3042}\u{3044}".encode("utf-16le")
|
|
|
|
assert_raise(Encoding::CompatibilityError) {Dir.glob(d)}
|
|
|
|
m = Class.new {define_method(:to_path) {d}}
|
|
|
|
assert_raise(Encoding::CompatibilityError) {Dir.glob(m.new)}
|
|
|
|
end
|
2013-03-19 04:06:53 -04:00
|
|
|
|
|
|
|
def test_glob_compose
|
|
|
|
bug7267 = '[ruby-core:48745] [Bug #7267]'
|
|
|
|
|
|
|
|
pp = Object.new.extend(Test::Unit::Assertions)
|
|
|
|
def pp.mu_pp(str) #:nodoc:
|
|
|
|
str.dump
|
|
|
|
end
|
|
|
|
|
|
|
|
with_tmpdir {|d|
|
|
|
|
orig = %W"d\u{e9}tente x\u{304c 304e 3050 3052 3054}"
|
|
|
|
orig.each {|n| open(n, "w") {}}
|
|
|
|
orig.each do |o|
|
|
|
|
n = Dir.glob("#{o[0..0]}*")[0]
|
|
|
|
pp.assert_equal(o, n, bug7267)
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
2013-05-20 14:11:23 -04:00
|
|
|
|
2015-02-06 03:37:27 -05:00
|
|
|
def with_enc_path
|
|
|
|
with_tmpdir do |d|
|
|
|
|
names = %W"\u{391 392 393 394 395} \u{3042 3044 3046 3048 304a}"
|
|
|
|
names.each do |dir|
|
2015-02-06 08:24:09 -05:00
|
|
|
EnvUtil.with_default_external(Encoding::UTF_8) do
|
|
|
|
Dir.mkdir(dir) rescue next
|
|
|
|
begin
|
|
|
|
yield(dir)
|
|
|
|
ensure
|
|
|
|
File.chmod(0700, dir)
|
|
|
|
end
|
2015-02-06 03:37:27 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_glob_warning_opendir
|
|
|
|
with_enc_path do |dir|
|
|
|
|
open("#{dir}/x", "w") {}
|
|
|
|
File.chmod(0300, dir)
|
2015-02-06 08:24:09 -05:00
|
|
|
next if File.readable?(dir)
|
2015-02-06 03:37:27 -05:00
|
|
|
assert_warning(/#{dir}/) do
|
|
|
|
Dir.glob("#{dir}/*")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_glob_warning_match_all
|
|
|
|
with_enc_path do |dir|
|
|
|
|
open("#{dir}/x", "w") {}
|
|
|
|
File.chmod(0000, dir)
|
2015-02-06 08:24:09 -05:00
|
|
|
next if File.readable?(dir)
|
2015-02-06 03:37:27 -05:00
|
|
|
assert_warning(/#{dir}/) do
|
|
|
|
Dir.glob("#{dir}/x")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_glob_warning_match_dir
|
|
|
|
with_enc_path do |dir|
|
|
|
|
Dir.mkdir("#{dir}/x")
|
|
|
|
File.chmod(0000, dir)
|
2015-02-06 08:24:09 -05:00
|
|
|
next if File.readable?(dir)
|
2015-02-06 03:37:27 -05:00
|
|
|
assert_warning(/#{dir}/) do
|
|
|
|
Dir.glob("#{dir}/x/")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-02-06 19:11:00 -05:00
|
|
|
def test_glob_escape_multibyte
|
|
|
|
name = "\x81\\".force_encoding(Encoding::Shift_JIS)
|
|
|
|
with_tmpdir do
|
|
|
|
open(name, "w") {} rescue next
|
|
|
|
match, = Dir.glob("#{name}*")
|
|
|
|
next unless match and match.encoding == Encoding::Shift_JIS
|
|
|
|
assert_equal([name], Dir.glob("\\#{name}*"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-02-25 01:59:39 -05:00
|
|
|
def test_glob_encoding
|
|
|
|
with_tmpdir do
|
2016-02-19 23:04:59 -05:00
|
|
|
list = %W"file_one.ext file_two.ext \u{6587 4ef6}1.txt \u{6587 4ef6}2.txt"
|
|
|
|
list.each {|f| open(f, "w") {}}
|
2015-02-25 01:59:39 -05:00
|
|
|
a = "file_one*".force_encoding Encoding::IBM437
|
|
|
|
b = "file_two*".force_encoding Encoding::EUC_JP
|
|
|
|
assert_equal([a, b].map(&:encoding), Dir[a, b].map(&:encoding))
|
2017-08-15 17:33:43 -04:00
|
|
|
if Bug::File::Fs.fsname(Dir.pwd) == "apfs"
|
|
|
|
# High Sierra's APFS cannot use filenames with undefined character
|
|
|
|
dir = "\u{76EE}"
|
|
|
|
else
|
|
|
|
dir = "\u{76EE 5F551}"
|
|
|
|
end
|
2016-02-19 23:04:59 -05:00
|
|
|
Dir.mkdir(dir)
|
|
|
|
list << dir
|
|
|
|
bug12081 = '[ruby-core:73868] [Bug #12081]'
|
|
|
|
a = "*".force_encoding("us-ascii")
|
2016-02-20 04:36:08 -05:00
|
|
|
result = Dir[a].map {|n|
|
2016-11-22 23:40:40 -05:00
|
|
|
if n.encoding == Encoding::ASCII_8BIT ||
|
|
|
|
n.encoding == Encoding::ISO_8859_1 ||
|
|
|
|
!n.valid_encoding?
|
2016-02-20 04:36:08 -05:00
|
|
|
n.force_encoding(Encoding::UTF_8)
|
|
|
|
else
|
|
|
|
n.encode(Encoding::UTF_8)
|
|
|
|
end
|
|
|
|
}
|
|
|
|
assert_equal(list, result.sort!, bug12081)
|
2015-02-25 01:59:39 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-10-03 22:18:58 -04:00
|
|
|
PP = Object.new.extend(Test::Unit::Assertions)
|
|
|
|
def PP.mu_pp(ary) #:nodoc:
|
|
|
|
'[' << ary.map {|str| "#{str.dump}(#{str.encoding})"}.join(', ') << ']'
|
|
|
|
end
|
|
|
|
|
2013-05-20 14:11:23 -04:00
|
|
|
def test_entries_compose
|
|
|
|
bug7267 = '[ruby-core:48745] [Bug #7267]'
|
|
|
|
|
|
|
|
with_tmpdir {|d|
|
|
|
|
orig = %W"d\u{e9}tente x\u{304c 304e 3050 3052 3054}"
|
|
|
|
orig.each {|n| open(n, "w") {}}
|
2017-05-16 20:28:01 -04:00
|
|
|
enc = Encoding.find("filesystem")
|
|
|
|
enc = Encoding::ASCII_8BIT if enc == Encoding::US_ASCII
|
2013-05-20 14:11:23 -04:00
|
|
|
if /mswin|mingw/ =~ RUBY_PLATFORM
|
2017-05-16 20:28:01 -04:00
|
|
|
opts = {:encoding => enc}
|
2015-10-03 22:18:58 -04:00
|
|
|
orig.map! {|o| o.encode("filesystem") rescue o.tr("^a-z", "?")}
|
2013-05-21 02:08:04 -04:00
|
|
|
else
|
2013-05-21 08:50:21 -04:00
|
|
|
orig.each {|o| o.force_encoding(enc) }
|
2013-05-20 14:11:23 -04:00
|
|
|
end
|
Make rb_scan_args handle keywords more similar to Ruby methods (#2460)
Cfuncs that use rb_scan_args with the : entry suffer similar keyword
argument separation issues that Ruby methods suffer if the cfuncs
accept optional or variable arguments.
This makes the following changes to : handling.
* Treats as **kw, prompting keyword argument separation warnings
if called with a positional hash.
* Do not look for an option hash if empty keywords are provided.
For backwards compatibility, treat an empty keyword splat as a empty
mandatory positional hash argument, but emit a a warning, as this
behavior will be removed in Ruby 3. The argument number check
needs to be moved lower so it can correctly handle an empty
positional argument being added.
* If the last argument is nil and it is necessary to treat it as an option
hash in order to make sure all arguments are processed, continue to
treat the last argument as the option hash. Emit a warning in this case,
as this behavior will be removed in Ruby 3.
* If splitting the keyword hash into two hashes, issue a warning, as we
will not be splitting hashes in Ruby 3.
* If the keyword argument is required to fill a mandatory positional
argument, continue to do so, but emit a warning as this behavior will
be going away in Ruby 3.
* If keyword arguments are provided and the last argument is not a hash,
that indicates something wrong. This can happen if a cfunc is calling
rb_scan_args multiple times, and providing arguments that were not
passed to it from Ruby. Callers need to switch to the new
rb_scan_args_kw function, which allows passing of whether keywords
were provided.
This commit fixes all warnings caused by the changes above.
It switches some function calls to *_kw versions with appropriate
kw_splat flags. If delegating arguments, RB_PASS_CALLED_KEYWORDS
is used. If creating new arguments, RB_PASS_KEYWORDS is used if
the last argument is a hash to be treated as keywords.
In open_key_args in io.c, use rb_scan_args_kw.
In this case, the arguments provided come from another C
function, not Ruby. The last argument may or may not be a hash,
so we can't set keyword argument mode. However, if it is a
hash, we don't want to warn when treating it as keywords.
In Ruby files, make sure to appropriately use keyword splats
or literal keywords when calling Cfuncs that now issue keyword
argument separation warnings through rb_scan_args. Also, make
sure not to pass nil in place of an option hash.
Work around Kernel#warn warnings due to problems in the Rubygems
override of the method. There is an open pull request to fix
these issues in Rubygems, but part of the Rubygems tests for
their override fail on ruby-head due to rb_scan_args not
recognizing empty keyword splats, which this commit fixes.
Implementation wise, adding rb_scan_args_kw is kind of a pain,
because rb_scan_args takes a variable number of arguments.
In order to not duplicate all the code, the function internals need
to be split into two functions taking a va_list, and to avoid passing
in a ton of arguments, a single struct argument is used to handle
the variables previously local to the function.
2019-09-25 14:18:49 -04:00
|
|
|
ents = Dir.entries(".", **(opts||{})).reject {|n| /\A\./ =~ n}
|
2013-05-21 03:43:40 -04:00
|
|
|
ents.sort!
|
2015-10-03 22:18:58 -04:00
|
|
|
PP.assert_equal(orig, ents, bug7267)
|
2013-05-20 14:11:23 -04:00
|
|
|
}
|
|
|
|
end
|
2015-10-03 21:10:00 -04:00
|
|
|
|
|
|
|
def test_pwd
|
2015-10-03 22:18:58 -04:00
|
|
|
orig = %W"d\u{e9}tente x\u{304c 304e 3050 3052 3054}"
|
|
|
|
expected = []
|
|
|
|
results = []
|
|
|
|
orig.each {|o|
|
|
|
|
if /mswin|mingw/ =~ RUBY_PLATFORM
|
|
|
|
n = (o.encode("filesystem") rescue next)
|
|
|
|
else
|
|
|
|
enc = Encoding.find("filesystem")
|
|
|
|
enc = Encoding::ASCII_8BIT if enc == Encoding::US_ASCII
|
|
|
|
n = o.dup.force_encoding(enc)
|
2015-10-03 21:10:00 -04:00
|
|
|
end
|
2015-10-03 22:18:58 -04:00
|
|
|
expected << n
|
|
|
|
with_tmpdir {
|
|
|
|
Dir.mkdir(o)
|
|
|
|
results << File.basename(Dir.chdir(o) {Dir.pwd})
|
|
|
|
}
|
2015-10-03 21:10:00 -04:00
|
|
|
}
|
2015-10-03 22:18:58 -04:00
|
|
|
PP.assert_equal(expected, results)
|
2015-10-03 21:10:00 -04:00
|
|
|
end
|
2012-02-24 17:53:51 -05:00
|
|
|
end
|