Skip to content

Commit 9e7b7d3

Browse files
committed
Specify goal order in backjumping unit test
1 parent 1725739 commit 9e7b7d3

File tree

1 file changed

+38
-14
lines changed
  • cabal-install/tests/UnitTests/Distribution/Solver/Modular

1 file changed

+38
-14
lines changed

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

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import Language.Haskell.Extension ( Extension(..)
1818
, KnownExtension(..), Language(..))
1919

2020
-- cabal-install
21+
import Distribution.Solver.Types.OptionalStanza
2122
import Distribution.Solver.Types.PkgConfigDb (PkgConfigDb, pkgConfigDbFromList)
2223
import Distribution.Solver.Types.Settings
2324
import Distribution.Client.Dependency.Types
@@ -133,7 +134,7 @@ tests = [
133134
]
134135
, testGroup "Independent goals" [
135136
runTest $ indep $ mkTest db16 "indepGoals1" ["A", "B"] (SolverSuccess [("A", 1), ("B", 1), ("C", 1), ("D", 1), ("D", 2), ("E", 1)])
136-
, runTest $ indep $ mkTest db17 "indepGoals2" ["A", "B"] (SolverSuccess [("A", 1), ("B", 1), ("C", 1), ("D", 1)])
137+
, runTest $ testIndepGoals2 "indepGoals2"
137138
, runTest $ indep $ mkTest db19 "indepGoals3" ["D", "E", "F"] anySolverFailure -- The target order is important.
138139
, runTest $ indep $ mkTest db20 "indepGoals4" ["C", "A", "B"] (SolverSuccess [("A", 1), ("B", 1), ("C", 1), ("D", 1), ("D", 2)])
139140
, runTest $ indep $ mkTest db23 "indepGoals5" ["X", "Y"] (SolverSuccess [("A", 1), ("A", 2), ("B", 1), ("C", 1), ("C", 2), ("X", 1), ("Y", 1)])
@@ -157,12 +158,17 @@ tests = [
157158
-- | Combinator to turn on --independent-goals behavior, i.e. solve
158159
-- for the goals as if we were solving for each goal independently.
159160
-- (This doesn't really work well at the moment, see #2842)
160-
indep test = test { testIndepGoals = IndependentGoals True }
161161
soft prefs test = test { testSoftConstraints = prefs }
162162
mkvrThis = V.thisVersion . makeV
163163
mkvrOrEarlier = V.orEarlierVersion . makeV
164164
makeV v = V.Version [v,0,0] []
165165

166+
indep :: SolverTest -> SolverTest
167+
indep test = test { testIndepGoals = IndependentGoals True }
168+
169+
goalOrder :: [ExampleVar] -> SolverTest -> SolverTest
170+
goalOrder order test = test { testGoalOrder = Just order }
171+
166172
{-------------------------------------------------------------------------------
167173
Solver tests
168174
-------------------------------------------------------------------------------}
@@ -604,23 +610,41 @@ db16 = [
604610
, Right $ exAv "E" 1 []
605611
]
606612

607-
-- | This database checks that when the solver discovers a constraint on a
613+
-- | This test checks that when the solver discovers a constraint on a
608614
-- package's version after choosing to link that package, it can backtrack to
609615
-- try alternative versions for the linked-to package. See pull request #3327.
610616
--
611617
-- When A and B are installed as independent goals, their dependencies on C
612618
-- must be linked. Since C depends on D, A and B's dependencies on D must also
613-
-- be linked. This test relies on the fact that the solver chooses D-2 for both
614-
-- 0.D and 1.D before it encounters the test suites' constraints. The solver
615-
-- must backtrack to try D-1 for both 0.D and 1.D.
616-
db17 :: ExampleDb
617-
db17 = [
618-
Right $ exAv "A" 1 [ExAny "C"] `withTest` ExTest "test" [ExFix "D" 1]
619-
, Right $ exAv "B" 1 [ExAny "C"] `withTest` ExTest "test" [ExFix "D" 1]
620-
, Right $ exAv "C" 1 [ExAny "D"]
621-
, Right $ exAv "D" 1 []
622-
, Right $ exAv "D" 2 []
623-
]
619+
-- be linked. This test fixes the goal order so that the solver chooses D-2 for
620+
-- both 0.D and 1.D before it encounters the test suites' constraints. It must
621+
-- backtrack to try D-1 for both 0.D and 1.D.
622+
testIndepGoals2 :: String -> SolverTest
623+
testIndepGoals2 name =
624+
goalOrder goals $ indep $
625+
mkTest db name ["A", "B"] $
626+
SolverSuccess [("A", 1), ("B", 1), ("C", 1), ("D", 1)]
627+
where
628+
goals :: [ExampleVar]
629+
goals = [
630+
P (Indep 0) "A"
631+
, P (Indep 0) "C"
632+
, P (Indep 0) "D"
633+
, P (Indep 1) "B"
634+
, P (Indep 1) "C"
635+
, P (Indep 1) "D"
636+
, S (Indep 1) "B" TestStanzas
637+
, S (Indep 0) "A" TestStanzas
638+
]
639+
640+
db :: ExampleDb
641+
db = [
642+
Right $ exAv "A" 1 [ExAny "C"] `withTest` ExTest "test" [ExFix "D" 1]
643+
, Right $ exAv "B" 1 [ExAny "C"] `withTest` ExTest "test" [ExFix "D" 1]
644+
, Right $ exAv "C" 1 [ExAny "D"]
645+
, Right $ exAv "D" 1 []
646+
, Right $ exAv "D" 2 []
647+
]
624648

625649
-- | Issue #2834
626650
-- When both A and B are installed as independent goals, their dependencies on

0 commit comments

Comments
 (0)