Skip to content

Commit 7e44f76

Browse files
mpickeringalt-romes
authored andcommitted
testsuite: Add userConstraints modifier
This allows you to add constraints to solver tests using the UserConstraintSource syntax, which is useful when you want to check how these UserConstraintSources are interpreted and influence the solver.
1 parent e34eaf1 commit 7e44f76

File tree

3 files changed

+36
-17
lines changed

3 files changed

+36
-17
lines changed

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

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import qualified Distribution.Package as C hiding
6868
)
6969
import qualified Distribution.PackageDescription as C
7070
import qualified Distribution.PackageDescription.Check as C
71+
import Distribution.Parsec
7172
import qualified Distribution.Simple.PackageIndex as C.PackageIndex
7273
import Distribution.Simple.Setup (BooleanFlag (..))
7374
import qualified Distribution.System as C
@@ -80,6 +81,7 @@ import Language.Haskell.Extension (Extension (..), Language (..))
8081
-- cabal-install
8182
import Distribution.Client.Dependency
8283
import qualified Distribution.Client.SolverInstallPlan as CI.SolverInstallPlan
84+
import Distribution.Client.Targets
8385
import Distribution.Client.Types
8486

8587
import Distribution.Solver.Types.ComponentDeps (ComponentDeps)
@@ -794,6 +796,7 @@ exResolve
794796
-> SolveExecutables
795797
-> Maybe (Variable P.QPN -> Variable P.QPN -> Ordering)
796798
-> [ExConstraint]
799+
-> [String]
797800
-> [ExPreference]
798801
-> C.Verbosity
799802
-> EnableAllTests
@@ -817,6 +820,7 @@ exResolve
817820
solveExes
818821
goalOrder
819822
constraints
823+
userConstraints
820824
prefs
821825
verbosity
822826
enableAllTests =
@@ -847,23 +851,24 @@ exResolve
847851
| otherwise = []
848852
targets' = fmap (\p -> NamedPackage (C.mkPackageName p) []) targets
849853
params =
850-
addConstraints (fmap toConstraint constraints) $
851-
addConstraints (fmap toLpc enableTests) $
852-
addPreferences (fmap toPref prefs) $
853-
setCountConflicts countConflicts $
854-
setFineGrainedConflicts fineGrainedConflicts $
855-
setMinimizeConflictSet minimizeConflictSet $
856-
setIndependentGoals indepGoals $
857-
(if asBool prefOldest then setPreferenceDefault PreferAllOldest else id) $
858-
setReorderGoals reorder $
859-
setMaxBackjumps mbj $
860-
setAllowBootLibInstalls allowBootLibInstalls $
861-
setOnlyConstrained onlyConstrained $
862-
setEnableBackjumping enableBj $
863-
setSolveExecutables solveExes $
864-
setGoalOrder goalOrder $
865-
setSolverVerbosity verbosity $
866-
standardInstallPolicy instIdx avaiIdx targets'
854+
addConstraints (map parseConstraint userConstraints) $
855+
addConstraints (fmap toConstraint constraints) $
856+
addConstraints (fmap toLpc enableTests) $
857+
addPreferences (fmap toPref prefs) $
858+
setCountConflicts countConflicts $
859+
setFineGrainedConflicts fineGrainedConflicts $
860+
setMinimizeConflictSet minimizeConflictSet $
861+
setIndependentGoals indepGoals $
862+
(if asBool prefOldest then setPreferenceDefault PreferAllOldest else id) $
863+
setReorderGoals reorder $
864+
setMaxBackjumps mbj $
865+
setAllowBootLibInstalls allowBootLibInstalls $
866+
setOnlyConstrained onlyConstrained $
867+
setEnableBackjumping enableBj $
868+
setSolveExecutables solveExes $
869+
setGoalOrder goalOrder $
870+
setSolverVerbosity verbosity $
871+
standardInstallPolicy instIdx avaiIdx targets'
867872
toLpc pc = LabeledPackageConstraint pc ConstraintSourceUnknown
868873

869874
toConstraint (ExVersionConstraint scope v) =
@@ -873,6 +878,12 @@ exResolve
873878
toConstraint (ExStanzaConstraint scope stanzas) =
874879
toLpc $ PackageConstraint scope (PackagePropertyStanzas stanzas)
875880

881+
parseConstraint :: String -> LabeledPackageConstraint
882+
parseConstraint str =
883+
case explicitEitherParsec parsec str of
884+
Left err -> error ("Bad user constraint: " ++ err)
885+
Right user_constraint -> toLpc (userToPackageConstraint user_constraint)
886+
876887
toPref (ExPkgPref n v) = PackageVersionPreference (C.mkPackageName n) v
877888
toPref (ExStanzaPref n stanzas) = PackageStanzasPreference (C.mkPackageName n) stanzas
878889

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module UnitTests.Distribution.Solver.Modular.DSL.TestCaseUtils
1515
, disableSolveExecutables
1616
, goalOrder
1717
, constraints
18+
, userConstraints
1819
, preferences
1920
, setVerbose
2021
, enableAllTests
@@ -95,6 +96,9 @@ goalOrder order test = test{testGoalOrder = Just order}
9596
constraints :: [ExConstraint] -> SolverTest -> SolverTest
9697
constraints cs test = test{testConstraints = cs}
9798

99+
userConstraints :: [String] -> SolverTest -> SolverTest
100+
userConstraints cs test = test{testUserConstraints = cs}
101+
98102
preferences :: [ExPreference] -> SolverTest -> SolverTest
99103
preferences prefs test = test{testSoftConstraints = prefs}
100104

@@ -126,6 +130,7 @@ data SolverTest = SolverTest
126130
, testGoalOrder :: Maybe [ExampleVar]
127131
, testConstraints :: [ExConstraint]
128132
, testSoftConstraints :: [ExPreference]
133+
, testUserConstraints :: [String]
129134
, testVerbosity :: Verbosity
130135
, testDb :: ExampleDb
131136
, testSupportedExts :: Maybe [Extension]
@@ -228,6 +233,7 @@ mkTestExtLangPC exts langs mPkgConfigDb db label targets result =
228233
, testSolveExecutables = SolveExecutables True
229234
, testGoalOrder = Nothing
230235
, testConstraints = []
236+
, testUserConstraints = []
231237
, testSoftConstraints = []
232238
, testVerbosity = normal
233239
, testDb = db
@@ -260,6 +266,7 @@ runTest SolverTest{..} = askOption $ \(OptionShowSolverLog showSolverLog) ->
260266
testSolveExecutables
261267
(sortGoals <$> testGoalOrder)
262268
testConstraints
269+
testUserConstraints
263270
testSoftConstraints
264271
testVerbosity
265272
testEnableAllTests

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ solve enableBj fineGrainedConflicts reorder countConflicts indep prefOldest goal
244244
(SolveExecutables True)
245245
(unVarOrdering <$> goalOrder)
246246
(testConstraints test)
247+
[]
247248
(testPreferences test)
248249
normal
249250
(EnableAllTests False)

0 commit comments

Comments
 (0)