Skip to content

Commit

Permalink
Test cases for GHCi data, class, etc.
Browse files Browse the repository at this point in the history
Test cases for GHCi data, type, newtype, class, instance,
deriving, etc declarations.
  • Loading branch information
dwincort authored and simonmar committed Sep 21, 2011
1 parent 967d417 commit 73d2c7b
Show file tree
Hide file tree
Showing 44 changed files with 336 additions and 11 deletions.
4 changes: 4 additions & 0 deletions ghci054.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--Testing type synonyms
type Foo = String
let foo = "foo" :: Foo
:t foo
2 changes: 1 addition & 1 deletion tests/ghci/prog009/ghci.prog009.stderr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

A.hs:1:16: parse error on input `where'

<interactive>:1:1:
<interactive>:26:1:
Not in scope: `yan'
Perhaps you meant `tan' (imported from Prelude)

Expand Down
2 changes: 1 addition & 1 deletion tests/ghci/scripts/2816.stderr
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

<interactive>:1:1: Not in scope: `α'
<interactive>:2:1: Not in scope: `α'
14 changes: 7 additions & 7 deletions tests/ghci/scripts/T4127a.stderr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<interactive>:1:68:
Multiple declarations of `f'
Declared at: <interactive>:1:32
<interactive>:1:68
<interactive>:1:108: `f' is not a (visible) method of class `Foo'

<interactive>:3:68:
Multiple declarations of `f'
Declared at: <interactive>:3:32
<interactive>:3:68

<interactive>:3:108: `f' is not a (visible) method of class `Foo'
2 changes: 1 addition & 1 deletion tests/ghci/scripts/T5130.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

