Skip to content

Commit cd9b1fd

Browse files
authored
Merge pull request #9468 from mpickering/wip/unit-tests
testsuite: Add some unit tests for #9466 #9467
2 parents d4dcd51 + 573c15d commit cd9b1fd

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed

cabal-install/cabal-install.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ test-suite unit-tests
355355
tasty >= 1.2.3 && <1.6,
356356
tasty-golden >=2.3.1.1 && <2.4,
357357
tasty-quickcheck,
358+
tasty-expected-failure,
358359
tasty-hunit >= 0.10,
359360
tree-diff,
360361
QuickCheck >= 2.14.3 && <2.15

cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import qualified Distribution.Version as V
1313

1414
-- test-framework
1515
import Test.Tasty as TF
16+
import Test.Tasty.ExpectedFailure
1617

1718
-- Cabal
1819
import Language.Haskell.Extension
@@ -181,6 +182,8 @@ tests =
181182
, runTest $ mkTest db9 "setupDeps7" ["F", "G"] (solverSuccess [("A", 1), ("B", 1), ("B", 2), ("C", 1), ("D", 1), ("E", 1), ("E", 2), ("F", 1), ("G", 1)])
182183
, runTest $ mkTest db10 "setupDeps8" ["C"] (solverSuccess [("C", 1)])
183184
, runTest $ indep $ mkTest dbSetupDeps "setupDeps9" ["A", "B"] (solverSuccess [("A", 1), ("B", 1), ("C", 1), ("D", 1), ("D", 2)])
185+
, runTest $ setupStanzaTest1
186+
, runTest $ setupStanzaTest2
184187
]
185188
, testGroup
186189
"Base shim"
@@ -190,6 +193,9 @@ tests =
190193
, runTest $ mkTest db12 "baseShim4" ["C"] (solverSuccess [("A", 1), ("B", 1), ("C", 1)])
191194
, runTest $ mkTest db12 "baseShim5" ["D"] anySolverFailure
192195
, runTest $ mkTest db12 "baseShim6" ["E"] (solverSuccess [("E", 1), ("syb", 2)])
196+
, expectFailBecause "#9467" $ runTest $ mkTest db12s "baseShim7" ["A"] (solverSuccess [("A", 1)])
197+
, expectFailBecause "#9467" $ runTest $ mkTest db11s "baseShim7-simple" ["A"] (solverSuccess [("A", 1)])
198+
, runTest $ mkTest db11s2 "baseShim8" ["A"] (solverSuccess [("A", 1)])
193199
]
194200
, testGroup
195201
"Base and non-reinstallable"
@@ -357,6 +363,8 @@ tests =
357363
, runTest $ testIndepGoals5 "indepGoals5 - default goal order" DefaultGoalOrder
358364
, runTest $ testIndepGoals6 "indepGoals6 - fixed goal order" FixedGoalOrder
359365
, runTest $ testIndepGoals6 "indepGoals6 - default goal order" DefaultGoalOrder
366+
, expectFailBecause "#9466" $ runTest $ testIndepGoals7 "indepGoals7"
367+
, runTest $ testIndepGoals8 "indepGoals8"
360368
]
361369
, -- Tests designed for the backjumping blog post
362370
testGroup
@@ -1325,6 +1333,61 @@ db12 =
13251333
, Right $ exAv "E" 1 [ExFix "base" 4, ExFix "syb" 2]
13261334
]
13271335

1336+
-- | A version of db12 where the dependency on base happens via a setup dependency
1337+
--
1338+
-- * The setup dependency is solved in it's own qualified scope, so should be solved
1339+
-- independently of the rest of the build plan.
1340+
--
1341+
-- * The setup dependency depends on `base-3` and hence `syb1`
1342+
--
1343+
-- * A depends on `base-4` and `syb-2`, should be fine as the setup stanza should
1344+
-- be solved independently.
1345+
db12s :: ExampleDb
1346+
db12s =
1347+
let base3 = exInst "base" 3 "base-3-inst" [base4, syb1]
1348+
base4 = exInst "base" 4 "base-4-inst" []
1349+
syb1 = exInst "syb" 1 "syb-1-inst" [base4]
1350+
in [ Left base3
1351+
, Left base4
1352+
, Left syb1
1353+
, Right $ exAv "syb" 2 [ExFix "base" 4]
1354+
, Right $
1355+
exAv "A" 1 [ExFix "base" 4, ExFix "syb" 2]
1356+
`withSetupDeps` [ExFix "base" 3]
1357+
]
1358+
1359+
-- | A version of db11 where the dependency on base happens via a setup dependency
1360+
--
1361+
-- * The setup dependency is solved in it's own qualified scope, so should be solved
1362+
-- independently of the rest of the build plan.
1363+
--
1364+
-- * The setup dependency depends on `base-3`
1365+
--
1366+
-- * A depends on `base-4`, should be fine as the setup stanza should
1367+
-- be solved independently.
1368+
db11s :: ExampleDb
1369+
db11s =
1370+
let base3 = exInst "base" 3 "base-3-inst" [base4]
1371+
base4 = exInst "base" 4 "base-4-inst" []
1372+
in [ Left base3
1373+
, Left base4
1374+
, Right $
1375+
exAv "A" 1 [ExFix "base" 4]
1376+
`withSetupDeps` [ExFix "base" 3]
1377+
]
1378+
1379+
-- Works without the base-shimness, choosing different versions of base
1380+
db11s2 :: ExampleDb
1381+
db11s2 =
1382+
let base3 = exInst "base" 3 "base-3-inst" []
1383+
base4 = exInst "base" 4 "base-4-inst" []
1384+
in [ Left base3
1385+
, Left base4
1386+
, Right $
1387+
exAv "A" 1 [ExFix "base" 4]
1388+
`withSetupDeps` [ExFix "base" 3]
1389+
]
1390+
13281391
dbBase :: ExampleDb
13291392
dbBase =
13301393
[ Right $
@@ -1954,6 +2017,33 @@ dbLangs1 =
19542017
, Right $ exAv "C" 1 [ExLang (UnknownLanguage "Haskell3000"), ExAny "B"]
19552018
]
19562019

