mirror of
https://github.com/ruby/ruby.git
synced 2026-10-28 16:36:20 +08:00
sprintf.c: don't raise "too many arguments" errors when $DEBUG is set
[Feature #22136] This is as far as I can tell the only method that changes its behavior in debug mode, and that's all but helpful because it might cause the program to abort. Usually when you run a program with $DEBUG set, it is to find some error that may have been swallowed, so aside from the extra output you would expect Ruby to behave the same than in normal mode.
This commit is contained in:
1 parent
b9be3d6b6d
commit
64450290f3
2 files changed
+13
-12
Notes:
git
2026-07-10 05:35:12 +00:00
No files matched your search
@@ -67,18 +67,20 @@ describe "String#%" do
|
||||
end
|
||||
end
|
||||
|
||||
it "raises an ArgumentError for unused arguments when $DEBUG is true" do
|
||||
begin
|
||||
old_debug = $DEBUG
|
||||
$DEBUG = true
|
||||
s = $stderr
|
||||
$stderr = IOStub.new
|
||||
ruby_version_is ""..."4.1" do
|
||||
it "raises an ArgumentError for unused arguments when $DEBUG is true" do
|
||||
begin
|
||||
old_debug = $DEBUG
|
||||
$DEBUG = true
|
||||
s = $stderr
|
||||
$stderr = IOStub.new
|
||||
|
||||
-> { "" % [1, 2, 3] }.should.raise(ArgumentError)
|
||||
-> { "%s" % [1, 2, 3] }.should.raise(ArgumentError)
|
||||
ensure
|
||||
$DEBUG = old_debug
|
||||
$stderr = s
|
||||
-> { "" % [1, 2, 3] }.should.raise(ArgumentError)
|
||||
-> { "%s" % [1, 2, 3] }.should.raise(ArgumentError)
|
||||
ensure
|
||||
$DEBUG = old_debug
|
||||
$stderr = s
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -947,7 +947,6 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
|
||||
*/
|
||||
if (posarg >= 0 && nextarg < argc && !(argc == 2 && RB_TYPE_P(argv[1], T_HASH))) {
|
||||
const char *mesg = "too many arguments for format string";
|
||||
if (RTEST(ruby_debug)) rb_raise(rb_eArgError, "%s", mesg);
|
||||
if (RTEST(ruby_verbose)) rb_warn("%s", mesg);
|
||||
}
|
||||
rb_str_resize(result, blen);
|
||||
|
||||
Reference in new issue
Block a user