Commit 2a68da8b authored by dterei's avatar dterei
Browse files

Add some tests for ghci under -XSafe

parent 8ebdadb0
{-# LANGUAGE Trustworthy #-}
module A (a) where
import System.IO.Unsafe
a :: Int
a = 1
unsafe = unsafePerformIO
{-# LANGUAGE Unsafe #-}
module B where
import System.IO.Unsafe
a :: Int
a = 1
{-# LANGUAGE Safe #-}
module C (a, C(), D(..)) where
a :: Int
a = 1
b :: Int
b = 2
data C a = C a Int
data D a = D a Int
module D where
a :: Int
a = 1
b :: Int
b = 2
module E where
import System.IO.Unsafe
a :: Int
a = 1
TOP=../../..
include $(TOP)/mk/boilerplate.mk
include $(TOP)/mk/test.mk
{-# LANGUAGE OverlappingInstances, FlexibleInstances #-}
module P13_A where
class Pos a where { res :: a -> Bool }
instance Pos [a] where { res _ = True }
instance Pos Char where { res _ = True }
# Test GHCi works with Safe Haskell
test('p1', normal, ghci_script, ['p1.script'])
test('p2', normal, ghci_script, ['p2.script'])
test('p3', normal, ghci_script, ['p3.script'])
test('p4', normal, ghci_script, ['p4.script'])
test('p5', normal, ghci_script, ['p5.script'])
test('p6', normal, ghci_script, ['p6.script'])
test('p7', normal, ghci_script, ['p7.script'])
test('p8', normal, ghci_script, ['p8.script'])
test('p9', normal, ghci_script, ['p9.script'])
test('p10', normal, ghci_script, ['p10.script'])
test('p11', normal, ghci_script, ['p11.script'])
test('p12', normal, ghci_script, ['p12.script'])
test('p13', normal, ghci_script, ['p13.script'])
test('p14', normal, ghci_script, ['p14.script'])
test('p15', normal, ghci_script, ['p15.script'])
test('p16', normal, ghci_script, ['p16.script'])
-- Test disabled language extensions
:unset +s
:set -XSafe
:set -XTemplateHaskell
:set -XGeneralizedNewtypeDeriving
<no location info>: Warning:
-XTemplateHaskell is not allowed in Safe Haskell; ignoring -XTemplateHaskell
<no location info>: Warning:
-XGeneralizedNewtypeDeriving is not allowed in Safe Haskell; ignoring -XGeneralizedNewtypeDeriving
-- Test load works
:unset +s
:set -XSafe
:load D
a
b
Warning: can't use * imports with Safe Haskell; ignoring *
1
2
-- Test load works
:unset +s
:set -XSafe
:load E
E.hs:3:1:
base:System.IO.Unsafe can't be safely imported! The module itself isn't safe.
-- Test you can't unset options
:unset +s
:set -XSafe
:unset -XSafe
:set -fpackage-trust
:unset -fpackage-trust
import Data.ByteString
don't know how to reverse -XSafe
Some flags have not been recognized: -fno-package-trust
*** Exception: bytestring-0.9.2.0:Data.ByteString can't be safely imported! The package (bytestring-0.9.2.0) the module resides in isn't trusted.
-- Test restricted functionality: Overlapping
:unset +s
:set -XSafe
:set -XOverlappingInstances
:set -XFlexibleInstances
:l P13_A
instance Pos [Int] where { res _ = error "This curry is poisoned!" }
res [1::Int, 2::Int]
-- res 'c'
-- res ['c']
<interactive>:12:1:
Unsafe overlapping instances for Pos [Int]
arising from a use of `res'
The matching instance is:
instance [overlap ok] [safe] Pos [Int]
-- Defined at <interactive>:10:10
It is compiled in a Safe module and as such can only
overlap instances from the same module, however it
overlaps the following instances from different modules:
instance [overlap ok] [safe] Pos [a] -- Defined at P13_A.hs:6:10
In the expression: res [1 :: Int, 2 :: Int]
In an equation for `it': it = res [1 :: Int, 2 :: Int]
Warning: can't use * imports with Safe Haskell; ignoring *
-- Test restricted functionality: RULES
:unset +s
:set -XSafe
:set -fenable-rewrite-rules
let f x = x - 1
{-# RULES "id/Int" id = f #-}
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