From 69f3ecdfa4e657aea1c012640e9ab1594bcfec78 Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Sun, 8 May 2011 22:04:51 +0100 Subject: [PATCH] Move tests from testsuite/tests/libraries --- tests/all.T | 2 ++ tests/fixed.hs | 19 +++++++++++++ tests/fixed.stdout | 72 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/tempfiles.hs | 36 ++++++++++++++++++++++++ tests/tempfiles.stdout | 12 ++++++++ 5 files changed, 141 insertions(+) create mode 100644 tests/fixed.hs create mode 100644 tests/fixed.stdout create mode 100644 tests/tempfiles.hs create mode 100644 tests/tempfiles.stdout diff --git a/tests/all.T b/tests/all.T index 4906495..bc10ec0 100644 --- a/tests/all.T +++ b/tests/all.T @@ -2,3 +2,5 @@ test('readFloat', exit_code(1), compile_and_run, ['']) test('enumDouble', normal, compile_and_run, ['']) test('enumRatio', normal, compile_and_run, ['']) +test('tempfiles', normal, compile_and_run, ['']) +test('fixed', normal, compile_and_run, ['']) diff --git a/tests/fixed.hs b/tests/fixed.hs new file mode 100644 index 0000000..d19bda0 --- /dev/null +++ b/tests/fixed.hs @@ -0,0 +1,19 @@ +{-# OPTIONS_GHC -Wall -Werror #-} + +module Main where + +import Data.Fixed + +nums :: Fractional a => [a] +nums = [0,7,7.1,7.01,7.9,7.09,5 + 7,3.2 - 7.8,5.75 * (-2)] + +main :: IO () +main = do mapM_ putStrLn $ doit (nums :: [Micro]) + mapM_ putStrLn $ doit (nums :: [Pico]) + +doit :: HasResolution a => [Fixed a] -> [String] +doit xs = [ showFun (signFun x) + | showFun <- [show, showFixed True] + , signFun <- [id, negate] + , x <- xs ] + diff --git a/tests/fixed.stdout b/tests/fixed.stdout new file mode 100644 index 0000000..3c42965 --- /dev/null +++ b/tests/fixed.stdout @@ -0,0 +1,72 @@ +0.000000 +7.000000 +7.100000 +7.010000 +7.900000 +7.090000 +12.000000 +-4.600000 +-11.500000 +0.000000 +-7.000000 +-7.100000 +-7.010000 +-7.900000 +-7.090000 +-12.000000 +4.600000 +11.500000 +0 +7 +7.1 +7.01 +7.9 +7.09 +12 +-4.6 +-11.5 +0 +-7 +-7.1 +-7.01 +-7.9 +-7.09 +-12 +4.6 +11.5 +0.000000000000 +7.000000000000 +7.100000000000 +7.010000000000 +7.900000000000 +7.090000000000 +12.000000000000 +-4.600000000000 +-11.500000000000 +0.000000000000 +-7.000000000000 +-7.100000000000 +-7.010000000000 +-7.900000000000 +-7.090000000000 +-12.000000000000 +4.600000000000 +11.500000000000 +0 +7 +7.1 +7.01 +7.9 +7.09 +12 +-4.6 +-11.5 +0 +-7 +-7.1 +-7.01 +-7.9 +-7.09 +-12 +4.6 +11.5 diff --git a/tests/tempfiles.hs b/tests/tempfiles.hs new file mode 100644 index 0000000..2fc1560 --- /dev/null +++ b/tests/tempfiles.hs @@ -0,0 +1,36 @@ + +import Control.Exception +import Data.List +import System.FilePath +import System.Directory +import System.IO + +-- Checks that openTempFile returns filenames with the right structure +main :: IO () +main = do + fp0 <- otf ".no_prefix.hs" + print (".hs" `isSuffixOf` fp0) + print (".no_prefix" `isPrefixOf` takeFileName fp0) + + fp1 <- otf "no_suffix" + print (not ('.' `elem` fp1)) + print ("no_suffix" `isPrefixOf` takeFileName fp1) + + fp2 <- otf "one_suffix.hs" + print (".hs" `isSuffixOf` fp2) + print ("one_suffix" `isPrefixOf` takeFileName fp2) + + fp3 <- otf "two_suffixes.hs.blah" + print (".blah" `isSuffixOf` fp3) + print ("two_suffixes.hs" `isPrefixOf` takeFileName fp3) + +otf :: FilePath -> IO FilePath +otf fp = do putStrLn fp + bracket (openTempFile "." fp) + (\(fp', h) -> do hClose h + removeFile fp') + (\(fp', _) -> case fp' of + '.' : '/' : fp'' -> return fp'' + '.' : '\\' : fp'' -> return fp'' + _ -> return fp') + diff --git a/tests/tempfiles.stdout b/tests/tempfiles.stdout new file mode 100644 index 0000000..4dc72ce --- /dev/null +++ b/tests/tempfiles.stdout @@ -0,0 +1,12 @@ +.no_prefix.hs +True +True +no_suffix +True +True +one_suffix.hs +True +True +two_suffixes.hs.blah +True +True -- 1.7.10.4