Skip to content

Commit 81bdaca

Browse files
committed
Adapting tests for the new implementation
1 parent 96cb20f commit 81bdaca

File tree

4 files changed

+44
-70
lines changed

4 files changed

+44
-70
lines changed

cabal-install/tests/UnitTests/Distribution/Client/Configure.hs

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ import Distribution.Client.CmdConfigure
55

66
import Test.Tasty
77
import Test.Tasty.HUnit
8+
import System.Directory
89
import System.FilePath
910
import Distribution.Verbosity
1011
import Distribution.Client.Setup
11-
import Distribution.Client.Sandbox
12-
import Distribution.Client.Config
1312
import Distribution.Client.NixStyleOptions
1413
import Distribution.Client.ProjectConfig.Types
1514
import Distribution.Client.ProjectFlags
@@ -19,61 +18,78 @@ import Distribution.Simple.Flag
1918
tests :: [TestTree]
2019
tests =
2120
[ configureTests
22-
, reconfigureTests
2321
]
2422

2523
configureTests :: TestTree
2624
configureTests = testGroup "Configure tests"
2725
[ testCase "New config" $ do
28-
let flags = ((defaultNixStyleFlags ())
26+
let flags = (defaultNixStyleFlags ())
2927
{ configFlags = mempty
3028
{ configOptimization = Flag MaximumOptimisation
3129
, configVerbosity = Flag silent
3230
}
33-
})
31+
}
3432
projConfig <- configureAction' flags [] defaultGlobalFlags
3533

3634
Flag MaximumOptimisation @=?
3735
(packageConfigOptimization . projectConfigLocalPackages $ snd projConfig)
38-
]
3936

