From 3a6a262ceafab67508b2dbafadddff70680e6a71 Mon Sep 17 00:00:00 2001 From: Veit Heller Date: Thu, 17 Sep 2026 00:52:47 +0200 Subject: [PATCH 1/4] Run the test suites on macos as well as linux --- test/dynlib.carp | 11 ++++--- test/platform.carp | 3 ++ test/typed.carp | 82 +++++++++++++++++++++++++++++++++------------- 3 files changed, 68 insertions(+), 28 deletions(-) create mode 100644 test/platform.carp diff --git a/test/dynlib.carp b/test/dynlib.carp index 2a4829a..a981f82 100644 --- a/test/dynlib.carp +++ b/test/dynlib.carp @@ -1,18 +1,19 @@ (load "../dynlib.carp") +(load "platform.carp") (load "Test.carp") (use Test) (defn main [] (with-test test (assert-true test - (Result.success? &(DynLib.open "libm.so.6")) + (Result.success? &(DynLib.open (libm-path))) "open succeeds for libm") (assert-true test (Result.error? &(DynLib.open "libnonexistent.so")) "open fails for nonexistent library") - (match (DynLib.open "libm.so.6") + (match (DynLib.open (libm-path)) (Result.Success lib) (let-do [result (the (Result (Fn [Double] Double) String) (DynLib.get lib "floor")) @@ -22,7 +23,7 @@ (assert-true test ok "get succeeds for known symbol")) (Result.Error _) (assert-true test false "get succeeds for known symbol")) - (match (DynLib.open "libm.so.6") + (match (DynLib.open (libm-path)) (Result.Success lib) (let-do [result (the (Result (Fn [] ()) String) (DynLib.get lib "nonexistent_symbol_xyz")) @@ -33,14 +34,14 @@ (Result.Error _) (assert-true test false "get fails for nonexistent symbol")) - (match (DynLib.open "libm.so.6") + (match (DynLib.open (libm-path)) (Result.Success lib) (assert-true test (Result.success? &(DynLib.close lib)) "close succeeds on valid handle") (Result.Error _) (assert-true test false "close succeeds on valid handle")) - (match (DynLib.open "libm.so.6") + (match (DynLib.open (libm-path)) (Result.Success lib) (assert-equal test &(Result.Success ()) diff --git a/test/platform.carp b/test/platform.carp new file mode 100644 index 0000000..f82cb24 --- /dev/null +++ b/test/platform.carp @@ -0,0 +1,3 @@ +; the math symbols live in different libraries per platform: macos keeps them +; in libSystem, glibc in libm.so.6. +(defmacro libm-path [] (if mac-target? "/usr/lib/libSystem.B.dylib" "libm.so.6")) diff --git a/test/typed.carp b/test/typed.carp index b6b346f..f477eb9 100644 --- a/test/typed.carp +++ b/test/typed.carp @@ -1,4 +1,7 @@ (load "../dynlib.carp") +(load "platform.carp") +(load "Test.carp") +(use Test) (DynLib.defbinder bind-owned-floor (Fn [Double] Double)) (DynLib.defpinned-binder bind-pinned-floor (Fn [Double] Double)) @@ -7,30 +10,63 @@ (DynLib.defpinned-binder bind-missing (Fn [] ())) (defn main [] - (do - (match (DynLib.open-owned "libm.so.6") - (Result.Error error) (IO.errorln &error) + (with-test test + (match (DynLib.open-owned (libm-path)) + (Result.Error error) + (assert-true test false &(fmt "open-owned failed: %s" &error)) (Result.Success library) (match (bind-owned-floor library "floor") - (Result.Error error) (IO.errorln &error) + (Result.Error error) + (assert-true test false &(fmt "binding floor failed: %s" &error)) (Result.Success function) - (assert (= 3.0 (DynLibBoundFn.call1 &function 3.9))))) - (match (DynLib.open-pinned "libm.so.6") - (Result.Error error) (IO.errorln &error) + (assert-equal test + 3.0 + (DynLibBoundFn.call1 &function 3.9) + "owned binding calls floor"))) + + (match (DynLib.open-pinned (libm-path)) + (Result.Error error) + (assert-true test false &(fmt "open-pinned failed: %s" &error)) + (Result.Success library) + (match (bind-pinned-floor &library "floor") + (Result.Error error) + (assert-true test false &(fmt "binding floor failed: %s" &error)) + (Result.Success function) + (assert-equal test + 4.0 + (DynLibPinnedFn.call1 &function 4.9) + "pinned binding calls floor"))) + + (match (DynLib.open-pinned (libm-path)) + (Result.Error error) + (assert-true test false &(fmt "open-pinned failed: %s" &error)) + (Result.Success library) + (match (bind-pinned-ceil &library "ceil") + (Result.Error error) + (assert-true test false &(fmt "binding ceil failed: %s" &error)) + (Result.Success function) + (assert-equal test + 6.0 + (DynLibPinnedFn.call1 &function 5.1) + "pinned binding calls ceil"))) + + (match (DynLib.open-pinned (libm-path)) + (Result.Error error) + (assert-true test false &(fmt "open-pinned failed: %s" &error)) + (Result.Success library) + (match (bind-pinned-pow &library "pow") + (Result.Error error) + (assert-true test false &(fmt "binding pow failed: %s" &error)) + (Result.Success function) + (assert-equal test + 8.0 + (DynLibPinnedFn.call2 &function 2.0 3.0) + "pinned binding calls pow"))) + + (match (DynLib.open-pinned (libm-path)) + (Result.Error error) + (assert-true test false &(fmt "open-pinned failed: %s" &error)) (Result.Success library) - (do - (match (bind-pinned-floor &library "floor") - (Result.Error error) (IO.errorln &error) - (Result.Success function) - (assert (= 4.0 (DynLibPinnedFn.call1 &function 4.9)))) - (match (bind-pinned-ceil &library "ceil") - (Result.Error error) (IO.errorln &error) - (Result.Success function) - (assert (= 6.0 (DynLibPinnedFn.call1 &function 5.1)))) - (match (bind-pinned-pow &library "pow") - (Result.Error error) (IO.errorln &error) - (Result.Success function) - (assert (= 8.0 (DynLibPinnedFn.call2 &function 2.0 3.0)))) - (match (bind-missing &library "dynlib_missing_symbol") - (Result.Error _) () - (Result.Success _) (assert false)))))) + (assert-true test + (Result.error? &(bind-missing &library "dynlib_missing_symbol")) + "binding a missing symbol fails")))) From 8116032b23f4772d5fe04722bd0a6dbccae1705b Mon Sep 17 00:00:00 2001 From: Veit Heller Date: Thu, 17 Sep 2026 00:52:47 +0200 Subject: [PATCH 2/4] Run the test suites in CI --- .github/workflows/ci.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3dcb993..ac1cefa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,6 +19,11 @@ jobs: - name: Setup Carp uses: carpentry-org/setup-carp@v1 + - name: Run tests + run: | + carp -x test/dynlib.carp + carp -x test/typed.carp + - name: Install angler run: | set -euo pipefail From 4a2dc4a636ff74d61044d378afbe7b346e5dda11 Mon Sep 17 00:00:00 2001 From: Veit Heller Date: Thu, 17 Sep 2026 00:56:44 +0200 Subject: [PATCH 3/4] Note the platform-specific library path in the readme example --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 0fca25f..2a5c2ef 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,8 @@ pinned or owned library: (DynLib.defpinned-binder bind-floor (Fn [Double] Double)) (defn main [] + ; the math symbols live in different libraries per platform: glibc keeps + ; them in libm.so.6, macos in /usr/lib/libSystem.B.dylib (match (DynLib.open-pinned "libm.so.6") (Result.Error error) (IO.errorln &error) (Result.Success library) From 4a8c75d9ff35305297e64b5efd470ca01dbaf0e1 Mon Sep 17 00:00:00 2001 From: Veit Heller Date: Thu, 17 Sep 2026 00:58:22 +0200 Subject: [PATCH 4/4] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2a5c2ef..624640a 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ pinned or owned library: (DynLib.defpinned-binder bind-floor (Fn [Double] Double)) (defn main [] - ; the math symbols live in different libraries per platform: glibc keeps + ; nb: the math symbols live in different libraries per platform: glibc keeps ; them in libm.so.6, macos in /usr/lib/libSystem.B.dylib (match (DynLib.open-pinned "libm.so.6") (Result.Error error) (IO.errorln &error)