Skip to content

Commit 1bd501e

Browse files
committed
Add test for capi
1 parent fe094f0 commit 1bd501e

File tree

8 files changed

+53
-0
lines changed

8 files changed

+53
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{-# LANGUAGE CApiFFI #-}
2+
3+
module Main where
4+
5+
import Foreign.C (CInt (..))
6+
7+
foreign import capi "clib.h myplus"
8+
myplus :: CInt -> CInt -> IO CInt
9+
10+
main :: IO ()
11+
main = do
12+
result <- myplus 5 6
13+
if (result == 11)
14+
then putStrLn ("The result is " ++ show result)
15+
else error ("Expected value 11, got " ++ show result)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# ForeignOptsCapi
2+
3+
This test case asserts that cabal passes `cc-options` to the C compiler when use `foreign import capi`.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# cabal v2-build
2+
Configuration is affected by the following files:
3+
- cabal.project
4+
Resolving dependencies...
5+
Build profile: -w ghc-<GHCVER> -O1
6+
In order, the following will be built:
7+
- foreign-opts-capi-0.1 (exe:foreign-opts-capi-exe) (first run)
8+
Configuring executable 'foreign-opts-capi-exe' for foreign-opts-capi-0.1...
9+
Preprocessing executable 'foreign-opts-capi-exe' for foreign-opts-capi-0.1...
10+
Building executable 'foreign-opts-capi-exe' for foreign-opts-capi-0.1...
11+
# foreign-opts-capi foreign-opts-capi-exe
12+
The result is 11
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: .
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import Test.Cabal.Prelude
2+
main = cabalTest $ do
3+
cabal "v2-build" ["foreign-opts-capi-exe"]
4+
withPlan $ runPlanExe "foreign-opts-capi" "foreign-opts-capi-exe" []

cabal-testsuite/PackageTests/FFI/ForeignOptsCapi/cbits/clib.c

Whitespace-only changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef MYDEF
2+
#error "Did not get required MYDEF from cc-options"
3+
#endif
4+
5+
static inline int myplus(int a, int b) {
6+
return a + b;
7+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cabal-version: 3.0
2+
name: foreign-opts-capi
3+
version: 0.1
4+
build-type: Simple
5+
6+
executable foreign-opts-capi-exe
7+
main-is: Main.hs
8+
build-depends: base
9+
default-language: Haskell2010
10+
include-dirs: cbits
11+
cc-options: -DMYDEF=1

0 commit comments

Comments
 (0)