summaryrefslogtreecommitdiff
path: root/testsuite/tests/safeHaskell/unsafeLibs
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/tests/safeHaskell/unsafeLibs')
-rw-r--r--testsuite/tests/safeHaskell/unsafeLibs/BadImport01.hs11
-rw-r--r--testsuite/tests/safeHaskell/unsafeLibs/BadImport01.stderr3
-rw-r--r--testsuite/tests/safeHaskell/unsafeLibs/BadImport02.hs27
-rw-r--r--testsuite/tests/safeHaskell/unsafeLibs/BadImport02.stdout3
-rw-r--r--testsuite/tests/safeHaskell/unsafeLibs/BadImport02_A.hs16
-rw-r--r--testsuite/tests/safeHaskell/unsafeLibs/BadImport03.hs29
-rw-r--r--testsuite/tests/safeHaskell/unsafeLibs/BadImport03.stderr5
-rw-r--r--testsuite/tests/safeHaskell/unsafeLibs/Dep01.hs13
-rw-r--r--testsuite/tests/safeHaskell/unsafeLibs/Dep01.stderr5
-rw-r--r--testsuite/tests/safeHaskell/unsafeLibs/Dep02.hs16
-rw-r--r--testsuite/tests/safeHaskell/unsafeLibs/Dep02.stderr5
-rw-r--r--testsuite/tests/safeHaskell/unsafeLibs/Dep03.hs7
-rw-r--r--testsuite/tests/safeHaskell/unsafeLibs/Dep03.stderr5
-rw-r--r--testsuite/tests/safeHaskell/unsafeLibs/Dep04.hs8
-rw-r--r--testsuite/tests/safeHaskell/unsafeLibs/Dep04.stderr5
-rw-r--r--testsuite/tests/safeHaskell/unsafeLibs/Dep05.hs13
-rw-r--r--testsuite/tests/safeHaskell/unsafeLibs/Dep05.stderr0
-rw-r--r--testsuite/tests/safeHaskell/unsafeLibs/Dep06.hs6
-rw-r--r--testsuite/tests/safeHaskell/unsafeLibs/Dep06.stderr0
-rw-r--r--testsuite/tests/safeHaskell/unsafeLibs/Dep07.hs6
-rw-r--r--testsuite/tests/safeHaskell/unsafeLibs/Dep07.stderr0
-rw-r--r--testsuite/tests/safeHaskell/unsafeLibs/Dep08.hs9
-rw-r--r--testsuite/tests/safeHaskell/unsafeLibs/Dep08.stderr0
-rw-r--r--testsuite/tests/safeHaskell/unsafeLibs/Dep09.hs6
-rw-r--r--testsuite/tests/safeHaskell/unsafeLibs/Dep09.stderr0
-rw-r--r--testsuite/tests/safeHaskell/unsafeLibs/Dep10.hs8
-rw-r--r--testsuite/tests/safeHaskell/unsafeLibs/Dep10.stderr0
-rw-r--r--testsuite/tests/safeHaskell/unsafeLibs/Makefile3
-rw-r--r--testsuite/tests/safeHaskell/unsafeLibs/all.T21
29 files changed, 230 insertions, 0 deletions
diff --git a/testsuite/tests/safeHaskell/unsafeLibs/BadImport01.hs b/testsuite/tests/safeHaskell/unsafeLibs/BadImport01.hs
new file mode 100644
index 0000000000..ae72dd6cd3
--- /dev/null
+++ b/testsuite/tests/safeHaskell/unsafeLibs/BadImport01.hs
@@ -0,0 +1,11 @@
+{-# LANGUAGE Safe #-}
+module Main where
+
+import System.IO.Unsafe
+
+f :: Int
+f = unsafePerformIO $ putStrLn "What kind of swallow?" >> return 2
+
+main :: IO ()
+main = putStrLn $ "X is: " ++ show f
+
diff --git a/testsuite/tests/safeHaskell/unsafeLibs/BadImport01.stderr b/testsuite/tests/safeHaskell/unsafeLibs/BadImport01.stderr
new file mode 100644
index 0000000000..983e043591
--- /dev/null
+++ b/testsuite/tests/safeHaskell/unsafeLibs/BadImport01.stderr
@@ -0,0 +1,3 @@
+
+BadImport01.hs:4:1:
+ base:System.IO.Unsafe can't be safely imported! The module itself isn't safe.
diff --git a/testsuite/tests/safeHaskell/unsafeLibs/BadImport02.hs b/testsuite/tests/safeHaskell/unsafeLibs/BadImport02.hs
new file mode 100644
index 0000000000..e9d5ca7577
--- /dev/null
+++ b/testsuite/tests/safeHaskell/unsafeLibs/BadImport02.hs
@@ -0,0 +1,27 @@
+{-# LANGUAGE StandaloneDeriving, DeriveDataTypeable #-}
+
+-- | Here we used typeable to produce an illegal value
+module Main where
+
+import Data.Typeable
+
+import BadImport02_A
+
+deriving instance Typeable Nat
+
+data NInt = NInt Int deriving Show
+
+instance Typeable NInt where
+ typeOf _ = typeOf (undefined::Nat)
+
+main = do
+ let a = succ' $ zero
+ Just n@(NInt z) = (cast a) :: Maybe NInt
+ n' = NInt (-z)
+ Just m = (cast n') :: Maybe Nat
+
+ putStrLn $ showNat a
+ putStrLn $ show n
+ putStrLn $ showNat m
+ return ()
+
diff --git a/testsuite/tests/safeHaskell/unsafeLibs/BadImport02.stdout b/testsuite/tests/safeHaskell/unsafeLibs/BadImport02.stdout
new file mode 100644
index 0000000000..c0f565d07c
--- /dev/null
+++ b/testsuite/tests/safeHaskell/unsafeLibs/BadImport02.stdout
@@ -0,0 +1,3 @@
+Nat 1
+NInt 1
+Nat -1
diff --git a/testsuite/tests/safeHaskell/unsafeLibs/BadImport02_A.hs b/testsuite/tests/safeHaskell/unsafeLibs/BadImport02_A.hs
new file mode 100644
index 0000000000..2ca43343eb
--- /dev/null
+++ b/testsuite/tests/safeHaskell/unsafeLibs/BadImport02_A.hs
@@ -0,0 +1,16 @@
+{-# LANGUAGE Trustworthy #-}
+module BadImport02_A (
+ Nat, zero, succ', showNat
+ ) where
+
+data Nat = NatC Int
+
+zero :: Nat
+zero = NatC 0
+
+succ' :: Nat -> Nat
+succ' (NatC n) = NatC $ n + 1
+
+showNat :: Nat -> String
+showNat (NatC n) = "Nat " ++ show n
+
diff --git a/testsuite/tests/safeHaskell/unsafeLibs/BadImport03.hs b/testsuite/tests/safeHaskell/unsafeLibs/BadImport03.hs
new file mode 100644
index 0000000000..835009a276
--- /dev/null
+++ b/testsuite/tests/safeHaskell/unsafeLibs/BadImport03.hs
@@ -0,0 +1,29 @@
+{-# LANGUAGE Safe #-}
+{-# LANGUAGE StandaloneDeriving, DeriveDataTypeable #-}
+
+-- | Here we used typeable to produce an illegal value
+-- Now using SAFE though so will fail
+module Main where
+
+import Data.Typeable
+
+import BadImport02_A
+
+deriving instance Typeable Nat
+
+data NInt = NInt Int deriving Show
+
+instance Typeable NInt where
+ typeOf _ = typeOf (undefined::Nat)
+
+main = do
+ let a = succ' $ zero
+ Just n@(NInt z) = (cast a) :: Maybe NInt
+ n' = NInt (-z)
+ Just m = (cast n') :: Maybe Nat
+
+ putStrLn $ showNat a
+ putStrLn $ show n
+ putStrLn $ showNat m
+ return ()
+
diff --git a/testsuite/tests/safeHaskell/unsafeLibs/BadImport03.stderr b/testsuite/tests/safeHaskell/unsafeLibs/BadImport03.stderr
new file mode 100644
index 0000000000..b1fcc3ca09
--- /dev/null
+++ b/testsuite/tests/safeHaskell/unsafeLibs/BadImport03.stderr
@@ -0,0 +1,5 @@
+[1 of 2] Compiling BadImport02_A ( BadImport02_A.hs, BadImport02_A.o )
+[2 of 2] Compiling Main ( BadImport03.hs, BadImport03.o )
+
+BadImport03.hs:8:1:
+ base:Data.Typeable can't be safely imported! The module itself isn't safe.
diff --git a/testsuite/tests/safeHaskell/unsafeLibs/Dep01.hs b/testsuite/tests/safeHaskell/unsafeLibs/Dep01.hs
new file mode 100644
index 0000000000..5ee1cd0288
--- /dev/null
+++ b/testsuite/tests/safeHaskell/unsafeLibs/Dep01.hs
@@ -0,0 +1,13 @@
+module Dep01 where
+
+import Control.Monad
+import Control.Monad.ST
+import Data.STRef
+
+sumST :: Num a => [a] -> IO a
+sumST xs = unsafeSTToIO $ do
+ n <- newSTRef 0
+ forM_ xs $ \x -> do
+ modifySTRef n (+x)
+ readSTRef n
+
diff --git a/testsuite/tests/safeHaskell/unsafeLibs/Dep01.stderr b/testsuite/tests/safeHaskell/unsafeLibs/Dep01.stderr
new file mode 100644
index 0000000000..a21b4861dd
--- /dev/null
+++ b/testsuite/tests/safeHaskell/unsafeLibs/Dep01.stderr
@@ -0,0 +1,5 @@
+
+Dep01.hs:4:1:
+ Warning: In the use of `unsafeSTToIO'
+ (imported from Control.Monad.ST):
+ Deprecated: "Please import from Control.Monad.ST.Unsafe instead; This will be removed in the next release"
diff --git a/testsuite/tests/safeHaskell/unsafeLibs/Dep02.hs b/testsuite/tests/safeHaskell/unsafeLibs/Dep02.hs
new file mode 100644
index 0000000000..f9dbb26064
--- /dev/null
+++ b/testsuite/tests/safeHaskell/unsafeLibs/Dep02.hs
@@ -0,0 +1,16 @@
+module Dep02 where
+
+import Control.Monad
+import Control.Monad.ST.Lazy
+import Data.STRef.Lazy
+
+sumST :: Num a => [a] -> a
+sumST xs = runST $ do
+ n <- newSTRef 0
+ forM_ xs $ \x -> do
+ modifySTRef n (+x)
+ readSTRef n
+
+badST :: ()
+badST = runST $ unsafeIOToST $ putStrLn "Hello World"
+
diff --git a/testsuite/tests/safeHaskell/unsafeLibs/Dep02.stderr b/testsuite/tests/safeHaskell/unsafeLibs/Dep02.stderr
new file mode 100644
index 0000000000..8ae7621251
--- /dev/null
+++ b/testsuite/tests/safeHaskell/unsafeLibs/Dep02.stderr
@@ -0,0 +1,5 @@
+
+Dep02.hs:4:1:
+ Warning: In the use of `unsafeIOToST'
+ (imported from Control.Monad.ST.Lazy):
+ Deprecated: "Please import from Control.Monad.ST.Lazy.Unsafe instead; This will be removed in the next release"
diff --git a/testsuite/tests/safeHaskell/unsafeLibs/Dep03.hs b/testsuite/tests/safeHaskell/unsafeLibs/Dep03.hs
new file mode 100644
index 0000000000..b5f39affc7
--- /dev/null
+++ b/testsuite/tests/safeHaskell/unsafeLibs/Dep03.hs
@@ -0,0 +1,7 @@
+module Dep03 where
+
+import Foreign
+
+bad :: IO a -> a
+bad = unsafePerformIO
+
diff --git a/testsuite/tests/safeHaskell/unsafeLibs/Dep03.stderr b/testsuite/tests/safeHaskell/unsafeLibs/Dep03.stderr
new file mode 100644
index 0000000000..51c4d0a850
--- /dev/null
+++ b/testsuite/tests/safeHaskell/unsafeLibs/Dep03.stderr
@@ -0,0 +1,5 @@
+
+Dep03.hs:3:1:
+ Warning: In the use of `unsafePerformIO'
+ (imported from Foreign):
+ Deprecated: "Use System.IO.Unsafe.unsafePerformIO instead; This function will be removed in the next release"
diff --git a/testsuite/tests/safeHaskell/unsafeLibs/Dep04.hs b/testsuite/tests/safeHaskell/unsafeLibs/Dep04.hs
new file mode 100644
index 0000000000..5ff23ea0ad
--- /dev/null
+++ b/testsuite/tests/safeHaskell/unsafeLibs/Dep04.hs
@@ -0,0 +1,8 @@
+module Dep04 where
+
+import Foreign.Ptr
+import Foreign.ForeignPtr
+
+bad :: ForeignPtr a -> Ptr a
+bad = unsafeForeignPtrToPtr
+
diff --git a/testsuite/tests/safeHaskell/unsafeLibs/Dep04.stderr b/testsuite/tests/safeHaskell/unsafeLibs/Dep04.stderr
new file mode 100644
index 0000000000..ef81bf4212
--- /dev/null
+++ b/testsuite/tests/safeHaskell/unsafeLibs/Dep04.stderr
@@ -0,0 +1,5 @@
+
+Dep04.hs:4:1:
+ Warning: In the use of `unsafeForeignPtrToPtr'
+ (imported from Foreign.ForeignPtr):
+ Deprecated: "Use Foreign.ForeignPtr.Unsafe.unsafeForeignPtrToPtr instead; This function will be removed in the next release"
diff --git a/testsuite/tests/safeHaskell/unsafeLibs/Dep05.hs b/testsuite/tests/safeHaskell/unsafeLibs/Dep05.hs
new file mode 100644
index 0000000000..da25c1a52a
--- /dev/null
+++ b/testsuite/tests/safeHaskell/unsafeLibs/Dep05.hs
@@ -0,0 +1,13 @@
+{-# LANGUAGE NoMonomorphismRestriction #-}
+module Dep05 where
+
+import GHC.Arr
+
+bad1 = unsafeArray
+
+bad2 = fill
+
+bad3 = done
+
+bad4 = unsafeThawSTArray
+
diff --git a/testsuite/tests/safeHaskell/unsafeLibs/Dep05.stderr b/testsuite/tests/safeHaskell/unsafeLibs/Dep05.stderr
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/testsuite/tests/safeHaskell/unsafeLibs/Dep05.stderr
diff --git a/testsuite/tests/safeHaskell/unsafeLibs/Dep06.hs b/testsuite/tests/safeHaskell/unsafeLibs/Dep06.hs
new file mode 100644
index 0000000000..0a5811d02b
--- /dev/null
+++ b/testsuite/tests/safeHaskell/unsafeLibs/Dep06.hs
@@ -0,0 +1,6 @@
+module Dep06 where
+
+import GHC.Conc
+
+bad1 = unsafeIOToSTM
+
diff --git a/testsuite/tests/safeHaskell/unsafeLibs/Dep06.stderr b/testsuite/tests/safeHaskell/unsafeLibs/Dep06.stderr
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/testsuite/tests/safeHaskell/unsafeLibs/Dep06.stderr
diff --git a/testsuite/tests/safeHaskell/unsafeLibs/Dep07.hs b/testsuite/tests/safeHaskell/unsafeLibs/Dep07.hs
new file mode 100644
index 0000000000..6f0df7af11
--- /dev/null
+++ b/testsuite/tests/safeHaskell/unsafeLibs/Dep07.hs
@@ -0,0 +1,6 @@
+module Dep07 where
+
+import GHC.ForeignPtr
+
+bad1 = unsafeForeignPtrToPtr
+
diff --git a/testsuite/tests/safeHaskell/unsafeLibs/Dep07.stderr b/testsuite/tests/safeHaskell/unsafeLibs/Dep07.stderr
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/testsuite/tests/safeHaskell/unsafeLibs/Dep07.stderr
diff --git a/testsuite/tests/safeHaskell/unsafeLibs/Dep08.hs b/testsuite/tests/safeHaskell/unsafeLibs/Dep08.hs
new file mode 100644
index 0000000000..a3fbc7be61
--- /dev/null
+++ b/testsuite/tests/safeHaskell/unsafeLibs/Dep08.hs
@@ -0,0 +1,9 @@
+{-# LANGUAGE NoMonomorphismRestriction #-}
+module Dep08 where
+
+import GHC.IOArray
+
+bad1 = unsafeReadIOArray
+
+bad2 = unsafeWriteIOArray
+
diff --git a/testsuite/tests/safeHaskell/unsafeLibs/Dep08.stderr b/testsuite/tests/safeHaskell/unsafeLibs/Dep08.stderr
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/testsuite/tests/safeHaskell/unsafeLibs/Dep08.stderr
diff --git a/testsuite/tests/safeHaskell/unsafeLibs/Dep09.hs b/testsuite/tests/safeHaskell/unsafeLibs/Dep09.hs
new file mode 100644
index 0000000000..beeb7ffe95
--- /dev/null
+++ b/testsuite/tests/safeHaskell/unsafeLibs/Dep09.hs
@@ -0,0 +1,6 @@
+module Dep09 where
+
+import GHC.Ptr
+
+bad1 = castFunPtrToPtr
+
diff --git a/testsuite/tests/safeHaskell/unsafeLibs/Dep09.stderr b/testsuite/tests/safeHaskell/unsafeLibs/Dep09.stderr
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/testsuite/tests/safeHaskell/unsafeLibs/Dep09.stderr
diff --git a/testsuite/tests/safeHaskell/unsafeLibs/Dep10.hs b/testsuite/tests/safeHaskell/unsafeLibs/Dep10.hs
new file mode 100644
index 0000000000..70d660ed1c
--- /dev/null
+++ b/testsuite/tests/safeHaskell/unsafeLibs/Dep10.hs
@@ -0,0 +1,8 @@
+module Dep10 where
+
+import GHC.ST
+
+bad1 = liftST
+
+bad2 = unsafeInterleaveST
+
diff --git a/testsuite/tests/safeHaskell/unsafeLibs/Dep10.stderr b/testsuite/tests/safeHaskell/unsafeLibs/Dep10.stderr
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/testsuite/tests/safeHaskell/unsafeLibs/Dep10.stderr
diff --git a/testsuite/tests/safeHaskell/unsafeLibs/Makefile b/testsuite/tests/safeHaskell/unsafeLibs/Makefile
new file mode 100644
index 0000000000..9101fbd40a
--- /dev/null
+++ b/testsuite/tests/safeHaskell/unsafeLibs/Makefile
@@ -0,0 +1,3 @@
+TOP=../../..
+include $(TOP)/mk/boilerplate.mk
+include $(TOP)/mk/test.mk
diff --git a/testsuite/tests/safeHaskell/unsafeLibs/all.T b/testsuite/tests/safeHaskell/unsafeLibs/all.T
new file mode 100644
index 0000000000..c985b65c3c
--- /dev/null
+++ b/testsuite/tests/safeHaskell/unsafeLibs/all.T
@@ -0,0 +1,21 @@
+# Just do the normal way, SafeHaskell is all in the frontend
+def f( opts ):
+ opts.only_ways = ['normal']
+
+setTestOpts(f)
+
+test('Dep01', normal, compile, [''])
+test('Dep02', normal, compile, [''])
+test('Dep03', normal, compile, [''])
+test('Dep04', normal, compile, [''])
+test('Dep05', normal, compile, [''])
+test('Dep06', normal, compile, [''])
+test('Dep07', normal, compile, [''])
+test('Dep08', normal, compile, [''])
+test('Dep09', normal, compile, [''])
+test('Dep10', normal, compile, [''])
+
+test('BadImport01', normal, compile_fail, [''])
+test('BadImport02', normal, compile_and_run, ['--make'])
+test('BadImport03', normal, compile_fail, ['--make'])
+