@@ -4,17 +4,17 @@ module Language.Haskell.Stylish.Config.Tests
44
55
66--------------------------------------------------------------------------------
7- import Control.Exception hiding (assert )
87import qualified Data.Set as Set
98import System.Directory
10- import System.FilePath ((</>) )
11- import System.IO.Error
12- import System.Random
139import Test.Framework (Test , testGroup )
1410import Test.Framework.Providers.HUnit (testCase )
1511import Test.HUnit (Assertion , assert )
12+
13+
1614--------------------------------------------------------------------------------
1715import Language.Haskell.Stylish.Config
16+ import Language.Haskell.Stylish.Tests.Util
17+
1818
1919--------------------------------------------------------------------------------
2020tests :: Test
@@ -32,33 +32,9 @@ tests = testGroup "Language.Haskell.Stylish.Config"
3232 , testCase " Correctly read .stylish-haskell.yaml file with no max column number"
3333 testNoColumns
3434 ]
35- --------------------------------------------------------------------------------
3635
37- -- | Create a temporary directory with a randomised name built from the template provided
38- createTempDirectory :: String -> IO FilePath
39- createTempDirectory template = do
40- tmpRootDir <- getTemporaryDirectory
41- dirId <- randomIO :: IO Word
42- findTempName tmpRootDir dirId
43- where
44- findTempName :: FilePath -> Word -> IO FilePath
45- findTempName tmpRootDir x = do
46- let dirpath = tmpRootDir </> template ++ show x
47- r <- try $ createDirectory dirpath
48- case r of
49- Right _ -> return dirpath
50- Left e | isAlreadyExistsError e -> findTempName tmpRootDir (x+ 1 )
51- | otherwise -> ioError e
52-
53- -- | Perform an action inside a temporary directory tree and purge the tree afterwords
54- withTestDirTree :: IO a -> IO a
55- withTestDirTree action = bracket
56- ((,) <$> getCurrentDirectory <*> createTempDirectory " stylish_haskell" )
57- (\ (current, temp) ->
58- setCurrentDirectory current *>
59- removeDirectoryRecursive temp)
60- (\ (_, temp) -> setCurrentDirectory temp *> action)
6136
37+ --------------------------------------------------------------------------------
6238-- | Put an example config files (.cabal/.stylish-haskell.yaml/both)
6339-- into the current directory and extract extensions from it.
6440createFilesAndGetConfig :: [(FilePath , String )] -> IO Config
@@ -72,6 +48,7 @@ createFilesAndGetConfig files = withTestDirTree $ do
7248 config <- loadConfig (const (pure () )) Nothing
7349 pure config
7450
51+
7552--------------------------------------------------------------------------------
7653testExtensionsFromDotCabal :: Assertion
7754testExtensionsFromDotCabal =
@@ -80,6 +57,7 @@ testExtensionsFromDotCabal =
8057 where
8158 expected = Set. fromList [" ScopedTypeVariables" , " DataKinds" ]
8259
60+
8361--------------------------------------------------------------------------------
8462testExtensionsFromDotStylish :: Assertion
8563testExtensionsFromDotStylish =
@@ -88,6 +66,7 @@ testExtensionsFromDotStylish =
8866 where
8967 expected = Set. fromList [" TemplateHaskell" , " QuasiQuotes" ]
9068
69+
9170--------------------------------------------------------------------------------
9271testExtensionsFromBoth :: Assertion
9372testExtensionsFromBoth =
@@ -98,6 +77,7 @@ testExtensionsFromBoth =
9877 expected = Set. fromList
9978 [" ScopedTypeVariables" , " DataKinds" , " TemplateHaskell" , " QuasiQuotes" ]
10079
80+
10181--------------------------------------------------------------------------------
10282testSpecifiedColumns :: Assertion
10383testSpecifiedColumns =
@@ -106,6 +86,7 @@ testSpecifiedColumns =
10686 where
10787 expected = Just 110
10888
89+
10990--------------------------------------------------------------------------------
11091testDefaultColumns :: Assertion
11192testDefaultColumns =
@@ -114,6 +95,7 @@ testDefaultColumns =
11495 where
11596 expected = Just 80
11697
98+
11799--------------------------------------------------------------------------------
118100testNoColumns :: Assertion
119101testNoColumns =
@@ -122,6 +104,7 @@ testNoColumns =
122104 where
123105 expected = Nothing
124106
107+
125108-- | Example cabal file borrowed from
126109-- https://www.haskell.org/cabal/users-guide/developing-packages.html
127110-- with some default-extensions added
0 commit comments