<interactive>:1:27:
<interactive>:3:27:
Couldn't match type `a' with `[Char]'
In the expression: "hi"
In the expression: [x, "hi"]
Expand Down
17 changes: 17 additions & 0 deletions tests/ghci/scripts/all.T
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,23 @@ test('ghci035', normal, ghci_script, ['ghci035.script'])
test('ghci036', normal, ghci_script, ['ghci036.script'])
test('ghci037', req_interp, run_command, ['$MAKE -s --no-print-directory ghci037'])
test('ghci038', normal, ghci_script, ['ghci038.script'])
test('ghci039', normal, ghci_script, ['ghci039.script'])
test('ghci040', normal, ghci_script, ['ghci040.script'])
test('ghci041', normal, ghci_script, ['ghci041.script'])
test('ghci042', normal, ghci_script, ['ghci042.script'])
test('ghci043', normal, ghci_script, ['ghci043.script'])
test('ghci044', normal, ghci_script, ['ghci044.script'])
test('ghci045', normal, ghci_script, ['ghci045.script'])
test('ghci046', normal, ghci_script, ['ghci046.script'])
test('ghci047', normal, ghci_script, ['ghci047.script'])
test('ghci048', normal, ghci_script, ['ghci048.script'])
test('ghci049', normal, ghci_script, ['ghci049.script'])
test('ghci050', normal, ghci_script, ['ghci050.script'])
test('ghci051', normal, ghci_script, ['ghci051.script'])
test('ghci052', normal, ghci_script, ['ghci052.script'])
test('ghci053', normal, ghci_script, ['ghci053.script'])
test('ghci054', normal, ghci_script, ['ghci054.script'])
test('ghci055', normal, ghci_script, ['ghci055.script'])
test('2452', normal, ghci_script, ['2452.script'])
test('T2766', normal, ghci_script, ['T2766.script'])

Expand Down
2 changes: 1 addition & 1 deletion tests/ghci/scripts/ghci012.stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
($$$) :: [b -> c] -> [b] -> [c] -- Defined at <interactive>:1:8
($$$) :: [b -> c] -> [b] -> [c] -- Defined at <interactive>:2:8
3 changes: 3 additions & 0 deletions tests/ghci/scripts/ghci039.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--Basic deriving test
data T = A | B deriving Show
show A
1 change: 1 addition & 0 deletions tests/ghci/scripts/ghci039.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"A"
4 changes: 4 additions & 0 deletions tests/ghci/scripts/ghci040.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--Testing type and constructor shadowing
data T = A | B
data T = B | C
:i A
2 changes: 2 additions & 0 deletions tests/ghci/scripts/ghci040.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
data main::Interactive.T = A | ...
-- Defined at <interactive>:3:10
4 changes: 4 additions & 0 deletions tests/ghci/scripts/ghci041.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--Testing more shadowing
data T = A | B
data R = A | C
:i A
1 change: 1 addition & 0 deletions tests/ghci/scripts/ghci041.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data R = A | ... -- Defined at <interactive>:4:10
10 changes: 10 additions & 0 deletions tests/ghci/scripts/ghci042.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--Testing record fields
data T = A {a :: Int}
:i A
:i a
let a = 3
:i a
a
data R = B {a :: Int}
:i a
:i T
7 changes: 7 additions & 0 deletions tests/ghci/scripts/ghci042.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
data T = A {...} -- Defined at <interactive>:3:10
data T = A {a :: Int} -- Defined at <interactive>:3:13
a :: Integer -- Defined at <interactive>:6:5
3
data R = B {a :: Int} -- Defined at <interactive>:9:13
data T = A {main::Interactive.a :: Int}
-- Defined at <interactive>:3:6
11 changes: 11 additions & 0 deletions tests/ghci/scripts/ghci043.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--Testing custom classes and instances as well as data type shadowing
class C a
instance C Int

data Foo = Bar | Baz
class MyEq a where ; myeq :: a -> a -> Bool ; a `myeq` b = True
instance MyEq Foo
Bar `myeq` Baz
data Foo = Bar | Baz
instance MyEq Foo where ; a `myeq` b = False
Baz `myeq` Bar
2 changes: 2 additions & 0 deletions tests/ghci/scripts/ghci043.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
True
False
10 changes: 10 additions & 0 deletions tests/ghci/scripts/ghci044.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--Testing flexible and Overlapping instances
class C a where { f :: a -> Int; f _ = 3 }
instance C Int where { f = id }
instance C [Int]
:set -XFlexibleInstances
instance C [Int]
instance C a => C [a] where f xs = length xs
-- ***This should be an overlapping instances error!***
:set -XOverlappingInstances
instance C a => C [a] where f xs = length xs
13 changes: 13 additions & 0 deletions tests/ghci/scripts/ghci044.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

<interactive>:5:10:
Illegal instance declaration for `C [Int]'
(All instance types must be of the form (T a1 ... an)
where a1 ... an are *distinct type variables*,
and each type variable appears at most once in the instance head.
Use -XFlexibleInstances if you want to disable this.)
In the instance declaration for `C [Int]'

<interactive>:8:10:
Overlapping instance declarations:
instance C a => C [a] -- Defined at <interactive>:8:10
instance C [Int] -- Defined at <interactive>:7:10
6 changes: 6 additions & 0 deletions tests/ghci/scripts/ghci045.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
--Testing standalone deriving
:set -XStandaloneDeriving
data Foo = A | B | C
deriving instance Show Foo
A
C
2 changes: 2 additions & 0 deletions tests/ghci/scripts/ghci045.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
A
C
22 changes: 22 additions & 0 deletions tests/ghci/scripts/ghci046.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--Testing type families and their shadowing
:set -XTypeFamilies
data HTrue
data HFalse
type family AND a b
type instance AND HTrue HTrue = HTrue
type instance AND HTrue HFalse = HFalse
type instance AND HFalse HTrue = HFalse
type instance AND HFalse HFalse = HFalse
type family OR a b
type instance OR HTrue HTrue = HTrue
type instance OR HTrue HFalse = HTrue
type instance OR HFalse HTrue = HTrue
type instance OR HFalse HFalse = HFalse
:t undefined :: AND HTrue HTrue
:t undefined :: AND (OR HFalse HTrue) (OR HTrue HFalse)
let t = undefined :: AND HTrue HTrue
let f = undefined :: AND HTrue HFalse
type instance AND HTrue HTrue = HFalse
:t t
let t = undefined :: AND HTrue HTrue
:t t
4 changes: 4 additions & 0 deletions tests/ghci/scripts/ghci046.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
undefined :: AND HTrue HTrue :: HTrue
undefined :: AND (OR HFalse HTrue) (OR HTrue HFalse) :: HTrue
t :: HTrue
t :: HFalse
40 changes: 40 additions & 0 deletions tests/ghci/scripts/ghci047.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
--Testing GADTs, type families as well as a ton of crazy type stuff
:set -XGADTs
:set -XTypeFamilies
:set -XOverlappingInstances
:set -XFunctionalDependencies
:set -XFlexibleContexts
:set -XFlexibleInstances
:set -XUndecidableInstances
data A
data B
data C
:{
data ABorC t where
Foo :: Int -> ABorC A
Bar :: Bool -> ABorC A
Baz :: Char -> ABorC B
Quz :: ABorC B
Yud :: String -> ABorC C
Myp :: Double -> ABorC C
:}
data HTrue
data HFalse

class TypeEq x y b | x y -> b
instance (HTrue ~ b) => TypeEq x x b
instance (HFalse ~ b) => TypeEq x y b

type family Or a b
type instance Or HTrue HTrue = HTrue
type instance Or HTrue HFalse = HTrue
type instance Or HFalse HTrue = HTrue
type instance Or HFalse HFalse = HFalse

let f :: (Or a c ~ HTrue, TypeEq t A a, TypeEq t C c) => ABorC t -> Int ; f x = 1
f $ Foo 1
f $ Bar True
f $ Baz 'a'
f $ Quz
f $ Yud "a"
f $ Myp 4.3
12 changes: 12 additions & 0 deletions tests/ghci/scripts/ghci047.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

<interactive>:38:1:
Couldn't match type `HFalse' with `HTrue'
In the expression: f
In the expression: f $ Baz 'a'
In an equation for `it': it = f $ Baz 'a'

<interactive>:39:1:
Couldn't match type `HFalse' with `HTrue'
In the expression: f
In the expression: f $ Quz
In an equation for `it': it = f $ Quz
4 changes: 4 additions & 0 deletions tests/ghci/scripts/ghci047.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
1
1
1
1
5 changes: 5 additions & 0 deletions tests/ghci/scripts/ghci048.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
--Testing proper error message for multiple declarations (a previous bug)
data Foo = A | B
data Foo = A | A
data Foo = A | B
data Foo = A | A
10 changes: 10 additions & 0 deletions tests/ghci/scripts/ghci048.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

<interactive>:4:16:
Multiple declarations of `A'
Declared at: <interactive>:4:12
<interactive>:4:16

