Commit 5db5edb1 authored by simonmar's avatar simonmar

[project @ 2003-07-23 11:40:31 by simonmar]

Copy some GHCi tests over from fptools/ghc/tests/ghci
parent 6c2bb842
module Main where
import B
main = print ("hello world" ++ show (f 42))
module B (module B, module C) where
import C
k x = x `mod` 11
module C (f, g, h) where
import D
g x = f x + 1
h x = x `div` 2
data C = C {x :: Int}
module D where
data T = A Int | B Float deriving Eq
f x = x + x
module D where
data T = A Int | B Float deriving Eq
f x = x + x
module D where
data T = A Int | B Float deriving Eq
f x = x + 1
TOP=../../../..
include $(TOP)/mk/boilerplate.mk
include $(TOP)/mk/test.mk
test('prog001', normal, ghci_script, ['prog001.script'])
:unset +s
-- first, tidy up:
:! rm -f *.hi *.o *~
:! cp D1.hs D.hs
-- load the program (all interpreted)
:load A
-- reloading should do nothing
:reload
-- make sure `main' works
main
-- touch a module + recompile
:! sleep 1
:! touch C.hs
:reload
-- make sure `main' still works
main
-- compile D & reload
:! $HC $HC_OPTS -no-recomp -c D.hs
:reload
main
-- change D, recompile & reload
:! cp D2.hs D.hs
:! $HC $HC_OPTS -no-recomp -c D.hs
:reload
:load A
-- make sure we're picking up the new D, via B
:module B
g 42
Compiling D ( D.hs, interpreted )
Compiling C ( C.hs, interpreted )
Compiling B ( B.hs, interpreted )
Compiling Main ( A.hs, interpreted )
Compiling C ( C.hs, interpreted )
Skipping B ( B.hs, interpreted )
Skipping Main ( A.hs, interpreted )
Compiling D ( D.hs, interpreted )
Skipping C ( C.hs, interpreted )
Skipping B ( B.hs, interpreted )
Skipping Main ( A.hs, interpreted )
Skipping D ( D.hs, D.o )
Compiling C ( C.hs, interpreted )
Compiling B ( B.hs, interpreted )
Compiling Main ( A.hs, interpreted )
"hello world84"
"hello world84"
"hello world84"
44
module A where
data T = A Int | B Float deriving Eq
f :: Int -> Int
f x = x + 3
module A where
data T = A Int | B Float deriving Eq
f :: Double -> Double
f x = x + x
module A where
data T = A Int | B Float deriving Eq
f :: Int -> Int
f x = x + 3
module B (f, g, h) where
import A
g x = f x + 1
h x = x `div` 2
module C (module B, module C) where
import B
k x = x `mod` 11
module Main where
import C
main = print ("hello world" ++ show (f 42))
TOP=../../../..
include $(TOP)/mk/boilerplate.mk
include $(TOP)/mk/test.mk
test('prog002', normal, ghci_script, ['prog002.script'])
:unset +s
:unset +t
-- first, clean up:
:! rm -f *.hi *.o *~
:! cp A1.hs A.hs
:load D
-- compile A & reload
:! $HC $HC_OPTS -no-recomp -c A.hs
:reload
B.g 42
B.g 42
B.g 42
-- swap A2 for A, compile & reload
:! cp A2.hs A.hs
:! $HC $HC_OPTS -no-recomp -c A.hs
:reload
-- the system should ignore the compiled version and compile its own.
B.g 42
B.g 42
B.g 42
-- pick up newly compiled A
:load D
B.g 42
B.g 42
B.g 42
-- remove A.o: system should recompile A
:! rm A.o
:reload
B.g 42
B.g 42
B.g 42
85.0
85.0
85.0
46
46
46
46
46
46
46
46
46
module Main(main,a) where
import B
import C(c)
main = print (a 42)
a x = b x + c x
module B where
import D
b x = d x
module C where
import D
c x = d x
module D where
-- data types and an instance
data D a = A Int | B Float deriving Eq
newtype N a = N Double
type T a = (Int,Double)
-- a class
class C a where c :: a -> Int
-- a function
d :: Float -> Float
d x = x / 3
module D where
-- data types and an instance
data D a = A Int | B Float deriving Eq
newtype N a = N Double
type T a = (Int,Double)
-- a class
class C a where c :: a -> Int
-- a function
d :: Int -> Int
d x = x * 2
module D where
-- data types and an instance
data D a = A Int | B Float deriving Eq
newtype N a = N Double
type T a = (Int,Double)
-- a class
class C a where c :: a -> Int
-- a function
d :: Float -> Float
d x = x / 3
TOP=../../../..
include $(TOP)/mk/boilerplate.mk
include $(TOP)/mk/test.mk
test('prog003', normal, ghci_script, ['prog003.script'])
:unset +s
:unset +t
-- A small multi-module program, with 4 modules, Main, B, C, D. B & C
-- depend on D, and A depends on B & C.
--
-- This test will try various combinations of compiled and interpreted
-- versions of each module, and make sure each combination behaves
-- sensibly.
-- clean up
:! rm *.o *.hi
:! cp D1.hs D.hs
:load A
:type a
a 42
-- sigh; sleep 1, because the filesystem only stores times in seconds
:! sleep 1; cp D2.hs D.hs
:reload
:type (Main.a,B.b,C.c,D.d)
a 42
-- compile D, check that :reload doesn't pick it up
:! $HC $HC_OPTS -c D.hs
:reload
:type (Main.a,B.b,C.c,D.d)
a 42
-- pick up the compiled D now, with :load
:load A
:type (Main.a,B.b,C.c,D.d)
a 42
-- D,C compiled
:! $HC $HC_OPTS -c C.hs
:load A
:type (Main.a,B.b,C.c,D.d)
a 42
-- D,C,B compiled
:! $HC $HC_OPTS -c B.hs
:load A
:type (Main.a,B.b,C.c,D.d)
a 42
-- D,C,B,A compiled
:! $HC $HC_OPTS -c A.hs
:load A
:type (Main.a,B.b,C.c,D.d)
a 42
-- D,C,A compiled (better not use A.o)
:! rm B.o
:load A
:type (Main.a,B.b,C.c,D.d)
a 42
-- D,A compiled (better not use A.o)
:! rm C.o
:load A
:type (Main.a,B.b,C.c,D.d)
a 42
-- A compiled (better not use A.o)
:! rm D.o
:load A
:type (Main.a,B.b,C.c,D.d)
a 42
-- A,B,C compiled (better not use A.o, B.o, C.o)
:! $HC $HC_OPTS --make -v0 A
:! rm D.o
:load A
:type (Main.a,B.b,C.c,D.d)
a 42
a :: Int -> Int
168
(Main.a,B.b,C.c,D.d) :: (Float -> Float,
Float -> Float,
Float -> Float,
Float -> Float)
28.0
(Main.a,B.b,C.c,D.d) :: (Float -> Float,
Float -> Float,
Float -> Float,
Float -> Float)
28.0
(Main.a,B.b,C.c,D.d) :: (Float -> Float,
Float -> Float,
Float -> Float,
Float -> Float)
28.0
(Main.a,B.b,C.c,D.d) :: (Float -> Float,
Float -> Float,
Float -> Float,
Float -> Float)
28.0
(Main.a,B.b,C.c,D.d) :: (Float -> Float,
Float -> Float,
Float -> Float,
Float -> Float)
28.0
(Main.a,B.b,C.c,D.d) :: (Float -> Float,
Float -> Float,
Float -> Float,
Float -> Float)
28.0
(Main.a,B.b,C.c,D.d) :: (Float -> Float,
Float -> Float,
Float -> Float,
Float -> Float)
28.0
(Main.a,B.b,C.c,D.d) :: (Float -> Float,
Float -> Float,
Float -> Float,
Float -> Float)
28.0
(Main.a,B.b,C.c,D.d) :: (Float -> Float,
Float -> Float,
Float -> Float,
Float -> Float)
28.0
(Main.a,B.b,C.c,D.d) :: (Float -> Float,
Float -> Float,
Float -> Float,
Float -> Float)
28.0
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment