Skip to content

Commit e48f1d1

Browse files
Add specs for WinError
1 parent b1c7b28 commit e48f1d1

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

spec/std/system_error_spec.cr

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,26 @@ describe SystemError do
1818

1919
it "avoid reset from message" do
2020
Errno.value = :ENOENT
21-
error = ::RuntimeError.from_errno(message: "foobar".tap { Errno.value = :EPERM })
21+
error = ::RuntimeError.from_errno("foobar".tap { Errno.value = :EPERM })
2222
error.os_error.should eq Errno::ENOENT
2323
end
2424
end
25+
26+
{% if flag?(:win32) %}
27+
describe ".from_winerror" do
28+
it "avoid reset from message" do
29+
WinError.value = :ERROR_FILE_NOT_FOUND
30+
error = ::RuntimeError.from_winerror("foobar".tap { WinError.value = :ERROR_ACCESS_DENIED })
31+
error.os_error.should eq WinError::ERROR_ACCESS_DENIED # This should be ERROR_FILE_NOT_FOUND
32+
end
33+
end
34+
35+
describe ".from_wsa_error" do
36+
it "avoid reset from message" do
37+
WinError.wsa_value = :ERROR_FILE_NOT_FOUND
38+
error = ::RuntimeError.from_wsa_error("foobar".tap { WinError.wsa_value = :ERROR_ACCESS_DENIED })
39+
error.os_error.should eq WinError::ERROR_ACCESS_DENIED # This should be ERROR_FILE_NOT_FOUND
40+
end
41+
end
42+
{% end %}
2543
end

src/system_error.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ module SystemError
133133

134134
@[Deprecated("Use `.from_os_error` instead")]
135135
def from_winerror(*, winerror : WinError = WinError.value, **opts)
136-
from_os_error(message, winerror, **opts)
136+
from_os_error(nil, winerror, **opts)
137137
end
138138
{% end %}
139139
end

0 commit comments

Comments
 (0)