Skip to content

Commit

Permalink
Merge pull request #10 from savi-lang/add/cross-platform
Browse files Browse the repository at this point in the history
Add C++ tests for cross-platform error code checks.
  • Loading branch information
jemc authored Oct 20, 2023
2 parents e975c43 + 1842b67 commit f43cf7c
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 5 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/library-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,28 @@ jobs:
#
# Add any custom jobs you need below this comment.
# The area above this comment is reserved for future standard jobs.

# Use a C++ compiler to check vs the "real" error codes on each platform.
cpp-check:
strategy:
fail-fast: false
matrix:
include:
- { os: ubuntu-latest, shell: bash }
- { os: macos-latest, shell: bash }
- { os: windows-latest, shell: 'wsl-bash {0}' }
runs-on: ${{ matrix.os }}
defaults:
run:
shell: ${{ matrix.shell }}
steps:
- uses: actions/checkout@v2
- uses: savi-lang/action-install@v1
- run: savi deps update --for c++-check-program
- run: sudo apt-get install mingw-w64 -y
if: runner.os == 'Windows'
- run: " \
savi run c++-check-program \
${{ runner.os == 'Windows' && '--cross-compile=x86_64-unknown-windows-msvc' || '' }} \
| ${{ runner.os == 'Windows' && 'x86_64-w64-mingw32-gcc' || 'c++' }} -x c++ -o /dev/null - \
"
25 changes: 25 additions & 0 deletions c++-check-program/Main.savi
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
:: Print a C++ program that checks the mapping of error codes by names,
:: comparing what we have implemented to what the C++ compiler resolves.
::
:: For this C++ program to compile, all of the `static_assert`s must pass,
:: which means all of our error code mappings in Savi must be correct.
::
:: Therefore we can test our error code mappings py piping the printed C++ code
:: into a C++ compiler, with a command like this:
:: ```
:: savi run c++-check-program | c++ -x c++ -o /dev/null -
:: ```
:actor Main
:new (env)
env.out.print("#include <errno.h>")

OSError.each_supported_in_platform -> (error |
next if error == 0

env.out.print("static_assert( \
\(error.name) == \(error.u32), \
\"\(error.name) == \(error.u32)\" \
);")
)

env.out.print("int main() { return 0; }")
4 changes: 4 additions & 0 deletions manifest.savi
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@
:transitive dependency Timer v0
:from "github:savi-lang/Timer"
:depends on Time

:manifest bin "c++-check-program"
:copies OSError
:sources "c++-check-program/*.savi"
2 changes: 1 addition & 1 deletion spec/OSError.Spec.savi
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
| Platform.is_linux | assert: count == 123
| Platform.is_bsd | assert: count == 76
| Platform.is_macos | assert: count == 76
| Platform.is_windows | assert: count == 41
| Platform.is_windows | assert: count == 40
| assert: count == 0 // (unsupported platform)
)

Expand Down
35 changes: 31 additions & 4 deletions src/OSError.savi
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,29 @@
:fun non enoexec @'val: 8
:fun non ebadf @'val: 9
:fun non echild @'val: 10
:fun non eagain @'val: 11

:fun non eagain @'val
case (
| Platform.is_linux | 11
| Platform.is_bsd | 35
| Platform.is_macos | 35
| Platform.is_windows | 11
| -1
)

:fun non enomem @'val: 12
:fun non eacces @'val: 13
:fun non efault @'val: 14
:fun non enotblk @'val: 15

:fun non enotblk @'val
case (
| Platform.is_linux | 15
| Platform.is_bsd | 15
| Platform.is_macos | 15
| Platform.is_windows | -1 // (doesn't have this error code)
| -1
)

:fun non ebusy @'val: 16
:fun non eexist @'val: 17
:fun non exdev @'val: 18
Expand All @@ -35,7 +53,16 @@
:fun non enfile @'val: 23
:fun non emfile @'val: 24
:fun non enotty @'val: 25
:fun non etxtbsy @'val: 26

:fun non etxtbsy @'val
case (
| Platform.is_linux | 26
| Platform.is_bsd | 26
| Platform.is_macos | 26
| Platform.is_windows | 139
| -1
)

:fun non efbig @'val: 27
:fun non enospc @'val: 28
:fun non espipe @'val: 29
Expand Down Expand Up @@ -448,7 +475,7 @@
case (
| Platform.is_linux | 95
| Platform.is_bsd | 45
| Platform.is_macos | 45
| Platform.is_macos | 102
| Platform.is_windows | -1 // (doesn't have this error code)
| -1
)
Expand Down

0 comments on commit f43cf7c

Please sign in to comment.