Commit 5faed3b3 authored by dterei's avatar dterei
Browse files

Add tests for Safe Haskell

parent a63069eb
TOP=../../..
include $(TOP)/mk/boilerplate.mk
include $(TOP)/mk/test.mk
{-# LANGUAGE SafeImports #-}
module Check01 ( main' ) where
import safe CheckB
main' = do
let n = mainM 1
print $ n
[3 of 3] Compiling Check01 ( Check01.hs, Check01.o )
<no location info>:
The package (base) is required to be trusted but it isn't!
[3 of 3] Compiling Check01 ( Check01.hs, Check01.o )
module Check02 where
import CheckB
mainN = do
let n = mainM 1
print $ n
[3 of 3] Compiling Check02 ( Check02.hs, Check02.o )
{-# LANGUAGE SafeImports #-}
module Main ( main ) where
import Check01
main = main'
[4 of 4] Compiling Main ( Check03.hs, Check03.o )
Linking Check03 ...
{-# LANGUAGE Trustworthy #-}
module CheckA (
trace
) where
import qualified Debug.Trace as D
import qualified Data.ByteString.Lazy.Char8 as BS
-- | Allowed declasification
trace :: String -> a -> a
trace s = D.trace $ s ++ show a3
a3 :: BS.ByteString
a3 = BS.take 3 $ BS.repeat 'a'
{-# LANGUAGE Safe #-}
-- Since Safe we require base package be trusted to compile
module CheckB where
import CheckA
mainM :: Int -> Int
mainM n = trace "Allowed Leak" $ n * 2
[1 of 2] Compiling CheckA ( CheckA.hs, CheckA.o )
[2 of 2] Compiling CheckB ( CheckB.hs, CheckB.o )
TOP=../../../..
include $(TOP)/mk/boilerplate.mk
include $(TOP)/mk/test.mk
\ No newline at end of file
# Just do the normal way, SafeHaskell is all in the frontend
def f( opts ):
opts.only_ways = ['normal']
setTestOpts(f)
test('CheckA', normal, compile, [''])
test('CheckB', normal, multimod_compile, ['CheckB', '-trust base'])
# fail as we don't trust base when compiling Check01
test('Check01_fail', normal, multi_compile_fail, ['Check01', [
('CheckA.hs', ''),
('CheckB.hs', '-trust base')
], ''])
# suceed this time since we trust base when we compile AND use CheckB
test('Check01_succeed', normal, multi_compile, ['Check01', [
('CheckA.hs', ''),
('CheckB.hs', '')
], '-trust base'])
# suceed as while like Check01_fail we don't import CheckB as a safe
# import this time, so don't require base trusted when used.
test('Check02', normal, multi_compile, ['Check02', [
('CheckA.hs', ''),
('CheckB.hs', '-trust base')
], ''])
# Check a slightly larger transitive program. Check01 isn't imported
# safely by Check03 so we don't require base trused at end.
test('Check03', normal, multi_compile, ['Check03', [
('CheckA.hs', ''),
('CheckB.hs', '-trust base'),
('Check01.hs', '-trust base')
], ''])
{-# LANGUAGE CPP #-}
-- | CPP should still be allowed
module Main where
#include "Flags01_A.cpp"
#define mainn main=putStrLn str
mainn
{-# OPTIONS_GHC -pgmlc pgmlc, -pgmdll pgmdll, -I., -L., -Uggg, -Dggg, -with-rtsopts full #-}
-- | These are all flags that should be allowed
module Flags02 where
f :: Int
f = 1
TOP=../../../..
include $(TOP)/mk/boilerplate.mk
include $(TOP)/mk/test.mk
\ No newline at end of file
{-# LANGUAGE Safe #-}
-- | Basic test to see if Safe flags compiles
module SafeFlags01 where
f :: Int
f = 1
{-# LANGUAGE Trustworthy #-}
-- | Basic test to see if Safe flags compiles
module SafeFlags02 where
f :: Int
f = 1
{-# LANGUAGE SafeImports #-}
-- | Basic test to see if Safe flags compiles
module SafeFlags03 where
f :: Int
f = 1
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