Update examples
This commit is contained in:
8
testsuite/hier/hier1/Makefile
Normal file
8
testsuite/hier/hier1/Makefile
Normal file
@ -0,0 +1,8 @@
|
||||
TEST= hier/hier1
|
||||
|
||||
EXTRA_OBJS=Plugin.o
|
||||
PRIOR_OBJS=Modules/Flags.o
|
||||
EXTRAFLAGS=
|
||||
|
||||
TOP=../../..
|
||||
include ../../build.mk
|
15
testsuite/hier/hier1/Modules/Flags.hs
Normal file
15
testsuite/hier/hier1/Modules/Flags.hs
Normal file
@ -0,0 +1,15 @@
|
||||
--
|
||||
-- A simple module
|
||||
--
|
||||
|
||||
module Modules.Flags where
|
||||
|
||||
|
||||
data FlagRec = FlagRec {
|
||||
f1 :: Int,
|
||||
f2 :: Int
|
||||
}
|
||||
|
||||
|
||||
foo :: FlagRec -> Int
|
||||
foo x = f1 x
|
6
testsuite/hier/hier1/Modules/Makefile
Normal file
6
testsuite/hier/hier1/Modules/Makefile
Normal file
@ -0,0 +1,6 @@
|
||||
|
||||
all:
|
||||
ghc -O -c Flags.hs
|
||||
|
||||
clean:
|
||||
rm -f *.hi *.o
|
14
testsuite/hier/hier1/Plugin.hs
Normal file
14
testsuite/hier/hier1/Plugin.hs
Normal file
@ -0,0 +1,14 @@
|
||||
--
|
||||
-- Plugin
|
||||
--
|
||||
|
||||
module Plugin where
|
||||
|
||||
import API
|
||||
import Modules.Flags as Flags
|
||||
|
||||
|
||||
resource = plugin {
|
||||
dbFunc = (\x -> Flags.f1 x)
|
||||
}
|
||||
|
16
testsuite/hier/hier1/api/API.hs
Normal file
16
testsuite/hier/hier1/api/API.hs
Normal file
@ -0,0 +1,16 @@
|
||||
--
|
||||
-- API for plugin test
|
||||
--
|
||||
|
||||
module API where
|
||||
|
||||
import Modules.Flags as Flags
|
||||
|
||||
data Interface = Interface {
|
||||
dbFunc :: Flags.FlagRec -> Int
|
||||
}
|
||||
|
||||
|
||||
plugin :: Interface
|
||||
plugin = Interface { dbFunc = (\x -> 1) }
|
||||
|
21
testsuite/hier/hier1/prog/Main.hs
Normal file
21
testsuite/hier/hier1/prog/Main.hs
Normal file
@ -0,0 +1,21 @@
|
||||
--
|
||||
-- Test multiple plugins
|
||||
--
|
||||
|
||||
|
||||
module Main where
|
||||
|
||||
import System.Plugins
|
||||
import API
|
||||
import Modules.Flags as Flags
|
||||
|
||||
|
||||
rec = Flags.FlagRec { Flags.f1 = 4, Flags.f2 = 10 }
|
||||
|
||||
|
||||
main = do
|
||||
status <- load "../Plugin.o" ["../api",".."] [] "resource"
|
||||
case status of
|
||||
LoadFailure _ -> error "load failed"
|
||||
LoadSuccess _ v -> do let func = dbFunc v
|
||||
print (func rec)
|
1
testsuite/hier/hier1/prog/expected
Normal file
1
testsuite/hier/hier1/prog/expected
Normal file
@ -0,0 +1 @@
|
||||
4
|
8
testsuite/hier/hier2/A/B/C/Module.hs
Normal file
8
testsuite/hier/hier2/A/B/C/Module.hs
Normal file
@ -0,0 +1,8 @@
|
||||
--
|
||||
-- A simple module
|
||||
--
|
||||
|
||||
module A.B.C.Module where
|
||||
|
||||
symbol = "You found me"
|
||||
|
7
testsuite/hier/hier2/A/Makefile
Normal file
7
testsuite/hier/hier2/A/Makefile
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
all:
|
||||
ghc -c B/C/Module.hs
|
||||
|
||||
|
||||
clean:
|
||||
rm -f B/C/*.hi B/C/*.o
|
7
testsuite/hier/hier2/Makefile
Normal file
7
testsuite/hier/hier2/Makefile
Normal file
@ -0,0 +1,7 @@
|
||||
TEST= hier/hier2
|
||||
|
||||
PRIOR_OBJS=A/B/C/Module.o
|
||||
EXTRAFLAGS=
|
||||
|
||||
TOP=../../..
|
||||
include ../../build.mk
|
4
testsuite/hier/hier2/api/API.hs
Normal file
4
testsuite/hier/hier2/api/API.hs
Normal file
@ -0,0 +1,4 @@
|
||||
module API where
|
||||
|
||||
-- just a dummy for the build system
|
||||
|
15
testsuite/hier/hier2/prog/Main.hs
Normal file
15
testsuite/hier/hier2/prog/Main.hs
Normal file
@ -0,0 +1,15 @@
|
||||
--
|
||||
-- Test if we can load a module with a hierarchical name from some weird
|
||||
-- path. Tests our the module name handling in the .hi file parser.
|
||||
--
|
||||
|
||||
|
||||
module Main where
|
||||
|
||||
import System.Plugins
|
||||
|
||||
main = do
|
||||
status <- load "../A/B/C/Module.o" [".."] [] "symbol"
|
||||
case status of
|
||||
LoadFailure ers -> mapM_ putStrLn ers
|
||||
LoadSuccess _ v -> print (v :: String)
|
1
testsuite/hier/hier2/prog/expected
Normal file
1
testsuite/hier/hier2/prog/expected
Normal file
@ -0,0 +1 @@
|
||||
"You found me"
|
25
testsuite/hier/hier3/Main.hs
Normal file
25
testsuite/hier/hier3/Main.hs
Normal file
@ -0,0 +1,25 @@
|
||||
module Main where
|
||||
|
||||
import System.Plugins
|
||||
|
||||
main = do
|
||||
|
||||
makeAll "One.hs" []
|
||||
|
||||
load2 "Two.o"
|
||||
|
||||
load2 "./Two.o" -- shouldn't load
|
||||
load2 "../hier3/Two.o" -- shouldn't load
|
||||
load2 "././././Two.o" -- shouldn't load
|
||||
|
||||
-- and this one pulls in "../hier3/Two.o" as a dep
|
||||
y <- load "One.o" ["../hier3"] [] "resource"
|
||||
case y of
|
||||
LoadSuccess _ s -> putStrLn $ "One plugin: " ++ s
|
||||
LoadFailure _ -> putStrLn "Failure: y"
|
||||
|
||||
load2 f = do
|
||||
x <- load f [".", "../hier3", ""] [] "resource" -- depend on One.o
|
||||
case x of
|
||||
LoadSuccess _ s -> putStrLn $ "Two plugin: " ++ s
|
||||
LoadFailure _ -> putStrLn "Failure: x"
|
7
testsuite/hier/hier3/Makefile
Normal file
7
testsuite/hier/hier3/Makefile
Normal file
@ -0,0 +1,7 @@
|
||||
TEST= hier/hier3
|
||||
|
||||
EXTRA_OBJS=One.o Two.o
|
||||
EXTRAFLAGS=
|
||||
|
||||
TOP=../../..
|
||||
include ../../eval.mk
|
7
testsuite/hier/hier3/One.hs
Normal file
7
testsuite/hier/hier3/One.hs
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
module One where
|
||||
|
||||
import qualified Two
|
||||
|
||||
resource = "This is the sub-plugin of (" ++ Two.resource ++ ")"
|
||||
|
4
testsuite/hier/hier3/Two.hs
Normal file
4
testsuite/hier/hier3/Two.hs
Normal file
@ -0,0 +1,4 @@
|
||||
module Two where
|
||||
|
||||
resource = "This is the top plugin"
|
||||
|
5
testsuite/hier/hier3/expected
Normal file
5
testsuite/hier/hier3/expected
Normal file
@ -0,0 +1,5 @@
|
||||
Two plugin: This is the top plugin
|
||||
Two plugin: This is the top plugin
|
||||
Two plugin: This is the top plugin
|
||||
Two plugin: This is the top plugin
|
||||
One plugin: This is the sub-plugin of (This is the top plugin)
|
11
testsuite/hier/hier4/A.hs
Normal file
11
testsuite/hier/hier4/A.hs
Normal file
@ -0,0 +1,11 @@
|
||||
|
||||
-- now, the question is: is it possible to not depend on a module or
|
||||
-- package, but nonetheless have an orphan to it? this could cause
|
||||
-- problems....
|
||||
|
||||
module A where
|
||||
|
||||
import B
|
||||
|
||||
u :: Int
|
||||
u = undefined
|
4
testsuite/hier/hier4/B.hs
Normal file
4
testsuite/hier/hier4/B.hs
Normal file
@ -0,0 +1,4 @@
|
||||
module B where
|
||||
|
||||
import C () -- instances, to make available to those who use B
|
||||
|
12
testsuite/hier/hier4/C.hs
Normal file
12
testsuite/hier/hier4/C.hs
Normal file
@ -0,0 +1,12 @@
|
||||
|
||||
-- try to construct an orphan module == an instance decl-only module,
|
||||
-- that uses classes and types not defined in this module
|
||||
|
||||
module C (C) where
|
||||
|
||||
import D
|
||||
|
||||
instance C a => D (T a) where
|
||||
|
||||
class C a where
|
||||
|
6
testsuite/hier/hier4/D.hs
Normal file
6
testsuite/hier/hier4/D.hs
Normal file
@ -0,0 +1,6 @@
|
||||
|
||||
module D where
|
||||
|
||||
class D a where
|
||||
|
||||
data T a = T
|
12
testsuite/hier/hier4/Main.hs
Normal file
12
testsuite/hier/hier4/Main.hs
Normal file
@ -0,0 +1,12 @@
|
||||
module Main where
|
||||
|
||||
import System.Plugins
|
||||
|
||||
main = do
|
||||
|
||||
makeAll "A.hs" []
|
||||
|
||||
y <- load "A.o" ["."] [] "u"
|
||||
case y of
|
||||
LoadSuccess _ _ -> putStrLn $ "YES"
|
||||
LoadFailure e -> mapM_ putStrLn e
|
4
testsuite/hier/hier4/Makefile
Normal file
4
testsuite/hier/hier4/Makefile
Normal file
@ -0,0 +1,4 @@
|
||||
TEST= hier/hier4
|
||||
|
||||
TOP=../../..
|
||||
include ../../eval.mk
|
1
testsuite/hier/hier4/expected
Normal file
1
testsuite/hier/hier4/expected
Normal file
@ -0,0 +1 @@
|
||||
YES
|
Reference in New Issue
Block a user