Fix Setup.hs `--dependency` example
[cabal.git] / cabal-install / tests / UnitTests / Distribution / Client / Configure.hs
blobc570d7a738ac192f07ac6f55a16c69dd4e16fa6c
1 {-# LANGUAGE RecordWildCards #-}
3 module UnitTests.Distribution.Client.Configure (tests) where
5 import Distribution.Client.CmdConfigure
7 import Control.Monad
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
18 import Test.Tasty
19 import Test.Tasty.HUnit
21 tests :: [TestTree]
22 tests =
23 [ configureTests
26 configureTests :: TestTree
27 configureTests =
28 testGroup
29 "Configure tests"
30 [ testCase "New config" $ do
31 let flags =
32 (defaultNixStyleFlags ())
33 { configFlags =
34 mempty
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
44 let flags =
45 (defaultNixStyleFlags ())
46 { configExFlags =
47 mempty
48 { configAppend = Flag True
50 , configFlags =
51 mempty
52 { configOptimization = Flag NoOptimisation
53 , configVerbosity = Flag silent
55 , projectFlags =
56 mempty
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
65 let flags =
66 (defaultNixStyleFlags ())
67 { configExFlags =
68 mempty
69 { configAppend = Flag True
71 , configFlags =
72 mempty
73 { configVerbosity = Flag silent
75 , projectFlags =
76 mempty
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
85 let flags =
86 (defaultNixStyleFlags ())
87 { configFlags =
88 mempty
89 { configVerbosity = Flag silent
91 , projectFlags =
92 mempty
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
101 let flags =
102 (defaultNixStyleFlags ())
103 { configFlags =
104 mempty
105 { configVerbosity = Flag silent
107 , projectFlags =
108 mempty
109 { flagProjectDir = Flag projectDir
112 backup = projectDir </> "cabal.project.local~"
114 exists <- doesFileExist backup
115 when exists $
116 removeFile backup
118 _ <- configureAction' flags [] defaultGlobalFlags
120 doesFileExist backup
121 >>= assertBool ("No file found, expected: " ++ backup)
122 , testCase "Local program options" $ do
123 let ghcFlags = ["-fno-full-laziness"]
124 flags =
125 (defaultNixStyleFlags ())
126 { configFlags =
127 mempty
128 { configVerbosity = Flag silent
129 , configProgramArgs = [("ghc", ghcFlags)]
131 , projectFlags =
132 mempty
133 { flagProjectDir = Flag projectDir
136 (_, ProjectConfig{..}) <- configureAction' flags [] defaultGlobalFlags
138 assertEqual
139 "global"
140 Nothing
141 (Map.lookup "ghc" (getMapMappend (packageConfigProgramArgs projectConfigAllPackages)))
143 assertEqual
144 "local"
145 (Just ghcFlags)
146 (Map.lookup "ghc" (getMapMappend (packageConfigProgramArgs projectConfigLocalPackages)))
149 projectDir :: FilePath
150 projectDir = "tests" </> "fixtures" </> "configure"