validate dependabot configuration
[cabal.git] / cabal-install / tests / UnitTests / Distribution / Client / Configure.hs
bloba5ec944369e0fe1c9989a76aa3b2e9b6c181924c
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 defaultTestFlags :: NixStyleFlags ()
27 defaultTestFlags =
28 (defaultNixStyleFlags ())
29 { projectFlags =
30 mempty
31 { flagProjectDir = Flag projectDir
35 configureTests :: TestTree
36 configureTests =
37 testGroup
38 "Configure tests"
39 [ testCase "New config" $ do
40 let flags =
41 defaultTestFlags
42 { configFlags =
43 mempty
44 { configOptimization = Flag MaximumOptimisation
45 , configCommonFlags =
46 mempty{setupVerbosity = Flag silent}
49 projConfig <- configureAction' flags [] defaultGlobalFlags
51 Flag MaximumOptimisation
52 @=? (packageConfigOptimization . projectConfigLocalPackages $ snd projConfig)
53 , testCase "Replacement + new config" $ do
54 let flags =
55 defaultTestFlags
56 { configExFlags =
57 mempty
58 { configAppend = Flag True
60 , configFlags =
61 mempty
62 { configOptimization = Flag NoOptimisation
63 , configCommonFlags =
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
72 let flags =
73 defaultTestFlags
74 { configExFlags =
75 mempty
76 { configAppend = Flag True
78 , configFlags =
79 mempty
80 { configCommonFlags =
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
89 let flags =
90 defaultTestFlags
91 { configFlags =
92 mempty
93 { configCommonFlags =
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
102 let flags =
103 defaultTestFlags
104 { configFlags =
105 mempty
106 { configCommonFlags =
107 mempty{setupVerbosity = Flag silent}
110 backup = projectDir </> "cabal.project.local~"
112 exists <- doesFileExist backup
113 when exists $
114 removeFile backup
116 _ <- configureAction' flags [] defaultGlobalFlags
118 doesFileExist backup
119 >>= assertBool ("No file found, expected: " ++ backup)
120 , testCase "Local program options" $ do
121 let ghcFlags = ["-fno-full-laziness"]
122 flags =
123 defaultTestFlags
124 { configFlags =
125 mempty
126 { configCommonFlags =
127 mempty{setupVerbosity = Flag silent}
128 , configProgramArgs = [("ghc", ghcFlags)]
131 (_, ProjectConfig{..}) <- configureAction' flags [] defaultGlobalFlags
133 assertEqual
134 "global"
135 Nothing
136 (Map.lookup "ghc" (getMapMappend (packageConfigProgramArgs projectConfigAllPackages)))
138 assertEqual
139 "local"
140 (Just ghcFlags)
141 (Map.lookup "ghc" (getMapMappend (packageConfigProgramArgs projectConfigLocalPackages)))
144 projectDir :: FilePath
145 projectDir = "tests" </> "fixtures" </> "configure"