<interactive>:6:16:
Multiple declarations of `A'
Declared at: <interactive>:6:12
<interactive>:6:16
9 changes: 9 additions & 0 deletions tests/ghci/scripts/ghci049.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
--Testing RecordWildCards (a previous bug)
data C = C {a :: Integer, b :: Integer, c :: Integer, d :: Integer} deriving Show
let myc = C 1 2 3 4
:set -XFlexibleInstances
instance Show (C -> Integer) where ; show a = "C -> field " ++ (show $ a myc)
(a,b,c,d)
:set -XRecordWildCards
let C{..} = myc
(a,b,c,d)
2 changes: 2 additions & 0 deletions tests/ghci/scripts/ghci049.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(C -> field 1,C -> field 2,C -> field 3,C -> field 4)
(1,2,3,4)
7 changes: 7 additions & 0 deletions tests/ghci/scripts/ghci050.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
--Testing for proper name printing in complex error messages (a previous bug)
:set -XTypeFamilies
:set -XFlexibleInstances
class Listable t where ; type ListableElem t :: * ; asList :: t -> [ListableElem t]
instance Listable (a,a) where ; asList (a,b) = [a,b]
instance Listable (a,a) where ; type ListableElem (a,a) = a ; asList (a,b) = [a,b]
asList ("as","df")
8 changes: 8 additions & 0 deletions tests/ghci/scripts/ghci050.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

<interactive>:6:51:
Couldn't match type `a' with `ListableElem (a, a)'
`a' is a rigid type variable bound by
the instance declaration at <interactive>:6:20
In the expression: b
In the expression: [a, b]
In an equation for `asList': asList (a, b) = [a, b]
1 change: 1 addition & 0 deletions tests/ghci/scripts/ghci050.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["as","df"]
18 changes: 18 additions & 0 deletions tests/ghci/scripts/ghci051.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--Testing complex type and constructor shadowing
data T = A | B
type T' = T
let b = B :: T'
data T = B | C
let c = C :: T'
let c = C
data T = C | D
let d = D
:i T
:i T'
:i A
:i B
:i C
:i D
:i b
:i c
:i d
5 changes: 5 additions & 0 deletions tests/ghci/scripts/ghci051.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

