diff options
Diffstat (limited to 'testsuite/tests/safeHaskell/unsafeLibs')
16 files changed, 237 insertions, 6 deletions
diff --git a/testsuite/tests/safeHaskell/unsafeLibs/BadImport01.hs b/testsuite/tests/safeHaskell/unsafeLibs/BadImport01.hs index ae72dd6cd3..175365c17c 100644 --- a/testsuite/tests/safeHaskell/unsafeLibs/BadImport01.hs +++ b/testsuite/tests/safeHaskell/unsafeLibs/BadImport01.hs @@ -1,4 +1,5 @@ {-# LANGUAGE Safe #-} +-- | Import unsafe module System.IO.Unsafe to make sure it fails module Main where import System.IO.Unsafe diff --git a/testsuite/tests/safeHaskell/unsafeLibs/BadImport04.hs b/testsuite/tests/safeHaskell/unsafeLibs/BadImport04.hs new file mode 100644 index 0000000000..c22b0362f7 --- /dev/null +++ b/testsuite/tests/safeHaskell/unsafeLibs/BadImport04.hs @@ -0,0 +1,12 @@ +{-# LANGUAGE Safe #-} +-- | Import unsafe module Foreign to make sure it fails +module Main where + +import Foreign (unsafePerformIO) + +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/BadImport05.hs b/testsuite/tests/safeHaskell/unsafeLibs/BadImport05.hs new file mode 100644 index 0000000000..137f3b5f31 --- /dev/null +++ b/testsuite/tests/safeHaskell/unsafeLibs/BadImport05.hs @@ -0,0 +1,12 @@ +{-# LANGUAGE Safe #-} +-- | Import unsafe module Foreign.Unsafe to make sure it fails +module Main where + +import Foreign.Unsafe (unsafePerformIO) + +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/BadImport06.hs b/testsuite/tests/safeHaskell/unsafeLibs/BadImport06.hs new file mode 100644 index 0000000000..e64a7ea09b --- /dev/null +++ b/testsuite/tests/safeHaskell/unsafeLibs/BadImport06.hs @@ -0,0 +1,12 @@ +{-# LANGUAGE Safe #-} +-- | Import unsafe module Debug.Trace to make sure it fails +module Main where + +import Debug.Trace + +f :: Int +f = trace "What kind of swallow?" 2 + +main :: IO () +main = putStrLn $ "X is: " ++ show f + diff --git a/testsuite/tests/safeHaskell/unsafeLibs/BadImport07.hs b/testsuite/tests/safeHaskell/unsafeLibs/BadImport07.hs new file mode 100644 index 0000000000..ea2b6402d3 --- /dev/null +++ b/testsuite/tests/safeHaskell/unsafeLibs/BadImport07.hs @@ -0,0 +1,12 @@ +{-# LANGUAGE Safe #-} +-- | Import unsafe module Unsafe.Coerce to make sure it fails +module Main where + +import Unsafe.Coerce + +f :: Int +f = trace "What kind of swallow?" 2 + +main :: IO () +main = putStrLn $ "X is: " ++ show f + diff --git a/testsuite/tests/safeHaskell/unsafeLibs/BadImport08.hs b/testsuite/tests/safeHaskell/unsafeLibs/BadImport08.hs new file mode 100644 index 0000000000..0df948ecd6 --- /dev/null +++ b/testsuite/tests/safeHaskell/unsafeLibs/BadImport08.hs @@ -0,0 +1,12 @@ +{-# LANGUAGE Safe #-} +-- | Import unsafe module Control.ST to make sure it fails +module Main where + +import Control.ST + +f :: Int +f = trace "What kind of swallow?" 2 + +main :: IO () +main = putStrLn $ "X is: " ++ show f + diff --git a/testsuite/tests/safeHaskell/unsafeLibs/Dep05.hs b/testsuite/tests/safeHaskell/unsafeLibs/Dep05.hs index da25c1a52a..a5c13bb5aa 100644 --- a/testsuite/tests/safeHaskell/unsafeLibs/Dep05.hs +++ b/testsuite/tests/safeHaskell/unsafeLibs/Dep05.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE Safe #-} {-# LANGUAGE NoMonomorphismRestriction #-} module Dep05 where diff --git a/testsuite/tests/safeHaskell/unsafeLibs/Dep06.hs b/testsuite/tests/safeHaskell/unsafeLibs/Dep06.hs index 0a5811d02b..2dbb15e197 100644 --- a/testsuite/tests/safeHaskell/unsafeLibs/Dep06.hs +++ b/testsuite/tests/safeHaskell/unsafeLibs/Dep06.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE Safe #-} module Dep06 where import GHC.Conc diff --git a/testsuite/tests/safeHaskell/unsafeLibs/Dep07.hs b/testsuite/tests/safeHaskell/unsafeLibs/Dep07.hs index 6f0df7af11..662b6a4754 100644 --- a/testsuite/tests/safeHaskell/unsafeLibs/Dep07.hs +++ b/testsuite/tests/safeHaskell/unsafeLibs/Dep07.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE Safe #-} module Dep07 where import GHC.ForeignPtr diff --git a/testsuite/tests/safeHaskell/unsafeLibs/Dep08.hs b/testsuite/tests/safeHaskell/unsafeLibs/Dep08.hs index a3fbc7be61..76a0dde570 100644 --- a/testsuite/tests/safeHaskell/unsafeLibs/Dep08.hs +++ b/testsuite/tests/safeHaskell/unsafeLibs/Dep08.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE Safe #-} {-# LANGUAGE NoMonomorphismRestriction #-} module Dep08 where diff --git a/testsuite/tests/safeHaskell/unsafeLibs/Dep09.hs b/testsuite/tests/safeHaskell/unsafeLibs/Dep09.hs index beeb7ffe95..a92f739b50 100644 --- a/testsuite/tests/safeHaskell/unsafeLibs/Dep09.hs +++ b/testsuite/tests/safeHaskell/unsafeLibs/Dep09.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE Safe #-} module Dep09 where import GHC.Ptr diff --git a/testsuite/tests/safeHaskell/unsafeLibs/Dep10.hs b/testsuite/tests/safeHaskell/unsafeLibs/Dep10.hs index 70d660ed1c..84a7adcff7 100644 --- a/testsuite/tests/safeHaskell/unsafeLibs/Dep10.hs +++ b/testsuite/tests/safeHaskell/unsafeLibs/Dep10.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE Safe #-} module Dep10 where import GHC.ST diff --git a/testsuite/tests/safeHaskell/unsafeLibs/GoodImport01.hs b/testsuite/tests/safeHaskell/unsafeLibs/GoodImport01.hs new file mode 100644 index 0000000000..7834de52bc --- /dev/null +++ b/testsuite/tests/safeHaskell/unsafeLibs/GoodImport01.hs @@ -0,0 +1,14 @@ +{-# LANGUAGE Safe #-} +-- | Import SYB stuff that should be safe +module Main where + +import Data.Typeable +import Data.Dynamic +import Data.Data + +f :: Int +f = 2 + +main :: IO () +main = putStrLn $ "X is: " ++ show f + diff --git a/testsuite/tests/safeHaskell/unsafeLibs/GoodImport02.hs b/testsuite/tests/safeHaskell/unsafeLibs/GoodImport02.hs new file mode 100644 index 0000000000..85a781f982 --- /dev/null +++ b/testsuite/tests/safeHaskell/unsafeLibs/GoodImport02.hs @@ -0,0 +1,15 @@ +{-# LANGUAGE Safe #-} +-- | Import safe versions of unsafe modules from prelude +module Main where + +import Control.Monad.ST.Safe +import Control.Monad.ST.Lazy.Safe +import Foreign.ForeignPtr.Safe +import Foreign.Safe + +f :: Int +f = 2 + +main :: IO () +main = putStrLn $ "X is: " ++ show f + diff --git a/testsuite/tests/safeHaskell/unsafeLibs/GoodImport03.hs b/testsuite/tests/safeHaskell/unsafeLibs/GoodImport03.hs new file mode 100644 index 0000000000..5ad44026a8 --- /dev/null +++ b/testsuite/tests/safeHaskell/unsafeLibs/GoodImport03.hs @@ -0,0 +1,121 @@ +{-# LANGUAGE Safe #-} +-- | Import all modules from prelude that should be safe +module Main where + +import Numeric +import Prelude +-- import Foreign + +import Control.Applicative +import Control.Arrow +import Control.Category + +-- import Control.ST +-- import Control.ST.Lazy +-- import Control.ST.Strict + +import Control.Concurrent +import Control.Concurrent.Chan +import Control.Concurrent.MVar +import Control.Concurrent.QSem +import Control.Concurrent.QSemN +import Control.Concurrent.SampleVar + +import Control.Exception +import Control.OldException +import Control.Exception.Base + +import Control.Monad +import Control.Monad.Fix +import Control.Monad.Group +import Control.Monad.Instances +import Control.Monad.Zip + +import Data.Bits +import Data.Bool +import Data.Char +import Data.Complex +import Data.Either +import Data.Eq +import Data.Fixed +import Data.Foldable +import Data.Function +import Data.Functor +import Data.HashTable +import Data.IORef +import Data.Int +import Data.Ix +import Data.List +import Data.Maybe +import Data.Monoid +import Data.Ord +import Data.Ratio +import Data.String +import Data.Traversable +import Data.Tuple +import Data.Typeable +import Data.Unique +import Data.Version +import Data.Word + +import Data.STRef +import Data.STRef.Lazy +import Data.STRef.Strict + +-- import Debug.Trace + +import Foreign.Concurrent +-- import Foreign.ForeignPtr +import Foreign.Ptr +import Foreign.StablePtr +import Foreign.Storable + +import Foreign.C +import Foreign.C.Error +import Foreign.C.String +import Foreign.C.Types + +import Foreign.Marshal +import Foreign.Marshal.Alloc +import Foreign.Marshal.Array +import Foreign.Marshal.Error +import Foreign.Marshal.Pool +import Foreign.Marshal.Utils + +import System.CPUTime +import System.Environment +import System.Exit +import System.Info +import System.Mem +import System.Timeout + +import System.Console.GetOpt + +import System.IO +import System.IO.Error + +import System.Mem.StableName +import System.Mem.Weak + +import System.Posix.Internals +import System.Posix.Types + +import Text.Printf + +import Text.Read +import Text.Read.Lex + +import Text.Show +import Text.Show.Functions + +import Text.ParserCombinators.ReadP +import Text.ParserCombinators.ReadPrec + +-- import Unsafe.Coerce + +f :: Int +f = 2 + +main :: IO () +main = putStrLn $ "X is: " ++ show f + diff --git a/testsuite/tests/safeHaskell/unsafeLibs/all.T b/testsuite/tests/safeHaskell/unsafeLibs/all.T index c43fe0d191..949511579d 100644 --- a/testsuite/tests/safeHaskell/unsafeLibs/all.T +++ b/testsuite/tests/safeHaskell/unsafeLibs/all.T @@ -1,6 +1,7 @@ # unsafeLib tests are all about testing that the correct # standard library modules have been marked as unsafe. # e.g no importing unsafePerformIO +# Checking base package is properly safe basically # Just do the normal way, SafeHaskell is all in the frontend def f( opts ): @@ -8,17 +9,19 @@ def f( opts ): setTestOpts(f) +# Check correct methods are deprecated 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('Dep05', normal, compile_fail, ['']) +test('Dep06', normal, compile_fail, ['']) +test('Dep07', normal, compile_fail, ['']) +test('Dep08', normal, compile_fail, ['']) +test('Dep09', normal, compile_fail, ['']) +test('Dep10', normal, compile_fail, ['']) +# check unsafe modules are marked unsafe test('BadImport01', normal, compile_fail, ['']) test('BadImport02', extra_clean(['BadImport02_A.o', 'BadImport02_A.hi']), @@ -28,3 +31,14 @@ test('BadImport03', extra_clean(['BadImport03_A.o', 'BadImport03_A.hi']), multimod_compile_fail, ['BadImport03', '']) +test('BadImport04', normal, compile_fail, ['']) +test('BadImport05', normal, compile_fail, ['']) +test('BadImport06', normal, compile_fail, ['']) +test('BadImport07', normal, compile_fail, ['']) +test('BadImport08', normal, compile_fail, ['']) + +# check safe modules are marked safe +test('GoodImport01', normal, compile, ['']) +test('GoodImport02', normal, compile, ['']) +test('GoodImport03', normal, compile, ['']) + |