2020+
-- This test checks how the scope of a constraint interacts with qualified goals.
2021+
-- If you specify `A == 2`, that top-level should /not/ apply to an independent goal!
2022+
testIndepGoals7 :: String -> SolverTest
2023+
testIndepGoals7 name =
2024+
constraints [ExVersionConstraint (scopeToplevel "A") (V.thisVersion (V.mkVersion [2, 0, 0]))] $
2025+
independentGoals $
2026+
mkTest dbIndepGoals78 name ["A"] $
2027+
-- The more recent version should be picked by the solver. As said
2028+
-- above, the top-level A==2 should not apply to an independent goal.
2029+
solverSuccess [("A", 3)]
2030+
2031+
dbIndepGoals78 :: ExampleDb
2032+
dbIndepGoals78 =
2033+
[ Right $ exAv "A" 1 []
2034+
, Right $ exAv "A" 2 []
2035+
, Right $ exAv "A" 3 []
2036+
]
2037+
2038+
-- This test checks how the scope of a constraint interacts with qualified goals.
2039+
-- If you specify `any.A == 2`, then that should apply inside an independent goal.
2040+
testIndepGoals8 :: String -> SolverTest
2041+
testIndepGoals8 name =
2042+
constraints [ExVersionConstraint (ScopeAnyQualifier "A") (V.thisVersion (V.mkVersion [2, 0, 0]))] $
2043+
independentGoals $
2044+
mkTest dbIndepGoals78 name ["A"] $
2045+
solverSuccess [("A", 2)]
2046+
19572047
-- | cabal must set enable-exe to false in order to avoid the unavailable
19582048
-- dependency. Flags are true by default. The flag choice causes "pkg" to
19592049
-- depend on "false-dep".
@@ -2467,6 +2557,32 @@ dbIssue3775 =
24672557
, Right $ exAv "B" 2 [ExAny "A", ExAny "warp"]
24682558
]
24692559

2560+
-- A database where the setup depends on something which has a test stanza, does the
2561+
-- test stanza get enabled?
2562+
dbSetupStanza :: ExampleDb
2563+
dbSetupStanza =
2564+
[ Right $
2565+
exAv "A" 1 []
2566+
`withSetupDeps` [ExAny "B"]
2567+
, Right $
2568+
exAv "B" 1 []
2569+
`withTest` exTest "test" [ExAny "C"]
2570+
]
2571+
2572+
-- With the "top-level" qualifier syntax
2573+
setupStanzaTest1 :: SolverTest
2574+
setupStanzaTest1 = constraints [ExStanzaConstraint (scopeToplevel "B") [TestStanzas]] $ mkTest dbSetupStanza "setupStanzaTest1" ["A"] (solverSuccess [("A", 1), ("B", 1)])
2575+
2576+
-- With the "any" qualifier syntax
2577+
setupStanzaTest2 :: SolverTest
2578+
setupStanzaTest2 =
2579+
constraints [ExStanzaConstraint (ScopeAnyQualifier "B") [TestStanzas]] $
2580+
mkTest
2581+
dbSetupStanza
2582+
"setupStanzaTest2"
2583+
["A"]
2584+
(solverFailure ("unknown package: A:setup.C (dependency of A:setup.B *test)" `isInfixOf`))
2585+
24702586
-- | Returns true if the second list contains all elements of the first list, in
24712587
-- order.
24722588
containsInOrder :: Eq a => [a] -> [a] -> Bool

0 commit comments

Comments
 (0)