Update examples
This commit is contained in:
4
testsuite/makewith/io/Makefile
Normal file
4
testsuite/makewith/io/Makefile
Normal file
@ -0,0 +1,4 @@
|
||||
TEST=makewith/io
|
||||
|
||||
TOP=../../..
|
||||
include ../../build.mk
|
2
testsuite/makewith/io/README
Normal file
2
testsuite/makewith/io/README
Normal file
@ -0,0 +1,2 @@
|
||||
An example using IO monad fields in the .conf file.
|
||||
|
22
testsuite/makewith/io/TestIO.conf.in
Normal file
22
testsuite/makewith/io/TestIO.conf.in
Normal file
@ -0,0 +1,22 @@
|
||||
{-# OPTIONS -cpp #-}
|
||||
--
|
||||
-- Copyright (c) 2004 Don Stewart - http://www.cse.unsw.edu.au/~dons
|
||||
-- LGPL version 2.1 or later (see http://www.gnu.org/copyleft/lesser.html)
|
||||
--
|
||||
|
||||
import System.IO
|
||||
import System.Process
|
||||
|
||||
resource = testio { field = date }
|
||||
|
||||
--
|
||||
-- call a shell command , returning it's output
|
||||
--
|
||||
date :: IO String
|
||||
date = do
|
||||
#if !defined(CYGWIN) || !defined(__MINGW32__)
|
||||
(_,out,_,_) <- catch (runInteractiveCommand "/bin/date") (\_->error "popen failed")
|
||||
#else
|
||||
(_,out,_,_) <- catch (runInteractiveCommand "@PREFIX@/../../bin/date") (\_->error "popen failed")
|
||||
#endif
|
||||
hGetLine out
|
10
testsuite/makewith/io/TestIO.stub
Normal file
10
testsuite/makewith/io/TestIO.stub
Normal file
@ -0,0 +1,10 @@
|
||||
|
||||
module TestIO ( resource, resource_dyn ) where
|
||||
|
||||
import API
|
||||
import Data.Dynamic
|
||||
|
||||
resource = testio
|
||||
|
||||
resource_dyn :: Dynamic
|
||||
resource_dyn = toDyn resource
|
16
testsuite/makewith/io/api/API.hs
Normal file
16
testsuite/makewith/io/api/API.hs
Normal file
@ -0,0 +1,16 @@
|
||||
{-# OPTIONS -fglasgow-exts #-}
|
||||
|
||||
module API where
|
||||
|
||||
import Data.Dynamic
|
||||
|
||||
data TestIO = TestIO {
|
||||
field :: IO String
|
||||
}
|
||||
deriving (Typeable, Show)
|
||||
|
||||
instance Show (IO String) where
|
||||
show _ = "<<io action>>"
|
||||
|
||||
testio :: TestIO
|
||||
testio = TestIO { field = return "default value" }
|
21
testsuite/makewith/io/prog/Main.hs
Normal file
21
testsuite/makewith/io/prog/Main.hs
Normal file
@ -0,0 +1,21 @@
|
||||
|
||||
import System.Plugins
|
||||
import API
|
||||
|
||||
conf = "../TestIO.conf"
|
||||
stub = "../TestIO.stub"
|
||||
apipath = "../api"
|
||||
|
||||
main = do
|
||||
status <- makeWith conf stub ["-i"++apipath]
|
||||
o <- case status of
|
||||
MakeFailure e -> mapM_ putStrLn e >> error "failed"
|
||||
MakeSuccess _ o -> return o
|
||||
m_v <- load o [apipath] [] "resource"
|
||||
v <- case m_v of
|
||||
LoadSuccess _ v -> return v
|
||||
_ -> error "load failed"
|
||||
s <- field v
|
||||
|
||||
makeCleaner o
|
||||
if null s then print False else print True
|
6
testsuite/makewith/io/prog/expected
Normal file
6
testsuite/makewith/io/prog/expected
Normal file
@ -0,0 +1,6 @@
|
||||
merge failed:
|
||||
|
||||
parse error in ../TestIO.conf
|
||||
line: 17, col: 1
|
||||
|
||||
a.out: failed
|
Reference in New Issue
Block a user