summaryrefslogtreecommitdiff
path: root/testsuite/tests/th/TH_addCStub2.hs
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/tests/th/TH_addCStub2.hs')
-rw-r--r--testsuite/tests/th/TH_addCStub2.hs22
1 files changed, 22 insertions, 0 deletions
diff --git a/testsuite/tests/th/TH_addCStub2.hs b/testsuite/tests/th/TH_addCStub2.hs
new file mode 100644
index 0000000000..10119d9370
--- /dev/null
+++ b/testsuite/tests/th/TH_addCStub2.hs
@@ -0,0 +1,22 @@
+-- Tests that a reasonable error is reported when addCStub is used with
+-- incorrect C code.
+
+{-# LANGUAGE ForeignFunctionInterface #-}
+{-# LANGUAGE TemplateHaskell #-}
+{-# OPTIONS_GHC -optc-DA_MACRO=1 #-}
+
+import Language.Haskell.TH.Syntax
+
+foreign import ccall f :: Int -> IO Int
+
+do addCStub $ unlines
+ [ "#include <stdio.h>"
+ , "int f(int x {"
+ , " printf(\"calling f(%d)\\n\",x);"
+ , " return A_MACRO + x;"
+ , "}"
+ ]
+ return []
+
+main :: IO ()
+main = f 2 >>= print