40-
reconfigureTests :: TestTree
41-
reconfigureTests = testGroup "Reconfigure tests"
42-
[ testCase "Replacement + new config" $ do
37+
, testCase "Replacement + new config" $ do
4338
let flags = (defaultNixStyleFlags ())
44-
{ configFlags = mempty
39+
{ configExFlags = mempty
40+
{ configAppend = Flag True }
41+
, configFlags = mempty
4542
{ configOptimization = Flag NoOptimisation
4643
, configVerbosity = Flag silent
4744
}
4845
, projectFlags = mempty
4946
{ flagProjectFileName = Flag projectFile }
5047
}
51-
projConfig <- reconfigureAction' flags [] defaultGlobalFlags
52-
53-
case projConfig of
54-
Right (_, ProjectConfig {..}) -> do
55-
Flag NoOptimisation @=? packageConfigOptimization projectConfigLocalPackages
56-
Flag silent @=? projectConfigVerbosity projectConfigBuildOnly
48+
(_, ProjectConfig {..}) <- configureAction' flags [] defaultGlobalFlags
5749

58-
Left _ -> assertFailure $
59-
"Called configureAction, check if " ++ projectFile ++ ".local exists."
50+
Flag NoOptimisation @=? packageConfigOptimization projectConfigLocalPackages
51+
Flag silent @=? projectConfigVerbosity projectConfigBuildOnly
6052

6153
, testCase "Old + new config" $ do
54+
let flags = (defaultNixStyleFlags ())
55+
{ configExFlags = mempty
56+
{ configAppend = Flag True }
57+
, configFlags = mempty
58+
{ configVerbosity = Flag silent }
59+
, projectFlags = mempty
60+
{ flagProjectFileName = Flag projectFile }
61+
}
62+
(_, ProjectConfig {..}) <- configureAction' flags [] defaultGlobalFlags
63+
64+
Flag MaximumOptimisation @=? packageConfigOptimization projectConfigLocalPackages
65+
Flag silent @=? projectConfigVerbosity projectConfigBuildOnly
66+
67+
, testCase "Old + new config, no appending" $ do
6268
let flags = (defaultNixStyleFlags ())
6369
{ configFlags = mempty
6470
{ configVerbosity = Flag silent }
6571
, projectFlags = mempty
6672
{ flagProjectFileName = Flag projectFile }
6773
}
68-
projConfig <- reconfigureAction' flags [] defaultGlobalFlags
69-
70-
case projConfig of
71-
Right (_, ProjectConfig {..}) -> do
72-
Flag MaximumOptimisation @=? packageConfigOptimization projectConfigLocalPackages
73-
Flag silent @=? projectConfigVerbosity projectConfigBuildOnly
74+
(_, ProjectConfig {..}) <- configureAction' flags [] defaultGlobalFlags
75+
76+
NoFlag @=? packageConfigOptimization projectConfigLocalPackages
77+
Flag silent @=? projectConfigVerbosity projectConfigBuildOnly
78+
79+
, testCase "Old + new config, backup check" $ do
80+
let flags = (defaultNixStyleFlags ())
81+
{ configFlags = mempty
82+
{ configVerbosity = Flag silent }
83+
, projectFlags = mempty
84+
{ flagProjectFileName = Flag projectFile }
85+
}
86+
backup = projectFile <.> "local~"
87+
88+
removeFile backup
89+
_ <- configureAction' flags [] defaultGlobalFlags
7490

75-
Left _ -> assertFailure $
76-
"Called configureAction, check if " ++ projectFile ++ ".local exists."
91+
doesFileExist backup >>=
92+
assertBool ("No file found, expected: " ++ backup)
7793
]
7894

7995
projectFile :: FilePath
Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,4 @@
11
# cabal v2-configure
22
'cabal.project.local' already exists, backing it up to 'cabal.project.local~'.
3-
Resolving dependencies...
4-
Build profile: -w ghc-<GHCVER> -O1
5-
In order, the following would be built:
6-
- NewConfigure-0.1.0.0 (lib) (first run)
73
# cabal v2-configure
8-
'cabal.project.local' already exists, backing it up to 'cabal.project.local~0'.
9-
Build profile: -w ghc-<GHCVER> -O1
10-
In order, the following would be built:
11-
- NewConfigure-0.1.0.0 (lib) (first run)
12-
# cabal v2-configure
13-
'cabal.project.local' already exists, backing it up to 'cabal.project.local~1'.
14-
Build profile: -w ghc-<GHCVER> -O1
15-
In order, the following would be built:
16-
- NewConfigure-0.1.0.0 (lib) (first run)
17-
# cabal v2-configure
18-
'foo.project.local' already exists, backing it up to 'foo.project.local~'.
19-
Build profile: -w ghc-<GHCVER> -O1
20-
In order, the following would be built:
21-
- NewConfigure-0.1.0.0 (lib) (first run)
22-
# cabal v2-configure
23-
'foo.project.local' already exists, backing it up to 'foo.project.local~0'.
24-
Build profile: -w ghc-<GHCVER> -O1
25-
In order, the following would be built:
26-
- NewConfigure-0.1.0.0 (lib) (first run)
27-
# cabal v2-configure
28-
'foo.project.local' already exists, backing it up to 'foo.project.local~1'.
29-
Build profile: -w ghc-<GHCVER> -O1
30-
In order, the following would be built:
31-
- NewConfigure-0.1.0.0 (lib) (first run)
4+
'foo.project.local' already exists, backing it up to 'foo.project.local~'.

cabal-testsuite/PackageTests/NewConfigure/LocalConfigOverwrite/cabal.test.hs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,8 @@ main = cabalTest $
44
withSourceCopy $ do
55
cabal' "v2-configure" [] >>=
66
assertOutputContains "backing it up to 'cabal.project.local~'"
7-
cabal' "v2-configure" [] >>=
8-
assertOutputContains "backing it up to 'cabal.project.local~0'"
9-
cabal' "v2-configure" [] >>=
10-
assertOutputContains "backing it up to 'cabal.project.local~1'"
117

128
-- With --project-file
139
cabal' "v2-configure" ["--project-file", "foo.project"] >>=
1410
assertOutputContains
1511
"'foo.project.local' already exists, backing it up to 'foo.project.local~'"
16-
cabal' "v2-configure" ["--project-file", "foo.project"] >>=
17-
assertOutputContains
18-
"'foo.project.local' already exists, backing it up to 'foo.project.local~0'"
19-
cabal' "v2-configure" ["--project-file", "foo.project"] >>=
20-
assertOutputContains
21-
"'foo.project.local' already exists, backing it up to 'foo.project.local~1'"
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
# cabal v2-configure
2-
Resolving dependencies...
3-
Build profile: -w ghc-<GHCVER> -O1
4-
In order, the following would be built:
5-
- happy-999.999.999 (exe:happy) (first run)
6-
- client-0.1.0.0 (exe:hello-world) (first run)
1+
# cabal v2-configure

0 commit comments

Comments
 (0)