Skip to content

Commit 2cc9cd2

Browse files
committed
Add a test case for a stanza preference bug (haskell#3930).
1 parent 58d86b5 commit 2cc9cd2

File tree

1 file changed

+28
-0
lines changed
  • cabal-install/tests/UnitTests/Distribution/Solver/Modular

1 file changed

+28
-0
lines changed

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ tests = [
216216
, runTest $ preferences [ExStanzaPref "pkg" [TestStanzas]] $
217217
mkTest dbStanzaPreferences2 "disable testing when it's not possible" ["pkg"] $
218218
solverSuccess [("pkg", 1)]
219+
220+
, testStanzaPreference "test stanza preference"
219221
]
220222
, testGroup "Buildable Field" [
221223
testBuildable "avoid building component with unknown dependency" (ExAny "unknown")
@@ -654,6 +656,32 @@ dbStanzaPreferences2 = [
654656
Right $ exAv "pkg" 1 [] `withTest` ExTest "test" [ExAny "unknown"]
655657
]
656658

659+
-- | This is a test case for a bug in stanza preferences (#3930). The solver
660+
-- should be able to install 'A' by enabling 'flag' and disabling testing. When
661+
-- it tries goals in the specified order and prefers testing, it encounters
662+
-- 'unknown-pkg2'. 'unknown-pkg2' is only introduced by testing and 'flag', so
663+
-- the conflict set should contain both of those variables. Before the fix, it
664+
-- only contained 'flag'. The solver backjumped past the choice to disable
665+
-- testing and failed to find the solution.
666+
testStanzaPreference :: String -> TestTree
667+
testStanzaPreference name =
668+
let pkg = exAv "A" 1 [exFlagged "flag"
669+
[]
670+
[ExAny "unknown-pkg1"]]
671+
`withTest`
672+
ExTest "test" [exFlagged "flag"
673+
[ExAny "unknown-pkg2"]
674+
[]]
675+
goals = [
676+
P None "A"
677+
, F None "A" "flag"
678+
, S None "A" TestStanzas
679+
]
680+
in runTest $ goalOrder goals $
681+
preferences [ ExStanzaPref "A" [TestStanzas]] $
682+
mkTest [Right pkg] name ["A"] $
683+
solverSuccess [("A", 1)]
684+
657685
-- | Database with some cycles
658686
--
659687
-- * Simplest non-trivial cycle: A -> B and B -> A

0 commit comments

Comments
 (0)