diff options
Diffstat (limited to 'testsuite/tests/safeHaskell/check/pkg01')
15 files changed, 186 insertions, 0 deletions
diff --git a/testsuite/tests/safeHaskell/check/pkg01/ImpSafe01.hs b/testsuite/tests/safeHaskell/check/pkg01/ImpSafe01.hs new file mode 100644 index 0000000000..deb0d57f8d --- /dev/null +++ b/testsuite/tests/safeHaskell/check/pkg01/ImpSafe01.hs @@ -0,0 +1,12 @@ +{-# LANGUAGE Safe #-} +{-# LANGUAGE NoImplicitPrelude #-} +module ImpSafe ( MyWord ) where + +-- While Data.Word is safe it imports trustworthy +-- modules in base, hence base needs to be trusted. +-- Note: Worthwhile giving out better error messages for cases +-- like this if I can. +import Data.Word + +type MyWord = Word + diff --git a/testsuite/tests/safeHaskell/check/pkg01/ImpSafe01.stderr b/testsuite/tests/safeHaskell/check/pkg01/ImpSafe01.stderr new file mode 100644 index 0000000000..9ca2bbe817 --- /dev/null +++ b/testsuite/tests/safeHaskell/check/pkg01/ImpSafe01.stderr @@ -0,0 +1,3 @@ + +ImpSafe01.hs:9:1: + base:Data.Word can't be safely imported! The package (base) the module resides in isn't trusted. diff --git a/testsuite/tests/safeHaskell/check/pkg01/ImpSafeOnly01.hs b/testsuite/tests/safeHaskell/check/pkg01/ImpSafeOnly01.hs new file mode 100644 index 0000000000..2143d3139b --- /dev/null +++ b/testsuite/tests/safeHaskell/check/pkg01/ImpSafeOnly01.hs @@ -0,0 +1,8 @@ +{-# LANGUAGE Safe #-} +module Main where + +import M_SafePkg + +main = do + putStrLn $ show bigInt + diff --git a/testsuite/tests/safeHaskell/check/pkg01/ImpSafeOnly02.hs b/testsuite/tests/safeHaskell/check/pkg01/ImpSafeOnly02.hs new file mode 100644 index 0000000000..27281b9cce --- /dev/null +++ b/testsuite/tests/safeHaskell/check/pkg01/ImpSafeOnly02.hs @@ -0,0 +1,8 @@ +{-# LANGUAGE Safe #-} +module Main where + +import M_SafePkg2 + +main = do + putStrLn $ show bigInt + diff --git a/testsuite/tests/safeHaskell/check/pkg01/ImpSafeOnly03.hs b/testsuite/tests/safeHaskell/check/pkg01/ImpSafeOnly03.hs new file mode 100644 index 0000000000..d09e39937d --- /dev/null +++ b/testsuite/tests/safeHaskell/check/pkg01/ImpSafeOnly03.hs @@ -0,0 +1,8 @@ +{-# LANGUAGE Safe #-} +module Main where + +import M_SafePkg3 + +main = do + putStrLn $ show bigInt + diff --git a/testsuite/tests/safeHaskell/check/pkg01/ImpSafeOnly03.stderr b/testsuite/tests/safeHaskell/check/pkg01/ImpSafeOnly03.stderr new file mode 100644 index 0000000000..bc6eecffee --- /dev/null +++ b/testsuite/tests/safeHaskell/check/pkg01/ImpSafeOnly03.stderr @@ -0,0 +1,3 @@ + +ImpSafeOnly03.hs:4:1: + safePkg01-1.0:M_SafePkg3 can't be safely imported! The package (safePkg01-1.0) the module resides in isn't trusted. diff --git a/testsuite/tests/safeHaskell/check/pkg01/M_SafePkg.hs b/testsuite/tests/safeHaskell/check/pkg01/M_SafePkg.hs new file mode 100644 index 0000000000..14c21132e7 --- /dev/null +++ b/testsuite/tests/safeHaskell/check/pkg01/M_SafePkg.hs @@ -0,0 +1,6 @@ +{-# LANGUAGE Safe #-} +module M_SafePkg where + +bigInt :: Int +bigInt = 9 + diff --git a/testsuite/tests/safeHaskell/check/pkg01/M_SafePkg2.hs b/testsuite/tests/safeHaskell/check/pkg01/M_SafePkg2.hs new file mode 100644 index 0000000000..74c263f61d --- /dev/null +++ b/testsuite/tests/safeHaskell/check/pkg01/M_SafePkg2.hs @@ -0,0 +1,6 @@ +{-# LANGUAGE Trustworthy #-} +module M_SafePkg2 where + +bigInt :: Int +bigInt = 9 + diff --git a/testsuite/tests/safeHaskell/check/pkg01/M_SafePkg3.hs b/testsuite/tests/safeHaskell/check/pkg01/M_SafePkg3.hs new file mode 100644 index 0000000000..67714c4731 --- /dev/null +++ b/testsuite/tests/safeHaskell/check/pkg01/M_SafePkg3.hs @@ -0,0 +1,8 @@ +{-# LANGUAGE Safe #-} +module M_SafePkg3 where + +import qualified M_SafePkg2 as M2 + +bigInt :: Int +bigInt = M2.bigInt + diff --git a/testsuite/tests/safeHaskell/check/pkg01/M_SafePkg4.hs b/testsuite/tests/safeHaskell/check/pkg01/M_SafePkg4.hs new file mode 100644 index 0000000000..52367b113b --- /dev/null +++ b/testsuite/tests/safeHaskell/check/pkg01/M_SafePkg4.hs @@ -0,0 +1,11 @@ +{-# LANGUAGE Safe #-} +module M_SafePkg4 where + +import qualified M_SafePkg3 as M3 +import Data.Word + +bigInt :: Int +bigInt = M3.bigInt + +type MyWord = Word + diff --git a/testsuite/tests/safeHaskell/check/pkg01/Makefile b/testsuite/tests/safeHaskell/check/pkg01/Makefile new file mode 100644 index 0000000000..7cc80494a1 --- /dev/null +++ b/testsuite/tests/safeHaskell/check/pkg01/Makefile @@ -0,0 +1,46 @@ +TOP=../../../.. +include $(TOP)/mk/boilerplate.mk +include $(TOP)/mk/test.mk + +clean: + rm -rf setup a.out + rm -rf dist + find . -name "*.o" | xargs rm -f + find . -name "*.hi" | xargs rm -f + rm -rf local.db + rm -rf install + +# We use the global package database as there's no easy way to tell +# ghc-pkg (via Cabal) to use one in ., and the global one at least +# won't affect the installed GHC and is more likely to work + +PREFIX := $(abspath install) +$(eval $(call canonicalise,PREFIX)) + +PKGCONF = local.db +LGHC_PKG = '$(GHC_PKG)' --no-user-package-conf -f '$(PKGCONF)' + +safePkg01: + '$(MAKE)' clean + '$(TEST_HC)' --make -o setup Setup.hs -v0 + + '$(GHC_PKG)' init local.db + ./setup configure -v0 --prefix='$(PREFIX)' --with-compiler='$(TEST_HC)' --ghc-options='$(TEST_HC_OPTS) -trust base' --with-hc-pkg='$(GHC_PKG)' --package-db='$(PKGCONF)' $(PROF) + ./setup build -v0 + ./setup copy -v0 + ./setup register --inplace -v0 + $(LGHC_PKG) list + $(LGHC_PKG) field safePkg01-1.0 trusted + echo + echo 'M_SafePkg' + '$(TEST_HC)' --show-iface dist/build/M_SafePkg.hi | grep -E '^package dependencies:|^trusted:|^require own pkg trusted:' + echo + echo 'M_SafePkg2' + '$(TEST_HC)' --show-iface dist/build/M_SafePkg2.hi | grep -E '^package dependencies:|^trusted:|^require own pkg trusted:' + echo + echo 'M_SafePkg3' + '$(TEST_HC)' --show-iface dist/build/M_SafePkg3.hi | grep -E '^package dependencies:|^trusted:|^require own pkg trusted:' + echo + echo 'M_SafePkg4' + '$(TEST_HC)' --show-iface dist/build/M_SafePkg4.hi | grep -E '^package dependencies:|^trusted:|^require own pkg trusted:' + diff --git a/testsuite/tests/safeHaskell/check/pkg01/Setup.hs b/testsuite/tests/safeHaskell/check/pkg01/Setup.hs new file mode 100644 index 0000000000..6479cb1c16 --- /dev/null +++ b/testsuite/tests/safeHaskell/check/pkg01/Setup.hs @@ -0,0 +1,4 @@ +import Distribution.Simple + +main = defaultMain + diff --git a/testsuite/tests/safeHaskell/check/pkg01/all.T b/testsuite/tests/safeHaskell/check/pkg01/all.T new file mode 100644 index 0000000000..bdbdc4c56d --- /dev/null +++ b/testsuite/tests/safeHaskell/check/pkg01/all.T @@ -0,0 +1,24 @@ +# Just do the normal way, SafeHaskell is all in the frontend +def f( opts ): + opts.only_ways = ['normal'] + +setTestOpts(f) + +if config.have_profiling: + prof = '--enable-library-profiling' +else: + prof = '' + +test('safePkg01', + [normal, alone], + run_command, + ['$MAKE -s --no-print-directory safePkg01 PROF=' + prof]) + +test('ImpSafe01', normal, compile_fail, ['']) + +test('ImpSafeOnly01', [normal, alone], compile, ['-package-conf local.db -trust base']) + +test('ImpSafeOnly02', [normal, alone], compile, ['-package-conf local.db -trust base -trust safePkg01']) + +test('ImpSafeOnly03', [normal, alone], compile_fail, ['-package-conf local.db -trust base']) + diff --git a/testsuite/tests/safeHaskell/check/pkg01/p.cabal b/testsuite/tests/safeHaskell/check/pkg01/p.cabal new file mode 100644 index 0000000000..f6d84b5f8a --- /dev/null +++ b/testsuite/tests/safeHaskell/check/pkg01/p.cabal @@ -0,0 +1,15 @@ +Name: safePkg01 +Version: 1.0 +Description: SafeHaskell Test Package +License: BSD3 +Build-Type: Simple + +Library { + Build-Depends: base >= 4 + Exposed-Modules: + M_SafePkg + M_SafePkg2 + M_SafePkg3 + M_SafePkg4 +} + diff --git a/testsuite/tests/safeHaskell/check/pkg01/safePkg01.stdout b/testsuite/tests/safeHaskell/check/pkg01/safePkg01.stdout new file mode 100644 index 0000000000..c1a5642c17 --- /dev/null +++ b/testsuite/tests/safeHaskell/check/pkg01/safePkg01.stdout @@ -0,0 +1,24 @@ +local.db: + safePkg01-1.0 + +trusted: False + +M_SafePkg +package dependencies: base* ghc-prim integer-gmp +trusted: safe +require own pkg trusted: False + +M_SafePkg2 +package dependencies: base ghc-prim integer-gmp +trusted: trustworthy +require own pkg trusted: False + +M_SafePkg3 +package dependencies: base* ghc-prim integer-gmp +trusted: safe +require own pkg trusted: True + +M_SafePkg4 +package dependencies: base* ghc-prim integer-gmp +trusted: safe +require own pkg trusted: True |