1 {-# LANGUAGE RecordWildCards #-}
3 module UnitTests
.Distribution
.Client
.Configure
(tests
) where
5 import Distribution
.Client
.CmdConfigure
8 import qualified Data
.Map
as Map
9 import Distribution
.Client
.NixStyleOptions
10 import Distribution
.Client
.ProjectConfig
.Types
11 import Distribution
.Client
.ProjectFlags
12 import Distribution
.Client
.Setup
13 import Distribution
.Simple
14 import Distribution
.Simple
.Flag
15 import Distribution
.Verbosity
16 import System
.Directory
17 import System
.FilePath
19 import Test
.Tasty
.HUnit
26 defaultTestFlags
:: NixStyleFlags
()
28 (defaultNixStyleFlags
())
31 { flagProjectDir
= Flag projectDir
35 configureTests
:: TestTree
39 [ testCase
"New config" $ do
44 { configOptimization
= Flag MaximumOptimisation
46 mempty
{setupVerbosity
= Flag silent
}
49 projConfig
<- configureAction
' flags
[] defaultGlobalFlags
51 Flag MaximumOptimisation
52 @=?
(packageConfigOptimization
. projectConfigLocalPackages
$ snd projConfig
)
53 , testCase
"Replacement + new config" $ do
58 { configAppend
= Flag
True
62 { configOptimization
= Flag NoOptimisation
64 mempty
{setupVerbosity
= Flag silent
}
67 (_
, ProjectConfig
{..}) <- configureAction
' flags
[] defaultGlobalFlags
69 Flag NoOptimisation
@=? packageConfigOptimization projectConfigLocalPackages
70 Flag silent
@=? projectConfigVerbosity projectConfigBuildOnly
71 , testCase
"Old + new config" $ do
76 { configAppend
= Flag
True
81 mempty
{setupVerbosity
= Flag silent
}
84 (_
, ProjectConfig
{..}) <- configureAction
' flags
[] defaultGlobalFlags
86 Flag MaximumOptimisation
@=? packageConfigOptimization projectConfigLocalPackages
87 Flag silent
@=? projectConfigVerbosity projectConfigBuildOnly
88 , testCase
"Old + new config, no appending" $ do
94 mempty
{setupVerbosity
= Flag silent
}
97 (_
, ProjectConfig
{..}) <- configureAction
' flags
[] defaultGlobalFlags
99 NoFlag
@=? packageConfigOptimization projectConfigLocalPackages
100 Flag silent
@=? projectConfigVerbosity projectConfigBuildOnly
101 , testCase
"Old + new config, backup check" $ do
106 { configCommonFlags
=
107 mempty
{setupVerbosity
= Flag silent
}
110 backup
= projectDir
</> "cabal.project.local~"
112 exists
<- doesFileExist backup
116 _
<- configureAction
' flags
[] defaultGlobalFlags
119 >>= assertBool
("No file found, expected: " ++ backup
)
120 , testCase
"Local program options" $ do
121 let ghcFlags
= ["-fno-full-laziness"]
126 { configCommonFlags
=
127 mempty
{setupVerbosity
= Flag silent
}
128 , configProgramArgs
= [("ghc", ghcFlags
)]
131 (_
, ProjectConfig
{..}) <- configureAction
' flags
[] defaultGlobalFlags
136 (Map
.lookup "ghc" (getMapMappend
(packageConfigProgramArgs projectConfigAllPackages
)))
141 (Map
.lookup "ghc" (getMapMappend
(packageConfigProgramArgs projectConfigLocalPackages
)))
144 projectDir
:: FilePath
145 projectDir
= "tests" </> "fixtures" </> "configure"