<interactive>:7:9:
Couldn't match expected type `T'' with actual type `T'
In the expression: C :: T'
In an equation for `c': c = C :: T'
9 changes: 9 additions & 0 deletions tests/ghci/scripts/ghci051.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
data T = C | D -- Defined at <interactive>:0:10
type T' = :Interactive.T -- Defined at <interactive>:0:6-7
data :Interactive.T = A | ... -- Defined at <interactive>:0:10
data :Interactive.T = B | ... -- Defined at <interactive>:0:12
data T = C | ... -- Defined at <interactive>:0:14
data T = ... | D -- Defined at <interactive>:0:18
b :: T' -- Defined at <interactive>:0:5
c :: :Interactive.T -- Defined at <interactive>:0:5
d :: T -- Defined at <interactive>:0:5
10 changes: 10 additions & 0 deletions tests/ghci/scripts/ghci052.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--Testing data type and constructor shadowing with functions
data Planet = Mercury | Venus | Earth
let pn Mercury = "M" ; pn Venus = "V" ; pn Earth = "E"
pn Mercury
data Planet = Mercury | Venus | Mars
pn Mercury
pn Venus
pn Mars
pn Earth
let pn Mercury = "M" ; pn Venus = "V" ; pn Earth = "E" ; pn Mars = "M"
27 changes: 27 additions & 0 deletions tests/ghci/scripts/ghci052.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

<interactive>:7:4:
Couldn't match expected type `main::Interactive.Planet'
with actual type `Planet'
In the first argument of `pn', namely `Mercury'
In the expression: pn Mercury
In an equation for `it': it = pn Mercury

<interactive>:8:4:
Couldn't match expected type `main::Interactive.Planet'
with actual type `Planet'
In the first argument of `pn', namely `Venus'
In the expression: pn Venus
In an equation for `it': it = pn Venus

<interactive>:9:4:
Couldn't match expected type `main::Interactive.Planet'
with actual type `Planet'
In the first argument of `pn', namely `Mars'
In the expression: pn Mars
In an equation for `it': it = pn Mars

<interactive>:11:44:
Couldn't match expected type `Planet'
with actual type `main::Interactive.Planet'
In the pattern: Earth
In an equation for `pn': pn Earth = "E"
2 changes: 2 additions & 0 deletions tests/ghci/scripts/ghci052.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"M"
"E"
10 changes: 10 additions & 0 deletions tests/ghci/scripts/ghci053.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--Testing deriving in the presence of shadowing
data Planet = Mercury | Venus | Earth deriving Eq
let mercury = Mercury
Venus == Earth
data Planet = Mercury | Venus deriving Eq
Mercury == Mercury
mercury == Mercury
Mercury == Venus
Venus == Earth
Earth == Earth
14 changes: 14 additions & 0 deletions tests/ghci/scripts/ghci053.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

<interactive>:8:12:
Couldn't match expected type `main::Interactive.Planet'
with actual type `Planet'
In the second argument of `(==)', namely `Mercury'
In the expression: mercury == Mercury
In an equation for `it': it = mercury == Mercury

<interactive>:10:10:
Couldn't match expected type `Planet'
with actual type `main::Interactive.Planet'
In the second argument of `(==)', namely `Earth'
In the expression: Venus == Earth
In an equation for `it': it = Venus == Earth

0 comments on commit 73d2c7b

Please sign in to comment.