Update examples
This commit is contained in:
5
testsuite/makewith/global_pragma/Makefile
Normal file
5
testsuite/makewith/global_pragma/Makefile
Normal file
@ -0,0 +1,5 @@
|
||||
|
||||
TEST=makewith/global_pragma
|
||||
|
||||
TOP=../../..
|
||||
include ../../build.mk
|
17
testsuite/makewith/global_pragma/Plugin.hs
Normal file
17
testsuite/makewith/global_pragma/Plugin.hs
Normal file
@ -0,0 +1,17 @@
|
||||
{-# GLOBALOPTIONS -package mtl #-}
|
||||
|
||||
module M ( resource ) where
|
||||
|
||||
import API
|
||||
import System.IO.Unsafe
|
||||
import System.Process
|
||||
import System.IO
|
||||
|
||||
resource = tiny { field = date }
|
||||
|
||||
date :: String
|
||||
date = unsafePerformIO $ do
|
||||
(_,outh,_,proc) <- runInteractiveProcess "echo" ["hello"] Nothing Nothing
|
||||
waitForProcess proc
|
||||
s <- hGetContents outh
|
||||
return s
|
8
testsuite/makewith/global_pragma/api/API.hs
Normal file
8
testsuite/makewith/global_pragma/api/API.hs
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
module API where
|
||||
|
||||
data Tiny = Tiny { field :: String }
|
||||
|
||||
tiny :: Tiny
|
||||
tiny = Tiny { field = "default value" }
|
||||
|
19
testsuite/makewith/global_pragma/prog/Main.hs
Normal file
19
testsuite/makewith/global_pragma/prog/Main.hs
Normal file
@ -0,0 +1,19 @@
|
||||
|
||||
import System.Plugins
|
||||
import API
|
||||
|
||||
conf = "../Plugin.hs"
|
||||
apipath = "../api"
|
||||
|
||||
main = do
|
||||
status <- makeWith conf conf ["-i"++apipath]
|
||||
o <- case status of
|
||||
MakeFailure e -> mapM_ putStrLn e >> error "compile failed"
|
||||
MakeSuccess _ o -> return o
|
||||
m_v <- load o [apipath] [] "resource"
|
||||
v <- case m_v of
|
||||
LoadSuccess _ v -> return v
|
||||
LoadFailure ers -> mapM_ putStrLn ers >> error "load failed"
|
||||
putStr $ field v
|
||||
makeCleaner o
|
||||
|
1
testsuite/makewith/global_pragma/prog/expected
Normal file
1
testsuite/makewith/global_pragma/prog/expected
Normal file
@ -0,0 +1 @@
|
||||
hello
|
Reference in New Issue
Block a user