Update examples
This commit is contained in:
69
testsuite/plugs/plugs/Main.hs
Normal file
69
testsuite/plugs/plugs/Main.hs
Normal file
@ -0,0 +1,69 @@
|
||||
--
|
||||
-- Copyright (c) 2004 Don Stewart - http://www.cse.unsw.edu.au/~dons
|
||||
-- GPL version 2 or later (see http://www.gnu.org/copyleft/gpl.html)
|
||||
--
|
||||
|
||||
import System.Eval.Haskell
|
||||
import System.Plugins.Load
|
||||
|
||||
import System.Exit ( ExitCode(..), exitWith )
|
||||
import System.IO
|
||||
import System.Console.Readline ( readline, addHistory )
|
||||
|
||||
symbol = "resource"
|
||||
|
||||
main = do
|
||||
putStrLn banner
|
||||
putStr "Loading package base" >> hFlush stdout
|
||||
loadPackage "base"
|
||||
putStr " ... linking ... " >> hFlush stdout
|
||||
resolveObjs (return ())
|
||||
putStrLn "done"
|
||||
|
||||
shell []
|
||||
|
||||
shell :: [String] -> IO ()
|
||||
shell imps = do
|
||||
s <- readline "plugs> "
|
||||
cmd <- case s of
|
||||
Nothing -> exitWith ExitSuccess
|
||||
Just (':':'q':_) -> exitWith ExitSuccess
|
||||
Just s -> addHistory s >> return s
|
||||
imps' <- run cmd imps
|
||||
shell imps'
|
||||
|
||||
run :: String -> [String] -> IO [String]
|
||||
run "" is = return is
|
||||
run ":?" is = putStrLn help >> return is
|
||||
|
||||
run ":l" _ = return []
|
||||
run (':':'l':' ':m) is = return (m:is)
|
||||
|
||||
run (':':'t':' ':s) is = do
|
||||
ty <- typeOf s is
|
||||
when (not $ null ty) (putStrLn $ s ++ " :: " ++ ty)
|
||||
return is
|
||||
|
||||
run (':':_) is = putStrLn help >> return is
|
||||
|
||||
run s is = do
|
||||
s <- unsafeEval ("show $ "++s) is
|
||||
when (isJust s) (putStrLn (fromJust s))
|
||||
return is
|
||||
|
||||
banner = "\
|
||||
\ __ \n\
|
||||
\ ____ / /_ ______ ______ \n\
|
||||
\ / __ \\/ / / / / __ `/ ___/ PLugin User's GHCi System, for Haskell 98\n\
|
||||
\ / /_/ / / /_/ / /_/ (__ ) http://www.cse.unsw.edu.au/~dons/hs-plugins\n\
|
||||
\ / .___/_/\\__,_/\\__, /____/ Type :? for help \n\
|
||||
\/_/ /____/ \n"
|
||||
|
||||
help = "\
|
||||
\Commands :\n\
|
||||
\ <expr> evaluate expression\n\
|
||||
\ :t <expr> show type of expression (monomorphic only)\n\
|
||||
\ :l module bring module in to scope\n\
|
||||
\ :l clear module list\n\
|
||||
\ :quit quit\n\
|
||||
\ :? display this list of commands"
|
28
testsuite/plugs/plugs/Makefile
Normal file
28
testsuite/plugs/plugs/Makefile
Normal file
@ -0,0 +1,28 @@
|
||||
GHCFLAGS= -O
|
||||
PKGFLAGS+= -package plugins -package readline
|
||||
|
||||
all: build
|
||||
|
||||
build:
|
||||
@$(GHC) $(GHCFLAGS) $(PKGFLAGS) $(EXTRAFLAGS) Main.hs -o plugs
|
||||
check: build
|
||||
@(if [ -f "expected" ] ;\
|
||||
then \
|
||||
actual_out="/tmp/hs-plugins-actual.out.$$$$" ;\
|
||||
diff_out="/tmp/hs-plugins.diff.$$$$" ;\
|
||||
cat test.in | ./plugs > $$actual_out 2>&1 || true ;\
|
||||
diff -u expected $$actual_out > $$diff_out || true ;\
|
||||
if [ -s "$$diff_out" ] ; then \
|
||||
echo "failed with:" ;\
|
||||
cat "$$diff_out" | sed '1,3d' ;\
|
||||
else \
|
||||
echo "ok." ;\
|
||||
fi ;\
|
||||
rm $$actual_out ;\
|
||||
else \
|
||||
cat test.in | ./plugs 2>&1 || true ;\
|
||||
fi)
|
||||
clean:
|
||||
rm -rf *.hi *.o *~ *.dep ./plugs
|
||||
|
||||
include ../../../config.mk
|
9
testsuite/plugs/plugs/expected
Normal file
9
testsuite/plugs/plugs/expected
Normal file
@ -0,0 +1,9 @@
|
||||
__
|
||||
____ / /_ ______ ______
|
||||
/ __ \/ / / / / __ `/ ___/ PLugin User's GHCi System, for Haskell 98
|
||||
/ /_/ / / /_/ / /_/ (__ ) http://www.cse.unsw.edu.au/~dons/hs-plugins
|
||||
/ .___/_/\__,_/\__, /____/ Type :? for help
|
||||
/_/ /____/
|
||||
|
||||
Loading package base ... linking ... plugs> plugs> done
|
||||
453973694165307953197296969697410619233826
|
2
testsuite/plugs/plugs/test.in
Normal file
2
testsuite/plugs/plugs/test.in
Normal file
@ -0,0 +1,2 @@
|
||||
let fibs = 1 : 1 : zipWith (+) fibs (tail fibs) in fibs !! 200
|
||||
:quit
|
45
testsuite/plugs/runplugs/Main.hs
Normal file
45
testsuite/plugs/runplugs/Main.hs
Normal file
@ -0,0 +1,45 @@
|
||||
--
|
||||
-- Copyright (c) 2004 Don Stewart - http://www.cse.unsw.edu.au/~dons
|
||||
-- GPL version 2 or later (see http://www.gnu.org/copyleft/gpl.html)
|
||||
--
|
||||
|
||||
--
|
||||
-- | Runplugs: use hs-plugins to run a Haskell expression under
|
||||
-- controlled conditions.
|
||||
--
|
||||
import System.Eval.Haskell (unsafeEval)
|
||||
|
||||
import Data.Maybe (isJust, fromJust)
|
||||
import Control.Monad (when)
|
||||
|
||||
import System.Exit (exitWith, ExitCode(ExitSuccess))
|
||||
import System.IO (getContents, putStrLn)
|
||||
import System.Posix.Resource (setResourceLimit,
|
||||
Resource(ResourceCPUTime),
|
||||
ResourceLimits(ResourceLimits),
|
||||
ResourceLimit(ResourceLimit))
|
||||
|
||||
rlimit = ResourceLimit 3
|
||||
|
||||
context = prehier ++ datas ++ qualifieds ++ controls
|
||||
|
||||
prehier = ["Char", "List", "Maybe", "Numeric", "Random" ]
|
||||
|
||||
qualifieds = ["qualified Data.Map as M", "qualified Data.Set as S"]
|
||||
|
||||
datas = map ("Data." ++) [
|
||||
"Bits", "Bool", "Char", "Dynamic", "Either",
|
||||
"Graph", "Int", "Ix", "List",
|
||||
"Maybe", "Ratio", "Tree", "Tuple", "Typeable", "Word"
|
||||
]
|
||||
|
||||
controls = map ("Control." ++) ["Monad", "Monad.Reader", "Monad.Fix", "Arrow"]
|
||||
|
||||
main = do
|
||||
setResourceLimit ResourceCPUTime (ResourceLimits rlimit rlimit)
|
||||
s <- getContents
|
||||
when (not . null $ s) $ do
|
||||
s <- unsafeEval ("(take 2048 (show ("++s++")))") context
|
||||
when (isJust s) (putStrLn (fromJust s))
|
||||
exitWith ExitSuccess
|
||||
|
30
testsuite/plugs/runplugs/Makefile
Normal file
30
testsuite/plugs/runplugs/Makefile
Normal file
@ -0,0 +1,30 @@
|
||||
GHCFLAGS= -Onot $(GHC_EXTRA_OPTS)
|
||||
PKGFLAGS= -package posix
|
||||
PKGFLAGS+= -package plugins
|
||||
|
||||
all: build
|
||||
|
||||
build:
|
||||
@$(GHC) $(GHCFLAGS) $(PKGFLAGS) $(EXTRAFLAGS) Main.hs -o runplugs
|
||||
include ../../../config.mk
|
||||
check: build
|
||||
@(if [ -f "expected" ] ;\
|
||||
then \
|
||||
actual_out="/tmp/hs-plugins-actual.out.$$$$" ;\
|
||||
diff_out="/tmp/hs-plugins.diff.$$$$" ;\
|
||||
cat test.in | ./runplugs > $$actual_out 2>&1 || true ;\
|
||||
diff -u expected $$actual_out > $$diff_out || true ;\
|
||||
if [ -s "$$diff_out" ] ; then \
|
||||
echo "failed with:" ;\
|
||||
cat "$$diff_out" | sed '1,3d' ;\
|
||||
else \
|
||||
echo "ok." ;\
|
||||
fi ;\
|
||||
rm $$actual_out ;\
|
||||
else \
|
||||
cat test.in | ./runplugs 2>&1 || true ;\
|
||||
fi)
|
||||
clean:
|
||||
rm -rf *.hi *.o *~ *.dep ./runplugs
|
||||
|
||||
include ../../../config.mk
|
1
testsuite/plugs/runplugs/expected
Normal file
1
testsuite/plugs/runplugs/expected
Normal file
@ -0,0 +1 @@
|
||||
453973694165307953197296969697410619233826
|
1
testsuite/plugs/runplugs/test.in
Normal file
1
testsuite/plugs/runplugs/test.in
Normal file
@ -0,0 +1 @@
|
||||
let fibs = 1 : 1 : zipWith (+) fibs (tail fibs) in fibs !! 200
|
Reference in New Issue
Block a user