summaryrefslogtreecommitdiff
path: root/testsuite/tests
diff options
context:
space:
mode:
authorAlec Theriault <alec.theriault@gmail.com>2018-03-25 13:59:27 -0400
committerBen Gamari <ben@smart-cactus.org>2018-03-25 14:33:22 -0400
commitceb914771aece0aa6d87339227ce406c7179d1d1 (patch)
tree1b63f9af0e0c7e212c840e1ccd1e6add484774cf /testsuite/tests
parentaffdea82bb70e5a912b679a169c6e9a230e4c93e (diff)
downloadhaskell-ceb914771aece0aa6d87339227ce406c7179d1d1.tar.gz
Support adding objects from TH
The user facing TH interface changes are: * 'addForeignFile' is renamed to 'addForeignSource' * 'qAddForeignFile'/'addForeignFile' now expect 'FilePath's * 'RawObject' is now a constructor for 'ForeignSrcLang' * 'qAddTempFile'/'addTempFile' let you request a temporary file from the compiler. Test Plan: unsure about this, added a TH test Reviewers: goldfire, bgamari, angerman Reviewed By: bgamari, angerman Subscribers: hsyl20, mboes, carter, simonmar, bitonic, ljli, rwbarton, thomie GHC Trac Issues: #14298 Differential Revision: https://phabricator.haskell.org/D4217
Diffstat (limited to 'testsuite/tests')
-rw-r--r--testsuite/tests/th/T13366.hs4
-rw-r--r--testsuite/tests/th/T14298.hs24
-rw-r--r--testsuite/tests/th/T14298.stdout2
-rw-r--r--testsuite/tests/th/all.T1
4 files changed, 29 insertions, 2 deletions
diff --git a/testsuite/tests/th/T13366.hs b/testsuite/tests/th/T13366.hs
index 2573235a01..6a3bda3d09 100644
--- a/testsuite/tests/th/T13366.hs
+++ b/testsuite/tests/th/T13366.hs
@@ -7,7 +7,7 @@ import System.IO (hFlush, stdout)
foreign import ccall fc :: Int -> IO Int
-do addForeignFile LangC $ unlines
+do addForeignSource LangC $ unlines
[ "#include <stdio.h>"
, "int fc(int x) {"
, " printf(\"calling f(%d)\\n\",x);"
@@ -19,7 +19,7 @@ do addForeignFile LangC $ unlines
foreign import ccall fcxx :: Int -> IO Int
-do addForeignFile LangCxx $ unlines
+do addForeignSource LangCxx $ unlines
[ "#include <iostream>"
, "extern \"C\" {"
, " int fcxx(int x) {"
diff --git a/testsuite/tests/th/T14298.hs b/testsuite/tests/th/T14298.hs
new file mode 100644
index 0000000000..7896e491cb
--- /dev/null
+++ b/testsuite/tests/th/T14298.hs
@@ -0,0 +1,24 @@
+{-# LANGUAGE ForeignFunctionInterface #-}
+{-# LANGUAGE TemplateHaskell #-}
+
+import Language.Haskell.TH.Syntax
+import System.IO (hFlush, stdout)
+
+foreign import ccall foo :: Int -> IO Int
+
+do fpIn <- addTempFile "c"
+ let cSrc = (unlines [ "#include <stdio.h>"
+ , "int foo(int x) {"
+ , " printf(\"calling f(%d)\\n\",x);"
+ , " fflush(stdout);"
+ , " return 1 + x;"
+ , "}"
+ ])
+ runIO $ writeFile fpIn cSrc
+ addForeignFilePath LangC fpIn
+ return []
+
+main :: IO ()
+main = do
+ foo 2 >>= print
+ hFlush stdout
diff --git a/testsuite/tests/th/T14298.stdout b/testsuite/tests/th/T14298.stdout
new file mode 100644
index 0000000000..2ab79e85b8
--- /dev/null
+++ b/testsuite/tests/th/T14298.stdout
@@ -0,0 +1,2 @@
+calling f(2)
+3
diff --git a/testsuite/tests/th/all.T b/testsuite/tests/th/all.T
index f391012d2b..b5fd6d826a 100644
--- a/testsuite/tests/th/all.T
+++ b/testsuite/tests/th/all.T
@@ -408,3 +408,4 @@ test('T14869', normal, compile,
['-v0 -ddump-splices -dsuppress-uniques ' + config.ghc_th_way_flags])
test('T14888', normal, compile,
['-v0 -ddump-splices -dsuppress-uniques ' + config.ghc_th_way_flags])
+test('T14298', normal, compile_and_run, ['-v0'])