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 configureTests
:: TestTree
30 [ testCase
"New config" $ do
32 (defaultNixStyleFlags
())
35 { configOptimization
= Flag MaximumOptimisation
36 , configVerbosity
= Flag silent
39 projConfig
<- configureAction
' flags
[] defaultGlobalFlags
41 Flag MaximumOptimisation
42 @=?
(packageConfigOptimization
. projectConfigLocalPackages
$ snd projConfig
)
43 , testCase
"Replacement + new config" $ do
45 (defaultNixStyleFlags
())
48 { configAppend
= Flag
True
52 { configOptimization
= Flag NoOptimisation
53 , configVerbosity
= Flag silent
57 { flagProjectDir
= Flag projectDir
60 (_
, ProjectConfig
{..}) <- configureAction
' flags
[] defaultGlobalFlags
62 Flag NoOptimisation
@=? packageConfigOptimization projectConfigLocalPackages
63 Flag silent
@=? projectConfigVerbosity projectConfigBuildOnly
64 , testCase
"Old + new config" $ do
66 (defaultNixStyleFlags
())
69 { configAppend
= Flag
True
73 { configVerbosity
= Flag silent
77 { flagProjectDir
= Flag projectDir
80 (_
, ProjectConfig
{..}) <- configureAction
' flags
[] defaultGlobalFlags
82 Flag MaximumOptimisation
@=? packageConfigOptimization projectConfigLocalPackages
83 Flag silent
@=? projectConfigVerbosity projectConfigBuildOnly
84 , testCase
"Old + new config, no appending" $ do
86 (defaultNixStyleFlags
())
89 { configVerbosity
= Flag silent
93 { flagProjectDir
= Flag projectDir
96 (_
, ProjectConfig
{..}) <- configureAction
' flags
[] defaultGlobalFlags
98 NoFlag
@=? packageConfigOptimization projectConfigLocalPackages
99 Flag silent
@=? projectConfigVerbosity projectConfigBuildOnly
100 , testCase
"Old + new config, backup check" $ do
102 (defaultNixStyleFlags
())
105 { configVerbosity
= Flag silent
109 { flagProjectDir
= Flag projectDir
112 backup
= projectDir
</> "cabal.project.local~"
114 exists
<- doesFileExist backup
118 _
<- configureAction
' flags
[] defaultGlobalFlags
121 >>= assertBool
("No file found, expected: " ++ backup
)
122 , testCase
"Local program options" $ do
123 let ghcFlags
= ["-fno-full-laziness"]
125 (defaultNixStyleFlags
())
128 { configVerbosity
= Flag silent
129 , configProgramArgs
= [("ghc", ghcFlags
)]
133 { flagProjectDir
= Flag projectDir
136 (_
, ProjectConfig
{..}) <- configureAction
' flags
[] defaultGlobalFlags
141 (Map
.lookup "ghc" (getMapMappend
(packageConfigProgramArgs projectConfigAllPackages
)))
146 (Map
.lookup "ghc" (getMapMappend
(packageConfigProgramArgs projectConfigLocalPackages
)))
149 projectDir
:: FilePath
150 projectDir
= "tests" </> "fixtures" </> "configure"