1 module UnitTests
.Distribution
.Client
.Targets
5 import Distribution
.Client
.Targets
7 , UserConstraintScope
(..)
11 import Distribution
.Package
(mkPackageName
)
12 import Distribution
.PackageDescription
(mkFlagAssignment
, mkFlagName
)
13 import Distribution
.Version
(anyVersion
, mkVersion
, thisVersion
)
15 import Distribution
.Parsec
(explicitEitherParsec
, parsec
, parsecCommaList
)
17 import Distribution
.Solver
.Types
.OptionalStanza
(OptionalStanza
(..))
18 import Distribution
.Solver
.Types
.PackageConstraint
(PackageProperty
(..))
21 import Test
.Tasty
.HUnit
23 import Data
.List
(intercalate
)
25 -- Helper function: makes a test group by mapping each element
26 -- of a list to a test case.
27 makeGroup
:: String -> (a
-> Assertion
) -> [a
] -> TestTree
30 zipWith testCase
(map show [0 :: Integer ..]) (map f xs
)
36 (uncurry readUserConstraintTest
)
40 (uncurry parseUserConstraintTest
)
44 (uncurry readUserConstraintsTest
)
45 [ -- First example only.
47 ( case exampleStrs
of (e
: _
) -> e
; _
-> error "empty examples"
50 , -- All examples separated by commas.
51 (intercalate
", " exampleStrs
, exampleUcs
)
55 (exampleStrs
, exampleUcs
) = unzip exampleConstraints
57 exampleConstraints
:: [(String, UserConstraint
)]
60 ( "template-haskell installed"
62 (UserQualified UserQualToplevel
(pn
"template-haskell"))
63 PackagePropertyInstalled
68 (UserQualified UserQualToplevel
(pn
"bytestring"))
69 (PackagePropertyVersion anyVersion
)
72 ( "any.directory test"
74 (UserAnyQualifier
(pn
"directory"))
75 (PackagePropertyStanzas
[TestStanzas
])
78 ( "setup.Cabal installed"
80 (UserAnySetupQualifier
(pn
"Cabal"))
81 PackagePropertyInstalled
84 ( "process:setup.bytestring ==5.2"
86 (UserQualified
(UserQualSetup
(pn
"process")) (pn
"bytestring"))
87 (PackagePropertyVersion
(thisVersion
(mkVersion
[5, 2])))
89 , -- flag MUST be prefixed with - or +
91 ( "network:setup.containers +foo -bar +baz"
93 (UserQualified
(UserQualSetup
(pn
"network")) (pn
"containers"))
94 ( PackagePropertyFlags
103 -- -- TODO: Re-enable UserQualExe tests once we decide on a syntax.
105 -- , ("foo:happy:exe.template-haskell test",
106 -- UserConstraint (UserQualified (UserQualExe (pn "foo") (pn "happy")) (pn "template-haskell"))
107 -- (PackagePropertyStanzas [TestStanzas]))
113 readUserConstraintTest
:: String -> UserConstraint
-> Assertion
114 readUserConstraintTest str uc
=
115 assertEqual
("Couldn't read constraint: '" ++ str
++ "'") expected actual
118 actual
= readUserConstraint str
120 parseUserConstraintTest
:: String -> UserConstraint
-> Assertion
121 parseUserConstraintTest str uc
=
122 assertEqual
("Couldn't parse constraint: '" ++ str
++ "'") expected actual
125 actual
= explicitEitherParsec parsec str
127 readUserConstraintsTest
:: String -> [UserConstraint
] -> Assertion
128 readUserConstraintsTest str ucs
=
129 assertEqual
("Couldn't read constraints: '" ++ str
++ "'") expected actual
132 actual
= explicitEitherParsec
(parsecCommaList parsec
) str