Skip to content

Commit

Permalink
Add support for error codes that vary across supported platforms.
Browse files Browse the repository at this point in the history
Prior to this commit, all error codes were Linux-specific.
This was okay for all the error codes near the start that have
the same value across all supported platforms, but to truly
support the rest of the error codes we need them on all platforms.

Note that I had to move away from this being an `:enum` because
there is currently no Savi support for varying values for an enum name
across platforms, and that frankly doesn't make sense for most enums,
so it's better to switch to a more verbose `:numeric` implementation.

One side-effect here is that the named members are now using
lowercase names (to be compatible with how named members usually are
named, which may be enforced by the compiler in the future sometime).

For this next release, the uppercase names will be retained as
compatibility synonyms, but they will be removed in a future release.
  • Loading branch information
jemc committed Oct 20, 2023
1 parent febf7a2 commit 201a319
Show file tree
Hide file tree
Showing 2 changed files with 1,385 additions and 141 deletions.
37 changes: 36 additions & 1 deletion spec/OSError.Spec.savi
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,39 @@
:const describes: "OSError"

:it "uses zero for success"
assert: OSError.None == 0
assert: OSError.success == 0

:it "lists all the error codes supported on the current platform"
count = 0
OSError.each_supported_in_platform -> (error |
assert: error != -1
count += 1
)

case (
| Platform.is_linux | assert: count == 123
| Platform.is_bsd | assert: count == 76
| Platform.is_macos | assert: count == 76
| Platform.is_windows | assert: count == 41
| assert: count == 0 // (unsupported platform)
)

:it "shows the name for all supported error codes"
OSError.each_supported_in_platform -> (error |
assert: !error.name.includes("unknown error code")
)

assert: OSError.success.name == "SUCCESS"
assert: OSError.eperm.name == "EPERM"
assert: OSError[-1].name == "UNSUPPORTED_ERROR_CODE"
assert: OSError[999].name == "UNKNOWN_ERROR_CODE_999"

:it "shows the description for all supported error codes"
OSError.each_supported_in_platform -> (error |
assert: !error.description.includes("unknown error code")
)

assert: OSError.success.description == "Success"
assert: OSError.eperm.description == "Operation not permitted"
assert: OSError[-1].description == "Unsupported error code for this platform"
assert: OSError[999].description == "Unknown error code 999"
Loading

0 comments on commit 201a319

Please sign in to comment.