avoid platform dependent message

(Bug #21083)
https://bugs.ruby-lang.org/issues/21083
This commit is contained in:
YO4 2025-01-23 22:40:02 +09:00 committed by Nobuyoshi Nakada
parent 3d6fc29169
commit 0f6c647b1a
Notes: git 2025-03-18 16:29:18 +00:00
2 changed files with 8 additions and 31 deletions

View File

@ -25,6 +25,7 @@ describe "SystemCallError.new" do
@example_errno_class = Errno::EINVAL
@last_known_errno = Errno.constants.size - 1
@unknown_errno = Errno.constants.size
@some_human_readable = "[[:graph:]]+"
end
it "requires at least one argument" do
@ -96,23 +97,11 @@ describe "SystemCallError.new" do
end
it "sets an 'unknown error' message when an unknown error number" do
platform_is_not :windows do
SystemCallError.new(-1).message.should =~ /Unknown error(:)? -1/
end
platform_is :windows do
SystemCallError.new(-1).message.should == "The operation completed successfully."
end
SystemCallError.new(-1).message.should =~ Regexp.new(@some_human_readable)
end
it "adds a custom error message to an 'unknown error' message when an unknown error number and a custom message specified" do
platform_is_not :windows do
SystemCallError.new("custom message", -1).message.should =~ /Unknown error(:)? -1 - custom message/
end
platform_is :windows do
SystemCallError.new("custom message", -1).message.should == "The operation completed successfully. - custom message"
end
SystemCallError.new("custom message", -1).message.should =~ Regexp.new("#{@some_human_readable}.* - custom message")
end
it "converts to Integer if errno is a Complex convertible to Integer" do
@ -153,7 +142,7 @@ describe "SystemCallError#message" do
SystemCallError.new(2**28).message.should =~ /Error .*occurred/i
end
platform_is_not :aix do
SystemCallError.new(2**28).message.should =~ /Unknown error/i
SystemCallError.new(2**28).message.should =~ Regexp.new(@some_human_readable)
end
end

View File

@ -196,14 +196,8 @@ describe "C-API Kernel function" do
end.should raise_error(Errno::EINVAL, "Invalid argument")
end
it "uses an 'unknown error' message when errno is unknown" do
platform_is_not :windows do
-> { @s.rb_syserr_fail(-10, nil) }.should raise_error(SystemCallError, /Unknown error(:)? -10/)
end
platform_is :windows do
-> { @s.rb_syserr_fail(-1, nil) }.should raise_error(SystemCallError, "The operation completed successfully.")
end
it "uses some kind of string as message when errno is unknown" do
-> { @s.rb_syserr_fail(-10, nil) }.should raise_error(SystemCallError, /[[:graph:]]+/)
end
end
@ -220,14 +214,8 @@ describe "C-API Kernel function" do
end.should raise_error(Errno::EINVAL, "Invalid argument")
end
it "uses an 'unknown error' message when errno is unknown" do
platform_is_not :windows do
-> { @s.rb_syserr_fail_str(-10, nil) }.should raise_error(SystemCallError, /Unknown error(:)? -10/)
end
platform_is :windows do
-> { @s.rb_syserr_fail_str(-1, nil) }.should raise_error(SystemCallError, "The operation completed successfully.")
end
it "uses some kind of string as message when errno is unknown" do
-> { @s.rb_syserr_fail_str(-10, nil) }.should raise_error(SystemCallError, /[[:graph:]]+/)
end
end